mirror of
https://github.com/overte-org/overte.git
synced 2025-08-16 08:11:59 +02:00
applying the shadowing improvment to the cascaceded path shader and cleaning the code
This commit is contained in:
parent
fe371730e3
commit
46ab4833be
3 changed files with 50 additions and 41 deletions
|
@ -45,15 +45,13 @@ void main(void) {
|
|||
// compute the view space position using the depth
|
||||
float z = near / (depthVal * depthScale - 1.0);
|
||||
vec4 position = vec4((depthTexCoordOffset + gl_TexCoord[0].st * depthTexCoordScale) * z, z, 0.0);
|
||||
|
||||
// get the normal from the map
|
||||
vec4 normal = normalVal;
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((normalVal.a >= 0.45) && (normalVal.a <= 0.55)) {
|
||||
normal.a = 1.0;
|
||||
normalVal.a = 0.0;
|
||||
gl_FragColor = vec4(diffuseVal.rgb * specularVal.rgb, 1.0);
|
||||
} else {
|
||||
vec3 normalizedNormal = normalize(normal.xyz * 2.0 - vec3(1.0));
|
||||
// get the normal from the map
|
||||
vec3 normalizedNormal = normalize(normalVal.xyz * 2.0 - vec3(1.0));
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position.xyz);
|
||||
|
@ -67,6 +65,6 @@ void main(void) {
|
|||
|
||||
// add specular contribution
|
||||
vec4 specularColor = specularVal;
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normal.a);
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normalVal.a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,29 +55,46 @@ void main(void) {
|
|||
float z = near / (depthVal * depthScale - 1.0);
|
||||
vec4 position = vec4((depthTexCoordOffset + gl_TexCoord[0].st * depthTexCoordScale) * z, z, 1.0);
|
||||
|
||||
// compute the index of the cascade to use and the corresponding texture coordinates
|
||||
int shadowIndex = int(dot(step(vec3(position.z), shadowDistances), vec3(1.0, 1.0, 1.0)));
|
||||
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[shadowIndex], position), dot(gl_EyePlaneT[shadowIndex], position),
|
||||
dot(gl_EyePlaneR[shadowIndex], position));
|
||||
|
||||
// evaluate the shadow test but only relevant for light facing fragments
|
||||
float shadowAttenuation = (0.25 *
|
||||
(shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, shadowScale, 0.0)).r));
|
||||
|
||||
// get the normal from the map
|
||||
vec4 normal = normalVal;
|
||||
vec3 normalizedNormal = normalize(normalVal.xyz * 2.0 - vec3(1.0));
|
||||
|
||||
// how much this fragment faces the light direction
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position.xyz);
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((normalVal.a >= 0.45) && (normalVal.a <= 0.55)) {
|
||||
normal.a = 1.0;
|
||||
normalVal.a = 0.0;
|
||||
gl_FragColor = vec4(diffuseVal.rgb * specularVal.rgb, 1.0);
|
||||
|
||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
||||
// it should be just 0, but we have innacurracy so we need to overshoot
|
||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuse);
|
||||
|
||||
// evaluate the shadow test but only relevant for light facing fragments
|
||||
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
||||
|
||||
// diffuse light is the lightmap dimmed by shadow
|
||||
vec3 diffuseLight = lightAttenuation * specularVal.rgb;
|
||||
// ambient is a tiny percentage of the lightmap and only when in the shadow
|
||||
vec3 ambientLight = (1 - lightAttenuation) * 0.5 * specularVal.rgb;
|
||||
|
||||
gl_FragColor = vec4(diffuseVal.rgb * (ambientLight + diffuseLight), 1.0);
|
||||
} else {
|
||||
|
||||
// compute the index of the cascade to use and the corresponding texture coordinates
|
||||
int shadowIndex = int(dot(step(vec3(position.z), shadowDistances), vec3(1.0, 1.0, 1.0)));
|
||||
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[shadowIndex], position), dot(gl_EyePlaneT[shadowIndex], position),
|
||||
dot(gl_EyePlaneR[shadowIndex], position));
|
||||
|
||||
// get the normal from the map
|
||||
vec3 normalizedNormal = normalize(normal.xyz * 2.0 - vec3(1.0));
|
||||
|
||||
|
||||
// average values from the shadow map
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position.xyz);
|
||||
float facingLight = step(0.0, diffuse) * 0.25 *
|
||||
(shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(-shadowScale, shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, -shadowScale, 0.0)).r +
|
||||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, shadowScale, 0.0)).r);
|
||||
float facingLight = step(0.0, diffuse) * shadowAttenuation;
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
vec3 baseColor = diffuseVal.rgb * (gl_FrontLightModelProduct.sceneColor.rgb +
|
||||
|
@ -89,6 +106,6 @@ void main(void) {
|
|||
|
||||
// add specular contribution
|
||||
vec4 specularColor = specularVal;
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normal.a);
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normalVal.a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,21 +63,19 @@ void main(void) {
|
|||
shadow2D(shadowMap, shadowTexCoord + vec3(shadowScale, shadowScale, 0.0)).r));
|
||||
|
||||
// get the normal from the map
|
||||
vec4 normal = normalVal;
|
||||
vec3 normalizedNormal = normalize(normalVal.xyz * 2.0 - vec3(1.0));
|
||||
|
||||
// how much this fragment faces the light direction
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position.xyz);
|
||||
|
||||
// Light mapped or not ?
|
||||
if ((normalVal.a >= 0.45) && (normalVal.a <= 0.55)) {
|
||||
normal.a = 1.0;
|
||||
normalVal.a = 0.0;
|
||||
|
||||
// get the normal from the map
|
||||
vec3 normalizedNormal = normalize(normal.xyz * 2.0 - vec3(1.0));
|
||||
|
||||
// how much this fragment faces the light direction
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position.xyz);
|
||||
|
||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
||||
// it should be just 0, be we have innacurracy so we need to overshoot
|
||||
const float PERPENDICULAR_THREASHOLD = -0.005;
|
||||
float facingLight = step(PERPENDICULAR_THREASHOLD, diffuse);
|
||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuse);
|
||||
|
||||
// evaluate the shadow test but only relevant for light facing fragments
|
||||
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
||||
|
@ -89,11 +87,7 @@ void main(void) {
|
|||
|
||||
gl_FragColor = vec4(diffuseVal.rgb * (ambientLight + diffuseLight), 1.0);
|
||||
} else {
|
||||
// get the normal from the map
|
||||
vec3 normalizedNormal = normalize(normal.xyz * 2.0 - vec3(1.0));
|
||||
|
||||
// average values from the shadow map
|
||||
float diffuse = dot(normalizedNormal, gl_LightSource[0].position.xyz);
|
||||
float facingLight = step(0.0, diffuse) * shadowAttenuation;
|
||||
|
||||
// compute the base color based on OpenGL lighting model
|
||||
|
@ -106,6 +100,6 @@ void main(void) {
|
|||
|
||||
// add specular contribution
|
||||
vec4 specularColor = specularVal;
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normal.a);
|
||||
gl_FragColor = vec4(baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb, normalVal.a);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue