Quantcast
Channel: Questions in topic: "hlsl"
Viewing all articles
Browse latest Browse all 206

regarding Shader Optimization

$
0
0
I have a shader with 3 seperate effects on it. 2 of the effects are mapped using textures (named "_TeamTex" and "_MuzzleTex"). If the effects shouldn't trigger, the base texture _MainTex should be used instead, with the addition of lighting. Here's the complete fragment code: fixed4 frag (v2f i) : SV_Target { const float3 team_mask = tex2D(_TeamTex, i.uv); float muzzle_mask = tex2D(_MuzzleTex, i.uv); if(muzzle_mask.x > 0 && i.uv.x > (1 -_MuzzlePercent)) { const float3 muzzle_color = _MuzzleColor * muzzle_mask; float3 color = muzzle_color * _Brightness; return fixed4(color.rgb,1); } if(team_mask.x > 0) { const float3 team_color = _TeamColor * team_mask; float3 color = team_color * _Brightness; return fixed4(color.rgb,1); } const float3 normal = i.normal; const float3 light = _WorldSpaceLightPos0.xyz; const float lambert_light = saturate(dot(normal,light)); const float4 texture_color = tex2D(_MainTex, i.uv); const float3 lit_texture_color = texture_color * (lambert_light + _MinimalSaturation) * _LightColor0; return fixed4(lit_texture_color.rgb,1); } My question is - Do you think it is worth it to use if statements to avoid calculating unnecessary data, or should I have calculated all 3 possible results and then used "Step" and "Clip" to choose between them in order to choose the correct result? Which path is more efficient? ![alt text][1] [1]: /storage/temp/185434-screenshot-2.png

Viewing all articles
Browse latest Browse all 206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>