- Home /
Finding object scale within a shader
I'm adding Standard Shader modified with "Cull Off" to a Sprite to achieve lighting, but of course the back face is not lit. I've seen some double pass shader solutions.
I'm wondering, is it possible instead of doing 2 passes one with "Cull Back" and one with "Cull Front", to know if your object is flipped (either SpriteRenderer flip toggle, or X scale toggle) and then choose, so unflipped uses "Cull Back" and flipped uses "Cull Front"?
Answer by phil_me_up · Feb 24, 2016 at 10:15 AM
You could pass a parameter into the the shader via MaterialPropertyBlocks to either indicate if it's flipped, or just pass in the scale. From that you can then modify your shader to do whatever is necessary.
http://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html
Thanks, I'm kind of a shader newb so how would I implement this in a shader?
I tried doing it like this but it's telling me it's incorrect syntax:
Shader "Standard TwoSided"
{
Properties
{
[Toggle] _Flipped("Flipped", Float) = 0
}
SubShader
{
Pass
{
_Flipped ? Cull Front : Cull Back
}
}
}
Also you wouldn't happen to know how to flip the lighting normals in Unity's Standard shader would you?