|
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?
(comments are locked)
|
|
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. Good, I think attempting to change shader clearly rules out a shader problem if the problem persists.
Dec 15 '10 at 05:05 PM
Statement ♦♦
Those were my thoughts, plus it's actually clear what the shaders in my answer are doing and they are actually ignoring lighting like the op described, unlike their shader which still does lighting.
Dec 15 '10 at 05:40 PM
skovacs1
(comments are locked)
|
Short answer:
Long answer:
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. Thanks for the reply's guys. I feel that i'm on the right track. skovacs1, i changed my shader to yours and i'm still getting the green effect... Can anyone please take a look at this for me? http://gaborszauer.com/NewSprites.rar Statement, your second possibility as to what the problem is seems head on, but my ambient light is not green...
Dec 15 '10 at 05:55 PM
Gabriel 4
Do you have Unity Pro? Because the GL commands are for Unity Pro only.
Dec 15 '10 at 06:01 PM
Statement ♦♦
Yes, i'm using Unity Pro.
Dec 15 '10 at 06:08 PM
Gabriel 4
Did you check your console for any error messages at all? I am spammed with error "Material doesn't have a texture property '_MainTex' UnityEngine.Material:set_mainTexture(Texture)". It seems your shader has a property for a texture that isn't named _MainTex. Instead you call it _DiffuseMap. Either change the shader, or change the code to update _DiffuseMap instead of _MainTex.
Dec 15 '10 at 06:23 PM
Statement ♦♦
I put the Main script on an empty game object, and the KZSpriteCamera on the main camera. I just noticed the outdated readme file, please ignore the word file that is attached. I don't get any output error messages at all, this is what it looks like on my machine: http://imagefrog.net/show.php/132476_Untitled1.png
Dec 15 '10 at 06:33 PM
Gabriel 4
(comments are locked)
|
|
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! lol, so i deleted the newly made material and everything still works. I can no longer re-create the issue...
Dec 15 '10 at 06:43 PM
Gabriel 4
Well you have several errors. You're updating _Alpha (that doesn't exist) instead of _AlphaFade. You're updating _MainTex (that doesn't exist) instead of _DiffuseMap. You're also only using the first pass, but IIRC surface shaders create additional passes. You're using Texture which I'm not sure if the class you should use, use Texture2D. I fiddled around a bit and managed to get it pulsating but the texture doesn't show up so I'm not sure what is going on with that thing.
Dec 15 '10 at 06:49 PM
Statement ♦♦
If you set the variables on the material, it is bound to work since the inspector sets the correct variables. Your script does not. The error part I am not sure of, it might be a bad newline (mac/pc?). Clean your shader. Clean your code. Shader variables you're using from code should be called _Alpha and _MainTex. Make sure you do render with all passes. Finally, this solution seems overly complex (to my eyes, but I dont know your goals) but please try to finish it so you'll learn something out of it. :)
Dec 15 '10 at 06:54 PM
Statement ♦♦
Also, to add insult to the injury - dont post replys as answes. This is not how unityAnswers work. It's not a forum. :)
Dec 15 '10 at 06:55 PM
Statement ♦♦
(comments are locked)
|


