| View previous topic :: View next topic |
yonek
Joined: 07 Jun 2009 Posts: 22 Location: Poland
|
Posted: Tue Nov 03, 2009 12:33 pm Post subject: alpha channel from light color |
|
|
|
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 |
|
|
andeeee Forum Moderator

Joined: 19 Jul 2005 Posts: 1603 Location: Blackpool, United Kingdom
|
Posted: Tue Nov 03, 2009 8:26 pm Post subject: |
|
|
|
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 |
|
|
yonek
Joined: 07 Jun 2009 Posts: 22 Location: Poland
|
Posted: Wed Nov 04, 2009 9:01 am Post subject: |
|
|
|
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 |
|
|
dreamora
Joined: 05 Apr 2008 Posts: 6664 Location: Zürich, Switzerland
|
|
| Back to top |
|
|
yonek
Joined: 07 Jun 2009 Posts: 22 Location: Poland
|
Posted: Wed Nov 04, 2009 1:29 pm Post subject: |
|
|
|
Did I mentioned that this should be a iPhone shader ?  _________________ Infinite Dreams inc. |
|
| Back to top |
|
|
Daniel Brauer
Joined: 11 Aug 2006 Posts: 1051 Location: GMA950
|
Posted: Wed Nov 04, 2009 4:02 pm Post subject: |
|
|
|
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 |
|
|
yonek
Joined: 07 Jun 2009 Posts: 22 Location: Poland
|
Posted: Wed Nov 04, 2009 4:11 pm Post subject: |
|
|
|
That is not true. The diffuse light color alpha works! But still is constant for all vertices. _________________ Infinite Dreams inc. |
|
| Back to top |
|
|
Daniel Brauer
Joined: 11 Aug 2006 Posts: 1051 Location: GMA950
|
Posted: Wed Nov 04, 2009 6:39 pm Post subject: |
|
|
|
| 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 |
|
|
yonek
Joined: 07 Jun 2009 Posts: 22 Location: Poland
|
Posted: Thu Nov 05, 2009 9:01 am Post subject: |
|
|
|
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 |
|
|
Daniel Brauer
Joined: 11 Aug 2006 Posts: 1051 Location: GMA950
|
Posted: Thu Nov 05, 2009 2:32 pm Post subject: |
|
|
|
| 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 |
|
|