* Fixed issue with spot light shader not taking into account alpha
* Reduced number of varyings by 2 in lighting shader git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7909 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
d8afde19cf
commit
7308cdfca6
@ -7,14 +7,16 @@ varying vec2 texCoord;
|
|||||||
varying vec2 texCoord2;
|
varying vec2 texCoord2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
varying vec4 AmbientSum;
|
varying vec3 AmbientSum;
|
||||||
varying vec4 DiffuseSum;
|
varying vec4 DiffuseSum;
|
||||||
varying vec4 SpecularSum;
|
varying vec3 SpecularSum;
|
||||||
|
|
||||||
#ifndef VERTEX_LIGHTING
|
#ifndef VERTEX_LIGHTING
|
||||||
varying vec3 vPosition;
|
varying vec3 vPosition;
|
||||||
varying vec3 vViewDir;
|
varying vec3 vViewDir;
|
||||||
varying vec4 vLightDir;
|
varying vec4 vLightDir;
|
||||||
|
#else
|
||||||
|
varying vec2 vertexLightValues;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DIFFUSEMAP
|
#ifdef DIFFUSEMAP
|
||||||
@ -128,7 +130,7 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w
|
|||||||
void main(){
|
void main(){
|
||||||
vec2 newTexCoord;
|
vec2 newTexCoord;
|
||||||
|
|
||||||
#if defined(PARALLAXMAP) || defined(NORMALMAP_PARALLAX)
|
#if (defined(PARALLAXMAP) || defined(NORMALMAP_PARALLAX)) && !defined(VERTEX_LIGHTING)
|
||||||
float h;
|
float h;
|
||||||
#ifdef PARALLAXMAP
|
#ifdef PARALLAXMAP
|
||||||
h = texture2D(m_ParallaxMap, texCoord).r;
|
h = texture2D(m_ParallaxMap, texCoord).r;
|
||||||
@ -149,22 +151,6 @@ void main(){
|
|||||||
#else
|
#else
|
||||||
vec4 diffuseColor = vec4(1.0);
|
vec4 diffuseColor = vec4(1.0);
|
||||||
#endif
|
#endif
|
||||||
#ifndef VERTEX_LIGHTING
|
|
||||||
float spotFallOff = 1.0;
|
|
||||||
if(spotVec.w!=0.0){
|
|
||||||
vec3 L=normalize(lightVec.xyz);
|
|
||||||
vec3 spotdir = normalize(spotVec.xyz);
|
|
||||||
float curAngleCos = dot(-L, spotdir);
|
|
||||||
float innerAngleCos = spotVec.w;
|
|
||||||
float outerAngleCos = lightVec.w;
|
|
||||||
float innerMinusOuter = innerAngleCos - outerAngleCos;
|
|
||||||
spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0);
|
|
||||||
if(spotFallOff<=0.0){
|
|
||||||
gl_FragColor = AmbientSum * diffuseColor;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
float alpha = DiffuseSum.a * diffuseColor.a;
|
float alpha = DiffuseSum.a * diffuseColor.a;
|
||||||
#ifdef ALPHAMAP
|
#ifdef ALPHAMAP
|
||||||
@ -174,6 +160,24 @@ void main(){
|
|||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef VERTEX_LIGHTING
|
||||||
|
float spotFallOff = 1.0;
|
||||||
|
if(spotVec.w != 0.0){
|
||||||
|
vec3 L = normalize(lightVec.xyz);
|
||||||
|
vec3 spotdir = normalize(spotVec.xyz);
|
||||||
|
float curAngleCos = dot(-L, spotdir);
|
||||||
|
float innerAngleCos = spotVec.w;
|
||||||
|
float outerAngleCos = lightVec.w;
|
||||||
|
float innerMinusOuter = innerAngleCos - outerAngleCos;
|
||||||
|
spotFallOff = clamp((curAngleCos - outerAngleCos) / innerMinusOuter, 0.0, 1.0);
|
||||||
|
if(spotFallOff <= 0.0){
|
||||||
|
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;
|
||||||
|
gl_FragColor.a = alpha;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ***********************
|
// ***********************
|
||||||
// Read from textures
|
// Read from textures
|
||||||
// ***********************
|
// ***********************
|
||||||
@ -209,15 +213,14 @@ void main(){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VERTEX_LIGHTING
|
#ifdef VERTEX_LIGHTING
|
||||||
vec2 light = vec2(AmbientSum.a, SpecularSum.a);
|
|
||||||
#ifdef COLORRAMP
|
#ifdef COLORRAMP
|
||||||
light.x = texture2D(m_ColorRamp, vec2(light.x, 0.0)).r;
|
light.x = texture2D(m_ColorRamp, vec2(vertexLightValues.x, 0.0)).r;
|
||||||
light.y = texture2D(m_ColorRamp, vec2(light.y, 0.0)).r;
|
light.y = texture2D(m_ColorRamp, vec2(vertexLightValues.y, 0.0)).r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_FragColor = AmbientSum * diffuseColor +
|
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
|
||||||
DiffuseSum * diffuseColor * light.x +
|
DiffuseSum.rgb * diffuseColor.rgb * vec3(vertexLightValues.x) +
|
||||||
SpecularSum * specularColor * light.y;
|
SpecularSum * specularColor.rgb * vec3(vertexLightValues.y);
|
||||||
#else
|
#else
|
||||||
vec4 lightDir = vLightDir;
|
vec4 lightDir = vLightDir;
|
||||||
lightDir.xyz = normalize(lightDir.xyz);
|
lightDir.xyz = normalize(lightDir.xyz);
|
||||||
@ -229,7 +232,7 @@ void main(){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Workaround, since it is not possible to modify varying variables
|
// Workaround, since it is not possible to modify varying variables
|
||||||
vec4 SpecularSum2 = SpecularSum;
|
vec4 SpecularSum2 = vec4(SpecularSum, 1.0);
|
||||||
#ifdef USE_REFLECTION
|
#ifdef USE_REFLECTION
|
||||||
vec4 refColor = Optics_GetEnvColor(m_EnvMap, refVec.xyz);
|
vec4 refColor = Optics_GetEnvColor(m_EnvMap, refVec.xyz);
|
||||||
|
|
||||||
@ -241,9 +244,9 @@ void main(){
|
|||||||
light.y = 1.0;
|
light.y = 1.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_FragColor = AmbientSum * diffuseColor +
|
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb +
|
||||||
DiffuseSum * diffuseColor * light.x +
|
DiffuseSum.rgb * diffuseColor.rgb * vec3(light.x) +
|
||||||
SpecularSum2 * specularColor * light.y;
|
SpecularSum2.rgb * specularColor.rgb * vec3(light.y);
|
||||||
#endif
|
#endif
|
||||||
gl_FragColor.a = alpha;
|
gl_FragColor.a = alpha;
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ varying vec2 texCoord;
|
|||||||
attribute vec2 inTexCoord2;
|
attribute vec2 inTexCoord2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
varying vec4 AmbientSum;
|
varying vec3 AmbientSum;
|
||||||
varying vec4 DiffuseSum;
|
varying vec4 DiffuseSum;
|
||||||
varying vec4 SpecularSum;
|
varying vec3 SpecularSum;
|
||||||
|
|
||||||
attribute vec3 inPosition;
|
attribute vec3 inPosition;
|
||||||
attribute vec2 inTexCoord;
|
attribute vec2 inTexCoord;
|
||||||
@ -46,6 +46,8 @@ varying vec4 spotVec;
|
|||||||
varying vec3 vPosition;
|
varying vec3 vPosition;
|
||||||
varying vec3 vViewDir;
|
varying vec3 vViewDir;
|
||||||
varying vec4 vLightDir;
|
varying vec4 vLightDir;
|
||||||
|
#else
|
||||||
|
varying vec2 vertexLightValues;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_REFLECTION
|
#ifdef USE_REFLECTION
|
||||||
@ -112,7 +114,7 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec4 w
|
|||||||
vec4 lightDir;
|
vec4 lightDir;
|
||||||
lightComputeDir(wvPos, g_LightColor, wvLightPos, lightDir);
|
lightComputeDir(wvPos, g_LightColor, wvLightPos, lightDir);
|
||||||
float spotFallOff = 1.0;
|
float spotFallOff = 1.0;
|
||||||
if(spotVec.w!=0.0){
|
if(spotVec.w != 0.0){
|
||||||
vec3 L=normalize(lightVec.xyz);
|
vec3 L=normalize(lightVec.xyz);
|
||||||
vec3 spotdir = normalize(spotVec.xyz);
|
vec3 spotdir = normalize(spotVec.xyz);
|
||||||
float curAngleCos = dot(-L, spotdir);
|
float curAngleCos = dot(-L, spotdir);
|
||||||
@ -174,31 +176,28 @@ void main(){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//computing spot direction in view space and unpacking spotlight cos
|
//computing spot direction in view space and unpacking spotlight cos
|
||||||
spotVec=(g_ViewMatrix *vec4(g_LightDirection.xyz,0.0) );
|
spotVec = (g_ViewMatrix * vec4(g_LightDirection.xyz, 0.0) );
|
||||||
spotVec.w=floor(g_LightDirection.w)*0.001;
|
spotVec.w = floor(g_LightDirection.w) * 0.001;
|
||||||
lightVec.w = fract(g_LightDirection.w);
|
lightVec.w = fract(g_LightDirection.w);
|
||||||
|
|
||||||
lightColor.w = 1.0;
|
lightColor.w = 1.0;
|
||||||
#ifdef MATERIAL_COLORS
|
#ifdef MATERIAL_COLORS
|
||||||
AmbientSum = m_Ambient * g_AmbientLightColor;
|
AmbientSum = (m_Ambient * g_AmbientLightColor).rgb;
|
||||||
DiffuseSum = m_Diffuse * lightColor;
|
DiffuseSum = m_Diffuse * lightColor;
|
||||||
SpecularSum = m_Specular * lightColor;
|
SpecularSum = (m_Specular * lightColor).rgb;
|
||||||
#else
|
#else
|
||||||
AmbientSum = vec4(0.2, 0.2, 0.2, 1.0) * g_AmbientLightColor; // Default: ambient color is dark gray
|
AmbientSum = vec3(0.2, 0.2, 0.2) * g_AmbientLightColor.rgb; // Default: ambient color is dark gray
|
||||||
DiffuseSum = lightColor;
|
DiffuseSum = lightColor;
|
||||||
SpecularSum = lightColor;
|
SpecularSum = lightColor.rgb;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VERTEX_COLOR
|
#ifdef VERTEX_COLOR
|
||||||
AmbientSum *= inColor;
|
AmbientSum *= inColor.rgb;
|
||||||
DiffuseSum *= inColor;
|
DiffuseSum *= inColor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VERTEX_LIGHTING
|
#ifdef VERTEX_LIGHTING
|
||||||
vec2 light = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
|
vertexLightValues = computeLighting(wvPosition, wvNormal, viewDir, wvLightPos);
|
||||||
|
|
||||||
AmbientSum.a = light.x;
|
|
||||||
SpecularSum.a = light.y;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_REFLECTION
|
#ifdef USE_REFLECTION
|
||||||
|
Loading…
x
Reference in New Issue
Block a user