alpha channel from light color

 
Post new topic   Reply to topic    Unity Community Index // ShaderLab
View previous topic :: View next topic  
Author Message
yonek



Joined: 07 Jun 2009
Posts: 22
Location: Poland

PostPosted: Tue Nov 03, 2009 12:33 pm    Post subject: alpha channel from light color Reply with quote
I want to write a shader that uses alpha from vertex colors that are calculated from light.
All I could get is a shader that uses the alpha from diffuse color but is a solid color. I isn't interpolated to the ambient alpha which is 0.0

_________________
Infinite Dreams inc.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
andeeee
Forum Moderator


Joined: 19 Jul 2005
Posts: 1603
Location: Blackpool, United Kingdom

PostPosted: Tue Nov 03, 2009 8:26 pm    Post subject: Reply with quote
What effect do you want to achieve with this shader?
_________________
None of you understand... I'm not logged-in here with you - YOU'RE LOGGED-IN HERE WITH ME!
Back to top
View user's profile Send private message
yonek



Joined: 07 Jun 2009
Posts: 22
Location: Poland

PostPosted: Wed Nov 04, 2009 9:01 am    Post subject: Reply with quote
Imagine, a sphere with no texture and directional light in front of it facing towards the sphere. Now let the sphere have a vertex lit shader. I set the ambient color to (0,0,0,0) and diffuse color to (1,1,1,1).
This will result in a sphere that is white in the middle and getting darker toward the edges.
The color is nicely interpolated, as one can predict.
The problem is that the alpha isn't! it is 1.0 all over the sphere.
It seems that somewhere in the light formula vertices get alpha = 1.0.

_________________
Infinite Dreams inc.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dreamora



Joined: 05 Apr 2008
Posts: 6661
Location: Zürich, Switzerland

PostPosted: Wed Nov 04, 2009 9:24 am    Post subject: Reply with quote
lights don't have alpha so you would have to interpolate the alpha from RGB ( r + b + g / 3 )
_________________
Technologies: Unity Pro, iPhone Advanced
Site: GayaSoft & PatchLaunch Technology
My Blogs:My Development & Persistent Online Worlds
Back to top
View user's profile Send private message
yonek



Joined: 07 Jun 2009
Posts: 22
Location: Poland

PostPosted: Wed Nov 04, 2009 1:29 pm    Post subject: Reply with quote
Did I mentioned that this should be a iPhone shader ? Wink
_________________
Infinite Dreams inc.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Daniel Brauer



Joined: 11 Aug 2006
Posts: 1051
Location: GMA950

PostPosted: Wed Nov 04, 2009 4:02 pm    Post subject: Reply with quote
Indeed, fixed function vertex lighting always produces an alpha of 1.

And yes, you should mention if a shader is supposed to be for the iPhone. Most shaders can't be made to work on it (this one included).
Back to top
View user's profile Send private message MSN Messenger
yonek



Joined: 07 Jun 2009
Posts: 22
Location: Poland

PostPosted: Wed Nov 04, 2009 4:11 pm    Post subject: Reply with quote
That is not true. The diffuse light color alpha works! But still is constant for all vertices.
_________________
Infinite Dreams inc.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Daniel Brauer



Joined: 11 Aug 2006
Posts: 1051
Location: GMA950

PostPosted: Wed Nov 04, 2009 6:39 pm    Post subject: Reply with quote
yonek wrote:
That is not true. The diffuse light color alpha works! But still is constant for all vertices.

Can you explain what you mean, preferably with an example shader? I tried out a simple fixed function shader and tried to get it to respond to the light alpha value, and it always seemed to be one.
Back to top
View user's profile Send private message MSN Messenger
yonek



Joined: 07 Jun 2009
Posts: 22
Location: Poland

PostPosted: Thu Nov 05, 2009 9:01 am    Post subject: Reply with quote
Shader "VertexLitt" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass {
Material {
Diffuse [_Color]
}
Blend SrcAlpha OneMinusSrcAlpha
Lighting On
SetTexture [_MainTex] {
Combine texture * primary, primary
}
}
}
}


Now you can see that the Main Color affects alpha

_________________
Infinite Dreams inc.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Daniel Brauer



Joined: 11 Aug 2006
Posts: 1051
Location: GMA950

PostPosted: Thu Nov 05, 2009 2:32 pm    Post subject: Reply with quote
I see. I only tried changing the light alpha, which doesn't work. Unfortunately, all the other colours you put into the lighting equation will be uniform across the surface.
Back to top
View user's profile Send private message MSN Messenger
Post new topic   Reply to topic    Unity Community Index // ShaderLab All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum