Commit c18cd416 authored by Alexander Maximilian Nilles's avatar Alexander Maximilian Nilles
Browse files

Add a clear function for ss shadow map

parent ebf5a917
......@@ -45,8 +45,8 @@ void main()
for(int i = 0; i < lightData.length(); ++i)
{
Light l = getLight(i, uv);
uint shadowType = (0x0FF00000U & lightData[i].data4) >> 24;
Light l = getLight(i, uv);
uint shadowType = (0x0FF00000U & lightData[i].data4) >> 24;
if(shadowType != 1)
continue;
......
......@@ -59,18 +59,15 @@ void Light::setDirection(glm::vec3 dir)
if(direction() == glm::vec3(0.0f))
throw std::runtime_error("Tried to set direction for point light.");
//const glm::vec3 lightPos = -dir * 50.f;
// const glm::vec3 lightPos = -dir * 50.f;
dir = glm::normalize(dir);
//m_data1 = glm::packHalf2x16(glm::vec2(lightPos.x, lightPos.y));
dir = glm::normalize(dir);
// m_data1 = glm::packHalf2x16(glm::vec2(lightPos.x, lightPos.y));
m_data2 = glm::packHalf2x16(glm::vec2(position().z, dir.x));
m_data3 = glm::packHalf2x16(glm::vec2(dir.y, dir.z));
}
glm::vec3 Light::color() const
{
return glm::vec3(glm::unpackUnorm4x8(m_data4));
}
glm::vec3 Light::color() const { return glm::vec3(glm::unpackUnorm4x8(m_data4)); }
void Light::setColor(glm::vec3 color)
{
......@@ -251,12 +248,17 @@ ShadowMapLight::GpuSm ShadowMapLight::gpuStruct()
return {m_lightSpaceMatrix, m_smTexture->handle(), 0.f, 0.f};
}
void TracedLight::clearSsShadowTexture()
{
float clearVal = 1.0f;
m_ssShadowTexture.clear(GL_RED, GL_FLOAT, &clearVal);
}
void TracedLight::setSsShadowTextureSize(glm::ivec2 size)
{
m_ssShadowTexture.resize(GL_TEXTURE_2D, GL_R16F, size, 1);
m_ssShadowTexture.set(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
float clearVal = 1.0f;
m_ssShadowTexture.clear(GL_RED, GL_FLOAT, &clearVal);
clearSsShadowTexture();
m_ssShadowImageHandle = m_ssShadowTexture.imageHandle(0, false, 0, GL_WRITE_ONLY, GL_R16F);
m_ssShadowTextureHandle = m_ssShadowTexture.handle();
......
......@@ -115,11 +115,11 @@ struct Light
ShadowType shadowType() const;
protected:
uint32_t m_data1 = 0; // pos.xy
uint32_t m_data2 = 0; // pos.z, dir.x
uint32_t m_data3 = 0; // dir.yz
uint32_t m_data4 = 0; // col.rgb (8bit), shadowType
uint32_t m_data5 = 0; // intensity, cutoff (8bit), shadowMapIndex (8bit)
uint32_t m_data1 = 0; // pos.xy
uint32_t m_data2 = 0; // pos.z, dir.x
uint32_t m_data3 = 0; // dir.yz
uint32_t m_data4 = 0; // col.rgb (8bit), shadowType
uint32_t m_data5 = 0; // intensity, cutoff (8bit), shadowMapIndex (8bit)
GLuint64 m_ssShadowTextureHandle = 0;
GLuint64 m_ssShadowImageHandle = 0;
......@@ -147,10 +147,15 @@ public:
glm::vec3 direction = glm::vec3(0.0f), float cutoff = 0.f);
/**
* @breif Sets the site of the screen space shadow texture (i.e. the viewport dimensions).
* @brief Sets the site of the screen space shadow texture (i.e. the viewport dimensions).
*/
void setSsShadowTextureSize(glm::ivec2 size);
/**
* @brief Clears the associated screen space shadow texture to 1.f.
*/
void clearSsShadowTexture();
protected:
Texture m_ssShadowTexture;
};
......
......@@ -393,6 +393,16 @@ void Renderer::render(const glm::mat4& view, const glm::mat4& projection)
m_smBuffer.assign(shadowMaps);
m_smBuffer.bind(GL_SHADER_STORAGE_BUFFER, SM_STORAGE_BINDING);
/* Clear screen space shadow textures */
/* for(auto& l : m_lights)
{
if(l.second->shadowType() == ShadowType::SHADOWMAP_SHADOW ||
l.second->shadowType() == ShadowType::TRACED_SHADOW)
{
std::static_pointer_cast<TracedLight>(l.second)->clearSsShadowTexture();
}
} */
// render scene
glCullFace(GL_FRONT);
m_program.use();
......@@ -646,7 +656,7 @@ uint32_t Renderer::addRenderLayer(RenderLayer::Type type)
GL_VERTEX_SHADER, dino::ShaderFile::load("screenFilling.vert"));
m_invalidRenderables = true;
return m_renderLayers.size() - 2;
return m_renderLayers.size() - 2;
}
void Renderer::removeRenderLayer(int layerIndex)
......
Subproject commit da1805f3c0542d6c584eddf627b2ebc34d2ce64d
Subproject commit ef594607829ad6ed2bd462a0ddcbb0ee698b3f4f
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment