Hello. In the vert function, I want to calculate the emission value and pass it to frag. To do this, I declared the emissionDelta variable in the v2f structure and after that my shader broke. How can I do it right?
You need to define which register that data will be bound to, notice the other variables in the struct have : SOMETHING;
on the right?
The TEXCOORD# channels are the common ones to bind to for arbitrary data, of which there are 4 or 8 (depending on target platform/shader level).
So in this case you’d want float emissionDelta : TEXCOORD2;
to use the second texcoord register. (Because UNITY_FOG_COORDS(1)
is already saying to use TEXCOORD1 for its own data)
TEXCOORD#
are also where UV channels are stored. So if you had data in the third UV channel of your mesh, then TEXCOORD2
would be containing that data in the buffer that’s passed to the vertex program if you defined it in that first buffer.
You’re also probably getting a warning like “shader is not supported on this GPU”. And if you look at your shader you’ll find Unity has “helpfully” added this to your shader without noting it in the log anywhere.
// Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members test)
#pragma exclude_renderers d3d11
That got added because you didn’t have a semantic defined (what those all caps things are called), and the shader got disabled by Unity rather than logging an error. You’ll need to remove that too.