Make cascade split modifiable

This commit is contained in:
Vincent Lejeune 2014-10-27 21:19:03 +01:00
parent 6d07189474
commit 92ecd01e61
4 changed files with 32 additions and 95 deletions

View File

@ -1,14 +1,14 @@
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform sampler2DArray shadowtex;
//uniform sampler2D warpx;
///uniform sampler2D warpy;
uniform float split0;
uniform float split1;
uniform float split2;
uniform float splitmax;
uniform vec3 direction;
uniform vec3 col;
//uniform int hasclouds;
//uniform vec2 wind;
//uniform float shadowoffset;
in vec2 uv;
out vec4 Diff;
@ -20,8 +20,7 @@ vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
float getShadowFactor(vec3 pos, float bias, int index)
{
//float a[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1);
vec2 shadowoffset[4] = vec2[](
vec2(-1., -1.),
vec2(-1., 1.),
@ -32,27 +31,6 @@ float getShadowFactor(vec3 pos, float bias, int index)
vec4 shadowcoord = (ShadowViewProjMatrixes[index] * InverseViewMatrix * vec4(pos, 1.0));
shadowcoord.xy /= shadowcoord.w;
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
// shadowcoord = (shadowcoord * 0.5) + vec3(0.5);
// float movex = decdepth(texture(warpx, shadowcoord.xy));
// float movey = decdepth(texture(warpy, shadowcoord.xy));
// float dx = movex * 2.0 - 1.0;
// float dy = movey * 2.0 - 1.0;
// shadowcoord.xy += vec2(dx, dy);*/
//float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.;
// bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping
// float sum = 0.;
// for (float i = -1.5; i <= 1.5; i+= 1.)
// {
// for (float j = -1.5; j <= 1.5; j+= 1.)
// {
// float z = texture(shadowtex, vec3(shadowtexcoord +vec2(i, j) / 1024., float(index))).x;
// sum += (z > 0.5 * shadowcoord.z + 0.5) ? 1. : 0.;
// }
// }
// return sum / 16.;
float z = texture(shadowtex, vec3(shadowtexcoord, float(index))).x;
float d = shadowcoord.z;
@ -78,86 +56,41 @@ void main() {
vec3 outcol = NdotL * col;
// if (hasclouds == 1)
// {
// vec2 cloudcoord = (xpos.xz * 0.00833333) + wind;
// float cloud = texture(cloudtex, cloudcoord).x;
// //float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y);
// outcol *= cloud;
// }
// Shadows
float bias = 0.005 * tan(acos(NdotL)); // According to the slope
bias = clamp(bias, 0., 0.01);
float factor;
if (xpos.z < 5.)
if (xpos.z < split0)
factor = getShadowFactor(xpos.xyz, bias, 0);
else if (xpos.z < 6.)
/* else if (xpos.z < 6.)
{
float a = getShadowFactor(xpos.xyz, bias, 0), b = getShadowFactor(xpos.xyz, bias, 1);
factor = mix(a, b, (xpos.z - 5.));
}
else if (xpos.z < 20.)
}*/
else if (xpos.z < split1)
factor = getShadowFactor(xpos.xyz, bias, 1);
else if (xpos.z < 21.)
/* else if (xpos.z < 21.)
{
float a = getShadowFactor(xpos.xyz, bias, 1), b = getShadowFactor(xpos.xyz, bias, 2);
factor = mix(a, b, (xpos.z - 20.));
}
else if (xpos.z < 50.)
}*/
else if (xpos.z < split2)
factor = getShadowFactor(xpos.xyz, bias, 2);
else if (xpos.z < 55.)
/* else if (xpos.z < 55.)
{
float a = getShadowFactor(xpos.xyz, bias, 2), b = getShadowFactor(xpos.xyz, bias, 3);
factor = mix(a, b, (xpos.z - 50.) / 5.);
}
else if (xpos.z < 145.)
}*/
else if (xpos.z < splitmax)
factor = getShadowFactor(xpos.xyz, bias, 3);
else if (xpos.z < 150.)
/* else if (xpos.z < 150.)
{
factor = mix(getShadowFactor(xpos.xyz, bias, 3), 1., (xpos.z - 145.) / 5.);
}
}*/
else
factor = 1.;
Diff = vec4(factor * NdotL * col, 1.);
Spec = vec4(factor * Specular, 1.);
return;
// float moved = (abs(dx) + abs(dy)) * 0.5;
// float avi = 0.002;
// float abi = 0.0025;
/* float avi = 0.0018;
float abi = 0.002;
float bias = avi * tan(acos(NdotL)); // According to the slope
bias += smoothstep(0.001, 0.1, moved) * abi; // According to the warping
bias = clamp(bias, 0.001, abi);
// This ID, and four IDs around this must match for a shadow pixel
float right = texture(shadowtex, shadowcoord.xy + vec2(shadowoffset, 0.0)).a;
float left = texture(shadowtex, shadowcoord.xy + vec2(-shadowoffset, 0.0)).a;
float up = texture(shadowtex, shadowcoord.xy + vec2(0.0, shadowoffset)).a;
float down = texture(shadowtex, shadowcoord.xy + vec2(0.0, -shadowoffset)).a;
float matching = ((right + left + up + down) * 0.25) - shadowread.a;
matching = abs(matching) * 400.0;
// If the ID is different, we're likely in shadow - cut the bias to cut peter panning
float off = 7.0 - step(abs(shadowread.a - depthread.a) - matching, 0.004) * 6.0;
bias /= off;
const float softness = 8.0; // How soft is the light?
float shadowed = step(shadowmapz + bias, shadowcoord.z);
float dist = (shadowcoord.z / shadowmapz) - 1.0;
float penumbra = dist * softness / gl_FragCoord.z;
penumbra *= shadowed;*/
/* outcol.r = (shadowcoord.z - shadowmapz) * 50.0;
outcol.g = moved;*/
// FragColor = vec4(outcol, 0.05);
// OtherOutput = vec4(shadowed, penumbra, shadowed, shadowed);
}

View File

@ -282,6 +282,8 @@ void PostProcessing::renderSunlight()
DrawFullScreenEffect<FullScreenShader::SunLightShader>(cb->getPosition(), video::SColorf(cb->getRed(), cb->getGreen(), cb->getBlue()));
}
extern float shadowSplit[5];
void PostProcessing::renderShadowedSunlight(const std::vector<core::matrix4> &sun_ortho_matrix, GLuint depthtex)
{
SunLightProvider * const cb = (SunLightProvider *)irr_driver->getCallback(ES_SUNLIGHT);
@ -292,7 +294,7 @@ void PostProcessing::renderShadowedSunlight(const std::vector<core::matrix4> &su
glBlendEquation(GL_FUNC_ADD);
FullScreenShader::ShadowedSunLightShader::getInstance()->SetTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), depthtex);
DrawFullScreenEffect<FullScreenShader::ShadowedSunLightShader>(cb->getPosition(), video::SColorf(cb->getRed(), cb->getGreen(), cb->getBlue()));
DrawFullScreenEffect<FullScreenShader::ShadowedSunLightShader>(shadowSplit[1], shadowSplit[2], shadowSplit[3], shadowSplit[4], cb->getPosition(), video::SColorf(cb->getRed(), cb->getGreen(), cb->getBlue()));
}

