Compare commits
2 Commits
bedd6c3ca0
...
884696feaa
Author | SHA1 | Date | |
---|---|---|---|
884696feaa | |||
ff9e23255c |
@ -31,6 +31,7 @@ elseif (MSVC) # vcpkg
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLEW CONFIG REQUIRED)
|
||||
find_package(glm CONFIG REQUIRED)
|
||||
find_package(EnTT CONFIG REQUIRED)
|
||||
endif()
|
||||
|
||||
add_executable(CodingGame
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
m_registry.emplace<transform>(cameraEntity, glm::vec3(0.f, 2.f, 2.f));
|
||||
m_registry.emplace<camera>(cameraEntity);
|
||||
|
||||
Object* targetObj = Object::LoadFile("./assets/cube.obj");
|
||||
Object* targetObj = Object::LoadFile("./assets/wizard/wizard.obj");
|
||||
const auto targetEntity = m_registry.create();
|
||||
m_registry.emplace<transform>(targetEntity, glm::vec3(0.f, 0.5f, 0.f));
|
||||
m_registry.emplace<mesh>(targetEntity, std::unique_ptr<Object>(targetObj));
|
||||
|
@ -1,7 +1,11 @@
|
||||
#include <iostream>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#ifdef WIN32
|
||||
#include <corecrt_math_defines.h>
|
||||
#endif
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/euler_angles.hpp>
|
||||
|
||||
#include "renderer/renderer.h"
|
||||
@ -154,23 +158,39 @@ void Renderer::Render(entt::registry& registry) {
|
||||
auto shadowLight = registry.view<light, transform>().back();
|
||||
auto &comp = registry.get<transform>(shadowLight);
|
||||
|
||||
float near_plane = -10.0f, far_plane = 20.0f;
|
||||
glm::mat4 lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
|
||||
|
||||
glm::mat4 lightView = glm::lookAt(comp.position,
|
||||
glm::vec3( 0.0f, 0.0f, 0.0f),
|
||||
glm::vec3( 0.0f, 1.0f, 0.0f));
|
||||
|
||||
float near_plane = 0.1f, far_plane = 50.0f; // pick bounds that cover your scene
|
||||
glm::vec3 lightPos = comp.position;
|
||||
glm::vec3 target = glm::vec3(0.0f, 0.5f, 0.0f);
|
||||
glm::mat4 lightView = glm::lookAt(lightPos, target, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
glm::mat4 lightProjection = glm::ortho(-6.0f, 6.0f, -6.0f, 6.0f, 1.0f, 20.0f);
|
||||
glm::mat4 lightSpaceMatrix = lightProjection * lightView;
|
||||
|
||||
// lightView = glm::lookAt(/*eye*/ -lightDir * distance, /*center*/ vec3(0), up)
|
||||
|
||||
// glm::mat4 lightSpaceMatrix = lightProjection * lightView;
|
||||
SwitchShader(&m_depthShader);
|
||||
m_currentShader->setMat4("u_lightSpace", lightSpaceMatrix);
|
||||
|
||||
// enable culling and render front faces to the shadow map
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT); // only for the depth pass
|
||||
// or use polygon offset:
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(2.0f, 4.0f);
|
||||
|
||||
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_depth_fbo);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
RenderScene(registry);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// enable culling and render front faces to the shadow map
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK); // only for the depth pass
|
||||
// or use polygon offset:
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(0.f, 1.f);
|
||||
|
||||
glViewport(0, 0, Window::GetWidth(), Window::GetHeight());
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
@ -60,7 +60,7 @@ float ShadowCalculation(vec4 fragPosLightSpace, vec3 N, vec3 L)
|
||||
float currentDepth = projCoords.z;
|
||||
|
||||
// bias to prevent self-shadowing (depend on slope)
|
||||
float bias = max(0.05 * (1.0 - dot(N, L)), 0.005);
|
||||
float bias = max(0.001 * (1.0 - dot(N, L)), 0.0005);
|
||||
|
||||
// PCF (3x3)
|
||||
float shadow = 0.0;
|
||||
|
Reference in New Issue
Block a user