Graphics: Add shadow mapping
Former-commit-id: ca404bee246991eab98df35396e3010ec5165c43
This commit is contained in:
@@ -68,6 +68,7 @@ class NAZARA_GRAPHICS_API NzAbstractRenderQueue
|
||||
{
|
||||
NzColor color;
|
||||
NzVector3f position;
|
||||
NzTexture* shadowMap;
|
||||
float ambientFactor;
|
||||
float attenuation;
|
||||
float diffuseFactor;
|
||||
@@ -78,8 +79,10 @@ class NAZARA_GRAPHICS_API NzAbstractRenderQueue
|
||||
struct SpotLight
|
||||
{
|
||||
NzColor color;
|
||||
NzMatrix4f transformMatrix;
|
||||
NzVector3f direction;
|
||||
NzVector3f position;
|
||||
NzTexture* shadowMap;
|
||||
float ambientFactor;
|
||||
float attenuation;
|
||||
float diffuseFactor;
|
||||
|
||||
@@ -33,7 +33,7 @@ class NAZARA_GRAPHICS_API NzForwardRenderTechnique : public NzAbstractRenderTech
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
protected:
|
||||
struct ShaderUniforms;
|
||||
|
||||
void ChooseLights(const NzSpheref& object, bool includeDirectionalLights = true) const;
|
||||
@@ -43,7 +43,7 @@ class NAZARA_GRAPHICS_API NzForwardRenderTechnique : public NzAbstractRenderTech
|
||||
void DrawTransparentModels(const NzSceneData& sceneData) const;
|
||||
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
|
||||
void OnShaderInvalidated(const NzShader* shader) const;
|
||||
void SendLightUniforms(const NzShader* shader, const NzLightUniforms& uniforms, unsigned int index, unsigned int uniformOffset) const;
|
||||
void SendLightUniforms(const NzShader* shader, const NzLightUniforms& uniforms, unsigned int index, unsigned int uniformOffset, nzUInt8 availableTextureUnit) const;
|
||||
|
||||
static float ComputeDirectionalLightScore(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light);
|
||||
static float ComputePointLightScore(const NzSpheref& object, const NzAbstractRenderQueue::PointLight& light);
|
||||
@@ -86,6 +86,7 @@ class NAZARA_GRAPHICS_API NzForwardRenderTechnique : public NzAbstractRenderTech
|
||||
unsigned int m_maxLightPassPerObject;
|
||||
|
||||
static NzIndexBuffer s_quadIndexBuffer;
|
||||
static NzTextureSampler s_shadowSampler;
|
||||
static NzVertexBuffer s_quadVertexBuffer;
|
||||
static NzVertexDeclaration s_billboardInstanceDeclaration;
|
||||
static NzVertexDeclaration s_billboardVertexDeclaration;
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
inline void NzForwardRenderTechnique::SendLightUniforms(const NzShader* shader, const NzLightUniforms& uniforms, unsigned int index, unsigned int uniformOffset) const
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
|
||||
inline void NzForwardRenderTechnique::SendLightUniforms(const NzShader* shader, const NzLightUniforms& uniforms, unsigned int index, unsigned int uniformOffset, nzUInt8 availableTextureUnit) const
|
||||
{
|
||||
// If anyone got a better idea..
|
||||
int dummyCubemap = NzRenderer::GetMaxTextureUnits() - 1;
|
||||
int dummyTexture = NzRenderer::GetMaxTextureUnits() - 2;
|
||||
|
||||
if (index < m_lights.size())
|
||||
{
|
||||
const LightIndex& lightIndex = m_lights[index];
|
||||
@@ -30,6 +36,19 @@ inline void NzForwardRenderTechnique::SendLightUniforms(const NzShader* shader,
|
||||
shader->SendVector(uniforms.locations.factors + uniformOffset, NzVector2f(light.ambientFactor, light.diffuseFactor));
|
||||
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, NzVector4f(light.position, light.attenuation));
|
||||
shader->SendVector(uniforms.locations.parameters2 + uniformOffset, NzVector4f(0.f, 0.f, 0.f, light.invRadius));
|
||||
|
||||
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
|
||||
if (light.shadowMap)
|
||||
{
|
||||
NzRenderer::SetTexture(availableTextureUnit, light.shadowMap);
|
||||
NzRenderer::SetTextureSampler(availableTextureUnit, s_shadowSampler);
|
||||
|
||||
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, availableTextureUnit);
|
||||
}
|
||||
else
|
||||
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, dummyCubemap);
|
||||
|
||||
shader->SendInteger(uniforms.locations.spotLightShadowMap + index, dummyTexture);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,12 +61,30 @@ inline void NzForwardRenderTechnique::SendLightUniforms(const NzShader* shader,
|
||||
shader->SendVector(uniforms.locations.parameters1 + uniformOffset, NzVector4f(light.position, light.attenuation));
|
||||
shader->SendVector(uniforms.locations.parameters2 + uniformOffset, NzVector4f(light.direction, light.invRadius));
|
||||
shader->SendVector(uniforms.locations.parameters3 + uniformOffset, NzVector2f(light.innerAngleCosine, light.outerAngleCosine));
|
||||
|
||||
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
|
||||
if (light.shadowMap)
|
||||
{
|
||||
NzRenderer::SetTexture(availableTextureUnit, light.shadowMap);
|
||||
NzRenderer::SetTextureSampler(availableTextureUnit, s_shadowSampler);
|
||||
|
||||
shader->SendMatrix(uniforms.locations.lightViewProjMatrix + index, light.transformMatrix);
|
||||
shader->SendInteger(uniforms.locations.spotLightShadowMap + index, availableTextureUnit);
|
||||
}
|
||||
else
|
||||
shader->SendInteger(uniforms.locations.spotLightShadowMap + index, dummyTexture);
|
||||
|
||||
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, dummyCubemap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shader->SendInteger(uniforms.locations.type + uniformOffset, -1); //< Disable the light in the shader
|
||||
shader->SendInteger(uniforms.locations.pointLightShadowMap + index, dummyCubemap);
|
||||
shader->SendInteger(uniforms.locations.spotLightShadowMap + index, dummyTexture);
|
||||
}
|
||||
}
|
||||
|
||||
inline float NzForwardRenderTechnique::ComputeDirectionalLightScore(const NzSpheref& object, const NzAbstractRenderQueue::DirectionalLight& light)
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
|
||||
class NzLight;
|
||||
struct NzLightUniforms;
|
||||
|
||||
class NAZARA_GRAPHICS_API NzLight : public NzRenderable
|
||||
{
|
||||
public:
|
||||
@@ -101,9 +98,13 @@ struct NzLightUniforms
|
||||
int type;
|
||||
int color;
|
||||
int factors;
|
||||
int lightViewProjMatrix;
|
||||
int parameters1;
|
||||
int parameters2;
|
||||
int parameters3;
|
||||
int pointLightShadowMap;
|
||||
int shadowMapping;
|
||||
int spotLightShadowMap;
|
||||
};
|
||||
|
||||
bool ubo;
|
||||
|
||||
Reference in New Issue
Block a user