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; lightResult.xyz += gl_FrontMaterial.emission.xyz;
#endif #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; return lightResult;
} }

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

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

Loading…
Cancel
Save