I'm making a Shadergraph to show a ripple effect around an island. I've made a simple setup where I take the outline of the island, slowly grow it, and fade it out, hooked up to a Fraction over Time to repeat it. It shows perfectly fine in the ShaderGraph preview and the Material preview. However, when I attach it to a sprite in my Scene, nothing happens. I've played around with thickness of the ripple, time, size of the sprite and order in layer, but for some reason it just doesn't show in Scene view or Play Mode.
Does anyone know why this could be happening? See screenshots for the shadergraph, material and sprite settings.
#Sprite Lit Shadergraph with working preview doesn't show in-game
1 messages · Page 1 of 1 (latest)
Have you set your shader to be a sprite shader?
Do you mean under Graph Inspector - Material? Yes, that's set to Sprite Lit
Is sprite field set to the default Square sprite intended? The SpriteRenderer will pass that sprite texture into the _MainTex reference, overriding what is set on the material.
The Replace Color node usage here is quite specific to that island sprite and likely won't work as intended for others. (And a bit of a strange setup. If the sprite has transparency/alpha channel you should just be able to use the A output from the texture sample)
(You also might end up drawing outside the mesh generated by the sprite. Under the texture asset you can change the type to Full Rect or edit the "outline" to adjust that mesh if needed)
.
Another potential issue I can see is that a Vector (3) is connected to the Alpha (1) port in the master stack. That will cause it to use the first/red channel. Currently okay but if you were to change the colour to green/blue/etc it would fade/disappear. Multiplying by the color property will also darken the colours at the edge.
Instead I'd recommend connecting the color property directly to the Base Color and keep the other calculations as Float (1) to use in the Alpha port.
Thanks, the Square sprite was the issue. I changed it to the correct one and it immediately works!
I'll take your other comments into account as well to clean up my graph a bit. Especially the proper assignment of the alpha channel is great advice, thanks!
In the screenshot you can see that the Sample Texture 2D Node in the top right has a weird outline that's not on the normal sprite. Do you know how to fix this? I've fiddled around with it and Googled, but I don't really see what could cause this
Of course just when you ask you discover the problem 😅
If I set "Alpha is Transparency" to disabled in the Sprite, it works normally
Indeed, that setting makes colours dilate into transparent areas. But it's intentional - it helps avoids the colour darkening along the alpha edge. https://www.cyanilux.com/faq/#sg-stretched-texture-preview
It doesn't affect the alpha channel though, so shouldn't be a problem if using the A output on the sample.
Thanks for the documentation link, interesting!