Jump to content
  • Advertisement
Alexander Nazarov

Applying a Shader to a sprites leads to strange things

Recommended Posts

In my game I have multiple sprites and I want to apply my shader to them. I do things by this sequence: Create Shader -> Create Material -> Add the shader to the Material -> Add the material to my sprite(s). But when I add my shader to the material, images get started looking like below. What I do wrong and which way is right?


I create Unlit shader and do not change nothing inside it.




Before applying shader


After applying shader


Share this post

Link to post
Share on other sites
Posted (edited)

So I just reproduced a version of your problem. Given this image (generated in paint.net):


And creating a sprite in unity and then assigning the unlit shader to material and assigning that material to a mesh I'm seeing this:


Now the problem seems to be the the unlit shader is marked as "Opaque", which means it renders mostly solid. The weird cutout you see is in the parts where the alpha is below a specific threshold (without going into details, this is then where the renderer just discards the pixels). 

The different colors you see in the transparent parts in your image are 'hidden' in the alpha channel of the images you have. If you have the source image you can verify this by upping the alpha for that layer, and they will then show.

If you were to want to see this:


Then you would just use a sprite and not assign an unlit shader. In general you should not be using an unlit shader with sprites.


I'm not sure what specific use you could have for wanting to override this shader.

Edited by deadc0deh

Share this post

Link to post
Share on other sites

Hi, @deadc0deh. Can you help me with some question about shaders?


I have written the simplest possible shader.

On the image below the fragment shader do nothing (it has no functionality).

It looks like this

fixed4 fragmentFunc(v2f IN) : SV_Target {
    float2 uv = IN.uv;
    float4 time = _Time;
    //uv *= 2;
    fixed4 pixColor = tex2D(_MainTexture, uv);
    return pixColor;





And this is the same sprite with the same shader, but with multiplied by 2 pixel position

fixed4 fragmentFunc(v2f IN) : SV_Target {
    float2 uv = IN.uv;
    float4 time = _Time;
    uv *= 2;
    fixed4 pixColor = tex2D(_MainTexture, uv);
    return pixColor;


Why this weird thing appears above the sprite. What should I do to avoid such things.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!