Add per-pixel lighting code

move
scrawl 9 years ago
parent 1223bca3d4
commit 18e80d5627

@ -33,5 +33,9 @@ vec4 doLighting(vec3 viewPos, vec3 viewNormal, vec4 vertexColor)
lightResult.xyz += gl_FrontMaterial.emission.xyz;
#endif
// TODO: make clamp configurable
// the following produces fixed-function compatible lighting, w/o clamp arguably looks better
//lightResult = clamp(lightResult, vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0));
return lightResult;
}

@ -22,7 +22,17 @@ varying vec2 emissiveMapUV;
varying float depth;
#define PER_PIXEL_LIGHTING 0
#if !PER_PIXEL_LIGHTING
varying vec4 lighting;
#else
varying vec3 passViewPos;
varying vec3 passViewNormal;
varying vec4 passColour;
#endif
#include "lighting.glsl"
void main()
{
@ -40,7 +50,12 @@ void main()
gl_FragData[0].xyz *= texture2D(darkMap, darkMapUV).xyz;
#endif
#if !PER_PIXEL_LIGHTING
gl_FragData[0] *= lighting;
#else
gl_FragData[0] *= doLighting(passViewPos, passViewNormal, passColour);
#endif
#if @emissiveMap
gl_FragData[0].xyz += texture2D(emissiveMap, emissiveMapUV).xyz;

@ -18,7 +18,15 @@ varying vec2 emissiveMapUV;
varying float depth;
#define PER_PIXEL_LIGHTING 0
#if !PER_PIXEL_LIGHTING
varying vec4 lighting;
#else
varying vec3 passViewPos;
varying vec3 passViewNormal;
varying vec4 passColour;
#endif
#include "lighting.glsl"
@ -47,9 +55,11 @@ void main(void)
emissiveMapUV = (gl_TextureMatrix[@emissiveMapUV] * gl_MultiTexCoord@emissiveMapUV).xy;
#endif
#if !PER_PIXEL_LIGHTING
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color);
// TODO: make clamp configurable
// the following produces fixed-function compatible lighting, w/o clamp arguably looks better
//lighting = clamp(lighting, vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0));
#else
passViewPos = viewPos.xyz;
passViewNormal = viewNormal;
passColour = gl_Color;
#endif
}

Loading…
Cancel
Save