Performance optimization for deciding when the directional shadow gets rendered.
This commit is contained in:
parent
a8ce6916e7
commit
c8ba61ca56
@ -47,6 +47,7 @@ uniform bool movingTexture;
|
|||||||
uniform vec2 movement;
|
uniform vec2 movement;
|
||||||
uniform vec2 movingTextureOffset;
|
uniform vec2 movingTextureOffset;
|
||||||
uniform float time;
|
uniform float time;
|
||||||
|
uniform bool sampleDirectionalShadowSwitch;
|
||||||
|
|
||||||
vec2 poissonDisk[16] = vec2[](
|
vec2 poissonDisk[16] = vec2[](
|
||||||
vec2( -0.94201624, -0.39906216 ),
|
vec2( -0.94201624, -0.39906216 ),
|
||||||
@ -171,10 +172,9 @@ void main()
|
|||||||
|
|
||||||
// direction lighting
|
// direction lighting
|
||||||
float sunAngle = -1.0;
|
float sunAngle = -1.0;
|
||||||
if(length(directionalLightVector)>0.0f) {
|
if(sampleDirectionalShadowSwitch) {
|
||||||
vec3 directionalVector = normalize(directionalLightVector);
|
vec3 directionalVector = normalize(directionalLightVector);
|
||||||
sunAngle = dot(vec3(0.0, 1.0, 0.0), directionalVector);
|
sunAngle = dot(vec3(0.0, 1.0, 0.0), directionalVector);
|
||||||
if ( sunAngle > 0.0) {
|
|
||||||
float directionalVisibility = 1.0f;
|
float directionalVisibility = 1.0f;
|
||||||
float directionalIntensity = sunIntensity(sunAngle);
|
float directionalIntensity = sunIntensity(sunAngle);
|
||||||
if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) {
|
if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) {
|
||||||
@ -205,7 +205,6 @@ void main()
|
|||||||
(length(cameraVector+directionalVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
|
(length(cameraVector+directionalVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
|
||||||
*specularFactor*directionalIntensity*sunColor(sunAngle)*directionalVisibility;
|
*specularFactor*directionalIntensity*sunColor(sunAngle)*directionalVisibility;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// point lights
|
// point lights
|
||||||
float visibility = 1.0;
|
float visibility = 1.0;
|
||||||
|
@ -30,6 +30,7 @@ Graphics::Graphics(glm::uvec2 windowSize, float nearPlane,
|
|||||||
renderFlames = true;
|
renderFlames = true;
|
||||||
renderWorld = true;
|
renderWorld = true;
|
||||||
renderDebug = false;
|
renderDebug = false;
|
||||||
|
directionalShadowSwitch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Graphics::Graphics() {
|
Graphics::Graphics() {
|
||||||
@ -196,6 +197,7 @@ void Graphics::init(Level* level) {
|
|||||||
lightingShader->setUniform("fogColorRise", level->getFogColourRise());
|
lightingShader->setUniform("fogColorRise", level->getFogColourRise());
|
||||||
lightingShader->setUniform("fogColorNight", level->getFogColourNight());
|
lightingShader->setUniform("fogColorNight", level->getFogColourNight());
|
||||||
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
lightingShader->setUniform("ambientColor", level->getAmbientLight());
|
||||||
|
lightingShader->setUniform("sampleDirectionalShadowSwitch", false);
|
||||||
if(level->getDirectionalLight()) {
|
if(level->getDirectionalLight()) {
|
||||||
lightingShader->setUniform("directionalLightVector",
|
lightingShader->setUniform("directionalLightVector",
|
||||||
level->getDirectionalLight()->getPosition());
|
level->getDirectionalLight()->getPosition());
|
||||||
@ -361,18 +363,22 @@ void Graphics::render(double time)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// render depth textures for sun
|
|
||||||
depthShader->use();
|
|
||||||
glViewport(0, 0, windowSize.x, windowSize.y);
|
glViewport(0, 0, windowSize.x, windowSize.y);
|
||||||
|
|
||||||
|
// render depth textures for sun
|
||||||
float sunAngle = glm::dot(glm::vec3(0.0f, 1.0f, 0.0f), glm::normalize(level->getDirectionalLight()->getPosition()));
|
float sunAngle = glm::dot(glm::vec3(0.0f, 1.0f, 0.0f), glm::normalize(level->getDirectionalLight()->getPosition()));
|
||||||
glm::vec3 sunVector = (level->getCameraCenter()->getPosition() + level->getDirectionalLight()->getPosition());
|
glm::vec3 sunVector = (level->getCameraCenter()->getPosition() + level->getDirectionalLight()->getPosition());
|
||||||
|
|
||||||
|
if (sunAngle > 0.0f) {
|
||||||
|
if (!directionalShadowSwitch) {
|
||||||
|
lightingShader->use();
|
||||||
|
lightingShader->setUniform("sampleDirectionalShadowSwitch", true);
|
||||||
|
directionalShadowSwitch = true;
|
||||||
|
}
|
||||||
|
depthShader->use();
|
||||||
for (unsigned int i = 0; i<framebuffer_directional.size(); i++) {
|
for (unsigned int i = 0; i<framebuffer_directional.size(); i++) {
|
||||||
framebuffer_directional.at(i)->bind();
|
framebuffer_directional.at(i)->bind();
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
if (sunAngle > 0.0f) {
|
|
||||||
float projection_size = 0.0f;
|
float projection_size = 0.0f;
|
||||||
switch(i) {
|
switch(i) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -393,6 +399,11 @@ void Graphics::render(double time)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (directionalShadowSwitch) {
|
||||||
|
lightingShader->use();
|
||||||
|
lightingShader->setUniform("sampleDirectionalShadowSwitch", false);
|
||||||
|
directionalShadowSwitch = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// lighting render pass
|
// lighting render pass
|
||||||
|
@ -84,6 +84,7 @@ class Graphics {
|
|||||||
bool renderFlames;
|
bool renderFlames;
|
||||||
bool renderDebug;
|
bool renderDebug;
|
||||||
bool renderWorld;
|
bool renderWorld;
|
||||||
|
bool directionalShadowSwitch;
|
||||||
DebugDraw debugDrawer;
|
DebugDraw debugDrawer;
|
||||||
SharedArrayBuffer debug_ab;
|
SharedArrayBuffer debug_ab;
|
||||||
SharedVertexArrayObject debug_vao;
|
SharedVertexArrayObject debug_vao;
|
||||||
|
Loading…
Reference in New Issue
Block a user