View File

@ -642,6 +642,8 @@ core::matrix4 getTighestFitOrthoProj(const core::matrix4 &transform, const std::
return tmp_matrix;
}
float shadowSplit[5] = {1., 5., 20., 50., 150 };
void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, size_t width, size_t height)
{
static_cast<scene::CSceneManager *>(m_scene_manager)->OnAnimate(os::Timer::getTime());
@ -656,17 +658,17 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
const float oldnear = camnode->getNearValue();
float FarValues[] =
{
6.,
21.,
55.,
150.,
shadowSplit[1],
shadowSplit[2],
shadowSplit[3],
shadowSplit[4],
};
float NearValues[] =
{
oldnear,
5.,
20.,
50.,
shadowSplit[0],
shadowSplit[1],
shadowSplit[2],
shadowSplit[3]
};

View File

@ -402,7 +402,7 @@ public:
EnvMapShader();
};
class ShadowedSunLightShader : public ShaderHelperSingleton<ShadowedSunLightShader, core::vector3df, video::SColorf>, public TextureRead<Nearest_Filtered, Nearest_Filtered, Shadow_Sampler>
class ShadowedSunLightShader : public ShaderHelperSingleton<ShadowedSunLightShader, float, float, float, float, core::vector3df, video::SColorf>, public TextureRead<Nearest_Filtered, Nearest_Filtered, Shadow_Sampler>
{
public:
ShadowedSunLightShader();