Some questions about shaders

There are some things I don’t understand when writing shaders in unity (no particular shader, just in general).
(fragment shaders mostly I guess)

  • Why is it sometimes (often) so that I get a different result when using a float variable instead of using a hardcoded value.
    (eg: in fragment shader: return color*_Brightness; with _Brightness set to 1, is different from return color;)

  • And why do I often get errors like: Shader error in ‘Custom/AtmosphereOverlayShader’: D3D shader assembly failed with: (34): error X5204: Read of uninitialized component(*) in r2: r/x/0 *g/y/1 b/z/2 a/w/3
    when I can see nothing wrong, and it is sometimes fixed by writing things slightly different, but essentially the same. eg: doing color = color5; color2 = color23; color = color + color2; instead of color = color5+color23;

-This particular error (the one I posted above) I get when I do :
overlay *= colorLumin;
overlay = 0.5coloroverlay + (1.0-0.5)*color;
with color and overlay beeing float4’s and colorLumin a float
But I don’t get the error when I comment out either of those 2 lines.

Any help ?

(but please don’t ask what I’m trying to achieve in my shaders, because that’s besides the point and these things have happened in numerous occasions, I’m only trying to understand what’s going wrong.)

Edit:
I noticed I’m writing for shader model 2, switching to 3 in a shader I’m working on fixed an issue.
I don’t get why, I thought the difference was only the number of instructions allowed

what are shaders?

Is that a joke ?
you’re in the shaderlab forum, the forum for asking shader related questions

I’m not sure about the D3D assembly failures, but I’m curious about exactly what differences you’re seeing when you use constants rather than property values. Can you provide an example shader that does this?

Don’t post unrelated questions in forum threads. Go and read the manual and start your own thread for specific questions.

ok, this is weird, I switched to shader model 3, and it fixes all the issues.
using a variable instead of a constant (with the same value) now has the same result.
and the D3D assembly failures are gone now as well.

How could using shader model 2 cause all these problems ?

Daniel Brauer,
I actually simplified it in my post, the actual code now that has this effect is:

 overlay = _Opacity*color*overlay + (1.0-_Opacity)*color;
overlayLumin = (overlay.r+overlay.g+overlay.b)/3.0;
overlay *= (colorLumin/overlayLumin);
return overlay*_Brightning;

It’s in the fragment shader of an image effect (post effect), in shader model 2, if I have a constant instead of _Opacity, I get a different result.
I can post images of how it looks if you want

that wasn’t any joke i just don’t know about shaders because i didn’t used in my whole development that’s why i asked