Deferred Shading update

-Deferred Shading now use a dynamics pass system
-Forward Shading is now capable of rendering more than three lights
(Multipass)


Former-commit-id: 74ed0b998d72aa9eb3bd2aab938a75985ebb2bf6
This commit is contained in:
Lynix
2013-12-28 10:22:03 +01:00
parent 6568cc7995
commit a332579c80
31 changed files with 2431 additions and 1354 deletions

View File

@@ -22,8 +22,8 @@ class NAZARA_API NzAbstractRenderTechnique : NzNonCopyable
NzAbstractRenderTechnique();
virtual ~NzAbstractRenderTechnique();
virtual void Clear(const NzScene* scene) = 0;
virtual bool Draw(const NzScene* scene) = 0;
virtual void Clear(const NzScene* scene) const = 0;
virtual bool Draw(const NzScene* scene) const = 0;
virtual void EnableInstancing(bool instancing);

View File

@@ -0,0 +1,54 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDBLOOMPASS_HPP
#define NAZARA_DEFERREDBLOOMPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
class NAZARA_API NzDeferredBloomPass : public NzDeferredRenderPass
{
public:
NzDeferredBloomPass();
virtual ~NzDeferredBloomPass();
unsigned int GetBlurPassCount() const;
float GetBrightLuminance() const;
float GetBrightMiddleGrey() const;
float GetBrightThreshold() const;
NzTexture* GetTexture(unsigned int i) const;
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
bool Resize(const NzVector2ui& dimensions);
void SetBlurPassCount(unsigned int passCount);
void SetBrightLuminance(float luminance);
void SetBrightMiddleGrey(float middleGrey);
void SetBrightThreshold(float threshold);
protected:
NzRenderStates m_bloomStates;
NzRenderTexture m_bloomRTT;
NzShaderProgramRef m_bloomBrightProgram;
NzShaderProgramRef m_bloomFinalProgram;
NzShaderProgramRef m_gaussianBlurProgram;
NzTextureRef m_bloomTextures[2];
NzTextureSampler m_bilinearSampler;
mutable bool m_uniformUpdated;
float m_brightLuminance;
float m_brightMiddleGrey;
float m_brightThreshold;
int m_gaussianBlurProgramFilterLocation;
unsigned int m_blurPassCount;
};
#endif // NAZARA_DEFERREDBLOOMPASS_HPP

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDDOFPASS_HPP
#define NAZARA_DEFERREDDOFPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
class NAZARA_API NzDeferredDOFPass : public NzDeferredRenderPass
{
public:
NzDeferredDOFPass();
virtual ~NzDeferredDOFPass();
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
bool Resize(const NzVector2ui& dimensions);
protected:
NzRenderTexture m_dofRTT;
NzRenderStates m_states;
NzShaderProgramRef m_blurProgram;
NzShaderProgramRef m_dofProgram;
NzTextureRef m_dofTextures[2];
NzTextureSampler m_bilinearSampler;
NzTextureSampler m_pointSampler;
int m_blurProgramFilterLocation;
};
#endif // NAZARA_DEFERREDDOFPASS_HPP

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDFXAAPASS_HPP
#define NAZARA_DEFERREDFXAAPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
class NAZARA_API NzDeferredFXAAPass : public NzDeferredRenderPass
{
public:
NzDeferredFXAAPass();
virtual ~NzDeferredFXAAPass();
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
protected:
NzRenderStates m_states;
NzShaderProgramRef m_fxaaProgram;
NzTextureSampler m_pointSampler;
};
#endif // NAZARA_DEFERREDFXAAPASS_HPP

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDFINALPASS_HPP
#define NAZARA_DEFERREDFINALPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
class NAZARA_API NzDeferredFinalPass : public NzDeferredRenderPass
{
public:
NzDeferredFinalPass();
virtual ~NzDeferredFinalPass();
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
protected:
NzRenderStates m_states;
NzShaderProgramRef m_program;
NzTextureSampler m_pointSampler;
};
#endif // NAZARA_DEFERREDFINALPASS_HPP

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDFOGPASS_HPP
#define NAZARA_DEFERREDFOGPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
class NAZARA_API NzDeferredFogPass : public NzDeferredRenderPass
{
public:
NzDeferredFogPass();
virtual ~NzDeferredFogPass();
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
protected:
NzRenderStates m_states;
NzShaderProgramRef m_program;
NzTextureSampler m_pointSampler;
};
#endif // NAZARA_DEFERREDFOGPASS_HPP

View File

@@ -0,0 +1,28 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDFORWARDPASS_HPP
#define NAZARA_DEFERREDFORWARDPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
class NzForwardRenderTechnique;
class NAZARA_API NzDeferredForwardPass : public NzDeferredRenderPass
{
public:
NzDeferredForwardPass();
virtual ~NzDeferredForwardPass();
void Initialize(NzDeferredRenderTechnique* technique);
bool Process(const NzScene* scene, unsigned int workTexture, unsigned sceneTexture) const;
protected:
const NzForwardRenderTechnique* m_forwardTechnique;
};
#endif // NAZARA_DEFERREDFORWARDPASS_HPP

View File

@@ -0,0 +1,29 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDGEOMETRYPASS_HPP
#define NAZARA_DEFERREDGEOMETRYPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
class NAZARA_API NzDeferredGeometryPass : public NzDeferredRenderPass
{
public:
NzDeferredGeometryPass();
virtual ~NzDeferredGeometryPass();
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
bool Resize(const NzVector2ui& dimensions);
protected:
NzRenderStates m_clearStates;
NzShaderProgramRef m_clearProgram;
};
#endif // NAZARA_DEFERREDGEOMETRYPASS_HPP

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP
#define NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
#include <Nazara/Utility/Mesh.hpp>
class NzStaticMesh;
class NAZARA_API NzDeferredPhongLightingPass : public NzDeferredRenderPass
{
public:
NzDeferredPhongLightingPass();
virtual ~NzDeferredPhongLightingPass();
void EnableLightMeshesDrawing(bool enable);
bool IsLightMeshesDrawingEnabled() const;
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
protected:
NzMeshRef m_cone;
NzMeshRef m_sphere;
NzShaderProgramRef m_directionalLightProgram;
NzShaderProgramRef m_pointLightProgram;
NzShaderProgramRef m_spotLightProgram;
NzTextureSampler m_pointSampler;
NzStaticMesh* m_coneMesh;
NzStaticMesh* m_sphereMesh;
bool m_lightMeshesDrawing;
};
#endif // NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP

View File

@@ -0,0 +1,52 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEFERREDRENDERPASS_HPP
#define NAZARA_DEFERREDRENDERPASS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Math/Vector2.hpp>
class NzDeferredRenderTechnique;
class NzDeferredRenderQueue;
class NzRenderBuffer;
class NzRenderTexture;
class NzScene;
class NzTexture;
class NAZARA_API NzDeferredRenderPass
{
friend NzDeferredRenderTechnique;
public:
NzDeferredRenderPass();
virtual ~NzDeferredRenderPass();
void Enable(bool enable);
virtual void Initialize(NzDeferredRenderTechnique* technique);
bool IsEnabled() const;
virtual bool Process(const NzScene* scene, unsigned int workTexture, unsigned sceneTexture) const = 0;
virtual bool Resize(const NzVector2ui& GBufferSize);
protected:
NzVector2ui m_dimensions;
NzDeferredRenderTechnique* m_deferredTechnique;
NzDeferredRenderQueue* m_renderQueue;
NzRenderBuffer* m_depthStencilBuffer;
NzRenderTexture* m_GBufferRTT;
NzRenderTexture* m_workRTT;
NzTexture* m_GBuffer[4];
NzTexture* m_workTextures[2];
private:
bool m_enabled;
};
#endif // NAZARA_DEFERREDRENDERPASS_HPP

View File

