P
P
PhilMcLaren2014-11-07 09:31:31
Shaders
PhilMcLaren, 2014-11-07 09:31:31

What can be the differences in the work of the pixel shader in the web player compared to the editor?

The shader creates a glow effect on the sprite, effectively creating a copy of the texture filled with the selected color. The created copy is placed behind the original sprite, thus getting a "highlight" along the contour of the opaque part of the texture. It works fine in the editor, but in the build for the web player, the shader reads the alpha channel differently and fills the entire texture area.
Looks in the editor:
4641280fc9bd42dab74f1482af72f711.png
Looks in the web player:
98581ec676bf45448145ce795027bcaa.png
The most mentioned problem with shaders in the web player is the lack of a shader file in the build when using Shader.Find, but this is definitely not my case, the shader in the player works. Although, just in case, I already put it in a serializable field, nothing has changed.
There is only one pass in the shader.
The dog is buried somewhere here:

half4 frag (v2f i) : COLOR
      {
        float blurAmount = _Radius * 0.0275;

        half4 sum;
                
        float a=0;
                
        for (float w = -4; w < 5; w ++)
        {
          for (float h = -4; h < 5; h ++)
          {		
              float4 buv = float4(i.uv.x + w * blurAmount, i.uv.y + h * blurAmount, 0, 0);
              half4 tex = tex2Dlod(_MainTex, buv) * (0.025 * (5 - abs(float(h)) + 1));
              
              if (buv.x > 0 && buv.x < 1 && buv.y > 0 && buv.y < 1)
              {
                sum += tex;
                a += tex.a / 4;
              }
          }
        }

        sum.rgb = lerp(_Color, _SecondColor, a);

        sum.a=_Color.a * a * _Transparency;
        
        return sum;
      }

Thanks for paying attention

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2014-11-07
@PhilMcLaren

I read that there are problems with tex2Dlod that are solved by adding
and / or
#pragma glsl

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question