SPLighting: vertex lighting fixes

- remove useless varyings
 - fix alpha from diffuse color
experimental
Kirill Vainer 10 years ago
parent 886bbc08b0
commit 6760771b20
  1. 12
      jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag
  2. 18
      jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert

@ -17,10 +17,7 @@ varying vec3 SpecularSum;
#ifndef VERTEX_LIGHTING
uniform mat4 g_ViewMatrix;
uniform vec4 g_LightData[NB_LIGHTS];
varying vec3 vPos;
#else
varying vec3 specularAccum;
varying vec4 diffuseAccum;
varying vec3 vPos;
#endif
#ifdef DIFFUSEMAP
@ -167,10 +164,9 @@ void main(){
#endif
#ifdef VERTEX_LIGHTING
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb
+diffuseAccum.rgb *diffuseColor.rgb
+specularAccum.rgb * specularColor.rgb;
gl_FragColor.a=1.0;
gl_FragColor.rgb = AmbientSum.rgb * diffuseColor.rgb
+ DiffuseSum.rgb * diffuseColor.rgb
+ SpecularSum.rgb * specularColor.rgb;
#else
int i = 0;

@ -43,8 +43,6 @@ attribute vec3 inNormal;
varying vec3 vBinormal;
#endif
#else
varying vec3 specularAccum;
varying vec4 diffuseAccum;
#ifdef COLORRAMP
uniform sampler2D m_ColorRamp;
#endif
@ -131,14 +129,13 @@ void main(){
#endif
#ifdef VERTEX_LIGHTING
int i = 0;
diffuseAccum = vec4(0.0);
specularAccum = vec3(0.0);
vec3 diffuseAccum = vec3(0.0);
vec3 specularAccum = vec3(0.0);
vec4 diffuseColor;
vec3 specularColor;
for (int i =0;i < NB_LIGHTS; i+=3){
vec4 lightColor = g_LightData[i];
vec4 lightData1 = g_LightData[i+1];
DiffuseSum = vec4(1.0);
#ifdef MATERIAL_COLORS
diffuseColor = m_Diffuse * vec4(lightColor.rgb, 1.0);
specularColor = m_Specular.rgb * lightColor.rgb;
@ -166,13 +163,16 @@ void main(){
vec2 light = computeLighting(wvNormal, viewDir, lightDir.xyz, lightDir.w * spotFallOff, m_Shininess);
#ifdef COLORRAMP
diffuseAccum.rgb += texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb * diffuseColor.rgb;
specularAccum.rgb += texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb * specularColor;
diffuseAccum += texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb * diffuseColor.rgb;
specularAccum += texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb * specularColor;
#else
diffuseAccum.rgb += light.x * diffuseColor.rgb;
specularAccum.rgb += light.y * specularColor;
diffuseAccum += light.x * diffuseColor.rgb;
specularAccum += light.y * specularColor;
#endif
}
DiffuseSum.rgb *= diffuseAccum.rgb;
SpecularSum.rgb *= specularAccum.rgb;
#endif

Loading…
Cancel
Save