@@ -23,8 +23,6 @@ class NzStaticMesh;
class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourceListener
{
friend class NzDeferredRenderTechnique;
public:
NzDeferredRenderQueue(NzForwardRenderQueue* forwardQueue);
~NzDeferredRenderQueue();
@@ -37,10 +35,6 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourc
void Clear(bool fully);
private:
bool OnResourceDestroy(const NzResource* resource, int index) override;
void OnResourceReleased(const NzResource* resource, int index) override;
struct SkeletalData
{
///TODO
@@ -84,6 +78,10 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourc
LightContainer pointLights;
LightContainer spotLights;
NzForwardRenderQueue* m_forwardQueue;
private:
bool OnResourceDestroy(const NzResource* resource, int index) override;
void OnResourceReleased(const NzResource* resource, int index) override;
};
#endif // NAZARA_DEFERREDRENDERQUEUE_HPP

View File

@@ -9,15 +9,19 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
#include <Nazara/Graphics/DeferredRenderPass.hpp>
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Renderer/RenderBuffer.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <map>
#include <memory>
class NAZARA_API NzDeferredRenderTechnique : public NzAbstractRenderTechnique, public NzRenderTarget::Listener
{
@@ -25,61 +29,47 @@ class NAZARA_API NzDeferredRenderTechnique : public NzAbstractRenderTechnique, p
NzDeferredRenderTechnique();
~NzDeferredRenderTechnique();
void Clear(const NzScene* scene);
bool Draw(const NzScene* scene);
void Clear(const NzScene* scene) const;
bool Draw(const NzScene* scene) const;
void EnablePass(nzRenderPassType renderPass, int position, bool enable);
NzRenderBuffer* GetDepthStencilBuffer() const;
NzTexture* GetGBuffer(unsigned int i) const;
NzRenderTexture* GetGBufferRTT() const;
const NzForwardRenderTechnique* GetForwardTechnique() const;
NzDeferredRenderPass* GetPass(nzRenderPassType renderPass, int position = 0);
NzAbstractRenderQueue* GetRenderQueue() override;
nzRenderTechniqueType GetType() const override;
NzRenderTexture* GetWorkRTT() const;
NzTexture* GetWorkTexture(unsigned int i) const;
bool IsPassEnabled(nzRenderPassType renderPass, int position);
NzDeferredRenderPass* ResetPass(nzRenderPassType renderPass, int position);
void SetPass(nzRenderPassType relativeTo, int position, NzDeferredRenderPass* pass);
static bool IsSupported();
private:
void GeomPass(const NzScene* scene);
void DirectionalLightPass(const NzScene* scene);
void PointLightPass(const NzScene* scene);
void SpotLightPass(const NzScene* scene);
bool UpdateTextures() const;
bool Resize(const NzVector2ui& dimensions) const;
struct RenderPassComparator
{
bool operator()(nzRenderPassType pass1, nzRenderPassType pass2);
};
std::map<nzRenderPassType, std::map<int, std::unique_ptr<NzDeferredRenderPass>>, RenderPassComparator> m_passes;
NzForwardRenderTechnique m_forwardTechnique; // Doit être initialisé avant la RenderQueue
NzDeferredRenderQueue m_renderQueue;
NzMeshRef m_sphere;
NzStaticMesh* m_sphereMesh;
mutable NzRenderTexture m_bloomRTT;
mutable NzRenderTexture m_dofRTT;
mutable NzRenderTexture m_geometryRTT;
mutable NzRenderTexture m_ssaoRTT;
NzRenderStates m_clearStates;
NzShaderProgramRef m_aaProgram;
NzShaderProgramRef m_blitProgram;
NzShaderProgramRef m_bloomBrightProgram;
NzShaderProgramRef m_bloomFinalProgram;
NzShaderProgramRef m_clearProgram;
NzShaderProgramRef m_directionalLightProgram;
NzShaderProgramRef m_depthOfFieldProgram;
NzShaderProgramRef m_gaussianBlurProgram;
NzShaderProgramRef m_pointLightProgram;
NzShaderProgramRef m_ssaoProgram;
NzShaderProgramRef m_ssaoFinalProgram;
NzShaderProgramRef m_spotLightProgram;
mutable NzTextureRef m_bloomTextureA;
mutable NzTextureRef m_bloomTextureB;
mutable NzTextureRef m_dofTextureA;
mutable NzTextureRef m_dofTextureB;
mutable NzRenderBufferRef m_depthStencilBuffer;
mutable NzRenderTexture m_GBufferRTT;
mutable NzRenderTexture m_workRTT;
mutable NzTextureRef m_GBuffer[4];
mutable NzTextureRef m_ssaoTextureA;
mutable NzTextureRef m_ssaoTextureB;
mutable NzTextureRef m_ssaoNoiseTexture;
mutable NzTextureRef m_workTextureA;
mutable NzTextureRef m_workTextureB;
NzTextureSampler m_bilinearSampler;
NzTextureSampler m_pointSampler;
NzTextureSampler m_ssaoSampler;
NzVector2ui m_GBufferSize;
mutable NzTextureRef m_workTextures[2];
mutable NzVector2ui m_GBufferSize;
const NzRenderTarget* m_viewerTarget;
mutable bool m_texturesUpdated;
int m_gaussianBlurProgramFilterLocation;
};
#endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP

View File

@@ -26,6 +26,21 @@ enum nzLightType
nzLightType_Max = nzLightType_Spot
};
enum nzRenderPassType
{
nzRenderPassType_AA,
nzRenderPassType_Bloom,
nzRenderPassType_DOF,
nzRenderPassType_Final,
nzRenderPassType_Fog,
nzRenderPassType_Forward,
nzRenderPassType_Lighting,
nzRenderPassType_Geometry,
nzRenderPassType_SSAO,
nzRenderPassType_Max = nzRenderPassType_SSAO
};
enum nzRenderTechniqueType
{
nzRenderTechniqueType_AdvancedForward, // NzAdvancedForwardRenderTechnique

View File

@@ -20,26 +20,26 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
NzForwardRenderTechnique();
~NzForwardRenderTechnique();
void Clear(const NzScene* scene);
bool Draw(const NzScene* scene);
void Clear(const NzScene* scene) const;
bool Draw(const NzScene* scene) const;
unsigned int GetMaxLightsPerObject() const;
unsigned int GetMaxLightPassPerObject() const;
NzAbstractRenderQueue* GetRenderQueue() override;
nzRenderTechniqueType GetType() const override;
void SetMaxLightsPerObject(unsigned int lightCount);
void SetMaxLightPassPerObject(unsigned int passCount);
private:
void DrawOpaqueModels(const NzScene* scene);
void DrawSprites(const NzScene* scene);
void DrawTransparentModels(const NzScene* scene);
void DrawOpaqueModels(const NzScene* scene) const;
void DrawSprites(const NzScene* scene) const;
void DrawTransparentModels(const NzScene* scene) const;
NzForwardRenderQueue m_renderQueue;
mutable NzForwardRenderQueue m_renderQueue;
NzIndexBufferRef m_indexBuffer;
NzLightManager m_directionalLights;
NzLightManager m_lights;
mutable NzLightManager m_directionalLights;
mutable NzLightManager m_lights;
NzVertexBuffer m_spriteBuffer;
unsigned int m_maxLightsPerObject;
unsigned int m_maxLightPassPerObject;
};
#endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP