Shader preview in Inspector does not match Game or Scene view

I’m not sure if there’s a Unity word for it, but you know the preview thumbnail for shaders in the Inspector? In the top-left:

I have a shader that clips the sprite’s opacity based on this Blink slider. It works as expected in the shader preview, but not in-game or in the Scene view. The effect happens much more quickly in-game, like within a range of 0.85-1.0 instead of 0.0-1.0.

How does the inspector view differ from the scene/game views? It is strange that the effect still works in the game, and that only the math is wrong.

The relevant part of the surf shader is just

float blinkPos = myInput.uv_MainTex.g - _Blink;
clip(blinkPos);

If this is for a sprite, the image shown in the preview is likely using the original sprite image as is, where as the in game view is using the sprite atlas. That means the UV position is some random location within an atlas, and not the 0 to 1 range you’re seeing in the preview.

1 Like

Ohhh. You’re right, thanks. In my case it’s not the Sprite Atlas, but rather a sprite sheet. Same end result though. Is there a way to work around this, or is it best practice to just not use sprite sheets if you’re writing shaders that depend on UVs?

I don’t really do 2D stuff, so I don’t know the solution. I’ve seen a couple of threads on the topic here on the forums you can try searching for.