diff --git a/files/shaders/lighting.glsl b/files/shaders/lighting.glsl index 98490b8b8..f856bc6bd 100644 --- a/files/shaders/lighting.glsl +++ b/files/shaders/lighting.glsl @@ -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; } diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index 016cae13f..f3a9aa766 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -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; diff --git a/files/shaders/objects_vertex.glsl b/files/shaders/objects_vertex.glsl index c322f6853..7a6f0ca21 100644 --- a/files/shaders/objects_vertex.glsl +++ b/files/shaders/objects_vertex.glsl @@ -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 }