PDA

View Full Version : [Shadow] I have strange result from depth buffer.



jerome503
08-11-2017, 08:08 PM
Hello, mates.

I have strange result from depth buffer while working on shadows from directional light.

2441

The bunny and sphere have artifacts.

Could you guys help me to figure out what the problem is?

The funny thing is when I drew only a quad, it looks like working.

2442


Therefore, I've checked the models are okay.

2443

Unfortunately, it looks like the models are not problem.

I also checked the light's view.

Here's how I constructed the light view.



// Bring its direction from rotation factor at Transform Component
// The location factor is converted like PhysicalLength * -(Rotation)
// Physical length is 5.0f by default
mat4 EntityDirectionalLight::GetViewMatrix()
{
using namespace ComponentHelper;
assert(this->GetComponent<CameraComponent>() != nullptr);
assert(this->GetComponent<TransformComponent>() != nullptr);

auto cCamera = this->GetComponent<CameraComponent>()
auto cTrans = this->GetComponent<TransformComponent>();
if (cCamera->mFlag & CameraEnum::EViewUpdatable)
{
cCamera->SetViewMatrix(
glm::lookat(cTrans->GetLocation // eye
, cTrans->GetLocation() + cTrans->GetRotation() // center
, vec3(0.0f, 1.0f, 0.0f) // up
));
}
return cCamera->GetViewMatrix();
}


2444


It's from the light view. I, also, think light view matrix looks okay.

Projection matrix is constructed by glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near, far);
near and far are 0.1f and 10.0f by default.

I also tried to change the near from 0.1f to 0.01f because objects might be too close to the near clip plane.

However, the result is still same with the first picture that I've attached.

The depth test is enabled, of course and depth function's flag is GL_LEQUAL ( I also tried GL_LESS )

The color buffer from the depth frame buffer is using GL_RED and GL_R32F as its texture format and internal format.

I would appreciate so much if you give me what possible problems are.

Thank you for reading it!