Improve arm_physics guards

This commit is contained in:
Lubos Lenco
2022-02-23 18:32:50 +01:00
parent 05240497a9
commit c84cb48fa2
2 changed files with 22 additions and 16 deletions
+1 -16
View File
@@ -318,22 +318,7 @@ class MakePaint {
frag.write('if (opacity == 0.0) discard;');
if (Context.tool == ToolParticle) { // Particle mask
if (Context.particlePhysics) {
#if arm_physics
vert.add_out('vec4 wpos');
vert.add_uniform('mat4 W', '_worldMatrix');
vert.write_attrib('wpos = mul(vec4(pos.xyz, 1.0), W);');
frag.add_uniform('vec3 particleHit', '_particleHit');
#end
}
else {
frag.add_uniform('sampler2D texparticle', '_texparticle');
#if (kha_direct3d11 || kha_direct3d12 || kha_metal || kha_vulkan)
frag.write('float str = textureLod(texparticle, sp.xy, 0.0).r;');
#else
frag.write('float str = textureLod(texparticle, vec2(sp.x, (1.0 - sp.y)), 0.0).r;');
#end
}
MakeParticle.mask(vert, frag);
}
else { // Brush cursor mask
frag.write('float str = clamp((brushRadius - dist) * brushHardness * 400.0, 0.0, 1.0) * opacity;');
+21
View File
@@ -89,4 +89,25 @@ class MakeParticle {
return con_part;
}
public static function mask(vert: NodeShader, frag: NodeShader) {
#if arm_physics
if (Context.particlePhysics) {
vert.add_out('vec4 wpos');
vert.add_uniform('mat4 W', '_worldMatrix');
vert.write_attrib('wpos = mul(vec4(pos.xyz, 1.0), W);');
frag.add_uniform('vec3 particleHit', '_particleHit');
frag.write('float str = clamp(1.0 - distance(particleHit, wpos.xyz) * 2.0, 0.0, 1.0);');
frag.write('if (particleHit.x == 0.0 && particleHit.y == 0.0 && particleHit.z == 0.0) str = 0.0;');
return;
}
#end
frag.add_uniform('sampler2D texparticle', '_texparticle');
#if (kha_direct3d11 || kha_direct3d12 || kha_metal || kha_vulkan)
frag.write('float str = textureLod(texparticle, sp.xy, 0.0).r;');
#else
frag.write('float str = textureLod(texparticle, vec2(sp.x, (1.0 - sp.y)), 0.0).r;');
#end
}
}