Fix for real-time shadows + more objects
The framebuffer wasn't properly cleared
This commit is contained in:
parent
6510f720cb
commit
ef649780c3
@ -18,9 +18,7 @@
|
|||||||
|
|
||||||
using namespace ECS;
|
using namespace ECS;
|
||||||
|
|
||||||
// For debugging:
|
// For Debugging
|
||||||
// renderQuad() renders a 1x1 XY quad in NDC
|
|
||||||
// -----------------------------------------
|
|
||||||
unsigned int quadVAO = 0;
|
unsigned int quadVAO = 0;
|
||||||
unsigned int quadVBO;
|
unsigned int quadVBO;
|
||||||
void renderQuad()
|
void renderQuad()
|
||||||
@ -162,7 +160,8 @@ public:
|
|||||||
RenderSystem() {
|
RenderSystem() {
|
||||||
// Configure depth map
|
// Configure depth map
|
||||||
glGenFramebuffers(1, &depthMapFBO);
|
glGenFramebuffers(1, &depthMapFBO);
|
||||||
// create depth texture
|
|
||||||
|
// Create depth texture
|
||||||
glGenTextures(1, &depthMap);
|
glGenTextures(1, &depthMap);
|
||||||
glBindTexture(GL_TEXTURE_2D, depthMap);
|
glBindTexture(GL_TEXTURE_2D, depthMap);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadow_width, shadow_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadow_width, shadow_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
||||||
@ -170,7 +169,8 @@ public:
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
// attach depth texture as FBO's depth buffer
|
|
||||||
|
// Attach depth texture as FBO's depth buffer
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
|
||||||
glDrawBuffer(GL_NONE);
|
glDrawBuffer(GL_NONE);
|
||||||
@ -181,10 +181,7 @@ public:
|
|||||||
|
|
||||||
void render(World *pWorld, Shader normalShader, Shader shadowShader, Shader debugShader) {
|
void render(World *pWorld, Shader normalShader, Shader shadowShader, Shader debugShader) {
|
||||||
pWorld->each<Camera, Transform>([&](Entity *ent, ComponentHandle<Camera> camera, ComponentHandle<Transform> cameraTransform) {
|
pWorld->each<Camera, Transform>([&](Entity *ent, ComponentHandle<Camera> camera, ComponentHandle<Transform> cameraTransform) {
|
||||||
// Common
|
// Get render objects
|
||||||
glClearColor(0.6f, 0.9f, 0.9f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
std::vector<std::vector<RenderObject>> allRenderObjects = getRenderObjects(pWorld, cameraTransform->get_origin());
|
std::vector<std::vector<RenderObject>> allRenderObjects = getRenderObjects(pWorld, cameraTransform->get_origin());
|
||||||
std::vector<RenderObject> renderObjects = allRenderObjects[0];
|
std::vector<RenderObject> renderObjects = allRenderObjects[0];
|
||||||
std::vector<RenderObject> transparentRenderObjects = allRenderObjects[1];
|
std::vector<RenderObject> transparentRenderObjects = allRenderObjects[1];
|
||||||
@ -208,6 +205,7 @@ public:
|
|||||||
|
|
||||||
glViewport(0, 0, shadow_width, shadow_height);
|
glViewport(0, 0, shadow_width, shadow_height);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
for (const RenderObject &obj : renderObjects) {
|
for (const RenderObject &obj : renderObjects) {
|
||||||
obj.render(shadowShader);
|
obj.render(shadowShader);
|
||||||
}
|
}
|
||||||
@ -217,12 +215,12 @@ public:
|
|||||||
} */
|
} */
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
// reset viewport
|
// Render Normal
|
||||||
glViewport(0, 0, screen_width, screen_height);
|
glViewport(0, 0, screen_width, screen_height);
|
||||||
|
|
||||||
|
glClearColor(0.6f, 0.9f, 0.9f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
||||||
// Render normal
|
|
||||||
normalShader.use();
|
normalShader.use();
|
||||||
|
|
||||||
// Lighting
|
// Lighting
|
||||||
@ -255,7 +253,7 @@ public:
|
|||||||
debugShader.setFloat("far_plane", far_plane);
|
debugShader.setFloat("far_plane", far_plane);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, depthMap);
|
glBindTexture(GL_TEXTURE_2D, depthMap);
|
||||||
//renderQuad(); // TODO: Add actual code switch instead of commenting
|
renderQuad();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
Resources/Gold.jpg
Normal file
BIN
Resources/Gold.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 MiB |
BIN
Resources/Wood.jpg
Normal file
BIN
Resources/Wood.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 MiB |
10
Resources/bench.mtl
Normal file
10
Resources/bench.mtl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Blender MTL File: 'ue1.blend1'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl None
|
||||||
|
Ns 500
|
||||||
|
Ka 0.8 0.8 0.8
|
||||||
|
Kd 0.8 0.8 0.8
|
||||||
|
Ks 0.8 0.8 0.8
|
||||||
|
d 1
|
||||||
|
illum 2
|
4105
Resources/bench.obj
Normal file
4105
Resources/bench.obj
Normal file
File diff suppressed because it is too large
Load Diff
10
Resources/ring.mtl
Normal file
10
Resources/ring.mtl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl None
|
||||||
|
Ns 500
|
||||||
|
Ka 0.8 0.8 0.8
|
||||||
|
Kd 0.8 0.8 0.8
|
||||||
|
Ks 0.8 0.8 0.8
|
||||||
|
d 1
|
||||||
|
illum 2
|
2083
Resources/ring.obj
Normal file
2083
Resources/ring.obj
Normal file
File diff suppressed because it is too large
Load Diff
17
main.cpp
17
main.cpp
@ -169,6 +169,21 @@ int main() {
|
|||||||
ground->assign<Material>(1.0, 0.0);
|
ground->assign<Material>(1.0, 0.0);
|
||||||
ground->get<Transform>()->set_origin(glm::vec3(0.0f, 0.0f, 0.0f));
|
ground->get<Transform>()->set_origin(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
|
|
||||||
|
Entity *bench = world->create();
|
||||||
|
bench->assign<Transform>();
|
||||||
|
bench->assign<ObjMesh>(ObjMesh("Resources/bench.obj", ObjMesh::Settings()));
|
||||||
|
bench->assign<Texture>("Resources/Wood.jpg", Texture::Settings(true, false));
|
||||||
|
bench->assign<Material>(0.8, 0.2);
|
||||||
|
bench->get<Transform>()->set_origin(glm::vec3(8.0f, 0.0f, 0.0f));
|
||||||
|
bench->get<Transform>()->rotate(-90.0, glm::vec3(0.0, 1.0, 0.0));
|
||||||
|
|
||||||
|
Entity *ring = world->create();
|
||||||
|
ring->assign<Transform>();
|
||||||
|
ring->assign<ObjMesh>(ObjMesh("Resources/ring.obj", ObjMesh::Settings()));
|
||||||
|
ring->assign<Texture>("Resources/Gold.jpg", Texture::Settings(true, false));
|
||||||
|
ring->assign<Material>(0.1, 0.9);
|
||||||
|
ring->get<Transform>()->set_origin(glm::vec3(-5.0f, 2.0f, 0.0f));
|
||||||
|
|
||||||
Entity *sun = world->create();
|
Entity *sun = world->create();
|
||||||
sun->assign<DirectionalLight>(glm::normalize(glm::vec3(1.0, 1.0, 1.0)));
|
sun->assign<DirectionalLight>(glm::normalize(glm::vec3(1.0, 1.0, 1.0)));
|
||||||
|
|
||||||
@ -189,6 +204,8 @@ int main() {
|
|||||||
world->tick(delta);
|
world->tick(delta);
|
||||||
renderSystem->render(world, defaultShader, shadowShader, debugShader);
|
renderSystem->render(world, defaultShader, shadowShader, debugShader);
|
||||||
|
|
||||||
|
ring->get<Transform>()->rotate(delta * 100.0, glm::vec3(0.0, 1.0, 0.0));
|
||||||
|
|
||||||
/* Swap front and back buffers */
|
/* Swap front and back buffers */
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user