I’ve been trying to use a reflection vector to sample a 2d texture for cheapo reflections.
I tried getting the necessary vector by reading the related docs but ran into rather
confusing errors:
When a variable is not used in calculations related to output, the compiler usually completely removes (or perhaps ignores) the code that created and manipulated the variable. So you can’t be sure that the error is caused in the code that uses the reflection vector, with the test you mentioned. If you output the vector directly as color, you might get more clarity about what causes the error.
If I use only finalAlbedo or only finalReflection in the last line then everything is fine. As soon as both of
them are referenced, the errors are back:
That’s not all that strange.
The error you were getting refers to the struct created by the surface shader, based on your input struct and I believe some other things too. (Add #pragma debug below #pragma target 3.0, and open the compiled shader, to see what happens). That struct is used to move data from vertex to fragment shader, using Semantics (e.g.: TEXCOORD0, POSITION, and others). There is only a limited number of these semantics. So when you removed sWorldNormal, one of these was freed up, and the shader no longer exceeded the limit.
Thank you for the explanation, it makes sense now. So I guess if I run out semantics
then I should start computing stuff in the fragment shader. In this case
Reflect(viewDir, sWorldNormal) or something like that.