mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 12:39:53 +00:00
Merge branch 'discolighting' into 'master'
Consolidate shader lighting See merge request OpenMW/openmw!3660
This commit is contained in:
commit
fc5f917b1a
@ -61,34 +61,30 @@ void main()
|
|||||||
gl_FragData[0].a *= diffuseColor.a;
|
gl_FragData[0].a *= diffuseColor.a;
|
||||||
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
|
gl_FragData[0].a = alphaTest(gl_FragData[0].a, alphaRef);
|
||||||
|
|
||||||
|
vec3 specularColor = getSpecularColor().xyz;
|
||||||
#if @normalMap
|
#if @normalMap
|
||||||
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
vec4 normalTex = texture2D(normalMap, normalMapUV);
|
||||||
vec3 viewNormal = normalToView(normalTex.xyz * 2.0 - 1.0);
|
vec3 viewNormal = normalToView(normalTex.xyz * 2.0 - 1.0);
|
||||||
|
specularColor *= normalTex.a;
|
||||||
#else
|
#else
|
||||||
vec3 viewNormal = normalToView(normalize(passNormal));
|
vec3 viewNormal = normalToView(normalize(passNormal));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float shadowing = unshadowedLightRatio(linearDepth);
|
float shadowing = unshadowedLightRatio(linearDepth);
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight, specularLight;
|
||||||
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
|
doLighting(passViewPos, viewNormal, gl_FrontMaterial.shininess, shadowing, diffuseLight, ambientLight, specularLight);
|
||||||
|
vec3 diffuse = diffuseColor.xyz * diffuseLight;
|
||||||
|
vec3 ambient = getAmbientColor().xyz * ambientLight;
|
||||||
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
||||||
#if @emissiveMap
|
#if @emissiveMap
|
||||||
emission *= texture2D(emissiveMap, emissiveMapUV).xyz;
|
emission *= texture2D(emissiveMap, emissiveMapUV).xyz;
|
||||||
#endif
|
#endif
|
||||||
vec3 lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
|
vec3 lighting = diffuse + ambient + emission;
|
||||||
|
vec3 specular = specularColor * specularLight * specStrength;
|
||||||
|
|
||||||
clampLightingResult(lighting);
|
clampLightingResult(lighting);
|
||||||
|
|
||||||
gl_FragData[0].xyz *= lighting;
|
gl_FragData[0].xyz = gl_FragData[0].xyz * lighting + specular;
|
||||||
|
|
||||||
float shininess = gl_FrontMaterial.shininess;
|
|
||||||
vec3 matSpec = getSpecularColor().xyz * specStrength;
|
|
||||||
#if @normalMap
|
|
||||||
matSpec *= normalTex.a;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (matSpec != vec3(0.0))
|
|
||||||
gl_FragData[0].xyz += matSpec * getSpecular(viewNormal, passViewPos, shininess, shadowing);
|
|
||||||
|
|
||||||
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
|
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ void main()
|
|||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
||||||
#else
|
#else
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight, specularLight;
|
||||||
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
|
doLighting(passViewPos, viewNormal, gl_FrontMaterial.shininess, shadowing, diffuseLight, ambientLight, specularLight);
|
||||||
lighting = diffuseLight + ambientLight;
|
lighting = diffuseLight + ambientLight;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -170,8 +170,9 @@ void main(void)
|
|||||||
#if PER_PIXEL_LIGHTING
|
#if PER_PIXEL_LIGHTING
|
||||||
passViewPos = viewPos.xyz;
|
passViewPos = viewPos.xyz;
|
||||||
#else
|
#else
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight, specularLight;
|
||||||
doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting);
|
vec3 unusedShadowSpecular;
|
||||||
|
doLighting(viewPos.xyz, viewNormal, gl_FrontMaterial.shininess, diffuseLight, ambientLight, specularLight, shadowDiffuseLighting, unusedShadowSpecular);
|
||||||
passLighting = diffuseLight + ambientLight;
|
passLighting = diffuseLight + ambientLight;
|
||||||
clampLightingResult(passLighting);
|
clampLightingResult(passLighting);
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,15 +67,17 @@ uniform float near;
|
|||||||
uniform float far;
|
uniform float far;
|
||||||
uniform float alphaRef;
|
uniform float alphaRef;
|
||||||
|
|
||||||
#define PER_PIXEL_LIGHTING (@normalMap || @forcePPL)
|
#define PER_PIXEL_LIGHTING (@normalMap || @specularMap || @forcePPL)
|
||||||
|
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
centroid varying vec3 passLighting;
|
centroid varying vec3 passLighting;
|
||||||
|
centroid varying vec3 passSpecular;
|
||||||
centroid varying vec3 shadowDiffuseLighting;
|
centroid varying vec3 shadowDiffuseLighting;
|
||||||
|
centroid varying vec3 shadowSpecularLighting;
|
||||||
#else
|
#else
|
||||||
uniform float emissiveMult;
|
uniform float emissiveMult;
|
||||||
#endif
|
|
||||||
uniform float specStrength;
|
uniform float specStrength;
|
||||||
|
#endif
|
||||||
varying vec3 passViewPos;
|
varying vec3 passViewPos;
|
||||||
varying vec3 passNormal;
|
varying vec3 passNormal;
|
||||||
#if @normalMap || @diffuseParallax
|
#if @normalMap || @diffuseParallax
|
||||||
@ -200,19 +202,27 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
float shadowing = unshadowedLightRatio(-passViewPos.z);
|
float shadowing = unshadowedLightRatio(-passViewPos.z);
|
||||||
vec3 lighting;
|
vec3 lighting, specular;
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
||||||
|
specular = passSpecular + shadowSpecularLighting * shadowing;
|
||||||
#else
|
#else
|
||||||
vec3 diffuseLight, ambientLight;
|
#if @specularMap
|
||||||
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
|
vec4 specTex = texture2D(specularMap, specularMapUV);
|
||||||
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
float shininess = specTex.a * 255.0;
|
||||||
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
|
vec3 specularColor = specTex.xyz;
|
||||||
|
#else
|
||||||
|
float shininess = gl_FrontMaterial.shininess;
|
||||||
|
vec3 specularColor = getSpecularColor().xyz;
|
||||||
|
#endif
|
||||||
|
vec3 diffuseLight, ambientLight, specularLight;
|
||||||
|
doLighting(passViewPos, viewNormal, shininess, shadowing, diffuseLight, ambientLight, specularLight);
|
||||||
|
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz * emissiveMult;
|
||||||
|
specular = specularColor * specularLight * specStrength;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
clampLightingResult(lighting);
|
clampLightingResult(lighting);
|
||||||
|
gl_FragData[0].xyz = gl_FragData[0].xyz * lighting + specular;
|
||||||
gl_FragData[0].xyz *= lighting;
|
|
||||||
|
|
||||||
#if @envMap && !@preLightEnv
|
#if @envMap && !@preLightEnv
|
||||||
gl_FragData[0].xyz += envEffect;
|
gl_FragData[0].xyz += envEffect;
|
||||||
@ -222,21 +232,6 @@ void main()
|
|||||||
gl_FragData[0].xyz += texture2D(emissiveMap, emissiveMapUV).xyz;
|
gl_FragData[0].xyz += texture2D(emissiveMap, emissiveMapUV).xyz;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if @specularMap
|
|
||||||
vec4 specTex = texture2D(specularMap, specularMapUV);
|
|
||||||
float shininess = specTex.a * 255.0;
|
|
||||||
vec3 matSpec = specTex.xyz;
|
|
||||||
#else
|
|
||||||
float shininess = gl_FrontMaterial.shininess;
|
|
||||||
vec3 matSpec = getSpecularColor().xyz;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
matSpec *= specStrength;
|
|
||||||
if (matSpec != vec3(0.0))
|
|
||||||
{
|
|
||||||
gl_FragData[0].xyz += matSpec * getSpecular(viewNormal, passViewPos, shininess, shadowing);
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_FragData[0] = applyFogAtPos(gl_FragData[0], passViewPos, far);
|
gl_FragData[0] = applyFogAtPos(gl_FragData[0], passViewPos, far);
|
||||||
|
|
||||||
vec2 screenCoords = gl_FragCoord.xy / screenRes;
|
vec2 screenCoords = gl_FragCoord.xy / screenRes;
|
||||||
|
@ -49,12 +49,15 @@ varying vec2 specularMapUV;
|
|||||||
varying vec2 glossMapUV;
|
varying vec2 glossMapUV;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PER_PIXEL_LIGHTING (@normalMap || @forcePPL)
|
#define PER_PIXEL_LIGHTING (@normalMap || @specularMap || @forcePPL)
|
||||||
|
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
centroid varying vec3 passLighting;
|
centroid varying vec3 passLighting;
|
||||||
|
centroid varying vec3 passSpecular;
|
||||||
centroid varying vec3 shadowDiffuseLighting;
|
centroid varying vec3 shadowDiffuseLighting;
|
||||||
|
centroid varying vec3 shadowSpecularLighting;
|
||||||
uniform float emissiveMult;
|
uniform float emissiveMult;
|
||||||
|
uniform float specStrength;
|
||||||
#endif
|
#endif
|
||||||
varying vec3 passViewPos;
|
varying vec3 passViewPos;
|
||||||
varying vec3 passNormal;
|
varying vec3 passNormal;
|
||||||
@ -145,12 +148,13 @@ void main(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight, specularLight;
|
||||||
doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting);
|
doLighting(viewPos.xyz, viewNormal, gl_FrontMaterial.shininess, diffuseLight, ambientLight, specularLight, shadowDiffuseLighting, shadowSpecularLighting);
|
||||||
vec3 emission = getEmissionColor().xyz * emissiveMult;
|
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz * emissiveMult;
|
||||||
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + emission;
|
passSpecular = getSpecularColor().xyz * specularLight * specStrength;
|
||||||
clampLightingResult(passLighting);
|
clampLightingResult(passLighting);
|
||||||
shadowDiffuseLighting *= getDiffuseColor().xyz;
|
shadowDiffuseLighting *= getDiffuseColor().xyz;
|
||||||
|
shadowSpecularLighting *= getSpecularColor().xyz * specStrength;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (@shadows_enabled)
|
#if (@shadows_enabled)
|
||||||
|
@ -23,11 +23,13 @@ uniform sampler2D blendMap;
|
|||||||
varying float euclideanDepth;
|
varying float euclideanDepth;
|
||||||
varying float linearDepth;
|
varying float linearDepth;
|
||||||
|
|
||||||
#define PER_PIXEL_LIGHTING (@normalMap || @forcePPL)
|
#define PER_PIXEL_LIGHTING (@normalMap || @specularMap || @forcePPL)
|
||||||
|
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
centroid varying vec3 passLighting;
|
centroid varying vec3 passLighting;
|
||||||
|
centroid varying vec3 passSpecular;
|
||||||
centroid varying vec3 shadowDiffuseLighting;
|
centroid varying vec3 shadowDiffuseLighting;
|
||||||
|
centroid varying vec3 shadowSpecularLighting;
|
||||||
#endif
|
#endif
|
||||||
varying vec3 passViewPos;
|
varying vec3 passViewPos;
|
||||||
varying vec3 passNormal;
|
varying vec3 passNormal;
|
||||||
@ -67,31 +69,26 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
float shadowing = unshadowedLightRatio(linearDepth);
|
float shadowing = unshadowedLightRatio(linearDepth);
|
||||||
vec3 lighting;
|
vec3 lighting, specular;
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
lighting = passLighting + shadowDiffuseLighting * shadowing;
|
||||||
|
specular = passSpecular + shadowSpecularLighting * shadowing;
|
||||||
#else
|
#else
|
||||||
vec3 diffuseLight, ambientLight;
|
#if @specularMap
|
||||||
doLighting(passViewPos, viewNormal, shadowing, diffuseLight, ambientLight);
|
float shininess = 128.0; // TODO: make configurable
|
||||||
|
vec3 specularColor = vec3(diffuseTex.a);
|
||||||
|
#else
|
||||||
|
float shininess = gl_FrontMaterial.shininess;
|
||||||
|
vec3 specularColor = getSpecularColor().xyz;
|
||||||
|
#endif
|
||||||
|
vec3 diffuseLight, ambientLight, specularLight;
|
||||||
|
doLighting(passViewPos, viewNormal, shininess, shadowing, diffuseLight, ambientLight, specularLight);
|
||||||
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
lighting = diffuseColor.xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
||||||
|
specular = specularColor * specularLight;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
clampLightingResult(lighting);
|
clampLightingResult(lighting);
|
||||||
|
gl_FragData[0].xyz = gl_FragData[0].xyz * lighting + specular;
|
||||||
gl_FragData[0].xyz *= lighting;
|
|
||||||
|
|
||||||
#if @specularMap
|
|
||||||
float shininess = 128.0; // TODO: make configurable
|
|
||||||
vec3 matSpec = vec3(diffuseTex.a);
|
|
||||||
#else
|
|
||||||
float shininess = gl_FrontMaterial.shininess;
|
|
||||||
vec3 matSpec = getSpecularColor().xyz;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (matSpec != vec3(0.0))
|
|
||||||
{
|
|
||||||
gl_FragData[0].xyz += matSpec * getSpecular(viewNormal, passViewPos, shininess, shadowing);
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
|
gl_FragData[0] = applyFogAtDist(gl_FragData[0], euclideanDepth, linearDepth, far);
|
||||||
|
|
||||||
|
@ -13,11 +13,13 @@ varying vec2 uv;
|
|||||||
varying float euclideanDepth;
|
varying float euclideanDepth;
|
||||||
varying float linearDepth;
|
varying float linearDepth;
|
||||||
|
|
||||||
#define PER_PIXEL_LIGHTING (@normalMap || @forcePPL)
|
#define PER_PIXEL_LIGHTING (@normalMap || @specularMap || @forcePPL)
|
||||||
|
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
centroid varying vec3 passLighting;
|
centroid varying vec3 passLighting;
|
||||||
|
centroid varying vec3 passSpecular;
|
||||||
centroid varying vec3 shadowDiffuseLighting;
|
centroid varying vec3 shadowDiffuseLighting;
|
||||||
|
centroid varying vec3 shadowSpecularLighting;
|
||||||
#endif
|
#endif
|
||||||
varying vec3 passViewPos;
|
varying vec3 passViewPos;
|
||||||
varying vec3 passNormal;
|
varying vec3 passNormal;
|
||||||
@ -54,11 +56,13 @@ void main(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !PER_PIXEL_LIGHTING
|
#if !PER_PIXEL_LIGHTING
|
||||||
vec3 diffuseLight, ambientLight;
|
vec3 diffuseLight, ambientLight, specularLight;
|
||||||
doLighting(viewPos.xyz, viewNormal, diffuseLight, ambientLight, shadowDiffuseLighting);
|
doLighting(viewPos.xyz, viewNormal, gl_FrontMaterial.shininess, diffuseLight, ambientLight, specularLight, shadowDiffuseLighting, shadowSpecularLighting);
|
||||||
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
passLighting = getDiffuseColor().xyz * diffuseLight + getAmbientColor().xyz * ambientLight + getEmissionColor().xyz;
|
||||||
|
passSpecular = getSpecularColor().xyz * specularLight;
|
||||||
clampLightingResult(passLighting);
|
clampLightingResult(passLighting);
|
||||||
shadowDiffuseLighting *= getDiffuseColor().xyz;
|
shadowDiffuseLighting *= getDiffuseColor().xyz;
|
||||||
|
shadowSpecularLighting *= getSpecularColor().xyz;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uv = gl_MultiTexCoord0.xy;
|
uv = gl_MultiTexCoord0.xy;
|
||||||
|
@ -3,15 +3,13 @@
|
|||||||
|
|
||||||
#include "lighting_util.glsl"
|
#include "lighting_util.glsl"
|
||||||
|
|
||||||
void perLightSun(out vec3 diffuseOut, vec3 viewPos, vec3 viewNormal)
|
float calcLambert(vec3 viewNormal, vec3 lightDir, vec3 viewDir)
|
||||||
{
|
{
|
||||||
vec3 lightDir = normalize(lcalcPosition(0));
|
float lambert = dot(viewNormal, lightDir);
|
||||||
float lambert = dot(viewNormal.xyz, lightDir);
|
|
||||||
|
|
||||||
#ifndef GROUNDCOVER
|
#ifndef GROUNDCOVER
|
||||||
lambert = max(lambert, 0.0);
|
lambert = max(lambert, 0.0);
|
||||||
#else
|
#else
|
||||||
float eyeCosine = dot(normalize(viewPos), viewNormal.xyz);
|
float eyeCosine = dot(viewNormal, viewDir);
|
||||||
if (lambert < 0.0)
|
if (lambert < 0.0)
|
||||||
{
|
{
|
||||||
lambert = -lambert;
|
lambert = -lambert;
|
||||||
@ -19,75 +17,7 @@ void perLightSun(out vec3 diffuseOut, vec3 viewPos, vec3 viewNormal)
|
|||||||
}
|
}
|
||||||
lambert *= clamp(-8.0 * (1.0 - 0.3) * eyeCosine + 1.0, 0.3, 1.0);
|
lambert *= clamp(-8.0 * (1.0 - 0.3) * eyeCosine + 1.0, 0.3, 1.0);
|
||||||
#endif
|
#endif
|
||||||
|
return lambert;
|
||||||
diffuseOut = lcalcDiffuse(0).xyz * lambert;
|
|
||||||
}
|
|
||||||
|
|
||||||
void perLightPoint(out vec3 ambientOut, out vec3 diffuseOut, int lightIndex, vec3 viewPos, vec3 viewNormal)
|
|
||||||
{
|
|
||||||
vec3 lightPos = lcalcPosition(lightIndex) - viewPos;
|
|
||||||
float lightDistance = length(lightPos);
|
|
||||||
|
|
||||||
// cull non-FFP point lighting by radius, light is guaranteed to not fall outside this bound with our cutoff
|
|
||||||
#if !@lightingMethodFFP
|
|
||||||
float radius = lcalcRadius(lightIndex);
|
|
||||||
|
|
||||||
if (lightDistance > radius * 2.0)
|
|
||||||
{
|
|
||||||
ambientOut = vec3(0.0);
|
|
||||||
diffuseOut = vec3(0.0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lightPos = normalize(lightPos);
|
|
||||||
|
|
||||||
float illumination = lcalcIllumination(lightIndex, lightDistance);
|
|
||||||
ambientOut = lcalcAmbient(lightIndex) * illumination;
|
|
||||||
float lambert = dot(viewNormal.xyz, lightPos) * illumination;
|
|
||||||
|
|
||||||
#ifndef GROUNDCOVER
|
|
||||||
lambert = max(lambert, 0.0);
|
|
||||||
#else
|
|
||||||
float eyeCosine = dot(normalize(viewPos), viewNormal.xyz);
|
|
||||||
if (lambert < 0.0)
|
|
||||||
{
|
|
||||||
lambert = -lambert;
|
|
||||||
eyeCosine = -eyeCosine;
|
|
||||||
}
|
|
||||||
lambert *= clamp(-8.0 * (1.0 - 0.3) * eyeCosine + 1.0, 0.3, 1.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
diffuseOut = lcalcDiffuse(lightIndex) * lambert;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if PER_PIXEL_LIGHTING
|
|
||||||
void doLighting(vec3 viewPos, vec3 viewNormal, float shadowing, out vec3 diffuseLight, out vec3 ambientLight)
|
|
||||||
#else
|
|
||||||
void doLighting(vec3 viewPos, vec3 viewNormal, out vec3 diffuseLight, out vec3 ambientLight, out vec3 shadowDiffuse)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
vec3 ambientOut, diffuseOut;
|
|
||||||
|
|
||||||
perLightSun(diffuseOut, viewPos, viewNormal);
|
|
||||||
ambientLight = gl_LightModel.ambient.xyz;
|
|
||||||
#if PER_PIXEL_LIGHTING
|
|
||||||
diffuseLight = diffuseOut * shadowing;
|
|
||||||
#else
|
|
||||||
shadowDiffuse = diffuseOut;
|
|
||||||
diffuseLight = vec3(0.0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (int i = @startLight; i < @endLight; ++i)
|
|
||||||
{
|
|
||||||
#if @lightingMethodUBO
|
|
||||||
perLightPoint(ambientOut, diffuseOut, PointLightIndex[i], viewPos, viewNormal);
|
|
||||||
#else
|
|
||||||
perLightPoint(ambientOut, diffuseOut, i, viewPos, viewNormal);
|
|
||||||
#endif
|
|
||||||
ambientLight += ambientOut;
|
|
||||||
diffuseLight += diffuseOut;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float calcSpecIntensity(vec3 viewNormal, vec3 viewDir, float shininess, vec3 lightDir)
|
float calcSpecIntensity(vec3 viewNormal, vec3 viewDir, float shininess, vec3 lightDir)
|
||||||
@ -102,12 +32,28 @@ float calcSpecIntensity(vec3 viewNormal, vec3 viewDir, float shininess, vec3 lig
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 getSpecular(vec3 viewNormal, vec3 viewPos, float shininess, float shadowing)
|
#if PER_PIXEL_LIGHTING
|
||||||
|
void doLighting(vec3 viewPos, vec3 viewNormal, float shininess, float shadowing, out vec3 diffuseLight, out vec3 ambientLight, out vec3 specularLight)
|
||||||
|
#else
|
||||||
|
void doLighting(vec3 viewPos, vec3 viewNormal, float shininess, out vec3 diffuseLight, out vec3 ambientLight, out vec3 specularLight, out vec3 shadowDiffuse, out vec3 shadowSpecular)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
shininess = max(shininess, 1e-4);
|
|
||||||
vec3 viewDir = normalize(viewPos);
|
vec3 viewDir = normalize(viewPos);
|
||||||
vec3 specularLight = lcalcSpecular(0).xyz * calcSpecIntensity(viewNormal, viewDir, shininess, normalize(lcalcPosition(0)));
|
shininess = max(shininess, 1e-4);
|
||||||
|
|
||||||
|
vec3 sunDir = normalize(lcalcPosition(0));
|
||||||
|
diffuseLight = lcalcDiffuse(0) * calcLambert(viewNormal, sunDir, viewDir);
|
||||||
|
ambientLight = gl_LightModel.ambient.xyz;
|
||||||
|
specularLight = lcalcSpecular(0).xyz * calcSpecIntensity(viewNormal, viewDir, shininess, sunDir);
|
||||||
|
#if PER_PIXEL_LIGHTING
|
||||||
|
diffuseLight *= shadowing;
|
||||||
specularLight *= shadowing;
|
specularLight *= shadowing;
|
||||||
|
#else
|
||||||
|
shadowDiffuse = diffuseLight;
|
||||||
|
shadowSpecular = specularLight;
|
||||||
|
diffuseLight = vec3(0.0);
|
||||||
|
specularLight = vec3(0.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int i = @startLight; i < @endLight; ++i)
|
for (int i = @startLight; i < @endLight; ++i)
|
||||||
{
|
{
|
||||||
@ -116,21 +62,22 @@ vec3 getSpecular(vec3 viewNormal, vec3 viewPos, float shininess, float shadowing
|
|||||||
#else
|
#else
|
||||||
int lightIndex = i;
|
int lightIndex = i;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vec3 lightPos = lcalcPosition(lightIndex) - viewPos;
|
vec3 lightPos = lcalcPosition(lightIndex) - viewPos;
|
||||||
float lightDistance = length(lightPos);
|
float lightDistance = length(lightPos);
|
||||||
|
|
||||||
|
// cull non-FFP point lighting by radius, light is guaranteed to not fall outside this bound with our cutoff
|
||||||
#if !@lightingMethodFFP
|
#if !@lightingMethodFFP
|
||||||
if (lightDistance > lcalcRadius(lightIndex) * 2.0)
|
if (lightDistance > lcalcRadius(lightIndex) * 2.0)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float illumination = lcalcIllumination(lightIndex, lightDistance);
|
vec3 lightDir = lightPos / lightDistance;
|
||||||
float intensity = calcSpecIntensity(viewNormal, viewDir, shininess, normalize(lightPos));
|
|
||||||
specularLight += lcalcSpecular(lightIndex).xyz * intensity * illumination;
|
|
||||||
}
|
|
||||||
|
|
||||||
return specularLight;
|
float illumination = lcalcIllumination(lightIndex, lightDistance);
|
||||||
|
diffuseLight += lcalcDiffuse(lightIndex) * calcLambert(viewNormal, lightDir, viewDir) * illumination;
|
||||||
|
ambientLight += lcalcAmbient(lightIndex) * illumination;
|
||||||
|
specularLight += lcalcSpecular(lightIndex).xyz * calcSpecIntensity(viewNormal, viewDir, shininess, lightDir) * illumination;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user