Shado wip
This commit is contained in:
@@ -51,7 +51,7 @@ private:
|
|||||||
|
|
||||||
GLuint m_DepthFBO;
|
GLuint m_DepthFBO;
|
||||||
|
|
||||||
GLfloat m_NearFarPlane[2] = { -84.f, 28.f };
|
GLfloat m_NearFarPlane[2] = { -34.f, 27.f };
|
||||||
GLfloat m_LRBT[4] = { -77.f, 75.f, -89.f, 89.f };
|
GLfloat m_LRBT[4] = { -77.f, 75.f, -89.f, 89.f };
|
||||||
|
|
||||||
glm::mat4 m_LightProjection;
|
glm::mat4 m_LightProjection;
|
||||||
|
|||||||
@@ -238,6 +238,13 @@
|
|||||||
</Entity>
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
</Entity>
|
</Entity>
|
||||||
|
<Entity name="Ambient">
|
||||||
|
<Components>
|
||||||
|
<c:SceneLight/>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
|
|
||||||
</Entity>
|
</Entity>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ layout (binding = 0) uniform sampler2D DiffuseTexture;
|
|||||||
layout (binding = 1) uniform sampler2D NormalMapTexture;
|
layout (binding = 1) uniform sampler2D NormalMapTexture;
|
||||||
layout (binding = 2) uniform sampler2D SpecularMapTexture;
|
layout (binding = 2) uniform sampler2D SpecularMapTexture;
|
||||||
layout (binding = 3) uniform sampler2D GlowMapTexture;
|
layout (binding = 3) uniform sampler2D GlowMapTexture;
|
||||||
layout (binding = 4) uniform sampler2D DepthMap;
|
layout (binding = 4) uniform sampler2DShadow DepthMap;
|
||||||
|
|
||||||
#define TILE_SIZE 16
|
#define TILE_SIZE 16
|
||||||
|
|
||||||
@@ -114,49 +114,39 @@ vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textu
|
|||||||
return vec4(TBN * normalize(NormalMap), 0.0);
|
return vec4(TBN * normalize(NormalMap), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 poissonDisk[4] = vec2[](
|
float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampler2DShadow depthTexture)
|
||||||
vec2( -0.94201624, -0.39906216 ),
|
|
||||||
vec2( 0.94558609, -0.76890725 ),
|
|
||||||
vec2( -0.094184101, -0.92938870 ),
|
|
||||||
vec2( 0.34495938, 0.29387760 )
|
|
||||||
);
|
|
||||||
|
|
||||||
float CalcShadowValue(vec4 positionLightSpace, vec4 normal, vec4 lightDir, sampler2D depthTexture)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
float bias = 0.005;
|
float bias = 0.005;
|
||||||
//float bias = max(0.05 * (1.0 - dot(normal, -lightDir)), 0.005);
|
//float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
|
||||||
// perform perspective divide
|
//float bias = 0.005 * tan(acos(clamp(dot(normal, lightDir), 0,1))); bias = clamp(bias, 0,0.01);
|
||||||
|
|
||||||
vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w;
|
vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w;
|
||||||
// Transform to [0,1] range
|
|
||||||
projCoords = projCoords * 0.5 + 0.5;
|
projCoords = projCoords * 0.5 + 0.5;
|
||||||
// Get closest depth value from light's perspective (using [0,1] range fragPosLight as coords)
|
//float shadowMapDepth = texture(depthTexture, projCoords.xy).r;
|
||||||
//float lightDepth = texture(depthTexture, positionLightSpace.xy).r;
|
float shadowMapDepth = 1.0 - texture(depthTexture, projCoords);
|
||||||
float closestDepth = texture(depthTexture, projCoords.xy).r;
|
float geometryDepth = projCoords.z;
|
||||||
// Get depth of current fragment from light's perspective
|
//float shadow = geometryDepth - bias > shadowMapDepth ? 1.0 : 0.0;
|
||||||
//float currentDepth = positionLightSpace.z;
|
//float shadow = geometryDepth - bias > shadowMapDepth ? 0.0 : 1.0;
|
||||||
float currentDepth = projCoords.z;
|
float shadow = shadowMapDepth;
|
||||||
// Check whether current frag pos is in shadow
|
|
||||||
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
|
||||||
//float shadow = currentDepth > closestDepth ? 1.0 : 0.0;
|
|
||||||
|
|
||||||
//float shadow = 0.0;
|
//float shadow = 0.0;
|
||||||
////soft shadow - using percentage-closer filtering (PCF) is to simply sample the surrounding texels of the depth map and average the results:
|
|
||||||
//vec2 texelSize = 1.0 / textureSize(depthTexture, 0);
|
//vec2 texelSize = 1.0 / textureSize(depthTexture, 0);
|
||||||
//for(int x = -1; x <= 1; ++x)
|
//for(int x = -1; x <= 1; x++)
|
||||||
//{
|
//{
|
||||||
// for(int y = -1; y <= 1; ++y)
|
// for(int y = -1; y <= 1; y++)
|
||||||
// {
|
// {
|
||||||
// float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r;
|
// float pcfDepth = texture(depthTexture, projCoords.xy + vec2(x, y) * texelSize).r;
|
||||||
// shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
|
// shadow += geometryDepth - bias > pcfDepth ? 1.0 : 0.0;
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
//shadow /= 9.0;
|
//shadow /= 9.0;
|
||||||
//
|
|
||||||
if(projCoords.z > 0.9)
|
//if(projCoords.z > 1.0)
|
||||||
{
|
//{
|
||||||
shadow = 1.0;
|
// shadow = 0.0;
|
||||||
}
|
//}
|
||||||
|
|
||||||
return shadow;
|
return shadow;
|
||||||
|
|
||||||
@@ -184,7 +174,7 @@ void main()
|
|||||||
int start = int(LightGrids.Data[currentTile].Start);
|
int start = int(LightGrids.Data[currentTile].Start);
|
||||||
int amount = int(LightGrids.Data[currentTile].Amount);
|
int amount = int(LightGrids.Data[currentTile].Amount);
|
||||||
|
|
||||||
float shadowFactor = 1.0;
|
float shadowFactor = 0.0;
|
||||||
|
|
||||||
for(int i = start; i < start + amount; i++) {
|
for(int i = start; i < start + amount; i++) {
|
||||||
|
|
||||||
@@ -197,15 +187,16 @@ void main()
|
|||||||
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
|
light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff);
|
||||||
} else if (light.Type == 2) { //Directional
|
} else if (light.Type == 2) { //Directional
|
||||||
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
|
||||||
shadowFactor = CalcShadowValue(Input.PositionLightSpace, vec4(Input.Normal, 0.0), light.Direction, DepthMap);
|
shadowFactor = CalcShadowValue(Input.PositionLightSpace, Input.Normal, vec3(light.Direction), DepthMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalLighting.Diffuse += light_result.Diffuse;
|
totalLighting.Diffuse += light_result.Diffuse;
|
||||||
totalLighting.Specular += light_result.Specular;
|
totalLighting.Specular += light_result.Specular;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalLighting.Diffuse += (1.0 - shadowFactor);
|
totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0);
|
||||||
totalLighting.Specular += (1.0 - shadowFactor);
|
totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgb, 1.0)) - vec4(vec3(shadowFactor), 0.0);
|
||||||
|
|
||||||
//LightResult getInformation;
|
//LightResult getInformation;
|
||||||
|
|
||||||
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
|
vec4 color_result = mix((Color * diffuseTexel * DiffuseColor), Input.ExplosionColor, Input.ExplosionPercentageElapsed);
|
||||||
|
|||||||
@@ -25,12 +25,15 @@ void ShadowPass::InitializeFrameBuffers()
|
|||||||
// Depth texture
|
// Depth texture
|
||||||
glGenTextures(1, &m_DepthMap);
|
glGenTextures(1, &m_DepthMap);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_DepthMap);
|
glBindTexture(GL_TEXTURE_2D, m_DepthMap);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, resolutionSizeWidth, resolutionSizeHeigth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, resolutionSizeWidth, resolutionSizeHeigth, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
|
||||||
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, 0);
|
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height, 0, GL_RGB, GL_FLOAT, 0);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
|
||||||
|
|
||||||
|
|
||||||
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_DEPTH_ATTACHMENT)));
|
||||||
@@ -67,7 +70,8 @@ void ShadowPass::Draw(RenderScene & scene)
|
|||||||
m_ShadowProgram->Bind();
|
m_ShadowProgram->Bind();
|
||||||
|
|
||||||
glViewport(0, 0, resolutionSizeWidth, resolutionSizeHeigth);
|
glViewport(0, 0, resolutionSizeWidth, resolutionSizeHeigth);
|
||||||
glCullFace(GL_BACK);
|
|
||||||
|
//glCullFace(GL_FRONT);
|
||||||
//state->Disable(GL_CULL_FACE);
|
//state->Disable(GL_CULL_FACE);
|
||||||
|
|
||||||
ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f);
|
ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f);
|
||||||
@@ -117,7 +121,7 @@ void ShadowPass::Draw(RenderScene & scene)
|
|||||||
|
|
||||||
|
|
||||||
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||||
glCullFace(GL_BACK);
|
//glCullFace(GL_BACK);
|
||||||
m_ShadowProgram->Unbind();
|
m_ShadowProgram->Unbind();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user