Shadow WIP
- DepthTexture working
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "../Core/World.h"
|
||||
#include "ShadowPassState.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
//#include "ShadowPassState.h" // not created yet
|
||||
|
||||
@@ -45,6 +46,14 @@ private:
|
||||
|
||||
GLuint m_DepthFBO;
|
||||
|
||||
GLfloat m_NearPlane = -40.f;
|
||||
GLfloat m_FarPlane = 80.f;
|
||||
//GLfloat m_Left = -10.f;
|
||||
//GLfloat m_Right = 10.f;
|
||||
//GLfloat m_Bottom = -10.f;
|
||||
//GLfloat m_Top = 10.f;
|
||||
GLfloat m_LRBT[4] = { -40.f, 100.f, -50.f, 50.f };
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
|
||||
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
}Input;
|
||||
//in VertexData{
|
||||
// vec3 Position;
|
||||
//}Input;
|
||||
|
||||
//layout(location = 0 ) out vec4 ShadowMap;
|
||||
layout(location = 0 ) out float ShadowMap;
|
||||
@@ -12,7 +12,7 @@ layout(location = 0 ) out float ShadowMap;
|
||||
void main()
|
||||
{
|
||||
//ShadowMap = vec4(vec3(gl_FragCoord.z), 1.0);
|
||||
ShadowMap = (gl_FragCoord.z);
|
||||
//ShadowMap = (gl_FragCoord.z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ uniform mat4 P;
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
|
||||
out VertexData{
|
||||
vec3 Position;
|
||||
}Output;
|
||||
//out VertexData{
|
||||
// vec3 Position;
|
||||
//}Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Position = Position;
|
||||
// Output.Position = Position;
|
||||
gl_Position = P * V * M * vec4(Position, 1.0);
|
||||
}
|
||||
@@ -26,15 +26,15 @@ void ShadowPass::InitializeFrameBuffers()
|
||||
glGenTextures(1, &m_DepthMap);
|
||||
glBindTexture(GL_TEXTURE_2D, m_DepthMap);
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 1024, 1024, 0, GL_RGB, GL_FLOAT, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
|
||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 1024, 1024, 0, GL_RGB, GL_FLOAT, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
//m_DepthBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT)));
|
||||
m_DepthBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0)));
|
||||
m_DepthBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT)));
|
||||
//m_DepthBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthMap, GL_COLOR_ATTACHMENT0)));
|
||||
m_DepthBuffer.Generate();
|
||||
|
||||
GLERROR("depthMap failed");
|
||||
@@ -70,16 +70,16 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
// glClear(GL_COLOR_BUFFER_BIT);
|
||||
//}
|
||||
|
||||
ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f);
|
||||
|
||||
for (auto &job : scene.DirectionalLightJobs) {
|
||||
auto directionalLightJob = std::dynamic_pointer_cast<DirectionalLightJob>(job);
|
||||
|
||||
if(directionalLightJob) {
|
||||
|
||||
GLfloat near_plane = 1.0f, far_plane = 75.5f;
|
||||
glm::mat4 lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
|
||||
glm::mat4 lightProjection = glm::ortho(m_LRBT[0], m_LRBT[1], m_LRBT[2], m_LRBT[3], m_NearPlane, m_FarPlane);
|
||||
|
||||
// broken?
|
||||
glm::mat4 lightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)) * (float)50.0 , glm::vec3(0,0,0), glm::vec3(0,1,0));
|
||||
glm::mat4 lightView = glm::lookAt(-glm::normalize(glm::vec3(directionalLightJob->Direction)) * (float)20.0 , glm::vec3(0,0,0), glm::vec3(0,1,0));
|
||||
//glm::mat4 lightView = glm::lookAt(glm::vec3(10.f, 10.f, 50.f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 1.f, 0.f));
|
||||
//glm::mat4 lightSpaceMatrix = lightProjection * lightView;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user