I am having an issue with a shader.
I want to add a texture property to an existing shader to use for emission.
I declare it as follows:
_EmissionTexture (" Emission Texture (RGB)", 2D) = "white"
I declare it inside the Properties{} area
I later use it like this:
outSurfaceData.emission = SAMPLE_TEXTURE2D(_EmissionTexture, sampler_MaskMap, uv);
However, I get an error claiming that it is an undeclared identifier, the line of the error is the code where I use it.
I do see the field inside the inspector in Unity.
It does show the field itself and the texture.
I can also add a texture into it.
But the shader does not work.
Any help or ideas are appreciated.
You need to declare any material property within the shader code itself. If you’re using the SAMPLE_TEXTURE2D()
macro to sample the texture, then this is a shader for the post processing stack or URP, and presumably _MaskMap
is also using the same SAMPLE_TEXTURE2D()
macro. If you look in the code you should see a line like this:
TEXTURE2D_PARAM(_MaskMap, sampler_MaskMap);
That’s declaring the texture and the sampler. You could declare your new texture the same way, though since you’re reusing the existing sampler, you would probably want to declare it like this:
TEXTURE2D(_EmissionTexture);
Note, those lines need to exist inside the HLSLPROGRAM
block, but outside of a function.
If you’re not writing this for the URP or post processing stack, then that line will likely error as well as those macros don’t exist for you. In which case look at how the _MaskMap
is declared and sampled.