mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 16:14:35 +02:00
Improving the shadow effect with lightmaps
This commit is contained in:
parent
02949dbc5a
commit
ef7c002237
2 changed files with 28 additions and 4 deletions
|
@ -2907,7 +2907,7 @@ void Application::updateShadowMap() {
|
||||||
|
|
||||||
{
|
{
|
||||||
PerformanceTimer perfTimer("entities");
|
PerformanceTimer perfTimer("entities");
|
||||||
_entities.render(RenderArgs::SHADOW_RENDER_MODE);
|
// _entities.render(RenderArgs::SHADOW_RENDER_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// render JS/scriptable overlays
|
// render JS/scriptable overlays
|
||||||
|
|
|
@ -51,15 +51,39 @@ void main(void) {
|
||||||
// compute the view space position using the depth
|
// compute the view space position using the depth
|
||||||
float z = near / (depthVal * depthScale - 1.0);
|
float z = near / (depthVal * depthScale - 1.0);
|
||||||
vec4 position = vec4((depthTexCoordOffset + gl_TexCoord[0].st * depthTexCoordScale) * z, z, 1.0);
|
vec4 position = vec4((depthTexCoordOffset + gl_TexCoord[0].st * depthTexCoordScale) * z, z, 1.0);
|
||||||
|
|
||||||
|
// compute the corresponding texture coordinates
|
||||||
|
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[0], position), dot(gl_EyePlaneT[0], position), dot(gl_EyePlaneR[0], position));
|
||||||
|
|
||||||
// get the normal from the map
|
// get the normal from the map
|
||||||
vec4 normal = normalVal;
|
vec4 normal = normalVal;
|
||||||
if ((normalVal.a >= 0.45) && (normalVal.a <= 0.55)) {
|
if ((normalVal.a >= 0.45) && (normalVal.a <= 0.55)) {
|
||||||
normal.a = 1.0;
|
normal.a = 1.0;
|
||||||
normalVal.a = 0.0;
|
normalVal.a = 0.0;
|
||||||
gl_FragColor = vec4(diffuseVal.rgb * specularVal.rgb, 1.0);
|
|
||||||
|
// compute the corresponding texture coordinates
|
||||||
|
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[0], position), dot(gl_EyePlaneT[0], position), dot(gl_EyePlaneR[0], position));
|
||||||
|
|
||||||
|
// 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 faceLight = step(-0.005, dot(normalizedNormal, gl_LightSource[0].position.xyz));
|
||||||
|
|
||||||
|
// evaluate the shadow test but only relevant for light facing fragments
|
||||||
|
float attenuation = (1 - faceLight) + faceLight * (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));
|
||||||
|
|
||||||
|
|
||||||
|
gl_FragColor = vec4(diffuseVal.rgb * (
|
||||||
|
(gl_FrontLightModelProduct.sceneColor.rgb + gl_FrontLightProduct[0].ambient.rgb) * (1.0 - attenuation) +
|
||||||
|
specularVal.rgb * attenuation), 1.0);
|
||||||
|
|
||||||
|
// gl_FragColor = vec4(diffuseVal.rgb * specularVal.rgb, 1.0);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// compute the corresponding texture coordinates
|
// compute the corresponding texture coordinates
|
||||||
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[0], position), dot(gl_EyePlaneT[0], position), dot(gl_EyePlaneR[0], position));
|
vec3 shadowTexCoord = vec3(dot(gl_EyePlaneS[0], position), dot(gl_EyePlaneT[0], position), dot(gl_EyePlaneR[0], position));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue