I'm trying to write a simple diffuse shader that ignores lighting and ztesting and turns off culling. Additionally it takes in a float that specifyes the alpha value of what to draw. Here is what i have so far:
This works to an extent. My issue is when the script runs everything is saturated to green :( Can anyone help me out?
asked Dec 15 '10 at 04:31 PM
What you describe is a Transparent/Unlit shader like this:
This won't ignore ambient lighting. It's almost like you want a to customize the standard Transparent/Cut-off/Soft-Edge Unlit. That would look something like:
Nothing in your shader will result in over-saturated greens so the problem must lie elsewhere.
Cube using a material with the original shader posted, with standard assets "glass" texture and AlphaFade value of 1.0f, run in the editor.
I don't know your script (or do you mean your shader?), what texture you're using nor your alpha range but I just tried this with some random texture and fed alpha random values and I saw no green saturation. I don't know what you're talking about. I can't see any obvious errors. How can I reproduce your green saturated state?
A rule of thumb though when colors go wild, is to use saturate() in places such as function returns and parameter passing. If intermediate colors have other color ranges than 0 to 1, often errors can emerge. Make sure all your values are within expected ranges with saturate or clamp.
A possibility that struck me is that your ambient color in Render Settings is at bright green. I tested this and the result changed to behave like this:
Here, strong green ambient is applied to the scene.
Another possibility is that you are creating render/textures improperly. If you know you are using rendertextures or creating textures manually, you might want to suspect that code doing something fishy.
FML... I right clicked on the shader and made a material out of it. Now everything works as it should... I guess i don't understand how to create a material trough code as well as i tought.
Another odd issue is if i try to convert the shader source into a string and make a material that way i get a "Error in [SHADER] on line1" error....
I'm confused, but something is working. Thanks for all the help guys!
answered Dec 15 '10 at 06:38 PM