Big UberShader update
-Added GRAPHICS_MAX_LIGHTPERPASS macro -Added glGetActiveUniform OpenGL function -Added (Uber)ShaderLibrary -Added (Uber)ShaderName parameter to models -Changed uniform system -Fixed Node copying -Moved Material class to Graphics module -Optimized lights -Remade Shader class -Renamed Node::Invalidate to Node::InvalidateNode -Renamed ShaderProgram to Shader Former-commit-id: 15f0cad52969e91a2442e7d750ba2dc412f3549d
This commit is contained in:
parent
4ee2ceaef0
commit
86bdab9055
|
|
@ -337,6 +337,9 @@ int main()
|
||||||
// Pour terminer, il y a l'affichage en lui-même, de façon organisée et optimisée (Batching)
|
// Pour terminer, il y a l'affichage en lui-même, de façon organisée et optimisée (Batching)
|
||||||
scene.Draw();
|
scene.Draw();
|
||||||
|
|
||||||
|
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Identity());
|
||||||
|
NzDebugDrawer::Draw(spaceship.GetBoundingVolume().aabb);
|
||||||
|
|
||||||
// Après avoir dessiné sur la fenêtre, il faut s'assurer qu'elle affiche cela
|
// Après avoir dessiné sur la fenêtre, il faut s'assurer qu'elle affiche cela
|
||||||
// Cet appel ne fait rien d'autre qu'échanger les buffers de rendu (Double Buffering)
|
// Cet appel ne fait rien d'autre qu'échanger les buffers de rendu (Double Buffering)
|
||||||
window.Display();
|
window.Display();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Audio module
|
Nazara Engine - Audio module
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Core module
|
Nazara Engine - Core module
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <Nazara/Core/AbstractHash.hpp>
|
#include <Nazara/Core/AbstractHash.hpp>
|
||||||
#include <Nazara/Core/ByteArray.hpp>
|
#include <Nazara/Core/ByteArray.hpp>
|
||||||
|
#include <Nazara/Core/CallOnExit.hpp>
|
||||||
#include <Nazara/Core/Clock.hpp>
|
#include <Nazara/Core/Clock.hpp>
|
||||||
#include <Nazara/Core/Color.hpp>
|
#include <Nazara/Core/Color.hpp>
|
||||||
#include <Nazara/Core/ConditionVariable.hpp>
|
#include <Nazara/Core/ConditionVariable.hpp>
|
||||||
|
|
@ -56,6 +57,7 @@
|
||||||
#include <Nazara/Core/MemoryStream.hpp>
|
#include <Nazara/Core/MemoryStream.hpp>
|
||||||
#include <Nazara/Core/Mutex.hpp>
|
#include <Nazara/Core/Mutex.hpp>
|
||||||
#include <Nazara/Core/NonCopyable.hpp>
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
|
#include <Nazara/Core/ParameterList.hpp>
|
||||||
#include <Nazara/Core/PluginManager.hpp>
|
#include <Nazara/Core/PluginManager.hpp>
|
||||||
#include <Nazara/Core/Primitive.hpp>
|
#include <Nazara/Core/Primitive.hpp>
|
||||||
#include <Nazara/Core/PrimitiveList.hpp>
|
#include <Nazara/Core/PrimitiveList.hpp>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Graphics module
|
Nazara Engine - Graphics module
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
#include <Nazara/Graphics/Graphics.hpp>
|
#include <Nazara/Graphics/Graphics.hpp>
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
#include <Nazara/Graphics/LightManager.hpp>
|
#include <Nazara/Graphics/LightManager.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/Model.hpp>
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||||
#include <Nazara/Graphics/Scene.hpp>
|
#include <Nazara/Graphics/Scene.hpp>
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class NAZARA_API NzCamera : public NzAbstractViewer, public NzNode, NzRenderTarg
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ApplyView() const override;
|
void ApplyView() const override;
|
||||||
void Invalidate() override;
|
void InvalidateNode() override;
|
||||||
|
|
||||||
void OnRenderTargetReleased(const NzRenderTarget* renderTarget, void* userdata) override;
|
void OnRenderTargetReleased(const NzRenderTarget* renderTarget, void* userdata) override;
|
||||||
bool OnRenderTargetSizeChange(const NzRenderTarget* renderTarget, void* userdata) override;
|
bool OnRenderTargetSizeChange(const NzRenderTarget* renderTarget, void* userdata) override;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Color.hpp>
|
#include <Nazara/Core/Color.hpp>
|
||||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/UberShader.hpp>
|
||||||
|
|
||||||
class NAZARA_API NzColorBackground : public NzAbstractBackground
|
class NAZARA_API NzColorBackground : public NzAbstractBackground
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +26,10 @@ class NAZARA_API NzColorBackground : public NzAbstractBackground
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NzColor m_color;
|
NzColor m_color;
|
||||||
NzShaderProgramConstRef m_program;
|
NzUberShaderConstRef m_uberShader;
|
||||||
|
const NzUberShaderInstance* m_uberShaderInstance;
|
||||||
|
int m_materialDiffuseUniform;
|
||||||
|
int m_vertexDepthUniform;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_COLORBACKGROUND_HPP
|
#endif // NAZARA_COLORBACKGROUND_HPP
|
||||||
|
|
|
||||||
|
|
@ -38,4 +38,7 @@
|
||||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||||
#define NAZARA_GRAPHICS_SAFE 1
|
#define NAZARA_GRAPHICS_SAFE 1
|
||||||
|
|
||||||
|
// Le nombre maximum de lumières qu'un shader standard supportera
|
||||||
|
#define NAZARA_GRAPHICS_MAX_LIGHTPERPASS 3U // Unsigned
|
||||||
|
|
||||||
#endif // NAZARA_CONFIG_GRAPHICS_HPP
|
#endif // NAZARA_CONFIG_GRAPHICS_HPP
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||||
#include <Nazara/Renderer/RenderStates.hpp>
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
|
|
||||||
|
|
@ -38,16 +38,16 @@ class NAZARA_API NzDeferredBloomPass : public NzDeferredRenderPass
|
||||||
protected:
|
protected:
|
||||||
NzRenderStates m_bloomStates;
|
NzRenderStates m_bloomStates;
|
||||||
NzRenderTexture m_bloomRTT;
|
NzRenderTexture m_bloomRTT;
|
||||||
NzShaderProgramRef m_bloomBrightProgram;
|
NzShaderRef m_bloomBrightShader;
|
||||||
NzShaderProgramRef m_bloomFinalProgram;
|
NzShaderRef m_bloomFinalShader;
|
||||||
NzShaderProgramRef m_gaussianBlurProgram;
|
NzShaderRef m_gaussianBlurShader;
|
||||||
NzTextureRef m_bloomTextures[2];
|
NzTextureRef m_bloomTextures[2];
|
||||||
NzTextureSampler m_bilinearSampler;
|
NzTextureSampler m_bilinearSampler;
|
||||||
mutable bool m_uniformUpdated;
|
mutable bool m_uniformUpdated;
|
||||||
float m_brightLuminance;
|
float m_brightLuminance;
|
||||||
float m_brightMiddleGrey;
|
float m_brightMiddleGrey;
|
||||||
float m_brightThreshold;
|
float m_brightThreshold;
|
||||||
int m_gaussianBlurProgramFilterLocation;
|
int m_gaussianBlurShaderFilterLocation;
|
||||||
unsigned int m_blurPassCount;
|
unsigned int m_blurPassCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||||
#include <Nazara/Renderer/RenderStates.hpp>
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
|
|
||||||
|
|
@ -27,12 +27,12 @@ class NAZARA_API NzDeferredDOFPass : public NzDeferredRenderPass
|
||||||
protected:
|
protected:
|
||||||
NzRenderTexture m_dofRTT;
|
NzRenderTexture m_dofRTT;
|
||||||
NzRenderStates m_states;
|
NzRenderStates m_states;
|
||||||
NzShaderProgramRef m_blurProgram;
|
NzShaderConstRef m_dofShader;
|
||||||
NzShaderProgramRef m_dofProgram;
|
NzShaderConstRef m_gaussianBlurShader;
|
||||||
NzTextureRef m_dofTextures[2];
|
NzTextureRef m_dofTextures[2];
|
||||||
NzTextureSampler m_bilinearSampler;
|
NzTextureSampler m_bilinearSampler;
|
||||||
NzTextureSampler m_pointSampler;
|
NzTextureSampler m_pointSampler;
|
||||||
int m_blurProgramFilterLocation;
|
int m_gaussianBlurShaderFilterLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_DEFERREDDOFPASS_HPP
|
#endif // NAZARA_DEFERREDDOFPASS_HPP
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||||
#include <Nazara/Renderer/RenderStates.hpp>
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
|
|
||||||
class NAZARA_API NzDeferredFXAAPass : public NzDeferredRenderPass
|
class NAZARA_API NzDeferredFXAAPass : public NzDeferredRenderPass
|
||||||
|
|
@ -23,7 +23,7 @@ class NAZARA_API NzDeferredFXAAPass : public NzDeferredRenderPass
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NzRenderStates m_states;
|
NzRenderStates m_states;
|
||||||
NzShaderProgramRef m_fxaaProgram;
|
NzShaderRef m_fxaaShader;
|
||||||
NzTextureSampler m_pointSampler;
|
NzTextureSampler m_pointSampler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||||
#include <Nazara/Renderer/RenderStates.hpp>
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShader.hpp>
|
||||||
|
|
||||||
class NAZARA_API NzDeferredFinalPass : public NzDeferredRenderPass
|
class NAZARA_API NzDeferredFinalPass : public NzDeferredRenderPass
|
||||||
{
|
{
|
||||||
|
|
@ -23,8 +23,11 @@ class NAZARA_API NzDeferredFinalPass : public NzDeferredRenderPass
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NzRenderStates m_states;
|
NzRenderStates m_states;
|
||||||
NzShaderProgramRef m_program;
|
|
||||||
NzTextureSampler m_pointSampler;
|
NzTextureSampler m_pointSampler;
|
||||||
|
NzUberShaderConstRef m_uberShader;
|
||||||
|
const NzUberShaderInstance* m_uberShaderInstance;
|
||||||
|
int m_materialDiffuseUniform;
|
||||||
|
int m_materialDiffuseMapUniform;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_DEFERREDFINALPASS_HPP
|
#endif // NAZARA_DEFERREDFINALPASS_HPP
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||||
#include <Nazara/Renderer/RenderStates.hpp>
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
|
|
||||||
class NAZARA_API NzDeferredFogPass : public NzDeferredRenderPass
|
class NAZARA_API NzDeferredFogPass : public NzDeferredRenderPass
|
||||||
|
|
@ -23,7 +23,7 @@ class NAZARA_API NzDeferredFogPass : public NzDeferredRenderPass
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NzRenderStates m_states;
|
NzRenderStates m_states;
|
||||||
NzShaderProgramRef m_program;
|
NzShaderRef m_shader;
|
||||||
NzTextureSampler m_pointSampler;
|
NzTextureSampler m_pointSampler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||||
#include <Nazara/Renderer/RenderStates.hpp>
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
|
|
||||||
class NAZARA_API NzDeferredGeometryPass : public NzDeferredRenderPass
|
class NAZARA_API NzDeferredGeometryPass : public NzDeferredRenderPass
|
||||||
{
|
{
|
||||||
|
|
@ -23,7 +23,7 @@ class NAZARA_API NzDeferredGeometryPass : public NzDeferredRenderPass
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NzRenderStates m_clearStates;
|
NzRenderStates m_clearStates;
|
||||||
NzShaderProgramRef m_clearProgram;
|
NzShaderRef m_clearShader;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_DEFERREDGEOMETRYPASS_HPP
|
#endif // NAZARA_DEFERREDGEOMETRYPASS_HPP
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
#include <Nazara/Graphics/DeferredRenderPass.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
#include <Nazara/Utility/Mesh.hpp>
|
#include <Nazara/Utility/Mesh.hpp>
|
||||||
|
|
||||||
|
|
@ -28,16 +29,17 @@ class NAZARA_API NzDeferredPhongLightingPass : public NzDeferredRenderPass
|
||||||
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
bool Process(const NzScene* scene, unsigned int firstWorkTexture, unsigned secondWorkTexture) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
NzLightUniforms m_directionalLightUniforms;
|
||||||
|
NzLightUniforms m_pointSpotLightUniforms;
|
||||||
NzMeshRef m_cone;
|
NzMeshRef m_cone;
|
||||||
NzMeshRef m_sphere;
|
NzMeshRef m_sphere;
|
||||||
NzShaderProgramRef m_directionalLightProgram;
|
NzShaderRef m_directionalLightShader;
|
||||||
NzShaderProgramRef m_pointSpotLightProgram;
|
NzShaderRef m_pointSpotLightShader;
|
||||||
NzTextureSampler m_pointSampler;
|
NzTextureSampler m_pointSampler;
|
||||||
NzStaticMesh* m_coneMesh;
|
NzStaticMesh* m_coneMesh;
|
||||||
NzStaticMesh* m_sphereMesh;
|
NzStaticMesh* m_sphereMesh;
|
||||||
bool m_lightMeshesDrawing;
|
bool m_lightMeshesDrawing;
|
||||||
int m_pointSpotLightProgramDiscardLocation;
|
int m_pointSpotLightShaderDiscardLocation;
|
||||||
int m_pointSpotLightProgramSpotLightLocation;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP
|
#endif // NAZARA_DEFERREDPHONGLIGHTINGPASS_HPP
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
#include <Nazara/Renderer/RenderBuffer.hpp>
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <Nazara/Renderer/RenderStates.hpp>
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
#include <Nazara/Utility/Mesh.hpp>
|
#include <Nazara/Utility/Mesh.hpp>
|
||||||
|
|
@ -50,7 +49,9 @@ class NAZARA_API NzDeferredRenderTechnique : public NzAbstractRenderTechnique, p
|
||||||
|
|
||||||
void SetPass(nzRenderPassType relativeTo, int position, NzDeferredRenderPass* pass);
|
void SetPass(nzRenderPassType relativeTo, int position, NzDeferredRenderPass* pass);
|
||||||
|
|
||||||
|
static bool Initialize();
|
||||||
static bool IsSupported();
|
static bool IsSupported();
|
||||||
|
static void Uninitialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Resize(const NzVector2ui& dimensions) const;
|
bool Resize(const NzVector2ui& dimensions) const;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,23 @@ enum nzLightType
|
||||||
nzLightType_Max = nzLightType_Spot
|
nzLightType_Max = nzLightType_Spot
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum nzMaterialUniform
|
||||||
|
{
|
||||||
|
nzMaterialUniform_AlphaMap,
|
||||||
|
nzMaterialUniform_AlphaThreshold,
|
||||||
|
nzMaterialUniform_Ambient,
|
||||||
|
nzMaterialUniform_Diffuse,
|
||||||
|
nzMaterialUniform_DiffuseMap,
|
||||||
|
nzMaterialUniform_EmissiveMap,
|
||||||
|
nzMaterialUniform_HeightMap,
|
||||||
|
nzMaterialUniform_NormalMap,
|
||||||
|
nzMaterialUniform_Shininess,
|
||||||
|
nzMaterialUniform_Specular,
|
||||||
|
nzMaterialUniform_SpecularMap,
|
||||||
|
|
||||||
|
nzMaterialUniform_Max = nzMaterialUniform_SpecularMap
|
||||||
|
};
|
||||||
|
|
||||||
enum nzRenderPassType
|
enum nzRenderPassType
|
||||||
{
|
{
|
||||||
nzRenderPassType_AA,
|
nzRenderPassType_AA,
|
||||||
|
|
@ -63,4 +80,15 @@ enum nzSceneNodeType
|
||||||
nzSceneNodeType_Max = nzSceneNodeType_User
|
nzSceneNodeType_Max = nzSceneNodeType_User
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Ces paramètres sont indépendants du matériau: ils peuvent être demandés à tout moment
|
||||||
|
enum nzShaderFlags
|
||||||
|
{
|
||||||
|
nzShaderFlags_None = 0,
|
||||||
|
|
||||||
|
nzShaderFlags_Deferred = 0x1,
|
||||||
|
nzShaderFlags_Instancing = 0x2,
|
||||||
|
|
||||||
|
nzShaderFlags_Max = nzShaderFlags_Instancing*2-1
|
||||||
|
};
|
||||||
|
|
||||||
#endif // NAZARA_ENUMS_GRAPHICS_HPP
|
#endif // NAZARA_ENUMS_GRAPHICS_HPP
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,15 @@
|
||||||
#define NAZARA_FORWARDRENDERTECHNIQUE_HPP
|
#define NAZARA_FORWARDRENDERTECHNIQUE_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListener.hpp>
|
||||||
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||||
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
||||||
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
#include <Nazara/Graphics/LightManager.hpp>
|
#include <Nazara/Graphics/LightManager.hpp>
|
||||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||||
|
|
||||||
class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
|
class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique, NzResourceListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NzForwardRenderTechnique();
|
NzForwardRenderTechnique();
|
||||||
|
|
@ -30,10 +32,23 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique
|
||||||
void SetMaxLightPassPerObject(unsigned int passCount);
|
void SetMaxLightPassPerObject(unsigned int passCount);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct LightUniforms;
|
||||||
|
|
||||||
void DrawOpaqueModels(const NzScene* scene) const;
|
void DrawOpaqueModels(const NzScene* scene) const;
|
||||||
void DrawSprites(const NzScene* scene) const;
|
void DrawSprites(const NzScene* scene) const;
|
||||||
void DrawTransparentModels(const NzScene* scene) const;
|
void DrawTransparentModels(const NzScene* scene) const;
|
||||||
|
const LightUniforms* GetLightUniforms(const NzShader* shader) const;
|
||||||
|
|
||||||
|
struct LightUniforms
|
||||||
|
{
|
||||||
|
NzLightUniforms uniforms;
|
||||||
|
bool exists;
|
||||||
|
int offset; // "Distance" entre Lights[0].type et Lights[1].type
|
||||||
|
/// Moins coûteux en mémoire que de stocker un NzLightUniforms par index de lumière,
|
||||||
|
/// à voir si ça fonctionne chez tout le monde
|
||||||
|
};
|
||||||
|
|
||||||
|
mutable std::unordered_map<const NzShader*, LightUniforms> m_lightUniforms;
|
||||||
mutable NzForwardRenderQueue m_renderQueue;
|
mutable NzForwardRenderQueue m_renderQueue;
|
||||||
NzIndexBufferRef m_indexBuffer;
|
NzIndexBufferRef m_indexBuffer;
|
||||||
mutable NzLightManager m_directionalLights;
|
mutable NzLightManager m_directionalLights;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
#include <Nazara/Graphics/Enums.hpp>
|
#include <Nazara/Graphics/Enums.hpp>
|
||||||
#include <Nazara/Graphics/SceneNode.hpp>
|
#include <Nazara/Graphics/SceneNode.hpp>
|
||||||
|
|
||||||
class NzShaderProgram;
|
class NzShader;
|
||||||
|
struct NzLightUniforms;
|
||||||
|
|
||||||
class NAZARA_API NzLight : public NzSceneNode
|
class NAZARA_API NzLight : public NzSceneNode
|
||||||
{
|
{
|
||||||
|
|
@ -23,7 +24,7 @@ class NAZARA_API NzLight : public NzSceneNode
|
||||||
|
|
||||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
|
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
|
||||||
|
|
||||||
void Enable(const NzShaderProgram* program, unsigned int lightUnit) const;
|
void Enable(const NzShader* shader, const NzLightUniforms& uniforms, int offset = 0) const;
|
||||||
|
|
||||||
float GetAmbientFactor() const;
|
float GetAmbientFactor() const;
|
||||||
float GetAttenuation() const;
|
float GetAttenuation() const;
|
||||||
|
|
@ -49,11 +50,11 @@ class NAZARA_API NzLight : public NzSceneNode
|
||||||
|
|
||||||
NzLight& operator=(const NzLight& light);
|
NzLight& operator=(const NzLight& light);
|
||||||
|
|
||||||
static void Disable(const NzShaderProgram* program, unsigned int lightUnit);
|
static void Disable(const NzShader* program, const NzLightUniforms& uniforms, int offset = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool FrustumCull(const NzFrustumf& frustum) override;
|
bool FrustumCull(const NzFrustumf& frustum) override;
|
||||||
void Invalidate() override;
|
void InvalidateNode() override;
|
||||||
void Register() override;
|
void Register() override;
|
||||||
void Unregister() override;
|
void Unregister() override;
|
||||||
void UpdateBoundingVolume() const;
|
void UpdateBoundingVolume() const;
|
||||||
|
|
@ -70,4 +71,25 @@ class NAZARA_API NzLight : public NzSceneNode
|
||||||
float m_radius;
|
float m_radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NzLightUniforms
|
||||||
|
{
|
||||||
|
struct UniformLocations
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
int color;
|
||||||
|
int factors;
|
||||||
|
int parameters1;
|
||||||
|
int parameters2;
|
||||||
|
int parameters3;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ubo;
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
UniformLocations locations;
|
||||||
|
int blockLocation;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
#endif // NAZARA_LIGHT_HPP
|
#endif // NAZARA_LIGHT_HPP
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright (C) 2014 Jérôme Leclercq
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
@ -13,11 +13,11 @@
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
#include <Nazara/Graphics/Enums.hpp>
|
||||||
#include <Nazara/Renderer/RenderStates.hpp>
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShader.hpp>
|
||||||
|
|
||||||
struct NAZARA_API NzMaterialParams
|
struct NAZARA_API NzMaterialParams
|
||||||
{
|
{
|
||||||
|
|
@ -27,6 +27,7 @@ struct NAZARA_API NzMaterialParams
|
||||||
bool loadHeightMap = true;
|
bool loadHeightMap = true;
|
||||||
bool loadNormalMap = true;
|
bool loadNormalMap = true;
|
||||||
bool loadSpecularMap = true;
|
bool loadSpecularMap = true;
|
||||||
|
NzString shaderName = "Basic";
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
};
|
};
|
||||||
|
|
@ -48,11 +49,12 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
NzMaterial(NzMaterial&& material);
|
NzMaterial(NzMaterial&& material);
|
||||||
~NzMaterial();
|
~NzMaterial();
|
||||||
|
|
||||||
void Apply(const NzShaderProgram* program) const;
|
const NzShader* Apply(nzUInt32 shaderFlags = 0, nzUInt8 textureUnit = 0, nzUInt8* lastUsedUnit = nullptr) const;
|
||||||
|
|
||||||
void Enable(nzRendererParameter renderParameter, bool enable);
|
void Enable(nzRendererParameter renderParameter, bool enable);
|
||||||
void EnableAlphaTest(bool alphaTest);
|
void EnableAlphaTest(bool alphaTest);
|
||||||
void EnableLighting(bool lighting);
|
void EnableLighting(bool lighting);
|
||||||
|
void EnableTransform(bool transform);
|
||||||
|
|
||||||
NzTexture* GetAlphaMap() const;
|
NzTexture* GetAlphaMap() const;
|
||||||
float GetAlphaThreshold() const;
|
float GetAlphaThreshold() const;
|
||||||
|
|
@ -69,7 +71,8 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
NzTexture* GetHeightMap() const;
|
NzTexture* GetHeightMap() const;
|
||||||
NzTexture* GetNormalMap() const;
|
NzTexture* GetNormalMap() const;
|
||||||
const NzRenderStates& GetRenderStates() const;
|
const NzRenderStates& GetRenderStates() const;
|
||||||
const NzShaderProgram* GetShaderProgram(nzShaderTarget target, nzUInt32 flags) const;
|
const NzUberShader* GetShader() const;
|
||||||
|
const NzUberShaderInstance* GetShaderInstance(nzUInt32 flags = nzShaderFlags_None) const;
|
||||||
float GetShininess() const;
|
float GetShininess() const;
|
||||||
NzColor GetSpecularColor() const;
|
NzColor GetSpecularColor() const;
|
||||||
NzTexture* GetSpecularMap() const;
|
NzTexture* GetSpecularMap() const;
|
||||||
|
|
@ -78,7 +81,6 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
nzBlendFunc GetSrcBlend() const;
|
nzBlendFunc GetSrcBlend() const;
|
||||||
|
|
||||||
bool HasAlphaMap() const;
|
bool HasAlphaMap() const;
|
||||||
bool HasCustomShaderProgram(nzShaderTarget target, nzUInt32 flags) const;
|
|
||||||
bool HasDiffuseMap() const;
|
bool HasDiffuseMap() const;
|
||||||
bool HasEmissiveMap() const;
|
bool HasEmissiveMap() const;
|
||||||
bool HasHeightMap() const;
|
bool HasHeightMap() const;
|
||||||
|
|
@ -88,6 +90,7 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
bool IsAlphaTestEnabled() const;
|
bool IsAlphaTestEnabled() const;
|
||||||
bool IsEnabled(nzRendererParameter renderParameter) const;
|
bool IsEnabled(nzRendererParameter renderParameter) const;
|
||||||
bool IsLightingEnabled() const;
|
bool IsLightingEnabled() const;
|
||||||
|
bool IsTransformEnabled() const;
|
||||||
|
|
||||||
bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
|
bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
|
||||||
bool LoadFromMemory(const void* data, std::size_t size, const NzMaterialParams& params = NzMaterialParams());
|
bool LoadFromMemory(const void* data, std::size_t size, const NzMaterialParams& params = NzMaterialParams());
|
||||||
|
|
@ -114,7 +117,8 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
bool SetNormalMap(const NzString& texturePath);
|
bool SetNormalMap(const NzString& texturePath);
|
||||||
void SetNormalMap(NzTexture* map);
|
void SetNormalMap(NzTexture* map);
|
||||||
void SetRenderStates(const NzRenderStates& states);
|
void SetRenderStates(const NzRenderStates& states);
|
||||||
void SetShaderProgram(nzShaderTarget target, nzUInt32 flags, const NzShaderProgram* program);
|
void SetShader(const NzUberShader* uberShader);
|
||||||
|
bool SetShader(const NzString& uberShaderName);
|
||||||
void SetShininess(float shininess);
|
void SetShininess(float shininess);
|
||||||
void SetSpecularColor(const NzColor& specular);
|
void SetSpecularColor(const NzColor& specular);
|
||||||
bool SetSpecularMap(const NzString& texturePath);
|
bool SetSpecularMap(const NzString& texturePath);
|
||||||
|
|
@ -125,27 +129,26 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
NzMaterial& operator=(const NzMaterial& material);
|
NzMaterial& operator=(const NzMaterial& material);
|
||||||
NzMaterial& operator=(NzMaterial&& material);
|
NzMaterial& operator=(NzMaterial&& material);
|
||||||
|
|
||||||
|
static bool Initialize();
|
||||||
static NzMaterial* GetDefault();
|
static NzMaterial* GetDefault();
|
||||||
|
static void Uninitialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ProgramUnit
|
struct ShaderInstance
|
||||||
{
|
{
|
||||||
NzShaderProgramConstRef program;
|
const NzShader* shader;
|
||||||
bool custom = false;
|
NzUberShaderInstance* uberInstance;
|
||||||
|
int uniforms[nzMaterialUniform_Max+1];
|
||||||
};
|
};
|
||||||
|
|
||||||
void Copy(const NzMaterial& material);
|
void Copy(const NzMaterial& material);
|
||||||
void GenerateProgram(nzShaderTarget target, nzUInt32 flags) const;
|
void GenerateShader(nzUInt32 flags) const;
|
||||||
void InvalidatePrograms(nzShaderTarget target);
|
void InvalidateShaders();
|
||||||
|
|
||||||
static bool Initialize();
|
|
||||||
static void Uninitialize();
|
|
||||||
|
|
||||||
NzColor m_ambientColor;
|
NzColor m_ambientColor;
|
||||||
NzColor m_diffuseColor;
|
NzColor m_diffuseColor;
|
||||||
NzColor m_specularColor;
|
NzColor m_specularColor;
|
||||||
NzRenderStates m_states;
|
NzRenderStates m_states;
|
||||||
mutable ProgramUnit m_programs[nzShaderTarget_Max+1][nzShaderFlags_Max+1];
|
|
||||||
NzTextureSampler m_diffuseSampler;
|
NzTextureSampler m_diffuseSampler;
|
||||||
NzTextureSampler m_specularSampler;
|
NzTextureSampler m_specularSampler;
|
||||||
NzTextureRef m_alphaMap;
|
NzTextureRef m_alphaMap;
|
||||||
|
|
@ -154,8 +157,11 @@ class NAZARA_API NzMaterial : public NzResource
|
||||||
NzTextureRef m_heightMap;
|
NzTextureRef m_heightMap;
|
||||||
NzTextureRef m_normalMap;
|
NzTextureRef m_normalMap;
|
||||||
NzTextureRef m_specularMap;
|
NzTextureRef m_specularMap;
|
||||||
|
NzUberShaderConstRef m_uberShader;
|
||||||
|
mutable ShaderInstance m_shaders[nzShaderFlags_Max+1];
|
||||||
bool m_alphaTestEnabled;
|
bool m_alphaTestEnabled;
|
||||||
bool m_lightingEnabled;
|
bool m_lightingEnabled;
|
||||||
|
bool m_transformEnabled;
|
||||||
float m_alphaThreshold;
|
float m_alphaThreshold;
|
||||||
float m_shininess;
|
float m_shininess;
|
||||||
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
#include <Nazara/Core/Updatable.hpp>
|
#include <Nazara/Core/Updatable.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/SceneNode.hpp>
|
#include <Nazara/Graphics/SceneNode.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Utility/Animation.hpp>
|
#include <Nazara/Utility/Animation.hpp>
|
||||||
#include <Nazara/Utility/Mesh.hpp>
|
#include <Nazara/Utility/Mesh.hpp>
|
||||||
|
|
||||||
|
|
@ -22,6 +22,7 @@ struct NAZARA_API NzModelParameters
|
||||||
NzAnimationParams animation;
|
NzAnimationParams animation;
|
||||||
NzMaterialParams material;
|
NzMaterialParams material;
|
||||||
NzMeshParams mesh;
|
NzMeshParams mesh;
|
||||||
|
NzString shaderName = "PhongLighting";
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
};
|
};
|
||||||
|
|
@ -89,7 +90,7 @@ class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool FrustumCull(const NzFrustumf& frustum) override;
|
bool FrustumCull(const NzFrustumf& frustum) override;
|
||||||
void Invalidate() override;
|
void InvalidateNode() override;
|
||||||
void Register() override;
|
void Register() override;
|
||||||
void Unregister() override;
|
void Unregister() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||||
|
|
@ -35,7 +35,7 @@ class NAZARA_API NzSkyboxBackground : public NzAbstractBackground
|
||||||
NzTextureRef m_texture;
|
NzTextureRef m_texture;
|
||||||
NzTextureSampler m_sampler;
|
NzTextureSampler m_sampler;
|
||||||
NzIndexBufferRef m_indexBuffer;
|
NzIndexBufferRef m_indexBuffer;
|
||||||
NzShaderProgramRef m_program;
|
NzShaderRef m_shader;
|
||||||
NzVertexBufferRef m_vertexBuffer;
|
NzVertexBufferRef m_vertexBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
#define NAZARA_SPRITE_HPP
|
#define NAZARA_SPRITE_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/SceneNode.hpp>
|
#include <Nazara/Graphics/SceneNode.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
|
|
||||||
class NAZARA_API NzSprite : public NzSceneNode
|
class NAZARA_API NzSprite : public NzSceneNode
|
||||||
{
|
{
|
||||||
|
|
@ -38,7 +38,7 @@ class NAZARA_API NzSprite : public NzSceneNode
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool FrustumCull(const NzFrustumf& frustum) override;
|
bool FrustumCull(const NzFrustumf& frustum) override;
|
||||||
void Invalidate() override;
|
void InvalidateNode() override;
|
||||||
void Register() override;
|
void Register() override;
|
||||||
void Unregister() override;
|
void Unregister() override;
|
||||||
void UpdateBoundingVolume() const;
|
void UpdateBoundingVolume() const;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/UberShader.hpp>
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
|
|
||||||
class NAZARA_API NzTextureBackground : public NzAbstractBackground
|
class NAZARA_API NzTextureBackground : public NzAbstractBackground
|
||||||
|
|
@ -26,8 +26,12 @@ class NAZARA_API NzTextureBackground : public NzAbstractBackground
|
||||||
void SetTexture(NzTexture* texture);
|
void SetTexture(NzTexture* texture);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NzShaderProgramConstRef m_program;
|
|
||||||
NzTextureRef m_texture;
|
NzTextureRef m_texture;
|
||||||
|
NzUberShaderConstRef m_uberShader;
|
||||||
|
const NzUberShaderInstance* m_uberShaderInstance;
|
||||||
|
int m_materialDiffuseUniform;
|
||||||
|
int m_materialDiffuseMapUniform;
|
||||||
|
int m_vertexDepthUniform;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_TEXTUREBACKGROUND_HPP
|
#endif // NAZARA_TEXTUREBACKGROUND_HPP
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ApplyView() const override;
|
void ApplyView() const override;
|
||||||
void Invalidate() override;
|
void InvalidateNode() override;
|
||||||
|
|
||||||
void OnRenderTargetReleased(const NzRenderTarget* renderTarget, void* userdata) override;
|
void OnRenderTargetReleased(const NzRenderTarget* renderTarget, void* userdata) override;
|
||||||
bool OnRenderTargetSizeChange(const NzRenderTarget* renderTarget, void* userdata) override;
|
bool OnRenderTargetSizeChange(const NzRenderTarget* renderTarget, void* userdata) override;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Lua scripting module
|
Nazara Engine - Lua scripting module
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Mathematics module
|
Nazara Engine - Mathematics module
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Noise module
|
Nazara Engine - Noise module
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Physics module
|
Nazara Engine - Physics module
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Renderer module
|
Nazara Engine - Renderer module
|
||||||
|
|
@ -35,7 +35,6 @@
|
||||||
#include <Nazara/Renderer/DebugDrawer.hpp>
|
#include <Nazara/Renderer/DebugDrawer.hpp>
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
#include <Nazara/Renderer/GpuQuery.hpp>
|
#include <Nazara/Renderer/GpuQuery.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Renderer/OpenGL.hpp>
|
#include <Nazara/Renderer/OpenGL.hpp>
|
||||||
#include <Nazara/Renderer/RenderBuffer.hpp>
|
#include <Nazara/Renderer/RenderBuffer.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
|
|
@ -44,10 +43,17 @@
|
||||||
#include <Nazara/Renderer/RenderTargetParameters.hpp>
|
#include <Nazara/Renderer/RenderTargetParameters.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgramManagerParams.hpp>
|
#include <Nazara/Renderer/ShaderStage.hpp>
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShader.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderInstancePreprocessor.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderPreprocessor.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderPUniform.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderPUSubroutine.hpp>
|
||||||
|
|
||||||
#endif // NAZARA_GLOBAL_RENDERER_HPP
|
#endif // NAZARA_GLOBAL_RENDERER_HPP
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,4 @@
|
||||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||||
#define NAZARA_RENDERER_SAFE 1
|
#define NAZARA_RENDERER_SAFE 1
|
||||||
|
|
||||||
// Le nombre maximum de lumières qu'un forward shader supportera
|
|
||||||
#define NAZARA_RENDERER_SHADER_MAX_LIGHTCOUNT 8
|
|
||||||
|
|
||||||
#endif // NAZARA_CONFIG_MODULENAME_HPP
|
#endif // NAZARA_CONFIG_MODULENAME_HPP
|
||||||
|
|
|
||||||
|
|
@ -185,27 +185,6 @@ enum nzSamplerWrap
|
||||||
nzSamplerWrap_Max = nzSamplerWrap_Repeat
|
nzSamplerWrap_Max = nzSamplerWrap_Repeat
|
||||||
};
|
};
|
||||||
|
|
||||||
enum nzShaderFlags
|
|
||||||
{
|
|
||||||
nzShaderFlags_None = 0,
|
|
||||||
|
|
||||||
nzShaderFlags_Deferred = 0x1,
|
|
||||||
nzShaderFlags_FlipUVs = 0x2,
|
|
||||||
nzShaderFlags_Instancing = 0x4,
|
|
||||||
|
|
||||||
nzShaderFlags_Max = nzShaderFlags_Instancing*2-1
|
|
||||||
};
|
|
||||||
|
|
||||||
enum nzShaderLanguage
|
|
||||||
{
|
|
||||||
nzShaderLanguage_Unknown = -1,
|
|
||||||
|
|
||||||
nzShaderLanguage_Cg,
|
|
||||||
nzShaderLanguage_GLSL,
|
|
||||||
|
|
||||||
nzShaderLanguage_Max = nzShaderLanguage_GLSL
|
|
||||||
};
|
|
||||||
|
|
||||||
enum nzShaderTarget
|
enum nzShaderTarget
|
||||||
{
|
{
|
||||||
nzShaderTarget_FullscreenQuad,
|
nzShaderTarget_FullscreenQuad,
|
||||||
|
|
@ -226,21 +205,9 @@ enum nzShaderUniform
|
||||||
nzShaderUniform_InvWorldMatrix,
|
nzShaderUniform_InvWorldMatrix,
|
||||||
nzShaderUniform_InvWorldViewMatrix,
|
nzShaderUniform_InvWorldViewMatrix,
|
||||||
nzShaderUniform_InvWorldViewProjMatrix,
|
nzShaderUniform_InvWorldViewProjMatrix,
|
||||||
nzShaderUniform_MaterialAlphaMap,
|
|
||||||
nzShaderUniform_MaterialAlphaThreshold,
|
|
||||||
nzShaderUniform_MaterialAmbient,
|
|
||||||
nzShaderUniform_MaterialDiffuse,
|
|
||||||
nzShaderUniform_MaterialDiffuseMap,
|
|
||||||
nzShaderUniform_MaterialEmissiveMap,
|
|
||||||
nzShaderUniform_MaterialHeightMap,
|
|
||||||
nzShaderUniform_MaterialNormalMap,
|
|
||||||
nzShaderUniform_MaterialShininess,
|
|
||||||
nzShaderUniform_MaterialSpecular,
|
|
||||||
nzShaderUniform_MaterialSpecularMap,
|
|
||||||
nzShaderUniform_ProjMatrix,
|
nzShaderUniform_ProjMatrix,
|
||||||
nzShaderUniform_SceneAmbient,
|
nzShaderUniform_SceneAmbient,
|
||||||
nzShaderUniform_TargetSize,
|
nzShaderUniform_TargetSize,
|
||||||
nzShaderUniform_VertexDepth,
|
|
||||||
nzShaderUniform_ViewMatrix,
|
nzShaderUniform_ViewMatrix,
|
||||||
nzShaderUniform_ViewProjMatrix,
|
nzShaderUniform_ViewProjMatrix,
|
||||||
nzShaderUniform_WorldMatrix,
|
nzShaderUniform_WorldMatrix,
|
||||||
|
|
@ -250,13 +217,13 @@ enum nzShaderUniform
|
||||||
nzShaderUniform_Max = nzShaderUniform_WorldViewProjMatrix
|
nzShaderUniform_Max = nzShaderUniform_WorldViewProjMatrix
|
||||||
};
|
};
|
||||||
|
|
||||||
enum nzShaderType
|
enum nzShaderStage
|
||||||
{
|
{
|
||||||
nzShaderType_Fragment,
|
nzShaderStage_Fragment,
|
||||||
nzShaderType_Geometry,
|
nzShaderStage_Geometry,
|
||||||
nzShaderType_Vertex,
|
nzShaderStage_Vertex,
|
||||||
|
|
||||||
nzShaderType_Max = nzShaderType_Vertex
|
nzShaderStage_Max = nzShaderStage_Vertex
|
||||||
};
|
};
|
||||||
|
|
||||||
enum nzStencilOperation
|
enum nzStencilOperation
|
||||||
|
|
|
||||||
|
|
@ -140,15 +140,15 @@ class NAZARA_API NzOpenGL
|
||||||
static GLenum RendererComparison[nzRendererComparison_Max+1];
|
static GLenum RendererComparison[nzRendererComparison_Max+1];
|
||||||
static GLenum RendererParameter[nzRendererParameter_Max+1];
|
static GLenum RendererParameter[nzRendererParameter_Max+1];
|
||||||
static GLenum SamplerWrapMode[nzSamplerWrap_Max+1];
|
static GLenum SamplerWrapMode[nzSamplerWrap_Max+1];
|
||||||
static GLenum ShaderType[nzShaderType_Max+1];
|
static GLenum ShaderStage[nzShaderStage_Max+1];
|
||||||
static GLenum StencilOperation[nzStencilOperation_Max+1];
|
static GLenum StencilOperation[nzStencilOperation_Max+1];
|
||||||
static GLenum TextureTarget[nzImageType_Max+1];
|
static GLenum TextureTarget[nzImageType_Max+1];
|
||||||
static GLenum TextureTargetBinding[nzImageType_Max+1];
|
static GLenum TextureTargetBinding[nzImageType_Max+1];
|
||||||
static GLenum TextureTargetProxy[nzImageType_Max+1];
|
static GLenum TextureTargetProxy[nzImageType_Max+1];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void OnContextDestruction(const NzContext* context);
|
|
||||||
static void OnContextChange(const NzContext* newContext);
|
static void OnContextChange(const NzContext* newContext);
|
||||||
|
static void OnContextDestruction(const NzContext* context);
|
||||||
};
|
};
|
||||||
|
|
||||||
NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture;
|
NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture;
|
||||||
|
|
@ -221,6 +221,7 @@ NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
|
||||||
NAZARA_API extern PFNGLGENSAMPLERSPROC glGenSamplers;
|
NAZARA_API extern PFNGLGENSAMPLERSPROC glGenSamplers;
|
||||||
NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures;
|
NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures;
|
||||||
NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
|
NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
|
||||||
|
NAZARA_API extern PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform;
|
||||||
NAZARA_API extern PFNGLGETBOOLEANVPROC glGetBooleanv;
|
NAZARA_API extern PFNGLGETBOOLEANVPROC glGetBooleanv;
|
||||||
NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv;
|
NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv;
|
||||||
NAZARA_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog;
|
NAZARA_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog;
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,13 @@
|
||||||
class NzColor;
|
class NzColor;
|
||||||
class NzContext;
|
class NzContext;
|
||||||
class NzIndexBuffer;
|
class NzIndexBuffer;
|
||||||
class NzMaterial;
|
|
||||||
class NzRenderTarget;
|
class NzRenderTarget;
|
||||||
class NzShaderProgram;
|
class NzShader;
|
||||||
class NzTexture;
|
class NzTexture;
|
||||||
class NzVertexBuffer;
|
class NzVertexBuffer;
|
||||||
|
|
||||||
class NAZARA_API NzRenderer
|
class NAZARA_API NzRenderer
|
||||||
{
|
{
|
||||||
friend NzShaderProgram;
|
|
||||||
friend NzTexture;
|
friend NzTexture;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -64,7 +62,7 @@ class NAZARA_API NzRenderer
|
||||||
static float GetPointSize();
|
static float GetPointSize();
|
||||||
static const NzRenderStates& GetRenderStates();
|
static const NzRenderStates& GetRenderStates();
|
||||||
static NzRecti GetScissorRect();
|
static NzRecti GetScissorRect();
|
||||||
static const NzShaderProgram* GetShaderProgram();
|
static const NzShader* GetShader();
|
||||||
static const NzRenderTarget* GetTarget();
|
static const NzRenderTarget* GetTarget();
|
||||||
static NzRecti GetViewport();
|
static NzRecti GetViewport();
|
||||||
|
|
||||||
|
|
@ -89,7 +87,7 @@ class NAZARA_API NzRenderer
|
||||||
static void SetPointSize(float size);
|
static void SetPointSize(float size);
|
||||||
static void SetRenderStates(const NzRenderStates& states);
|
static void SetRenderStates(const NzRenderStates& states);
|
||||||
static void SetScissorRect(const NzRecti& rect);
|
static void SetScissorRect(const NzRecti& rect);
|
||||||
static void SetShaderProgram(const NzShaderProgram* shader);
|
static void SetShader(const NzShader* shader);
|
||||||
static void SetStencilCompareFunction(nzRendererComparison compareFunc, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
|
static void SetStencilCompareFunction(nzRendererComparison compareFunc, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
|
||||||
static void SetStencilFailOperation(nzStencilOperation failOperation, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
|
static void SetStencilFailOperation(nzStencilOperation failOperation, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
|
||||||
static void SetStencilMask(nzUInt32 mask, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
|
static void SetStencilMask(nzUInt32 mask, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
|
||||||
|
|
@ -107,7 +105,7 @@ class NAZARA_API NzRenderer
|
||||||
private:
|
private:
|
||||||
static void EnableInstancing(bool instancing);
|
static void EnableInstancing(bool instancing);
|
||||||
static bool EnsureStateUpdate();
|
static bool EnsureStateUpdate();
|
||||||
static void OnProgramReleased(const NzShaderProgram* program);
|
static void OnShaderReleased(const NzShader* shader);
|
||||||
static void OnTextureReleased(const NzTexture* texture);
|
static void OnTextureReleased(const NzTexture* texture);
|
||||||
static void UpdateMatrix(nzMatrixType type);
|
static void UpdateMatrix(nzMatrixType type);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_SHADER_HPP
|
||||||
|
#define NAZARA_SHADER_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/ByteArray.hpp>
|
||||||
|
#include <Nazara/Core/Color.hpp>
|
||||||
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
|
#include <Nazara/Core/String.hpp>
|
||||||
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
|
#include <Nazara/Math/Vector4.hpp>
|
||||||
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
|
|
||||||
|
class NzShader;
|
||||||
|
class NzShaderStage;
|
||||||
|
|
||||||
|
using NzShaderConstRef = NzResourceRef<const NzShader>;
|
||||||
|
using NzShaderRef = NzResourceRef<NzShader>;
|
||||||
|
|
||||||
|
class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
||||||
|
{
|
||||||
|
friend class NzRenderer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NzShader();
|
||||||
|
NzShader(NzShader&& shader);
|
||||||
|
~NzShader();
|
||||||
|
|
||||||
|
void AttachStage(nzShaderStage stage, const NzShaderStage& shaderStage);
|
||||||
|
bool AttachStageFromFile(nzShaderStage stage, const NzString& filePath);
|
||||||
|
bool AttachStageFromSource(nzShaderStage stage, const char* source, unsigned int length);
|
||||||
|
bool AttachStageFromSource(nzShaderStage stage, const NzString& source);
|
||||||
|
|
||||||
|
void Bind() const;
|
||||||
|
|
||||||
|
bool Create();
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
|
NzByteArray GetBinary() const;
|
||||||
|
NzString GetLog() const;
|
||||||
|
NzString GetSourceCode(nzShaderStage stage) const;
|
||||||
|
int GetUniformLocation(const NzString& name) const;
|
||||||
|
int GetUniformLocation(nzShaderUniform shaderUniform) const;
|
||||||
|
|
||||||
|
bool HasStage(nzShaderStage stage) const;
|
||||||
|
|
||||||
|
bool IsBinaryRetrievable() const;
|
||||||
|
bool IsLinked() const;
|
||||||
|
bool IsValid() const;
|
||||||
|
|
||||||
|
bool Link();
|
||||||
|
|
||||||
|
bool LoadFromBinary(const void* buffer, unsigned int size);
|
||||||
|
bool LoadFromBinary(const NzByteArray& byteArray);
|
||||||
|
|
||||||
|
void SendBoolean(int location, bool value) const;
|
||||||
|
void SendColor(int location, const NzColor& color) const;
|
||||||
|
void SendDouble(int location, double value) const;
|
||||||
|
void SendDoubleArray(int location, const double* values, unsigned int count) const;
|
||||||
|
void SendFloat(int location, float value) const;
|
||||||
|
void SendFloatArray(int location, const float* values, unsigned int count) const;
|
||||||
|
void SendInteger(int location, int value) const;
|
||||||
|
void SendIntegerArray(int location, const int* values, unsigned int count) const;
|
||||||
|
void SendMatrix(int location, const NzMatrix4d& matrix) const;
|
||||||
|
void SendMatrix(int location, const NzMatrix4f& matrix) const;
|
||||||
|
void SendVector(int location, const NzVector2d& vector) const;
|
||||||
|
void SendVector(int location, const NzVector2f& vector) const;
|
||||||
|
void SendVector(int location, const NzVector2i& vector) const;
|
||||||
|
void SendVector(int location, const NzVector3d& vector) const;
|
||||||
|
void SendVector(int location, const NzVector3f& vector) const;
|
||||||
|
void SendVector(int location, const NzVector3i& vector) const;
|
||||||
|
void SendVector(int location, const NzVector4d& vector) const;
|
||||||
|
void SendVector(int location, const NzVector4f& vector) const;
|
||||||
|
void SendVector(int location, const NzVector4i& vector) const;
|
||||||
|
void SendVectorArray(int location, const NzVector2d* vectors, unsigned int count) const;
|
||||||
|
void SendVectorArray(int location, const NzVector2f* vectors, unsigned int count) const;
|
||||||
|
void SendVectorArray(int location, const NzVector2i* vectors, unsigned int count) const;
|
||||||
|
void SendVectorArray(int location, const NzVector3d* vectors, unsigned int count) const;
|
||||||
|
void SendVectorArray(int location, const NzVector3f* vectors, unsigned int count) const;
|
||||||
|
void SendVectorArray(int location, const NzVector3i* vectors, unsigned int count) const;
|
||||||
|
void SendVectorArray(int location, const NzVector4d* vectors, unsigned int count) const;
|
||||||
|
void SendVectorArray(int location, const NzVector4f* vectors, unsigned int count) const;
|
||||||
|
void SendVectorArray(int location, const NzVector4i* vectors, unsigned int count) const;
|
||||||
|
|
||||||
|
// Fonctions OpenGL
|
||||||
|
unsigned int GetOpenGLID() const;
|
||||||
|
|
||||||
|
NzShader& operator=(NzShader&& shader);
|
||||||
|
|
||||||
|
static bool IsStageSupported(nzShaderStage stage);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool PostLinkage();
|
||||||
|
|
||||||
|
std::vector<unsigned int> m_attachedShaders[nzShaderStage_Max+1];
|
||||||
|
bool m_linked;
|
||||||
|
int m_uniformLocations[nzShaderUniform_Max+1];
|
||||||
|
unsigned int m_program;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_SHADER_HPP
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_SHADERLIBRARY_HPP
|
||||||
|
#define NAZARA_SHADERLIBRARY_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/String.hpp>
|
||||||
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class NAZARA_API NzShaderLibrary
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzShaderLibrary() = delete;
|
||||||
|
~NzShaderLibrary() = delete;
|
||||||
|
|
||||||
|
static NzShader* Get(const NzString& name);
|
||||||
|
static bool Has(const NzString& name);
|
||||||
|
|
||||||
|
static bool Initialize();
|
||||||
|
static void Register(const NzString& name, NzShader* shader);
|
||||||
|
static void Uninitialize();
|
||||||
|
static void Unregister(const NzString& name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::unordered_map<NzString, NzShaderRef> s_library;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_SHADERLIBRARY_HPP
|
||||||
|
|
@ -1,109 +0,0 @@
|
||||||
// Copyright (C) 2014 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_SHADERPROGRAM_HPP
|
|
||||||
#define NAZARA_SHADERPROGRAM_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Core/ByteArray.hpp>
|
|
||||||
#include <Nazara/Core/Color.hpp>
|
|
||||||
#include <Nazara/Core/NonCopyable.hpp>
|
|
||||||
#include <Nazara/Core/Resource.hpp>
|
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
|
||||||
#include <Nazara/Core/String.hpp>
|
|
||||||
#include <Nazara/Math/Matrix4.hpp>
|
|
||||||
#include <Nazara/Math/Vector2.hpp>
|
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
|
||||||
#include <Nazara/Math/Vector4.hpp>
|
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
|
||||||
|
|
||||||
class NzShaderProgram;
|
|
||||||
|
|
||||||
using NzShaderProgramConstRef = NzResourceRef<const NzShaderProgram>;
|
|
||||||
using NzShaderProgramRef = NzResourceRef<NzShaderProgram>;
|
|
||||||
|
|
||||||
class NzAbstractShaderProgram;
|
|
||||||
class NzTexture;
|
|
||||||
|
|
||||||
class NAZARA_API NzShaderProgram : public NzResource, NzNonCopyable
|
|
||||||
{
|
|
||||||
friend class NzRenderer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
NzShaderProgram();
|
|
||||||
NzShaderProgram(nzShaderLanguage language);
|
|
||||||
NzShaderProgram(NzShaderProgram&& shader);
|
|
||||||
~NzShaderProgram();
|
|
||||||
|
|
||||||
bool Create(nzShaderLanguage language);
|
|
||||||
bool Compile();
|
|
||||||
|
|
||||||
void Destroy();
|
|
||||||
|
|
||||||
NzByteArray GetBinary() const;
|
|
||||||
nzUInt32 GetFlags() const;
|
|
||||||
NzString GetLog() const;
|
|
||||||
nzShaderLanguage GetLanguage() const;
|
|
||||||
NzString GetSourceCode(nzShaderType type) const;
|
|
||||||
int GetUniformLocation(const NzString& name) const;
|
|
||||||
int GetUniformLocation(nzShaderUniform uniform) const;
|
|
||||||
|
|
||||||
bool HasUniform(const NzString& name) const;
|
|
||||||
|
|
||||||
bool IsBinaryRetrievable() const;
|
|
||||||
bool IsCompiled() const;
|
|
||||||
bool IsLoaded(nzShaderType type) const;
|
|
||||||
bool IsValid() const;
|
|
||||||
|
|
||||||
bool LoadFromBinary(const void* buffer, unsigned int size);
|
|
||||||
bool LoadFromBinary(const NzByteArray& byteArray);
|
|
||||||
bool LoadShader(nzShaderType type, const NzString& source);
|
|
||||||
bool LoadShaderFromFile(nzShaderType type, const NzString& filePath);
|
|
||||||
|
|
||||||
bool SendBoolean(int location, bool value) const;
|
|
||||||
bool SendColor(int location, const NzColor& color) const;
|
|
||||||
bool SendDouble(int location, double value) const;
|
|
||||||
bool SendDoubleArray(int location, const double* values, unsigned int count) const;
|
|
||||||
bool SendFloat(int location, float value) const;
|
|
||||||
bool SendFloatArray(int location, const float* values, unsigned int count) const;
|
|
||||||
bool SendInteger(int location, int value) const;
|
|
||||||
bool SendIntegerArray(int location, const int* values, unsigned int count) const;
|
|
||||||
bool SendMatrix(int location, const NzMatrix4d& matrix) const;
|
|
||||||
bool SendMatrix(int location, const NzMatrix4f& matrix) const;
|
|
||||||
bool SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit = nullptr) const;
|
|
||||||
bool SendVector(int location, const NzVector2d& vector) const;
|
|
||||||
bool SendVector(int location, const NzVector2f& vector) const;
|
|
||||||
bool SendVector(int location, const NzVector2i& vector) const;
|
|
||||||
bool SendVector(int location, const NzVector3d& vector) const;
|
|
||||||
bool SendVector(int location, const NzVector3f& vector) const;
|
|
||||||
bool SendVector(int location, const NzVector3i& vector) const;
|
|
||||||
bool SendVector(int location, const NzVector4d& vector) const;
|
|
||||||
bool SendVector(int location, const NzVector4f& vector) const;
|
|
||||||
bool SendVector(int location, const NzVector4i& vector) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector2d* vectors, unsigned int count) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector2f* vectors, unsigned int count) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector2i* vectors, unsigned int count) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector3d* vectors, unsigned int count) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector3f* vectors, unsigned int count) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector3i* vectors, unsigned int count) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector4d* vectors, unsigned int count) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector4f* vectors, unsigned int count) const;
|
|
||||||
bool SendVectorArray(int location, const NzVector4i* vectors, unsigned int count) const;
|
|
||||||
|
|
||||||
void SetFlags(nzUInt32 flags);
|
|
||||||
|
|
||||||
NzShaderProgram& operator=(NzShaderProgram&& shader);
|
|
||||||
|
|
||||||
static bool IsLanguageSupported(nzShaderLanguage language);
|
|
||||||
static bool IsShaderTypeSupported(nzShaderType type);
|
|
||||||
|
|
||||||
private:
|
|
||||||
nzUInt32 m_flags;
|
|
||||||
NzAbstractShaderProgram* m_impl;
|
|
||||||
bool m_compiled;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // NAZARA_SHADERPROGRAM_HPP
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright (C) 2014 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_SHADERPROGRAMMANAGER_HPP
|
|
||||||
#define NAZARA_SHADERPROGRAMMANAGER_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
|
||||||
#include <Nazara/Renderer/ShaderProgramManagerParams.hpp>
|
|
||||||
|
|
||||||
class NAZARA_API NzShaderProgramManager
|
|
||||||
{
|
|
||||||
friend class NzRenderer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
NzShaderProgramManager() = delete;
|
|
||||||
~NzShaderProgramManager() = delete;
|
|
||||||
|
|
||||||
static const NzShaderProgram* Get(const NzShaderProgramManagerParams& params);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static NzString BuildFragmentCode(const NzShaderProgramManagerParams& params);
|
|
||||||
static NzString BuildVertexCode(const NzShaderProgramManagerParams& params);
|
|
||||||
static NzShaderProgram* GenerateProgram(const NzShaderProgramManagerParams& params);
|
|
||||||
|
|
||||||
static bool Initialize();
|
|
||||||
static void Uninitialize();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // NAZARA_SHADERPROGRAMMANAGER_HPP
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
// Copyright (C) 2014 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NAZARA_SHADERPROGRAMMANAGERPARAMS_HPP
|
|
||||||
#define NAZARA_SHADERPROGRAMMANAGERPARAMS_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
|
||||||
|
|
||||||
struct NzShaderProgramManagerParams
|
|
||||||
{
|
|
||||||
struct FullscreenQuad
|
|
||||||
{
|
|
||||||
bool alphaMapping;
|
|
||||||
bool alphaTest;
|
|
||||||
bool diffuseMapping;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Model
|
|
||||||
{
|
|
||||||
bool alphaMapping;
|
|
||||||
bool alphaTest;
|
|
||||||
bool diffuseMapping;
|
|
||||||
bool emissiveMapping;
|
|
||||||
bool lighting;
|
|
||||||
bool normalMapping;
|
|
||||||
bool parallaxMapping;
|
|
||||||
bool specularMapping;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Sprite
|
|
||||||
{
|
|
||||||
bool alphaMapping;
|
|
||||||
bool alphaTest;
|
|
||||||
bool diffuseMapping;
|
|
||||||
};
|
|
||||||
|
|
||||||
nzShaderTarget target;
|
|
||||||
nzUInt32 flags;
|
|
||||||
|
|
||||||
union
|
|
||||||
{
|
|
||||||
FullscreenQuad fullscreenQuad;
|
|
||||||
Model model;
|
|
||||||
Sprite sprite;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // NAZARA_SHADERPROGRAMMANAGERPARAMS_HPP
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_SHADERSTAGE_HPP
|
||||||
|
#define NAZARA_SHADERSTAGE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
|
#include <Nazara/Core/String.hpp>
|
||||||
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
|
|
||||||
|
class NAZARA_API NzShaderStage : NzNonCopyable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzShaderStage();
|
||||||
|
NzShaderStage(nzShaderStage stage);
|
||||||
|
NzShaderStage(NzShaderStage&& stage);
|
||||||
|
~NzShaderStage();
|
||||||
|
|
||||||
|
bool Compile();
|
||||||
|
|
||||||
|
bool Create(nzShaderStage stage);
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
|
NzString GetLog() const;
|
||||||
|
NzString GetSource() const;
|
||||||
|
|
||||||
|
bool IsCompiled() const;
|
||||||
|
bool IsValid() const;
|
||||||
|
|
||||||
|
void SetSource(const char* source, unsigned int length);
|
||||||
|
void SetSource(const NzString& source);
|
||||||
|
bool SetSourceFromFile(const NzString& filePath);
|
||||||
|
|
||||||
|
NzShaderStage& operator=(NzShaderStage&& shader);
|
||||||
|
|
||||||
|
// Fonctions OpenGL
|
||||||
|
unsigned int GetOpenGLID() const;
|
||||||
|
|
||||||
|
static bool IsSupported(nzShaderStage stage);
|
||||||
|
|
||||||
|
private:
|
||||||
|
nzShaderStage m_stage;
|
||||||
|
bool m_compiled;
|
||||||
|
unsigned int m_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_SHADERSTAGE_HPP
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_UBERSHADER_HPP
|
||||||
|
#define NAZARA_UBERSHADER_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/ParameterList.hpp>
|
||||||
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class NzUberShader;
|
||||||
|
|
||||||
|
using NzUberShaderConstRef = NzResourceRef<const NzUberShader>;
|
||||||
|
using NzUberShaderRef = NzResourceRef<NzUberShader>;
|
||||||
|
|
||||||
|
class NAZARA_API NzUberShader : public NzResource
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzUberShader() = default;
|
||||||
|
virtual ~NzUberShader();
|
||||||
|
|
||||||
|
virtual NzUberShaderInstance* Get(const NzParameterList& parameters) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_UBERSHADER_HPP
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_UBERSHADERINSTANCE_HPP
|
||||||
|
#define NAZARA_UBERSHADERINSTANCE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
|
|
||||||
|
class NAZARA_API NzUberShaderInstance
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzUberShaderInstance(const NzShader* shader);
|
||||||
|
virtual ~NzUberShaderInstance();
|
||||||
|
|
||||||
|
virtual bool Activate() const = 0;
|
||||||
|
|
||||||
|
const NzShader* GetShader() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
NzShaderConstRef m_shader;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_UBERSHADERINSTANCE_HPP
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_UBERSHADERINSTANCEPREPROCESSOR_HPP
|
||||||
|
#define NAZARA_UBERSHADERINSTANCEPREPROCESSOR_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||||
|
|
||||||
|
class NAZARA_API NzUberShaderInstancePreprocessor : public NzUberShaderInstance
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzUberShaderInstancePreprocessor(const NzShader* shader);
|
||||||
|
virtual ~NzUberShaderInstancePreprocessor();
|
||||||
|
|
||||||
|
bool Activate() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_UBERSHADERINSTANCEPREPROCESSOR_HPP
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_UBERSHADERLIBRARY_HPP
|
||||||
|
#define NAZARA_UBERSHADERLIBRARY_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/String.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShader.hpp>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class NAZARA_API NzUberShaderLibrary
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzUberShaderLibrary() = delete;
|
||||||
|
~NzUberShaderLibrary() = delete;
|
||||||
|
|
||||||
|
static NzUberShader* Get(const NzString& name);
|
||||||
|
static bool Has(const NzString& name);
|
||||||
|
|
||||||
|
static bool Initialize();
|
||||||
|
static void Register(const NzString& name, NzUberShader* uberShader);
|
||||||
|
static void Uninitialize();
|
||||||
|
static void Unregister(const NzString& name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::unordered_map<NzString, NzUberShaderRef> s_library;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_UBERSHADERLIBRARY_HPP
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_UBERSHADERPREPROCESSOR_HPP
|
||||||
|
#define NAZARA_UBERSHADERPREPROCESSOR_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderStage.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShader.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderInstancePreprocessor.hpp>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
class NAZARA_API NzUberShaderPreprocessor : public NzUberShader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzUberShaderPreprocessor() = default;
|
||||||
|
~NzUberShaderPreprocessor() = default;
|
||||||
|
|
||||||
|
NzUberShaderInstance* Get(const NzParameterList& parameters) const;
|
||||||
|
|
||||||
|
void SetShader(nzShaderStage stage, const NzString& source, const NzString& flags);
|
||||||
|
bool SetShaderFromFile(nzShaderStage stage, const NzString& filePath, const NzString& flags);
|
||||||
|
|
||||||
|
static bool IsSupported();
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Shader
|
||||||
|
{
|
||||||
|
mutable std::unordered_map<nzUInt32, NzShaderStage> cache;
|
||||||
|
std::unordered_map<NzString, nzUInt32> flags;
|
||||||
|
NzString source;
|
||||||
|
bool present = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
mutable std::unordered_map<nzUInt32, NzUberShaderInstancePreprocessor> m_cache;
|
||||||
|
std::unordered_map<NzString, nzUInt32> m_flags;
|
||||||
|
Shader m_shaders[nzShaderStage_Max+1];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_UBERSHADERPREPROCESSOR_HPP
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// This file was automatically generated on 12 Jan 2014 at 20:08:11
|
// This file was automatically generated on 21 Feb 2014 at 18:17:18
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Nazara Engine - Window module
|
Nazara Engine - Window module
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ class NAZARA_API NzNode
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void AddChild(NzNode* node) const;
|
void AddChild(NzNode* node) const;
|
||||||
virtual void Invalidate();
|
virtual void InvalidateNode();
|
||||||
virtual void OnParenting(const NzNode* parent);
|
virtual void OnParenting(const NzNode* parent);
|
||||||
void RemoveChild(NzNode* node) const;
|
void RemoveChild(NzNode* node) const;
|
||||||
void UpdateDerived() const;
|
void UpdateDerived() const;
|
||||||
|
|
|
||||||
|
|
@ -222,9 +222,9 @@ void NzCamera::ApplyView() const
|
||||||
NzRenderer::SetViewport(m_viewport);
|
NzRenderer::SetViewport(m_viewport);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzCamera::Invalidate()
|
void NzCamera::InvalidateNode()
|
||||||
{
|
{
|
||||||
NzNode::Invalidate();
|
NzNode::InvalidateNode();
|
||||||
|
|
||||||
// Le frustum et la view matrix dépendent des paramètres du node, invalidons-les
|
// Le frustum et la view matrix dépendent des paramètres du node, invalidons-les
|
||||||
m_frustumUpdated = false;
|
m_frustumUpdated = false;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <Nazara/Graphics/ColorBackGround.hpp>
|
#include <Nazara/Graphics/ColorBackGround.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -26,14 +26,15 @@ namespace
|
||||||
NzColorBackground::NzColorBackground(const NzColor& color) :
|
NzColorBackground::NzColorBackground(const NzColor& color) :
|
||||||
m_color(color)
|
m_color(color)
|
||||||
{
|
{
|
||||||
NzShaderProgramManagerParams params;
|
m_uberShader = NzUberShaderLibrary::Get("Basic");
|
||||||
params.target = nzShaderTarget_FullscreenQuad;
|
|
||||||
params.flags = 0;
|
|
||||||
params.fullscreenQuad.alphaMapping = false;
|
|
||||||
params.fullscreenQuad.alphaTest = false;
|
|
||||||
params.fullscreenQuad.diffuseMapping = false;
|
|
||||||
|
|
||||||
m_program = NzShaderProgramManager::Get(params);
|
NzParameterList list;
|
||||||
|
list.SetParameter("UNIFORM_VERTEX_DEPTH", true);
|
||||||
|
m_uberShaderInstance = m_uberShader->Get(list);
|
||||||
|
|
||||||
|
const NzShader* shader = m_uberShaderInstance->GetShader();
|
||||||
|
m_materialDiffuseUniform = shader->GetUniformLocation("MaterialDiffuse");
|
||||||
|
m_vertexDepthUniform = shader->GetUniformLocation("VertexDepth");
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzColorBackground::Draw(const NzScene* scene) const
|
void NzColorBackground::Draw(const NzScene* scene) const
|
||||||
|
|
@ -43,10 +44,12 @@ void NzColorBackground::Draw(const NzScene* scene) const
|
||||||
static NzRenderStates states(BuildRenderStates());
|
static NzRenderStates states(BuildRenderStates());
|
||||||
|
|
||||||
NzRenderer::SetRenderStates(states);
|
NzRenderer::SetRenderStates(states);
|
||||||
NzRenderer::SetShaderProgram(m_program);
|
|
||||||
|
|
||||||
m_program->SendColor(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), m_color);
|
m_uberShaderInstance->Activate();
|
||||||
m_program->SendFloat(m_program->GetUniformLocation(nzShaderUniform_VertexDepth), 1.f);
|
|
||||||
|
const NzShader* shader = m_uberShaderInstance->GetShader();
|
||||||
|
shader->SendColor(m_materialDiffuseUniform, m_color);
|
||||||
|
shader->SendFloat(m_vertexDepthUniform, 1.f);
|
||||||
|
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
}
|
}
|
||||||
|
|
@ -64,6 +67,5 @@ NzColor NzColorBackground::GetColor() const
|
||||||
void NzColorBackground::SetColor(const NzColor& color)
|
void NzColorBackground::SetColor(const NzColor& color)
|
||||||
{
|
{
|
||||||
m_color = color;
|
m_color = color;
|
||||||
m_program->SendColor(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), m_color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,142 +4,10 @@
|
||||||
|
|
||||||
#include <Nazara/Graphics/DeferredBloomPass.hpp>
|
#include <Nazara/Graphics/DeferredBloomPass.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
NzShaderProgram* BuildBloomBrightProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec3 VertexPosition;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = vec4(VertexPosition, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
program->SendInteger(program->GetUniformLocation("ColorTexture"), 0);
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
NzShaderProgram* BuildBloomFinalProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec3 VertexPosition;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = vec4(VertexPosition, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
program->SendInteger(program->GetUniformLocation("ColorTexture"), 0);
|
|
||||||
program->SendInteger(program->GetUniformLocation("BloomTexture"), 1);
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
NzShaderProgram* BuildGaussianBlurProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec3 VertexPosition;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = vec4(VertexPosition, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
program->SendInteger(program->GetUniformLocation("ColorTexture"), 0);
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NzDeferredBloomPass::NzDeferredBloomPass() :
|
NzDeferredBloomPass::NzDeferredBloomPass() :
|
||||||
m_uniformUpdated(false),
|
m_uniformUpdated(false),
|
||||||
m_brightLuminance(0.8),
|
m_brightLuminance(0.8),
|
||||||
|
|
@ -151,23 +19,17 @@ m_blurPassCount(5)
|
||||||
m_bilinearSampler.SetFilterMode(nzSamplerFilter_Bilinear);
|
m_bilinearSampler.SetFilterMode(nzSamplerFilter_Bilinear);
|
||||||
m_bilinearSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
m_bilinearSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
||||||
|
|
||||||
m_bloomBrightProgram = BuildBloomBrightProgram();
|
m_bloomBrightShader = NzShaderLibrary::Get("DeferredBloomBright");
|
||||||
m_bloomBrightProgram->SendInteger(m_bloomBrightProgram->GetUniformLocation("ColorTexture"), 0);
|
m_bloomFinalShader = NzShaderLibrary::Get("DeferredBloomFinal");
|
||||||
|
|
||||||
m_bloomFinalProgram = BuildBloomFinalProgram();
|
|
||||||
m_bloomFinalProgram->SendInteger(m_bloomFinalProgram->GetUniformLocation("BloomTexture"), 1);
|
|
||||||
m_bloomFinalProgram->SendInteger(m_bloomFinalProgram->GetUniformLocation("ColorTexture"), 0);
|
|
||||||
|
|
||||||
m_bloomStates.parameters[nzRendererParameter_DepthBuffer] = false;
|
m_bloomStates.parameters[nzRendererParameter_DepthBuffer] = false;
|
||||||
|
m_gaussianBlurShader = NzShaderLibrary::Get("DeferredGaussianBlur");
|
||||||
|
m_gaussianBlurShaderFilterLocation = m_gaussianBlurShader->GetUniformLocation("Filter");
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 2; ++i)
|
for (unsigned int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
m_bloomTextures[i] = new NzTexture;
|
m_bloomTextures[i] = new NzTexture;
|
||||||
m_bloomTextures[i]->SetPersistent(false);
|
m_bloomTextures[i]->SetPersistent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gaussianBlurProgram = BuildGaussianBlurProgram();
|
|
||||||
m_gaussianBlurProgramFilterLocation = m_gaussianBlurProgram->GetUniformLocation("Filter");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NzDeferredBloomPass::~NzDeferredBloomPass() = default;
|
NzDeferredBloomPass::~NzDeferredBloomPass() = default;
|
||||||
|
|
@ -217,12 +79,12 @@ bool NzDeferredBloomPass::Process(const NzScene* scene, unsigned int firstWorkTe
|
||||||
NzRenderer::SetTarget(m_workRTT);
|
NzRenderer::SetTarget(m_workRTT);
|
||||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
||||||
|
|
||||||
NzRenderer::SetShaderProgram(m_bloomBrightProgram);
|
NzRenderer::SetShader(m_bloomBrightShader);
|
||||||
if (!m_uniformUpdated)
|
if (!m_uniformUpdated)
|
||||||
{
|
{
|
||||||
m_bloomBrightProgram->SendFloat(m_bloomBrightProgram->GetUniformLocation("BrightLuminance"), m_brightLuminance);
|
m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightLuminance"), m_brightLuminance);
|
||||||
m_bloomBrightProgram->SendFloat(m_bloomBrightProgram->GetUniformLocation("BrightMiddleGrey"), m_brightMiddleGrey);
|
m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightMiddleGrey"), m_brightMiddleGrey);
|
||||||
m_bloomBrightProgram->SendFloat(m_bloomBrightProgram->GetUniformLocation("BrightThreshold"), m_brightThreshold);
|
m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightThreshold"), m_brightThreshold);
|
||||||
|
|
||||||
m_uniformUpdated = true;
|
m_uniformUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
@ -233,20 +95,20 @@ bool NzDeferredBloomPass::Process(const NzScene* scene, unsigned int firstWorkTe
|
||||||
NzRenderer::SetTarget(&m_bloomRTT);
|
NzRenderer::SetTarget(&m_bloomRTT);
|
||||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x/8, m_dimensions.y/8));
|
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x/8, m_dimensions.y/8));
|
||||||
|
|
||||||
NzRenderer::SetShaderProgram(m_gaussianBlurProgram);
|
NzRenderer::SetShader(m_gaussianBlurShader);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < m_blurPassCount; ++i)
|
for (unsigned int i = 0; i < m_blurPassCount; ++i)
|
||||||
{
|
{
|
||||||
m_bloomRTT.SetColorTarget(0); // bloomTextureA
|
m_bloomRTT.SetColorTarget(0); // bloomTextureA
|
||||||
|
|
||||||
m_gaussianBlurProgram->SendVector(m_gaussianBlurProgramFilterLocation, NzVector2f(1.f, 0.f));
|
m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, NzVector2f(1.f, 0.f));
|
||||||
|
|
||||||
NzRenderer::SetTexture(0, (i == 0) ? m_workTextures[firstWorkTexture] : static_cast<const NzTexture*>(m_bloomTextures[1]));
|
NzRenderer::SetTexture(0, (i == 0) ? m_workTextures[firstWorkTexture] : static_cast<const NzTexture*>(m_bloomTextures[1]));
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
|
|
||||||
m_bloomRTT.SetColorTarget(1); // bloomTextureB
|
m_bloomRTT.SetColorTarget(1); // bloomTextureB
|
||||||
|
|
||||||
m_gaussianBlurProgram->SendVector(m_gaussianBlurProgramFilterLocation, NzVector2f(0.f, 1.f));
|
m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, NzVector2f(0.f, 1.f));
|
||||||
|
|
||||||
NzRenderer::SetTexture(0, m_bloomTextures[0]);
|
NzRenderer::SetTexture(0, m_bloomTextures[0]);
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
|
|
@ -256,7 +118,7 @@ bool NzDeferredBloomPass::Process(const NzScene* scene, unsigned int firstWorkTe
|
||||||
NzRenderer::SetTarget(m_workRTT);
|
NzRenderer::SetTarget(m_workRTT);
|
||||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
||||||
|
|
||||||
NzRenderer::SetShaderProgram(m_bloomFinalProgram);
|
NzRenderer::SetShader(m_bloomFinalShader);
|
||||||
NzRenderer::SetTexture(0, m_bloomTextures[1]);
|
NzRenderer::SetTexture(0, m_bloomTextures[1]);
|
||||||
NzRenderer::SetTexture(1, m_workTextures[secondWorkTexture]);
|
NzRenderer::SetTexture(1, m_workTextures[secondWorkTexture]);
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,14 @@
|
||||||
#include <Nazara/Graphics/Scene.hpp>
|
#include <Nazara/Graphics/Scene.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// http://digitalerr0r.wordpress.com/2009/05/16/xna-shader-programming-tutorial-20-depth-of-field/
|
// http://digitalerr0r.wordpress.com/2009/05/16/xna-shader-programming-tutorial-20-depth-of-field/
|
||||||
NzShaderProgram* BuildDepthOfFieldProgram()
|
NzShader* BuildDepthOfFieldShader()
|
||||||
{
|
{
|
||||||
const char* fragmentSource =
|
const char* fragmentSource =
|
||||||
"#version 140\n"
|
"#version 140\n"
|
||||||
|
|
@ -62,84 +63,46 @@ namespace
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
///TODO: Remplacer ça par des ShaderNode
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
std::unique_ptr<NzShader> shader(new NzShader);
|
||||||
program->SetPersistent(false);
|
shader->SetPersistent(false);
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, fragmentSource))
|
if (!shader->Create())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to load create shader");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shader->AttachStageFromSource(nzShaderStage_Fragment, fragmentSource))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to load fragment shader");
|
NazaraError("Failed to load fragment shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
if (!shader->AttachStageFromSource(nzShaderStage_Vertex, vertexSource))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to load vertex shader");
|
NazaraError("Failed to load vertex shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!program->Compile())
|
if (!shader->Link())
|
||||||
{
|
{
|
||||||
NazaraError("Failed to compile program");
|
NazaraError("Failed to link shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return program.release();
|
return shader.release();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NzShaderProgram* BuildGaussianBlurProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec3 VertexPosition;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = vec4(VertexPosition, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NzDeferredDOFPass::NzDeferredDOFPass()
|
NzDeferredDOFPass::NzDeferredDOFPass()
|
||||||
{
|
{
|
||||||
m_blurProgram = BuildGaussianBlurProgram();
|
m_dofShader = BuildDepthOfFieldShader();
|
||||||
m_blurProgram->SendInteger(m_blurProgram->GetUniformLocation("ColorTexture"), 0);
|
m_dofShader->SendInteger(m_dofShader->GetUniformLocation("ColorTexture"), 0);
|
||||||
|
m_dofShader->SendInteger(m_dofShader->GetUniformLocation("BlurTexture"), 1);
|
||||||
|
m_dofShader->SendInteger(m_dofShader->GetUniformLocation("GBuffer1"), 2);
|
||||||
|
|
||||||
m_blurProgramFilterLocation = m_blurProgram->GetUniformLocation("Filer");
|
m_gaussianBlurShader = NzShaderLibrary::Get("DeferredGaussianBlur");
|
||||||
|
m_gaussianBlurShaderFilterLocation = m_gaussianBlurShader->GetUniformLocation("Filter");
|
||||||
m_dofProgram = BuildDepthOfFieldProgram();
|
|
||||||
m_dofProgram->SendInteger(m_dofProgram->GetUniformLocation("ColorTexture"), 0);
|
|
||||||
m_dofProgram->SendInteger(m_dofProgram->GetUniformLocation("BlurTexture"), 1);
|
|
||||||
m_dofProgram->SendInteger(m_dofProgram->GetUniformLocation("GBuffer1"), 2);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 2; ++i)
|
for (unsigned int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -169,21 +132,21 @@ bool NzDeferredDOFPass::Process(const NzScene* scene, unsigned int firstWorkText
|
||||||
NzRenderer::SetTarget(&m_dofRTT);
|
NzRenderer::SetTarget(&m_dofRTT);
|
||||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x/4, m_dimensions.y/4));
|
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x/4, m_dimensions.y/4));
|
||||||
|
|
||||||
NzRenderer::SetShaderProgram(m_blurProgram);
|
NzRenderer::SetShader(m_gaussianBlurShader);
|
||||||
|
|
||||||
const unsigned int dofBlurPass = 2;
|
const unsigned int dofBlurPass = 2;
|
||||||
for (unsigned int i = 0; i < dofBlurPass; ++i)
|
for (unsigned int i = 0; i < dofBlurPass; ++i)
|
||||||
{
|
{
|
||||||
m_dofRTT.SetColorTarget(0); // dofTextureA
|
m_dofRTT.SetColorTarget(0); // dofTextureA
|
||||||
|
|
||||||
m_blurProgram->SendVector(m_blurProgramFilterLocation, NzVector2f(1.f, 0.f));
|
m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, NzVector2f(1.f, 0.f));
|
||||||
|
|
||||||
NzRenderer::SetTexture(0, (i == 0) ? m_workTextures[secondWorkTexture] : static_cast<const NzTexture*>(m_dofTextures[1]));
|
NzRenderer::SetTexture(0, (i == 0) ? m_workTextures[secondWorkTexture] : static_cast<const NzTexture*>(m_dofTextures[1]));
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
|
|
||||||
m_dofRTT.SetColorTarget(1); // dofTextureB
|
m_dofRTT.SetColorTarget(1); // dofTextureB
|
||||||
|
|
||||||
m_blurProgram->SendVector(m_blurProgramFilterLocation, NzVector2f(0.f, 1.f));
|
m_gaussianBlurShader->SendVector(m_gaussianBlurShaderFilterLocation, NzVector2f(0.f, 1.f));
|
||||||
|
|
||||||
NzRenderer::SetTexture(0, m_dofTextures[0]);
|
NzRenderer::SetTexture(0, m_dofTextures[0]);
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
|
|
@ -193,7 +156,7 @@ bool NzDeferredDOFPass::Process(const NzScene* scene, unsigned int firstWorkText
|
||||||
NzRenderer::SetTarget(m_workRTT);
|
NzRenderer::SetTarget(m_workRTT);
|
||||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
||||||
|
|
||||||
NzRenderer::SetShaderProgram(m_dofProgram);
|
NzRenderer::SetShader(m_dofShader);
|
||||||
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
||||||
NzRenderer::SetTexture(1, m_dofTextures[1]);
|
NzRenderer::SetTexture(1, m_dofTextures[1]);
|
||||||
NzRenderer::SetTexture(2, m_GBuffer[1]);
|
NzRenderer::SetTexture(2, m_GBuffer[1]);
|
||||||
|
|
|
||||||
|
|
@ -5,57 +5,13 @@
|
||||||
#include <Nazara/Graphics/DeferredFXAAPass.hpp>
|
#include <Nazara/Graphics/DeferredFXAAPass.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
NzShaderProgram* BuildFXAAProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec3 VertexPosition;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = vec4(VertexPosition, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NzDeferredFXAAPass::NzDeferredFXAAPass()
|
NzDeferredFXAAPass::NzDeferredFXAAPass()
|
||||||
{
|
{
|
||||||
m_fxaaProgram = BuildFXAAProgram();
|
m_fxaaShader = NzShaderLibrary::Get("DeferredFXAA");
|
||||||
m_fxaaProgram->SendInteger(m_fxaaProgram->GetUniformLocation("ColorTexture"), 0);
|
|
||||||
|
|
||||||
m_pointSampler.SetAnisotropyLevel(1);
|
m_pointSampler.SetAnisotropyLevel(1);
|
||||||
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
||||||
|
|
@ -75,7 +31,7 @@ bool NzDeferredFXAAPass::Process(const NzScene* scene, unsigned int firstWorkTex
|
||||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
||||||
|
|
||||||
NzRenderer::SetRenderStates(m_states);
|
NzRenderer::SetRenderStates(m_states);
|
||||||
NzRenderer::SetShaderProgram(m_fxaaProgram);
|
NzRenderer::SetShader(m_fxaaShader);
|
||||||
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
||||||
NzRenderer::SetTextureSampler(0, m_pointSampler);
|
NzRenderer::SetTextureSampler(0, m_pointSampler);
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
|
|
|
||||||
|
|
@ -6,64 +6,30 @@
|
||||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
#include <Nazara/Graphics/Scene.hpp>
|
#include <Nazara/Graphics/Scene.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
NzShaderProgram* BuildBlitProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/Blit.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec3 VertexPosition;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = vec4(VertexPosition, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NzDeferredFinalPass::NzDeferredFinalPass()
|
NzDeferredFinalPass::NzDeferredFinalPass()
|
||||||
{
|
{
|
||||||
m_program = BuildBlitProgram();
|
|
||||||
m_program->SendInteger(m_program->GetUniformLocation("ColorTexture"), 0);
|
|
||||||
|
|
||||||
m_pointSampler.SetAnisotropyLevel(1);
|
m_pointSampler.SetAnisotropyLevel(1);
|
||||||
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
||||||
m_pointSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
m_pointSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
||||||
|
|
||||||
m_states.parameters[nzRendererParameter_DepthBuffer] = false;
|
m_states.parameters[nzRendererParameter_DepthBuffer] = false;
|
||||||
|
|
||||||
|
m_uberShader = NzUberShaderLibrary::Get("Basic");
|
||||||
|
|
||||||
|
NzParameterList list;
|
||||||
|
list.SetParameter("AUTO_TEXCOORDS", true);
|
||||||
|
list.SetParameter("DIFFUSE_MAPPING", true);
|
||||||
|
list.SetParameter("TEXTURE_MAPPING", false);
|
||||||
|
|
||||||
|
m_uberShaderInstance = m_uberShader->Get(list);
|
||||||
|
|
||||||
|
const NzShader* shader = m_uberShaderInstance->GetShader();
|
||||||
|
m_materialDiffuseUniform = shader->GetUniformLocation("MaterialDiffuse");
|
||||||
|
m_materialDiffuseMapUniform = shader->GetUniformLocation("MaterialDiffuseMap");
|
||||||
}
|
}
|
||||||
|
|
||||||
NzDeferredFinalPass::~NzDeferredFinalPass() = default;
|
NzDeferredFinalPass::~NzDeferredFinalPass() = default;
|
||||||
|
|
@ -75,10 +41,15 @@ bool NzDeferredFinalPass::Process(const NzScene* scene, unsigned int firstWorkTe
|
||||||
scene->GetViewer()->ApplyView();
|
scene->GetViewer()->ApplyView();
|
||||||
|
|
||||||
NzRenderer::SetRenderStates(m_states);
|
NzRenderer::SetRenderStates(m_states);
|
||||||
NzRenderer::SetShaderProgram(m_program);
|
|
||||||
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
||||||
NzRenderer::SetTextureSampler(0, m_pointSampler);
|
NzRenderer::SetTextureSampler(0, m_pointSampler);
|
||||||
|
|
||||||
|
m_uberShaderInstance->Activate();
|
||||||
|
|
||||||
|
const NzShader* shader = m_uberShaderInstance->GetShader();
|
||||||
|
shader->SendColor(m_materialDiffuseUniform, NzColor::White);
|
||||||
|
shader->SendInteger(m_materialDiffuseMapUniform, 0);
|
||||||
|
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
NzShaderProgram* BuildFogProgram()
|
NzShader* BuildFogShader()
|
||||||
{
|
{
|
||||||
/*const nzUInt8 fragmentSource[] = {
|
/*const nzUInt8 fragmentSource[] = {
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h>
|
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h>
|
||||||
|
|
@ -84,41 +84,48 @@ namespace
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
///TODO: Remplacer ça par des ShaderNode
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
std::unique_ptr<NzShader> shader(new NzShader);
|
||||||
program->SetPersistent(false);
|
shader->SetPersistent(false);
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, fragmentSource/*NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))*/))
|
if (!shader->Create())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to load create shader");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shader->AttachStageFromSource(nzShaderStage_Fragment, fragmentSource/*NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))*/))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to load fragment shader");
|
NazaraError("Failed to load fragment shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
if (!shader->AttachStageFromSource(nzShaderStage_Vertex, vertexSource))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to load vertex shader");
|
NazaraError("Failed to load vertex shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!program->Compile())
|
if (!shader->Link())
|
||||||
{
|
{
|
||||||
NazaraError("Failed to compile program");
|
NazaraError("Failed to link shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return program.release();
|
shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0);
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 1);
|
||||||
|
|
||||||
|
return shader.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NzDeferredFogPass::NzDeferredFogPass()
|
NzDeferredFogPass::NzDeferredFogPass()
|
||||||
{
|
{
|
||||||
m_program = BuildFogProgram();
|
|
||||||
m_program->SendInteger(m_program->GetUniformLocation("ColorTexture"), 0);
|
|
||||||
m_program->SendInteger(m_program->GetUniformLocation("GBuffer2"), 1);
|
|
||||||
|
|
||||||
m_pointSampler.SetAnisotropyLevel(1);
|
m_pointSampler.SetAnisotropyLevel(1);
|
||||||
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
||||||
m_pointSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
m_pointSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
||||||
|
|
||||||
|
m_shader = BuildFogShader();
|
||||||
|
|
||||||
m_states.parameters[nzRendererParameter_DepthBuffer] = false;
|
m_states.parameters[nzRendererParameter_DepthBuffer] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,8 +137,8 @@ bool NzDeferredFogPass::Process(const NzScene* scene, unsigned int firstWorkText
|
||||||
NzRenderer::SetTarget(m_workRTT);
|
NzRenderer::SetTarget(m_workRTT);
|
||||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
||||||
|
|
||||||
NzRenderer::SetShaderProgram(m_program);
|
NzRenderer::SetShader(m_shader);
|
||||||
m_program->SendVector(m_program->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
m_shader->SendVector(m_shader->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||||
|
|
||||||
NzRenderer::SetRenderStates(m_states);
|
NzRenderer::SetRenderStates(m_states);
|
||||||
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
||||||
|
|
|
||||||
|
|
@ -6,63 +6,20 @@
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/Scene.hpp>
|
#include <Nazara/Graphics/Scene.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||||
#include <Nazara/Utility/BufferMapper.hpp>
|
#include <Nazara/Utility/BufferMapper.hpp>
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
#include <Nazara/Utility/VertexStruct.hpp>
|
#include <Nazara/Utility/VertexStruct.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
NzShaderProgram* BuildClearProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/ClearGBuffer.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec2 VertexPosition;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = vec4(VertexPosition, 0.0, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NzDeferredGeometryPass::NzDeferredGeometryPass()
|
NzDeferredGeometryPass::NzDeferredGeometryPass()
|
||||||
{
|
{
|
||||||
m_clearProgram = BuildClearProgram();
|
m_clearShader = NzShaderLibrary::Get("DeferredGBufferClear");
|
||||||
m_clearStates.parameters[nzRendererParameter_DepthBuffer] = true;
|
m_clearStates.parameters[nzRendererParameter_DepthBuffer] = true;
|
||||||
m_clearStates.parameters[nzRendererParameter_FaceCulling] = true;
|
m_clearStates.parameters[nzRendererParameter_FaceCulling] = true;
|
||||||
m_clearStates.parameters[nzRendererParameter_StencilTest] = true;
|
m_clearStates.parameters[nzRendererParameter_StencilTest] = true;
|
||||||
|
|
@ -86,14 +43,14 @@ bool NzDeferredGeometryPass::Process(const NzScene* scene, unsigned int firstWor
|
||||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
||||||
|
|
||||||
NzRenderer::SetRenderStates(m_clearStates);
|
NzRenderer::SetRenderStates(m_clearStates);
|
||||||
NzRenderer::SetShaderProgram(m_clearProgram);
|
NzRenderer::SetShader(m_clearShader);
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
|
|
||||||
|
|
||||||
NzRenderer::SetMatrix(nzMatrixType_Projection, viewer->GetProjectionMatrix());
|
NzRenderer::SetMatrix(nzMatrixType_Projection, viewer->GetProjectionMatrix());
|
||||||
NzRenderer::SetMatrix(nzMatrixType_View, viewer->GetViewMatrix());
|
NzRenderer::SetMatrix(nzMatrixType_View, viewer->GetViewMatrix());
|
||||||
|
|
||||||
const NzShaderProgram* lastProgram = nullptr;
|
const NzShader* lastShader = nullptr;
|
||||||
|
|
||||||
for (auto& matIt : m_renderQueue->opaqueModels)
|
for (auto& matIt : m_renderQueue->opaqueModels)
|
||||||
{
|
{
|
||||||
|
|
@ -118,23 +75,19 @@ bool NzDeferredGeometryPass::Process(const NzScene* scene, unsigned int firstWor
|
||||||
if (useInstancing)
|
if (useInstancing)
|
||||||
flags |= nzShaderFlags_Instancing;
|
flags |= nzShaderFlags_Instancing;
|
||||||
|
|
||||||
const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Model, flags);
|
const NzShader* shader = material->Apply(flags);
|
||||||
|
|
||||||
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
||||||
if (program != lastProgram)
|
if (shader != lastShader)
|
||||||
{
|
{
|
||||||
NzRenderer::SetShaderProgram(program);
|
|
||||||
|
|
||||||
// Couleur ambiante de la scène
|
// Couleur ambiante de la scène
|
||||||
program->SendColor(program->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||||
// Position de la caméra
|
// Position de la caméra
|
||||||
program->SendVector(program->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
shader->SendVector(shader->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
||||||
|
|
||||||
lastProgram = program;
|
lastShader = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
material->Apply(program);
|
|
||||||
|
|
||||||
// Meshs squelettiques
|
// Meshs squelettiques
|
||||||
/*if (!skeletalContainer.empty())
|
/*if (!skeletalContainer.empty())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,122 +2,45 @@
|
||||||
// This file is part of the "Nazara Engine - Graphics module"
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#ifndef NAZARA_RENDERER_OPENGL
|
||||||
|
#define NAZARA_RENDERER_OPENGL
|
||||||
|
#endif // NAZARA_RENDERER_OPENGL
|
||||||
|
|
||||||
#include <Nazara/Graphics/DeferredPhongLightingPass.hpp>
|
#include <Nazara/Graphics/DeferredPhongLightingPass.hpp>
|
||||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
|
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
|
||||||
#include <Nazara/Graphics/Scene.hpp>
|
#include <Nazara/Graphics/Scene.hpp>
|
||||||
|
#include <Nazara/Renderer/OpenGL.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Renderer/OpenGL.hpp> // Supprimer
|
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
NzShaderProgram* BuildDirectionalLightProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec2 VertexPosition;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = vec4(VertexPosition, 0.0, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
program->SendInteger(program->GetUniformLocation("GBuffer0"), 0);
|
|
||||||
program->SendInteger(program->GetUniformLocation("GBuffer1"), 1);
|
|
||||||
program->SendInteger(program->GetUniformLocation("GBuffer2"), 2);
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
NzShaderProgram* BuildPointSpotLightProgram()
|
|
||||||
{
|
|
||||||
const nzUInt8 fragmentSource[] = {
|
|
||||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag.h>
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* vertexSource =
|
|
||||||
"#version 140\n"
|
|
||||||
|
|
||||||
"in vec3 VertexPosition;\n"
|
|
||||||
|
|
||||||
"uniform mat4 WorldViewProjMatrix;\n"
|
|
||||||
|
|
||||||
"void main()\n"
|
|
||||||
"{\n"
|
|
||||||
"\t" "gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);" "\n"
|
|
||||||
"}\n";
|
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
|
||||||
program->SetPersistent(false);
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, NzString(reinterpret_cast<const char*>(fragmentSource), sizeof(fragmentSource))))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load fragment shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile program");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
program->SendInteger(program->GetUniformLocation("GBuffer0"), 0);
|
|
||||||
program->SendInteger(program->GetUniformLocation("GBuffer1"), 1);
|
|
||||||
program->SendInteger(program->GetUniformLocation("GBuffer2"), 2);
|
|
||||||
|
|
||||||
return program.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NzDeferredPhongLightingPass::NzDeferredPhongLightingPass() :
|
NzDeferredPhongLightingPass::NzDeferredPhongLightingPass() :
|
||||||
m_lightMeshesDrawing(false)
|
m_lightMeshesDrawing(false)
|
||||||
{
|
{
|
||||||
m_directionalLightProgram = BuildDirectionalLightProgram();
|
m_directionalLightShader = NzShaderLibrary::Get("DeferredDirectionnalLight");
|
||||||
m_pointSpotLightProgram = BuildPointSpotLightProgram();
|
|
||||||
|
|
||||||
m_pointSpotLightProgramDiscardLocation = m_pointSpotLightProgram->GetUniformLocation("Discard");
|
m_directionalLightUniforms.ubo = false;
|
||||||
m_pointSpotLightProgramSpotLightLocation = m_pointSpotLightProgram->GetUniformLocation("SpotLight");
|
m_directionalLightUniforms.locations.type = -1; // Type déjà connu
|
||||||
|
m_directionalLightUniforms.locations.color = m_directionalLightShader->GetUniformLocation("LightColor");
|
||||||
|
m_directionalLightUniforms.locations.factors = m_directionalLightShader->GetUniformLocation("LightFactors");
|
||||||
|
m_directionalLightUniforms.locations.parameters1 = m_directionalLightShader->GetUniformLocation("LightDirection");
|
||||||
|
m_directionalLightUniforms.locations.parameters2 = -1;
|
||||||
|
m_directionalLightUniforms.locations.parameters3 = -1;
|
||||||
|
|
||||||
|
m_pointSpotLightShader = NzShaderLibrary::Get("DeferredPointSpotLight");
|
||||||
|
m_pointSpotLightShaderDiscardLocation = m_pointSpotLightShader->GetUniformLocation("Discard");
|
||||||
|
|
||||||
|
m_pointSpotLightUniforms.ubo = false;
|
||||||
|
m_pointSpotLightUniforms.locations.type = m_pointSpotLightShader->GetUniformLocation("LightType");
|
||||||
|
m_pointSpotLightUniforms.locations.color = m_pointSpotLightShader->GetUniformLocation("LightColor");
|
||||||
|
m_pointSpotLightUniforms.locations.factors = m_pointSpotLightShader->GetUniformLocation("LightFactors");
|
||||||
|
m_pointSpotLightUniforms.locations.parameters1 = m_pointSpotLightShader->GetUniformLocation("LightParameters1");
|
||||||
|
m_pointSpotLightUniforms.locations.parameters2 = m_pointSpotLightShader->GetUniformLocation("LightParameters2");
|
||||||
|
m_pointSpotLightUniforms.locations.parameters3 = m_pointSpotLightShader->GetUniformLocation("LightParameters3");
|
||||||
|
|
||||||
m_pointSampler.SetAnisotropyLevel(1);
|
m_pointSampler.SetAnisotropyLevel(1);
|
||||||
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
||||||
|
|
@ -177,13 +100,13 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
if (!m_renderQueue->directionalLights.empty())
|
if (!m_renderQueue->directionalLights.empty())
|
||||||
{
|
{
|
||||||
NzRenderer::SetRenderStates(lightStates);
|
NzRenderer::SetRenderStates(lightStates);
|
||||||
NzRenderer::SetShaderProgram(m_directionalLightProgram);
|
NzRenderer::SetShader(m_directionalLightShader);
|
||||||
m_directionalLightProgram->SendColor(m_directionalLightProgram->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
m_directionalLightShader->SendColor(m_directionalLightShader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||||
m_directionalLightProgram->SendVector(m_directionalLightProgram->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
m_directionalLightShader->SendVector(m_directionalLightShader->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||||
|
|
||||||
for (const NzLight* light : m_renderQueue->directionalLights)
|
for (const NzLight* light : m_renderQueue->directionalLights)
|
||||||
{
|
{
|
||||||
light->Enable(m_directionalLightProgram, 0);
|
light->Enable(m_directionalLightShader, m_directionalLightUniforms);
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -207,23 +130,21 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
|
|
||||||
NzRenderer::SetRenderStates(lightStates);
|
NzRenderer::SetRenderStates(lightStates);
|
||||||
|
|
||||||
NzRenderer::SetShaderProgram(m_pointSpotLightProgram);
|
NzRenderer::SetShader(m_pointSpotLightShader);
|
||||||
m_pointSpotLightProgram->SendColor(m_pointSpotLightProgram->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
m_pointSpotLightShader->SendColor(m_pointSpotLightShader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||||
m_pointSpotLightProgram->SendVector(m_pointSpotLightProgram->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
m_pointSpotLightShader->SendVector(m_pointSpotLightShader->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||||
|
|
||||||
NzMatrix4f lightMatrix;
|
NzMatrix4f lightMatrix;
|
||||||
lightMatrix.MakeIdentity();
|
lightMatrix.MakeIdentity();
|
||||||
if (!m_renderQueue->pointLights.empty())
|
if (!m_renderQueue->pointLights.empty())
|
||||||
{
|
{
|
||||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramSpotLightLocation, false);
|
|
||||||
|
|
||||||
const NzIndexBuffer* indexBuffer = m_sphereMesh->GetIndexBuffer();
|
const NzIndexBuffer* indexBuffer = m_sphereMesh->GetIndexBuffer();
|
||||||
NzRenderer::SetIndexBuffer(indexBuffer);
|
NzRenderer::SetIndexBuffer(indexBuffer);
|
||||||
NzRenderer::SetVertexBuffer(m_sphereMesh->GetVertexBuffer());
|
NzRenderer::SetVertexBuffer(m_sphereMesh->GetVertexBuffer());
|
||||||
|
|
||||||
for (const NzLight* light : m_renderQueue->pointLights)
|
for (const NzLight* light : m_renderQueue->pointLights)
|
||||||
{
|
{
|
||||||
light->Enable(m_pointSpotLightProgram, 0);
|
light->Enable(m_pointSpotLightShader, m_pointSpotLightUniforms);
|
||||||
lightMatrix.SetScale(NzVector3f(light->GetRadius()*1.1f)); // Pour corriger les imperfections liées à la sphère
|
lightMatrix.SetScale(NzVector3f(light->GetRadius()*1.1f)); // Pour corriger les imperfections liées à la sphère
|
||||||
lightMatrix.SetTranslation(light->GetPosition());
|
lightMatrix.SetTranslation(light->GetPosition());
|
||||||
|
|
||||||
|
|
@ -235,7 +156,7 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
NzRenderer::Enable(nzRendererParameter_FaceCulling, false);
|
NzRenderer::Enable(nzRendererParameter_FaceCulling, false);
|
||||||
NzRenderer::SetStencilCompareFunction(nzRendererComparison_Always);
|
NzRenderer::SetStencilCompareFunction(nzRendererComparison_Always);
|
||||||
|
|
||||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramDiscardLocation, true);
|
m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, true);
|
||||||
|
|
||||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
||||||
|
|
||||||
|
|
@ -246,7 +167,7 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
NzRenderer::SetStencilCompareFunction(nzRendererComparison_NotEqual, nzFaceSide_Back);
|
NzRenderer::SetStencilCompareFunction(nzRendererComparison_NotEqual, nzFaceSide_Back);
|
||||||
NzRenderer::SetStencilPassOperation(nzStencilOperation_Zero, nzFaceSide_Back);
|
NzRenderer::SetStencilPassOperation(nzStencilOperation_Zero, nzFaceSide_Back);
|
||||||
|
|
||||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramDiscardLocation, false);
|
m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, false);
|
||||||
|
|
||||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
||||||
}
|
}
|
||||||
|
|
@ -259,20 +180,8 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
NzRenderer::Enable(nzRendererParameter_StencilTest, false);
|
NzRenderer::Enable(nzRendererParameter_StencilTest, false);
|
||||||
NzRenderer::SetFaceFilling(nzFaceFilling_Line);
|
NzRenderer::SetFaceFilling(nzFaceFilling_Line);
|
||||||
|
|
||||||
NzShaderProgramManagerParams params;
|
const NzShader* shader = NzShaderLibrary::Get("DebugSimple");
|
||||||
params.flags = nzShaderFlags_None;
|
NzRenderer::SetShader(shader);
|
||||||
params.target = nzShaderTarget_Model;
|
|
||||||
params.model.alphaMapping = false;
|
|
||||||
params.model.alphaTest = false;
|
|
||||||
params.model.diffuseMapping = false;
|
|
||||||
params.model.emissiveMapping = false;
|
|
||||||
params.model.lighting = false;
|
|
||||||
params.model.normalMapping = false;
|
|
||||||
params.model.parallaxMapping = false;
|
|
||||||
params.model.specularMapping = false;
|
|
||||||
|
|
||||||
const NzShaderProgram* program = NzShaderProgramManager::Get(params);
|
|
||||||
NzRenderer::SetShaderProgram(program);
|
|
||||||
for (const NzLight* light : m_renderQueue->pointLights)
|
for (const NzLight* light : m_renderQueue->pointLights)
|
||||||
{
|
{
|
||||||
lightMatrix.SetScale(NzVector3f(light->GetRadius()*1.1f)); // Pour corriger les imperfections liées à la sphère
|
lightMatrix.SetScale(NzVector3f(light->GetRadius()*1.1f)); // Pour corriger les imperfections liées à la sphère
|
||||||
|
|
@ -280,7 +189,7 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
|
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, lightMatrix);
|
NzRenderer::SetMatrix(nzMatrixType_World, lightMatrix);
|
||||||
|
|
||||||
program->SendColor(program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), light->GetColor());
|
shader->SendColor(0, light->GetColor());
|
||||||
|
|
||||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
||||||
}
|
}
|
||||||
|
|
@ -295,15 +204,13 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
|
|
||||||
if (!m_renderQueue->spotLights.empty())
|
if (!m_renderQueue->spotLights.empty())
|
||||||
{
|
{
|
||||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramSpotLightLocation, true);
|
|
||||||
|
|
||||||
const NzIndexBuffer* indexBuffer = m_coneMesh->GetIndexBuffer();
|
const NzIndexBuffer* indexBuffer = m_coneMesh->GetIndexBuffer();
|
||||||
NzRenderer::SetIndexBuffer(indexBuffer);
|
NzRenderer::SetIndexBuffer(indexBuffer);
|
||||||
NzRenderer::SetVertexBuffer(m_coneMesh->GetVertexBuffer());
|
NzRenderer::SetVertexBuffer(m_coneMesh->GetVertexBuffer());
|
||||||
|
|
||||||
for (const NzLight* light : m_renderQueue->spotLights)
|
for (const NzLight* light : m_renderQueue->spotLights)
|
||||||
{
|
{
|
||||||
light->Enable(m_pointSpotLightProgram, 0);
|
light->Enable(m_pointSpotLightShader, m_pointSpotLightUniforms);
|
||||||
float radius = light->GetRadius()*std::tan(NzDegreeToRadian(light->GetOuterAngle()))*1.1f;
|
float radius = light->GetRadius()*std::tan(NzDegreeToRadian(light->GetOuterAngle()))*1.1f;
|
||||||
lightMatrix.MakeTransform(light->GetPosition(), light->GetRotation(), NzVector3f(radius, radius, light->GetRadius()));
|
lightMatrix.MakeTransform(light->GetPosition(), light->GetRotation(), NzVector3f(radius, radius, light->GetRadius()));
|
||||||
|
|
||||||
|
|
@ -315,7 +222,7 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
NzRenderer::Enable(nzRendererParameter_FaceCulling, false);
|
NzRenderer::Enable(nzRendererParameter_FaceCulling, false);
|
||||||
NzRenderer::SetStencilCompareFunction(nzRendererComparison_Always);
|
NzRenderer::SetStencilCompareFunction(nzRendererComparison_Always);
|
||||||
|
|
||||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramDiscardLocation, true);
|
m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, true);
|
||||||
|
|
||||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
||||||
|
|
||||||
|
|
@ -327,7 +234,7 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
NzRenderer::SetStencilCompareFunction(nzRendererComparison_NotEqual, nzFaceSide_Back);
|
NzRenderer::SetStencilCompareFunction(nzRendererComparison_NotEqual, nzFaceSide_Back);
|
||||||
NzRenderer::SetStencilPassOperation(nzStencilOperation_Zero, nzFaceSide_Back);
|
NzRenderer::SetStencilPassOperation(nzStencilOperation_Zero, nzFaceSide_Back);
|
||||||
|
|
||||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramDiscardLocation, false);
|
m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, false);
|
||||||
|
|
||||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
||||||
}
|
}
|
||||||
|
|
@ -340,20 +247,8 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
NzRenderer::Enable(nzRendererParameter_StencilTest, false);
|
NzRenderer::Enable(nzRendererParameter_StencilTest, false);
|
||||||
NzRenderer::SetFaceFilling(nzFaceFilling_Line);
|
NzRenderer::SetFaceFilling(nzFaceFilling_Line);
|
||||||
|
|
||||||
NzShaderProgramManagerParams params;
|
const NzShader* shader = NzShaderLibrary::Get("DebugSimple");
|
||||||
params.flags = nzShaderFlags_None;
|
NzRenderer::SetShader(shader);
|
||||||
params.target = nzShaderTarget_Model;
|
|
||||||
params.model.alphaMapping = false;
|
|
||||||
params.model.alphaTest = false;
|
|
||||||
params.model.diffuseMapping = false;
|
|
||||||
params.model.emissiveMapping = false;
|
|
||||||
params.model.lighting = false;
|
|
||||||
params.model.normalMapping = false;
|
|
||||||
params.model.parallaxMapping = false;
|
|
||||||
params.model.specularMapping = false;
|
|
||||||
|
|
||||||
const NzShaderProgram* program = NzShaderProgramManager::Get(params);
|
|
||||||
NzRenderer::SetShaderProgram(program);
|
|
||||||
for (const NzLight* light : m_renderQueue->spotLights)
|
for (const NzLight* light : m_renderQueue->spotLights)
|
||||||
{
|
{
|
||||||
float baseRadius = light->GetRadius()*std::tan(NzDegreeToRadian(light->GetOuterAngle()))*1.1f;
|
float baseRadius = light->GetRadius()*std::tan(NzDegreeToRadian(light->GetOuterAngle()))*1.1f;
|
||||||
|
|
@ -361,7 +256,7 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||||
|
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, lightMatrix);
|
NzRenderer::SetMatrix(nzMatrixType_World, lightMatrix);
|
||||||
|
|
||||||
program->SendColor(program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), light->GetColor());
|
shader->SendColor(0, light->GetColor());
|
||||||
|
|
||||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
#include <Nazara/Graphics/Camera.hpp>
|
#include <Nazara/Graphics/Camera.hpp>
|
||||||
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/Model.hpp>
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
#include <Nazara/Graphics/Sprite.hpp>
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
@ -252,19 +252,16 @@ void NzDeferredRenderQueue::OnResourceReleased(const NzResource* resource, int i
|
||||||
|
|
||||||
bool NzDeferredRenderQueue::BatchedModelMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
bool NzDeferredRenderQueue::BatchedModelMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
||||||
{
|
{
|
||||||
nzUInt32 possibleFlags[] = {
|
const NzUberShader* uberShader1 = mat1->GetShader();
|
||||||
nzShaderFlags_Deferred,
|
const NzUberShader* uberShader2 = mat2->GetShader();
|
||||||
nzShaderFlags_Deferred | nzShaderFlags_Instancing
|
if (uberShader1 != uberShader2)
|
||||||
};
|
return uberShader1 < uberShader2;
|
||||||
|
|
||||||
for (nzUInt32 flag : possibleFlags)
|
const NzShader* shader1 = mat1->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||||
{
|
const NzShader* shader2 = mat2->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||||
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
|
||||||
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
|
||||||
|
|
||||||
if (program1 != program2)
|
if (shader1 != shader2)
|
||||||
return program1 < program2;
|
return shader1 < shader2;
|
||||||
}
|
|
||||||
|
|
||||||
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
||||||
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
||||||
|
|
@ -276,18 +273,16 @@ bool NzDeferredRenderQueue::BatchedModelMaterialComparator::operator()(const NzM
|
||||||
|
|
||||||
bool NzDeferredRenderQueue::BatchedSpriteMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
bool NzDeferredRenderQueue::BatchedSpriteMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
||||||
{
|
{
|
||||||
nzUInt32 possibleFlags[] = {
|
const NzUberShader* uberShader1 = mat1->GetShader();
|
||||||
nzShaderFlags_Deferred
|
const NzUberShader* uberShader2 = mat2->GetShader();
|
||||||
};
|
if (uberShader1 != uberShader2)
|
||||||
|
return uberShader1 < uberShader2;
|
||||||
|
|
||||||
for (nzUInt32 flag : possibleFlags)
|
const NzShader* shader1 = mat1->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||||
{
|
const NzShader* shader2 = mat2->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||||
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
|
||||||
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
|
||||||
|
|
||||||
if (program1 != program2)
|
if (shader1 != shader2)
|
||||||
return program1 < program2;
|
return shader1 < shader2;
|
||||||
}
|
|
||||||
|
|
||||||
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
||||||
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@
|
||||||
// This file is part of the "Nazara Engine - Graphics module"
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#ifndef NAZARA_RENDERER_OPENGL
|
||||||
|
#define NAZARA_RENDERER_OPENGL // Nécessaire pour inclure les headers OpenGL
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
|
|
@ -16,12 +20,14 @@
|
||||||
#include <Nazara/Graphics/DeferredPhongLightingPass.hpp>
|
#include <Nazara/Graphics/DeferredPhongLightingPass.hpp>
|
||||||
#include <Nazara/Graphics/Drawable.hpp>
|
#include <Nazara/Graphics/Drawable.hpp>
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/Sprite.hpp>
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Renderer/OpenGL.hpp>
|
#include <Nazara/Renderer/OpenGL.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderStage.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
@ -43,6 +49,37 @@ namespace
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(RenderPassPriority)/sizeof(unsigned int) == nzRenderPassType_Max+1, "Render pass priority array is incomplete");
|
static_assert(sizeof(RenderPassPriority)/sizeof(unsigned int) == nzRenderPassType_Max+1, "Render pass priority array is incomplete");
|
||||||
|
|
||||||
|
inline NzShader* RegisterDeferredShader(const NzString& name, const nzUInt8* fragmentSource, unsigned int fragmentSourceLength, const NzShaderStage& vertexStage, NzString* err)
|
||||||
|
{
|
||||||
|
NzErrorFlags errFlags(nzErrorFlag_ThrowExceptionDisabled);
|
||||||
|
|
||||||
|
std::unique_ptr<NzShader> shader(new NzShader);
|
||||||
|
shader->SetPersistent(false);
|
||||||
|
|
||||||
|
if (!shader->Create())
|
||||||
|
{
|
||||||
|
err->Set("Failed to create shader");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shader->AttachStageFromSource(nzShaderStage_Fragment, reinterpret_cast<const char*>(fragmentSource), fragmentSourceLength))
|
||||||
|
{
|
||||||
|
err->Set("Failed to attach fragment stage");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
shader->AttachStage(nzShaderStage_Vertex, vertexStage);
|
||||||
|
|
||||||
|
if (!shader->Link())
|
||||||
|
{
|
||||||
|
err->Set("Failed to link shader");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
NzShaderLibrary::Register(name, shader.get());
|
||||||
|
return shader.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NzDeferredRenderTechnique::NzDeferredRenderTechnique() :
|
NzDeferredRenderTechnique::NzDeferredRenderTechnique() :
|
||||||
|
|
@ -67,7 +104,6 @@ m_GBufferSize(0U)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NzErrorFlags errFlags(nzErrorFlag_ThrowException);
|
NzErrorFlags errFlags(nzErrorFlag_ThrowException);
|
||||||
std::unique_ptr<NzDeferredRenderPass> smartPtr; // Nous évite un leak en cas d'exception
|
|
||||||
|
|
||||||
ResetPass(nzRenderPassType_Final, 0);
|
ResetPass(nzRenderPassType_Final, 0);
|
||||||
ResetPass(nzRenderPassType_Geometry, 0);
|
ResetPass(nzRenderPassType_Geometry, 0);
|
||||||
|
|
@ -343,14 +379,186 @@ void NzDeferredRenderTechnique::SetPass(nzRenderPassType relativeTo, int positio
|
||||||
m_passes[relativeTo].erase(position);
|
m_passes[relativeTo].erase(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NzDeferredRenderTechnique::Initialize()
|
||||||
|
{
|
||||||
|
const nzUInt8 fragmentSource_BloomBright[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/BloomBright.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 fragmentSource_BloomFinal[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/BloomFinal.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 fragmentSource_DirectionalLight[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/DirectionalLight.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 fragmentSource_FXAA[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 fragmentSource_GBufferClear[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/GBufferClear.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 fragmentSource_GaussianBlur[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/GaussianBlur.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 fragmentSource_PointSpotLight[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/PointSpotLight.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const char vertexSource_Basic[] =
|
||||||
|
"#version 140\n"
|
||||||
|
|
||||||
|
"in vec3 VertexPosition;\n"
|
||||||
|
"uniform mat4 WorldViewProjMatrix;\n"
|
||||||
|
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
"gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
const char vertexSource_PostProcess[] =
|
||||||
|
"#version 140\n"
|
||||||
|
|
||||||
|
"in vec3 VertexPosition;\n"
|
||||||
|
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
"gl_Position = vec4(VertexPosition, 1.0);"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
NzShaderStage basicVertexStage(nzShaderStage_Vertex);
|
||||||
|
if (!basicVertexStage.IsValid())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to create basic vertex shader");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
basicVertexStage.SetSource(vertexSource_Basic, sizeof(vertexSource_Basic));
|
||||||
|
|
||||||
|
if (!basicVertexStage.Compile())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to compile basic vertex shader");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NzShaderStage ppVertexStage(nzShaderStage_Vertex);
|
||||||
|
if (!ppVertexStage.IsValid())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to create vertex shader");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ppVertexStage.SetSource(vertexSource_PostProcess, sizeof(vertexSource_PostProcess));
|
||||||
|
|
||||||
|
if (!ppVertexStage.Compile())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to compile vertex shader");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NzString error;
|
||||||
|
NzShader* shader;
|
||||||
|
|
||||||
|
// Shaders critiques (Nécessaires pour le Deferred Shading minimal)
|
||||||
|
shader = RegisterDeferredShader("DeferredGBufferClear", fragmentSource_GBufferClear, sizeof(fragmentSource_GBufferClear), ppVertexStage, &error);
|
||||||
|
if (!shader)
|
||||||
|
{
|
||||||
|
NazaraError("Failed to register critical shader: " + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shader = RegisterDeferredShader("DeferredDirectionnalLight", fragmentSource_DirectionalLight, sizeof(fragmentSource_DirectionalLight), ppVertexStage, &error);
|
||||||
|
if (!shader)
|
||||||
|
{
|
||||||
|
NazaraError("Failed to register critical shader: " + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("GBuffer0"), 0);
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("GBuffer1"), 1);
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 2);
|
||||||
|
|
||||||
|
|
||||||
|
shader = RegisterDeferredShader("DeferredPointSpotLight", fragmentSource_PointSpotLight, sizeof(fragmentSource_PointSpotLight), basicVertexStage, &error);
|
||||||
|
if (!shader)
|
||||||
|
{
|
||||||
|
NazaraError("Failed to register critical shader: " + error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("GBuffer0"), 0);
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("GBuffer1"), 1);
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 2);
|
||||||
|
|
||||||
|
|
||||||
|
// Shaders optionnels (S'ils ne sont pas présents, le rendu minimal sera quand même assuré)
|
||||||
|
shader = RegisterDeferredShader("DeferredBloomBright", fragmentSource_BloomBright, sizeof(fragmentSource_BloomBright), ppVertexStage, &error);
|
||||||
|
if (shader)
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NazaraWarning("Failed to register bloom (bright pass) shader, certain features will not work: " + error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shader = RegisterDeferredShader("DeferredBloomFinal", fragmentSource_BloomFinal, sizeof(fragmentSource_BloomFinal), ppVertexStage, &error);
|
||||||
|
if (shader)
|
||||||
|
{
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0);
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("BloomTexture"), 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NazaraWarning("Failed to register bloom (final pass) shader, certain features will not work: " + error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shader = RegisterDeferredShader("DeferredFXAA", fragmentSource_FXAA, sizeof(fragmentSource_FXAA), ppVertexStage, &error);
|
||||||
|
if (shader)
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NazaraWarning("Failed to register FXAA shader, certain features will not work: " + error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shader = RegisterDeferredShader("DeferredGaussianBlur", fragmentSource_GaussianBlur, sizeof(fragmentSource_GaussianBlur), ppVertexStage, &error);
|
||||||
|
if (shader)
|
||||||
|
shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NazaraWarning("Failed to register gaussian blur shader, certain features will not work: " + error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool NzDeferredRenderTechnique::IsSupported()
|
bool NzDeferredRenderTechnique::IsSupported()
|
||||||
{
|
{
|
||||||
// On ne va pas s'embêter à écrire un Deferred Renderer qui ne passe pas par le MRT, ce serait lent et inutile (OpenGL 2 garanti cette fonctionnalité en plus)
|
// On ne va pas s'embêter à écrire un Deferred Renderer qui ne passe pas par le MRT, ce serait lent et inutile (OpenGL 2 garanti cette fonctionnalité en plus)
|
||||||
return NzRenderer::HasCapability(nzRendererCap_RenderTexture) &&
|
return NzOpenGL::GetGLSLVersion() >= 140 && // On ne va pas s'embêter non plus avec le mode de compatibilité
|
||||||
|
NzRenderer::HasCapability(nzRendererCap_RenderTexture) &&
|
||||||
NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets) &&
|
NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets) &&
|
||||||
NzRenderer::GetMaxColorAttachments() >= 4 &&
|
NzRenderer::GetMaxColorAttachments() >= 4 &&
|
||||||
NzRenderer::GetMaxRenderTargets() >= 4 &&
|
NzRenderer::GetMaxRenderTargets() >= 4;
|
||||||
NzTexture::IsFormatSupported(nzPixelFormat_RGBA32F);
|
}
|
||||||
|
|
||||||
|
void NzDeferredRenderTechnique::Uninitialize()
|
||||||
|
{
|
||||||
|
NzShaderLibrary::Unregister("DeferredGBufferClear");
|
||||||
|
NzShaderLibrary::Unregister("DeferredDirectionnalLight");
|
||||||
|
NzShaderLibrary::Unregister("DeferredPointSpotLight");
|
||||||
|
NzShaderLibrary::Unregister("DeferredBloomBright");
|
||||||
|
NzShaderLibrary::Unregister("DeferredBloomFinal");
|
||||||
|
NzShaderLibrary::Unregister("DeferredFXAA");
|
||||||
|
NzShaderLibrary::Unregister("DeferredGaussianBlur");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzDeferredRenderTechnique::Resize(const NzVector2ui& dimensions) const
|
bool NzDeferredRenderTechnique::Resize(const NzVector2ui& dimensions) const
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
||||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/Model.hpp>
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
#include <Nazara/Graphics/Sprite.hpp>
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
@ -186,8 +186,7 @@ void NzForwardRenderQueue::AddSubMesh(const NzMaterial* material, const NzSubMes
|
||||||
unsigned int instanceCount = staticDataContainer.size() + 1;
|
unsigned int instanceCount = staticDataContainer.size() + 1;
|
||||||
|
|
||||||
// Avons-nous suffisamment d'instances pour que le coût d'utilisation de l'instancing soit payé ?
|
// Avons-nous suffisamment d'instances pour que le coût d'utilisation de l'instancing soit payé ?
|
||||||
unsigned int tumasoublie = NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT;
|
if (instanceCount >= NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT)
|
||||||
if (instanceCount >= 10)
|
|
||||||
enableInstancing = true; // Apparemment oui, activons l'instancing avec ce matériau
|
enableInstancing = true; // Apparemment oui, activons l'instancing avec ce matériau
|
||||||
|
|
||||||
staticDataContainer.resize(instanceCount);
|
staticDataContainer.resize(instanceCount);
|
||||||
|
|
@ -350,19 +349,16 @@ void NzForwardRenderQueue::OnResourceReleased(const NzResource* resource, int in
|
||||||
|
|
||||||
bool NzForwardRenderQueue::BatchedModelMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
bool NzForwardRenderQueue::BatchedModelMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
||||||
{
|
{
|
||||||
nzUInt32 possibleFlags[] = {
|
const NzUberShader* uberShader1 = mat1->GetShader();
|
||||||
nzShaderFlags_None,
|
const NzUberShader* uberShader2 = mat2->GetShader();
|
||||||
nzShaderFlags_Instancing
|
if (uberShader1 != uberShader2)
|
||||||
};
|
return uberShader1 < uberShader2;
|
||||||
|
|
||||||
for (nzUInt32 flag : possibleFlags)
|
const NzShader* shader1 = mat1->GetShaderInstance()->GetShader();
|
||||||
{
|
const NzShader* shader2 = mat2->GetShaderInstance()->GetShader();
|
||||||
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
|
||||||
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
|
||||||
|
|
||||||
if (program1 != program2)
|
if (shader1 != shader2)
|
||||||
return program1 < program2;
|
return shader1 < shader2;
|
||||||
}
|
|
||||||
|
|
||||||
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
||||||
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
||||||
|
|
@ -374,18 +370,16 @@ bool NzForwardRenderQueue::BatchedModelMaterialComparator::operator()(const NzMa
|
||||||
|
|
||||||
bool NzForwardRenderQueue::BatchedSpriteMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
bool NzForwardRenderQueue::BatchedSpriteMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
||||||
{
|
{
|
||||||
nzUInt32 possibleFlags[] = {
|
const NzUberShader* uberShader1 = mat1->GetShader();
|
||||||
nzShaderFlags_None
|
const NzUberShader* uberShader2 = mat2->GetShader();
|
||||||
};
|
if (uberShader1 != uberShader2)
|
||||||
|
return uberShader1 < uberShader2;
|
||||||
|
|
||||||
for (nzUInt32 flag : possibleFlags)
|
const NzShader* shader1 = mat1->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||||
{
|
const NzShader* shader2 = mat2->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||||
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
|
||||||
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
|
||||||
|
|
||||||
if (program1 != program2)
|
if (shader1 != shader2)
|
||||||
return program1 < program2;
|
return shader1 < shader2;
|
||||||
}
|
|
||||||
|
|
||||||
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
||||||
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
#include <Nazara/Graphics/Camera.hpp>
|
#include <Nazara/Graphics/Camera.hpp>
|
||||||
#include <Nazara/Graphics/Drawable.hpp>
|
#include <Nazara/Graphics/Drawable.hpp>
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/Sprite.hpp>
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
#include <Nazara/Renderer/Config.hpp>
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Utility/BufferMapper.hpp>
|
#include <Nazara/Utility/BufferMapper.hpp>
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static NzIndexBuffer* s_indexBuffer = nullptr;
|
static NzIndexBuffer* s_indexBuffer = nullptr;
|
||||||
unsigned int s_maxLightPerPass = 3; ///TODO: Constante sur le nombre maximum de lumières
|
|
||||||
unsigned int s_maxSprites = 8192;
|
unsigned int s_maxSprites = 8192;
|
||||||
|
|
||||||
NzIndexBuffer* BuildIndexBuffer()
|
NzIndexBuffer* BuildIndexBuffer()
|
||||||
|
|
@ -164,7 +163,8 @@ void NzForwardRenderTechnique::SetMaxLightPassPerObject(unsigned int passCount)
|
||||||
void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
{
|
{
|
||||||
NzAbstractViewer* viewer = scene->GetViewer();
|
NzAbstractViewer* viewer = scene->GetViewer();
|
||||||
const NzShaderProgram* lastProgram = nullptr;
|
const LightUniforms* lightUniforms = nullptr;
|
||||||
|
const NzShader* lastShader = nullptr;
|
||||||
|
|
||||||
for (auto& matIt : m_renderQueue.opaqueModels)
|
for (auto& matIt : m_renderQueue.opaqueModels)
|
||||||
{
|
{
|
||||||
|
|
@ -184,23 +184,23 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
// (Le deferred shading n'a pas ce problème)
|
// (Le deferred shading n'a pas ce problème)
|
||||||
bool instancing = m_instancingEnabled && (!material->IsLightingEnabled() || m_lights.IsEmpty()) && renderQueueInstancing;
|
bool instancing = m_instancingEnabled && (!material->IsLightingEnabled() || m_lights.IsEmpty()) && renderQueueInstancing;
|
||||||
|
|
||||||
// On commence par récupérer le programme du matériau
|
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||||
const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Model, (instancing) ? nzShaderFlags_Instancing : 0);
|
const NzShader* shader = material->Apply((instancing) ? nzShaderFlags_Instancing : 0);
|
||||||
|
|
||||||
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
||||||
if (program != lastProgram)
|
if (shader != lastShader)
|
||||||
{
|
{
|
||||||
NzRenderer::SetShaderProgram(program);
|
|
||||||
|
|
||||||
// Couleur ambiante de la scène
|
// Couleur ambiante de la scène
|
||||||
program->SendColor(program->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||||
// Position de la caméra
|
// Position de la caméra
|
||||||
program->SendVector(program->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
shader->SendVector(shader->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
||||||
|
|
||||||
lastProgram = program;
|
// Index des uniformes d'éclairage dans le shader
|
||||||
|
lightUniforms = GetLightUniforms(shader);
|
||||||
|
|
||||||
|
lastShader = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
material->Apply(program);
|
|
||||||
|
|
||||||
// Meshs squelettiques
|
// Meshs squelettiques
|
||||||
/*if (!skeletalContainer.empty())
|
/*if (!skeletalContainer.empty())
|
||||||
|
|
@ -260,10 +260,10 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
unsigned int lightIndex = 0;
|
unsigned int lightIndex = 0;
|
||||||
nzRendererComparison oldDepthFunc = NzRenderer::GetDepthFunc();
|
nzRendererComparison oldDepthFunc = NzRenderer::GetDepthFunc();
|
||||||
|
|
||||||
unsigned int passCount = (lightCount == 0) ? 1 : (lightCount-1)/s_maxLightPerPass + 1;
|
unsigned int passCount = (lightCount == 0) ? 1 : (lightCount-1)/NAZARA_GRAPHICS_MAX_LIGHTPERPASS + 1;
|
||||||
for (unsigned int pass = 0; pass < passCount; ++pass)
|
for (unsigned int pass = 0; pass < passCount; ++pass)
|
||||||
{
|
{
|
||||||
unsigned int renderedLightCount = std::min(lightCount, s_maxLightPerPass);
|
unsigned int renderedLightCount = std::min(lightCount, NAZARA_GRAPHICS_MAX_LIGHTPERPASS);
|
||||||
lightCount -= renderedLightCount;
|
lightCount -= renderedLightCount;
|
||||||
|
|
||||||
if (pass == 1)
|
if (pass == 1)
|
||||||
|
|
@ -278,10 +278,10 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < renderedLightCount; ++i)
|
for (unsigned int i = 0; i < renderedLightCount; ++i)
|
||||||
m_directionalLights.GetLight(lightIndex++)->Enable(program, i);
|
m_directionalLights.GetLight(lightIndex++)->Enable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||||
|
|
||||||
for (unsigned int i = renderedLightCount; i < s_maxLightPerPass; ++i)
|
for (unsigned int i = renderedLightCount; i < NAZARA_GRAPHICS_MAX_LIGHTPERPASS; ++i)
|
||||||
NzLight::Disable(program, i);
|
NzLight::Disable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||||
|
|
||||||
const NzForwardRenderQueue::StaticData* data = &staticData[0];
|
const NzForwardRenderQueue::StaticData* data = &staticData[0];
|
||||||
unsigned int instanceCount = staticData.size();
|
unsigned int instanceCount = staticData.size();
|
||||||
|
|
@ -317,7 +317,7 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
for (const NzForwardRenderQueue::StaticData& data : staticData)
|
for (const NzForwardRenderQueue::StaticData& data : staticData)
|
||||||
{
|
{
|
||||||
unsigned int directionalLightCount = m_directionalLights.GetLightCount();
|
unsigned int directionalLightCount = m_directionalLights.GetLightCount();
|
||||||
unsigned int otherLightCount = m_lights.ComputeClosestLights(data.transformMatrix.GetTranslation() + boundingSphere.GetPosition(), boundingSphere.radius, m_maxLightPassPerObject*s_maxLightPerPass - directionalLightCount);
|
unsigned int otherLightCount = m_lights.ComputeClosestLights(data.transformMatrix.GetTranslation() + boundingSphere.GetPosition(), boundingSphere.radius, m_maxLightPassPerObject*NAZARA_GRAPHICS_MAX_LIGHTPERPASS - directionalLightCount);
|
||||||
unsigned int lightCount = directionalLightCount + otherLightCount;
|
unsigned int lightCount = directionalLightCount + otherLightCount;
|
||||||
|
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, data.transformMatrix);
|
NzRenderer::SetMatrix(nzMatrixType_World, data.transformMatrix);
|
||||||
|
|
@ -325,10 +325,10 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
unsigned int otherLightIndex = 0;
|
unsigned int otherLightIndex = 0;
|
||||||
nzRendererComparison oldDepthFunc = NzRenderer::GetDepthFunc();
|
nzRendererComparison oldDepthFunc = NzRenderer::GetDepthFunc();
|
||||||
|
|
||||||
unsigned int passCount = (lightCount == 0) ? 1 : (lightCount-1)/s_maxLightPerPass + 1;
|
unsigned int passCount = (lightCount == 0) ? 1 : (lightCount-1)/NAZARA_GRAPHICS_MAX_LIGHTPERPASS + 1;
|
||||||
for (unsigned int pass = 0; pass < passCount; ++pass)
|
for (unsigned int pass = 0; pass < passCount; ++pass)
|
||||||
{
|
{
|
||||||
unsigned int renderedLightCount = std::min(lightCount, s_maxLightPerPass);
|
unsigned int renderedLightCount = std::min(lightCount, NAZARA_GRAPHICS_MAX_LIGHTPERPASS);
|
||||||
lightCount -= renderedLightCount;
|
lightCount -= renderedLightCount;
|
||||||
|
|
||||||
if (pass == 1)
|
if (pass == 1)
|
||||||
|
|
@ -345,13 +345,13 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
for (unsigned int i = 0; i < renderedLightCount; ++i)
|
for (unsigned int i = 0; i < renderedLightCount; ++i)
|
||||||
{
|
{
|
||||||
if (directionalLightIndex >= directionalLightCount)
|
if (directionalLightIndex >= directionalLightCount)
|
||||||
m_lights.GetResult(otherLightIndex++)->Enable(program, i);
|
m_lights.GetResult(otherLightIndex++)->Enable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||||
else
|
else
|
||||||
m_directionalLights.GetLight(directionalLightIndex++)->Enable(program, i);
|
m_directionalLights.GetLight(directionalLightIndex++)->Enable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = renderedLightCount; i < s_maxLightPerPass; ++i)
|
for (unsigned int i = renderedLightCount; i < NAZARA_GRAPHICS_MAX_LIGHTPERPASS; ++i)
|
||||||
NzLight::Disable(program, i);
|
NzLight::Disable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||||
|
|
||||||
DrawFunc(primitiveMode, 0, indexCount);
|
DrawFunc(primitiveMode, 0, indexCount);
|
||||||
}
|
}
|
||||||
|
|
@ -375,7 +375,7 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
void NzForwardRenderTechnique::DrawSprites(const NzScene* scene) const
|
void NzForwardRenderTechnique::DrawSprites(const NzScene* scene) const
|
||||||
{
|
{
|
||||||
NzAbstractViewer* viewer = scene->GetViewer();
|
NzAbstractViewer* viewer = scene->GetViewer();
|
||||||
const NzShaderProgram* lastProgram = nullptr;
|
const NzShader* lastShader = nullptr;
|
||||||
|
|
||||||
NzRenderer::SetIndexBuffer(m_indexBuffer);
|
NzRenderer::SetIndexBuffer(m_indexBuffer);
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Identity());
|
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Identity());
|
||||||
|
|
@ -389,24 +389,20 @@ void NzForwardRenderTechnique::DrawSprites(const NzScene* scene) const
|
||||||
unsigned int spriteCount = spriteVector.size();
|
unsigned int spriteCount = spriteVector.size();
|
||||||
if (spriteCount > 0)
|
if (spriteCount > 0)
|
||||||
{
|
{
|
||||||
// On commence par récupérer le programme du matériau
|
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||||
const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Sprite, 0);
|
const NzShader* shader = material->Apply();
|
||||||
|
|
||||||
// Les uniformes sont conservées au sein du shader, inutile de les renvoyer tant que le shader reste le même
|
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
||||||
if (program != lastProgram)
|
if (shader != lastShader)
|
||||||
{
|
{
|
||||||
NzRenderer::SetShaderProgram(program);
|
|
||||||
|
|
||||||
// Couleur ambiante de la scène
|
// Couleur ambiante de la scène
|
||||||
program->SendColor(program->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||||
// Position de la caméra
|
// Position de la caméra
|
||||||
program->SendVector(program->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
shader->SendVector(shader->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
||||||
|
|
||||||
lastProgram = program;
|
lastShader = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
material->Apply(program);
|
|
||||||
|
|
||||||
const NzSprite** spritePtr = &spriteVector[0];
|
const NzSprite** spritePtr = &spriteVector[0];
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
@ -455,7 +451,8 @@ void NzForwardRenderTechnique::DrawSprites(const NzScene* scene) const
|
||||||
void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
||||||
{
|
{
|
||||||
NzAbstractViewer* viewer = scene->GetViewer();
|
NzAbstractViewer* viewer = scene->GetViewer();
|
||||||
const NzShaderProgram* lastProgram = nullptr;
|
const LightUniforms* lightUniforms = nullptr;
|
||||||
|
const NzShader* lastShader = nullptr;
|
||||||
unsigned int lightCount = 0;
|
unsigned int lightCount = 0;
|
||||||
|
|
||||||
for (const std::pair<unsigned int, bool>& pair : m_renderQueue.transparentsModels)
|
for (const std::pair<unsigned int, bool>& pair : m_renderQueue.transparentsModels)
|
||||||
|
|
@ -465,29 +462,28 @@ void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
||||||
m_renderQueue.transparentStaticModels[pair.first].material :
|
m_renderQueue.transparentStaticModels[pair.first].material :
|
||||||
m_renderQueue.transparentSkeletalModels[pair.first].material;
|
m_renderQueue.transparentSkeletalModels[pair.first].material;
|
||||||
|
|
||||||
// On commence par récupérer le shader du matériau
|
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||||
const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Model, 0);
|
const NzShader* shader = material->Apply();
|
||||||
|
|
||||||
// Les uniformes sont conservées au sein du shader, inutile de les renvoyer tant que le shader reste le même
|
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
||||||
if (program != lastProgram)
|
if (shader != lastShader)
|
||||||
{
|
{
|
||||||
NzRenderer::SetShaderProgram(program);
|
|
||||||
|
|
||||||
// Couleur ambiante de la scène
|
// Couleur ambiante de la scène
|
||||||
program->SendColor(program->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||||
// Position de la caméra
|
// Position de la caméra
|
||||||
program->SendVector(program->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
shader->SendVector(shader->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
||||||
|
|
||||||
|
// Index des uniformes d'éclairage dans le shader
|
||||||
|
lightUniforms = GetLightUniforms(shader);
|
||||||
|
|
||||||
// On envoie les lumières directionnelles s'il y a (Les mêmes pour tous)
|
// On envoie les lumières directionnelles s'il y a (Les mêmes pour tous)
|
||||||
lightCount = std::min(m_directionalLights.GetLightCount(), 3U);
|
lightCount = std::min(m_directionalLights.GetLightCount(), NAZARA_GRAPHICS_MAX_LIGHTPERPASS);
|
||||||
for (unsigned int i = 0; i < lightCount; ++i)
|
for (unsigned int i = 0; i < lightCount; ++i)
|
||||||
m_directionalLights.GetLight(i)->Enable(program, i);
|
m_directionalLights.GetLight(i)->Enable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||||
|
|
||||||
lastProgram = program;
|
lastShader = shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
material->Apply(program);
|
|
||||||
|
|
||||||
// Mesh
|
// Mesh
|
||||||
if (pair.second)
|
if (pair.second)
|
||||||
{
|
{
|
||||||
|
|
@ -518,15 +514,15 @@ void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
||||||
NzRenderer::SetVertexBuffer(vertexBuffer);
|
NzRenderer::SetVertexBuffer(vertexBuffer);
|
||||||
|
|
||||||
// Calcul des lumières les plus proches
|
// Calcul des lumières les plus proches
|
||||||
if (lightCount < s_maxLightPerPass && !m_lights.IsEmpty())
|
if (lightCount < NAZARA_GRAPHICS_MAX_LIGHTPERPASS && !m_lights.IsEmpty())
|
||||||
{
|
{
|
||||||
unsigned int count = std::min(s_maxLightPerPass - lightCount, m_lights.ComputeClosestLights(matrix.GetTranslation() + staticModel.boundingSphere.GetPosition(), staticModel.boundingSphere.radius, s_maxLightPerPass));
|
unsigned int count = std::min(NAZARA_GRAPHICS_MAX_LIGHTPERPASS - lightCount, m_lights.ComputeClosestLights(matrix.GetTranslation() + staticModel.boundingSphere.GetPosition(), staticModel.boundingSphere.radius, NAZARA_GRAPHICS_MAX_LIGHTPERPASS));
|
||||||
for (unsigned int i = 0; i < count; ++i)
|
for (unsigned int i = 0; i < count; ++i)
|
||||||
m_lights.GetResult(i)->Enable(program, lightCount++);
|
m_lights.GetResult(i)->Enable(shader, lightUniforms->uniforms, lightUniforms->offset*(lightCount++));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = lightCount; i < s_maxLightPerPass; ++i)
|
for (unsigned int i = lightCount; i < NAZARA_GRAPHICS_MAX_LIGHTPERPASS; ++i)
|
||||||
NzLight::Disable(program, i);
|
NzLight::Disable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||||
|
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, matrix);
|
NzRenderer::SetMatrix(nzMatrixType_World, matrix);
|
||||||
DrawFunc(mesh->GetPrimitiveMode(), 0, indexCount);
|
DrawFunc(mesh->GetPrimitiveMode(), 0, indexCount);
|
||||||
|
|
@ -537,3 +533,35 @@ void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NzForwardRenderTechnique::LightUniforms* NzForwardRenderTechnique::GetLightUniforms(const NzShader* shader) const
|
||||||
|
{
|
||||||
|
auto it = m_lightUniforms.find(shader);
|
||||||
|
if (it != m_lightUniforms.end())
|
||||||
|
return &(it->second);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int type0Location = shader->GetUniformLocation("Lights[0].type");
|
||||||
|
int type1Location = shader->GetUniformLocation("Lights[1].type");
|
||||||
|
|
||||||
|
LightUniforms lightUniforms;
|
||||||
|
|
||||||
|
if (type0Location > 0 && type1Location > 0)
|
||||||
|
{
|
||||||
|
lightUniforms.exists = true;
|
||||||
|
lightUniforms.offset = type1Location - type0Location;
|
||||||
|
lightUniforms.uniforms.ubo = false;
|
||||||
|
lightUniforms.uniforms.locations.type = type0Location;
|
||||||
|
lightUniforms.uniforms.locations.color = shader->GetUniformLocation("Lights[0].color");
|
||||||
|
lightUniforms.uniforms.locations.factors = shader->GetUniformLocation("Lights[0].factors");
|
||||||
|
lightUniforms.uniforms.locations.parameters1 = shader->GetUniformLocation("Lights[0].parameters1");
|
||||||
|
lightUniforms.uniforms.locations.parameters2 = shader->GetUniformLocation("Lights[0].parameters2");
|
||||||
|
lightUniforms.uniforms.locations.parameters3 = shader->GetUniformLocation("Lights[0].parameters3");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lightUniforms.exists = false;
|
||||||
|
|
||||||
|
auto pair = m_lightUniforms.emplace(shader, lightUniforms);
|
||||||
|
return &(pair.first->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,11 @@
|
||||||
#include <Nazara/Graphics/Config.hpp>
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
||||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||||
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
||||||
#include <Nazara/Graphics/Loaders/OBJ.hpp>
|
#include <Nazara/Graphics/Loaders/OBJ.hpp>
|
||||||
|
#include <Nazara/Graphics/Loaders/Texture.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -35,17 +37,27 @@ bool NzGraphics::Initialize()
|
||||||
// Initialisation du module
|
// Initialisation du module
|
||||||
NzCallOnExit onExit(NzGraphics::Uninitialize);
|
NzCallOnExit onExit(NzGraphics::Uninitialize);
|
||||||
|
|
||||||
|
if (!NzMaterial::Initialize())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to create material");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Loaders
|
// Loaders
|
||||||
NzLoaders_OBJ_Register();
|
NzLoaders_OBJ_Register();
|
||||||
|
|
||||||
// Loader générique
|
// Loaders génériques
|
||||||
NzLoaders_Mesh_Register();
|
NzLoaders_Mesh_Register();
|
||||||
|
NzLoaders_Texture_Register();
|
||||||
|
|
||||||
// RenderTechniques
|
// RenderTechniques
|
||||||
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_BasicForward), 0, []() -> NzAbstractRenderTechnique* { return new NzForwardRenderTechnique; });
|
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_BasicForward), 0, []() -> NzAbstractRenderTechnique* { return new NzForwardRenderTechnique; });
|
||||||
|
|
||||||
if (NzDeferredRenderTechnique::IsSupported())
|
if (NzDeferredRenderTechnique::IsSupported())
|
||||||
|
{
|
||||||
|
NzDeferredRenderTechnique::Initialize();
|
||||||
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_DeferredShading), 20, []() -> NzAbstractRenderTechnique* { return new NzDeferredRenderTechnique; });
|
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_DeferredShading), 20, []() -> NzAbstractRenderTechnique* { return new NzDeferredRenderTechnique; });
|
||||||
|
}
|
||||||
|
|
||||||
onExit.Reset();
|
onExit.Reset();
|
||||||
|
|
||||||
|
|
@ -75,6 +87,11 @@ void NzGraphics::Uninitialize()
|
||||||
// Loaders
|
// Loaders
|
||||||
NzLoaders_Mesh_Unregister();
|
NzLoaders_Mesh_Unregister();
|
||||||
NzLoaders_OBJ_Unregister();
|
NzLoaders_OBJ_Unregister();
|
||||||
|
NzLoaders_Texture_Unregister();
|
||||||
|
|
||||||
|
NzMaterial::Uninitialize();
|
||||||
|
|
||||||
|
NzDeferredRenderTechnique::Uninitialize();
|
||||||
|
|
||||||
NazaraNotice("Uninitialized: Graphics module");
|
NazaraNotice("Uninitialized: Graphics module");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#include <Nazara/Math/Basic.hpp>
|
#include <Nazara/Math/Basic.hpp>
|
||||||
#include <Nazara/Math/Sphere.hpp>
|
#include <Nazara/Math/Sphere.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -41,6 +41,7 @@ m_innerAngle(light.m_innerAngle),
|
||||||
m_outerAngle(light.m_outerAngle),
|
m_outerAngle(light.m_outerAngle),
|
||||||
m_radius(light.m_radius)
|
m_radius(light.m_radius)
|
||||||
{
|
{
|
||||||
|
SetParent(light);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
||||||
|
|
@ -48,7 +49,7 @@ void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
||||||
renderQueue->AddLight(this);
|
renderQueue->AddLight(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) const
|
void NzLight::Enable(const NzShader* shader, const NzLightUniforms& uniforms, int offset) const
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
struct Light
|
struct Light
|
||||||
|
|
@ -75,31 +76,9 @@ void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) con
|
||||||
-P3: float cosInnerAngle + float cosOuterAngle
|
-P3: float cosInnerAngle + float cosOuterAngle
|
||||||
*/
|
*/
|
||||||
|
|
||||||
///TODO: Optimiser
|
shader->SendInteger(uniforms.locations.type + offset, m_type);
|
||||||
int typeLocation = program->GetUniformLocation("Lights[0].type");
|
shader->SendColor(uniforms.locations.color + offset, m_color);
|
||||||
int colorLocation = program->GetUniformLocation("Lights[0].color");
|
shader->SendVector(uniforms.locations.factors + offset, NzVector2f(m_ambientFactor, m_diffuseFactor));
|
||||||
int factorsLocation = program->GetUniformLocation("Lights[0].factors");
|
|
||||||
int parameters1Location = program->GetUniformLocation("Lights[0].parameters1");
|
|
||||||
int parameters2Location = program->GetUniformLocation("Lights[0].parameters2");
|
|
||||||
int parameters3Location = program->GetUniformLocation("Lights[0].parameters3");
|
|
||||||
|
|
||||||
if (lightUnit > 0)
|
|
||||||
{
|
|
||||||
int type2Location = program->GetUniformLocation("Lights[1].type");
|
|
||||||
int offset = lightUnit * (type2Location - typeLocation); // type2Location - typeLocation donne la taille de la structure
|
|
||||||
|
|
||||||
// On applique cet offset
|
|
||||||
typeLocation += offset;
|
|
||||||
colorLocation += offset;
|
|
||||||
factorsLocation += offset;
|
|
||||||
parameters1Location += offset;
|
|
||||||
parameters2Location += offset;
|
|
||||||
parameters3Location += offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
program->SendInteger(typeLocation, m_type);
|
|
||||||
program->SendColor(colorLocation, m_color);
|
|
||||||
program->SendVector(factorsLocation, NzVector2f(m_ambientFactor, m_diffuseFactor));
|
|
||||||
|
|
||||||
if (!m_derivedUpdated)
|
if (!m_derivedUpdated)
|
||||||
UpdateDerived();
|
UpdateDerived();
|
||||||
|
|
@ -107,18 +86,18 @@ void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) con
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
case nzLightType_Directional:
|
case nzLightType_Directional:
|
||||||
program->SendVector(parameters1Location, NzVector4f(m_derivedRotation * NzVector3f::Forward()));
|
shader->SendVector(uniforms.locations.parameters1 + offset, NzVector4f(m_derivedRotation * NzVector3f::Forward()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nzLightType_Point:
|
case nzLightType_Point:
|
||||||
program->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation));
|
shader->SendVector(uniforms.locations.parameters1 + offset, NzVector4f(m_derivedPosition, m_attenuation));
|
||||||
program->SendVector(parameters2Location, NzVector4f(0.f, 0.f, 0.f, 1.f/m_radius));
|
shader->SendVector(uniforms.locations.parameters2 + offset, NzVector4f(0.f, 0.f, 0.f, 1.f/m_radius));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nzLightType_Spot:
|
case nzLightType_Spot:
|
||||||
program->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation));
|
shader->SendVector(uniforms.locations.parameters1 + offset, NzVector4f(m_derivedPosition, m_attenuation));
|
||||||
program->SendVector(parameters2Location, NzVector4f(m_derivedRotation * NzVector3f::Forward(), 1.f/m_radius));
|
shader->SendVector(uniforms.locations.parameters2 + offset, NzVector4f(m_derivedRotation * NzVector3f::Forward(), 1.f/m_radius));
|
||||||
program->SendVector(parameters3Location, NzVector2f(std::cos(NzDegreeToRadian(m_innerAngle)), std::cos(NzDegreeToRadian(m_outerAngle))));
|
shader->SendVector(uniforms.locations.parameters3 + offset, NzVector2f(std::cos(NzDegreeToRadian(m_innerAngle)), std::cos(NzDegreeToRadian(m_outerAngle))));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -245,10 +224,9 @@ NzLight& NzLight::operator=(const NzLight& light)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::Disable(const NzShaderProgram* program, unsigned int lightUnit)
|
void NzLight::Disable(const NzShader* shader, const NzLightUniforms& uniforms, int offset)
|
||||||
{
|
{
|
||||||
///TODO: Optimiser
|
shader->SendInteger(uniforms.locations.type + offset, -1);
|
||||||
program->SendInteger(program->GetUniformLocation("Lights[" + NzString::Number(lightUnit) + "].type"), -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzLight::FrustumCull(const NzFrustumf& frustum)
|
bool NzLight::FrustumCull(const NzFrustumf& frustum)
|
||||||
|
|
@ -276,9 +254,9 @@ bool NzLight::FrustumCull(const NzFrustumf& frustum)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzLight::Invalidate()
|
void NzLight::InvalidateNode()
|
||||||
{
|
{
|
||||||
NzSceneNode::Invalidate();
|
NzSceneNode::InvalidateNode();
|
||||||
|
|
||||||
m_boundingVolumeUpdated = false;
|
m_boundingVolumeUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/Model.hpp>
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Utility/Mesh.hpp>
|
#include <Nazara/Utility/Mesh.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
@ -63,8 +63,11 @@ namespace
|
||||||
{
|
{
|
||||||
std::unique_ptr<NzMaterial> material(new NzMaterial);
|
std::unique_ptr<NzMaterial> material(new NzMaterial);
|
||||||
material->SetPersistent(false);
|
material->SetPersistent(false);
|
||||||
|
|
||||||
if (material->LoadFromFile(mat, parameters.material))
|
if (material->LoadFromFile(mat, parameters.material))
|
||||||
{
|
{
|
||||||
|
material->SetShader(parameters.shaderName);
|
||||||
|
|
||||||
model->SetMaterial(i, material.get());
|
model->SetMaterial(i, material.get());
|
||||||
material.release();
|
material.release();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Graphics/Loaders/OBJ.hpp>
|
#include <Nazara/Graphics/Loaders/OBJ.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
#include <Nazara/Graphics/Loaders/OBJ/MTLParser.hpp>
|
#include <Nazara/Graphics/Loaders/OBJ/MTLParser.hpp>
|
||||||
#include <Nazara/Graphics/Loaders/OBJ/OBJParser.hpp>
|
#include <Nazara/Graphics/Loaders/OBJ/OBJParser.hpp>
|
||||||
#include <Nazara/Graphics/Model.hpp>
|
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
|
||||||
#include <Nazara/Utility/BufferMapper.hpp>
|
#include <Nazara/Utility/BufferMapper.hpp>
|
||||||
#include <Nazara/Utility/IndexMapper.hpp>
|
#include <Nazara/Utility/IndexMapper.hpp>
|
||||||
#include <Nazara/Utility/Mesh.hpp>
|
#include <Nazara/Utility/Mesh.hpp>
|
||||||
|
|
@ -212,6 +212,8 @@ namespace
|
||||||
std::unique_ptr<NzMaterial> material(new NzMaterial);
|
std::unique_ptr<NzMaterial> material(new NzMaterial);
|
||||||
material->SetPersistent(false);
|
material->SetPersistent(false);
|
||||||
|
|
||||||
|
material->SetShader(parameters.shaderName);
|
||||||
|
|
||||||
nzUInt8 alphaValue = static_cast<nzUInt8>(mtlMat->alpha*255.f);
|
nzUInt8 alphaValue = static_cast<nzUInt8>(mtlMat->alpha*255.f);
|
||||||
|
|
||||||
NzColor ambientColor(mtlMat->ambient);
|
NzColor ambientColor(mtlMat->ambient);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright (C) 2014 Jérôme Leclercq
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
// Copyright (C) 2014 Jérôme Leclercq
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/Loaders/Texture.hpp>
|
#include <Nazara/Graphics/Loaders/Texture.hpp>
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Renderer/Texture.hpp>
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
@ -1,17 +1,25 @@
|
||||||
// Copyright (C) 2014 Jérôme Leclercq
|
// Copyright (C) 2014 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Renderer module"
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/Material.hpp>
|
#ifndef NAZARA_RENDERER_OPENGL
|
||||||
|
#define NAZARA_RENDERER_OPENGL // Nécessaire pour inclure les headers OpenGL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
|
#include <Nazara/Renderer/OpenGL.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
#include <Nazara/Renderer/UberShaderPreprocessor.hpp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
bool NzMaterialParams::IsValid() const
|
bool NzMaterialParams::IsValid() const
|
||||||
{
|
{
|
||||||
|
if (!NzUberShaderLibrary::Has(shaderName))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,10 +45,7 @@ NzMaterial::NzMaterial(NzMaterial&& material)
|
||||||
material.m_heightMap.Reset();
|
material.m_heightMap.Reset();
|
||||||
material.m_normalMap.Reset();
|
material.m_normalMap.Reset();
|
||||||
material.m_specularMap.Reset();
|
material.m_specularMap.Reset();
|
||||||
|
material.m_uberShader.Reset();
|
||||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
|
||||||
for (ProgramUnit& unit : material.m_programs[i])
|
|
||||||
unit.program.Reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NzMaterial::~NzMaterial()
|
NzMaterial::~NzMaterial()
|
||||||
|
|
@ -48,108 +53,83 @@ NzMaterial::~NzMaterial()
|
||||||
NotifyDestroy();
|
NotifyDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::Apply(const NzShaderProgram* program) const
|
const NzShader* NzMaterial::Apply(nzUInt32 shaderFlags, nzUInt8 textureUnit, nzUInt8* lastUsedUnit) const
|
||||||
{
|
{
|
||||||
int alphaThresholdLocation = program->GetUniformLocation(nzShaderUniform_MaterialAlphaThreshold);
|
const ShaderInstance& instance = m_shaders[shaderFlags];
|
||||||
int ambientColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialAmbient);
|
if (!instance.uberInstance)
|
||||||
int diffuseColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialDiffuse);
|
GenerateShader(shaderFlags);
|
||||||
int shininessLocation = program->GetUniformLocation(nzShaderUniform_MaterialShininess);
|
|
||||||
int specularColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialSpecular);
|
|
||||||
|
|
||||||
if (m_alphaMap)
|
instance.uberInstance->Activate();
|
||||||
|
|
||||||
|
if (instance.uniforms[nzMaterialUniform_AlphaThreshold] != -1)
|
||||||
|
instance.shader->SendFloat(instance.uniforms[nzMaterialUniform_AlphaThreshold], m_alphaThreshold);
|
||||||
|
|
||||||
|
if (instance.uniforms[nzMaterialUniform_Ambient] != -1)
|
||||||
|
instance.shader->SendColor(instance.uniforms[nzMaterialUniform_Ambient], m_ambientColor);
|
||||||
|
|
||||||
|
if (instance.uniforms[nzMaterialUniform_Diffuse] != -1)
|
||||||
|
instance.shader->SendColor(instance.uniforms[nzMaterialUniform_Diffuse], m_diffuseColor);
|
||||||
|
|
||||||
|
if (instance.uniforms[nzMaterialUniform_Shininess] != -1)
|
||||||
|
instance.shader->SendFloat(instance.uniforms[nzMaterialUniform_Shininess], m_shininess);
|
||||||
|
|
||||||
|
if (instance.uniforms[nzMaterialUniform_Specular] != -1)
|
||||||
|
instance.shader->SendColor(instance.uniforms[nzMaterialUniform_Specular], m_specularColor);
|
||||||
|
|
||||||
|
if (m_alphaMap && instance.uniforms[nzMaterialUniform_AlphaMap] != -1)
|
||||||
{
|
{
|
||||||
int alphaMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialAlphaMap);
|
NzRenderer::SetTexture(textureUnit, m_alphaMap);
|
||||||
if (alphaMapLocation != -1)
|
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||||
{
|
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_AlphaMap], textureUnit);
|
||||||
nzUInt8 textureUnit;
|
textureUnit++;
|
||||||
if (program->SendTexture(alphaMapLocation, m_alphaMap, &textureUnit))
|
|
||||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
|
||||||
else
|
|
||||||
NazaraWarning("Failed to send diffuse map");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alphaThresholdLocation != -1)
|
if (m_diffuseMap && instance.uniforms[nzMaterialUniform_DiffuseMap] != -1)
|
||||||
program->SendFloat(alphaThresholdLocation, m_alphaThreshold);
|
|
||||||
|
|
||||||
if (ambientColorLocation != -1)
|
|
||||||
program->SendColor(ambientColorLocation, m_ambientColor);
|
|
||||||
|
|
||||||
if (diffuseColorLocation != -1)
|
|
||||||
program->SendColor(diffuseColorLocation, m_diffuseColor);
|
|
||||||
|
|
||||||
if (m_diffuseMap)
|
|
||||||
{
|
{
|
||||||
int diffuseMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialDiffuseMap);
|
NzRenderer::SetTexture(textureUnit, m_diffuseMap);
|
||||||
if (diffuseMapLocation != -1)
|
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||||
{
|
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_DiffuseMap], textureUnit);
|
||||||
nzUInt8 textureUnit;
|
textureUnit++;
|
||||||
if (program->SendTexture(diffuseMapLocation, m_diffuseMap, &textureUnit))
|
|
||||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
|
||||||
else
|
|
||||||
NazaraWarning("Failed to send diffuse map");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_emissiveMap)
|
if (m_emissiveMap && instance.uniforms[nzMaterialUniform_EmissiveMap] != -1)
|
||||||
{
|
{
|
||||||
int emissiveMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialEmissiveMap);
|
NzRenderer::SetTexture(textureUnit, m_emissiveMap);
|
||||||
if (emissiveMapLocation != -1)
|
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||||
{
|
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_EmissiveMap], textureUnit);
|
||||||
nzUInt8 textureUnit;
|
textureUnit++;
|
||||||
if (program->SendTexture(emissiveMapLocation, m_emissiveMap, &textureUnit))
|
|
||||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
|
||||||
else
|
|
||||||
NazaraWarning("Failed to send emissive map");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_heightMap)
|
if (m_heightMap && instance.uniforms[nzMaterialUniform_HeightMap] != -1)
|
||||||
{
|
{
|
||||||
int heightMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialHeightMap);
|
NzRenderer::SetTexture(textureUnit, m_heightMap);
|
||||||
if (heightMapLocation != -1)
|
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||||
{
|
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_HeightMap], textureUnit);
|
||||||
nzUInt8 textureUnit;
|
textureUnit++;
|
||||||
if (program->SendTexture(heightMapLocation, m_heightMap, &textureUnit))
|
|
||||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
|
||||||
else
|
|
||||||
NazaraWarning("Failed to send height map");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_normalMap)
|
if (m_normalMap && instance.uniforms[nzMaterialUniform_NormalMap] != -1)
|
||||||
{
|
{
|
||||||
int normalMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialNormalMap);
|
NzRenderer::SetTexture(textureUnit, m_normalMap);
|
||||||
if (normalMapLocation != -1)
|
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||||
{
|
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_NormalMap], textureUnit);
|
||||||
nzUInt8 textureUnit;
|
textureUnit++;
|
||||||
if (program->SendTexture(normalMapLocation, m_normalMap, &textureUnit))
|
|
||||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
|
||||||
else
|
|
||||||
NazaraWarning("Failed to send normal map");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shininessLocation != -1)
|
if (m_specularMap && instance.uniforms[nzMaterialUniform_SpecularMap] != -1)
|
||||||
program->SendFloat(shininessLocation, m_shininess);
|
|
||||||
|
|
||||||
if (specularColorLocation != -1)
|
|
||||||
program->SendColor(specularColorLocation, m_specularColor);
|
|
||||||
|
|
||||||
if (m_specularMap)
|
|
||||||
{
|
{
|
||||||
int specularMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialSpecularMap);
|
NzRenderer::SetTexture(textureUnit, m_specularMap);
|
||||||
if (specularMapLocation != -1)
|
NzRenderer::SetTextureSampler(textureUnit, m_specularSampler);
|
||||||
{
|
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_SpecularMap], textureUnit);
|
||||||
nzUInt8 textureUnit;
|
textureUnit++;
|
||||||
if (program->SendTexture(specularMapLocation, m_specularMap, &textureUnit))
|
|
||||||
NzRenderer::SetTextureSampler(textureUnit, m_specularSampler);
|
|
||||||
else
|
|
||||||
NazaraWarning("Failed to send specular map");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NzRenderer::SetRenderStates(m_states);
|
NzRenderer::SetRenderStates(m_states);
|
||||||
|
|
||||||
|
if (lastUsedUnit)
|
||||||
|
*lastUsedUnit = textureUnit;
|
||||||
|
|
||||||
|
return instance.shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::Enable(nzRendererParameter renderParameter, bool enable)
|
void NzMaterial::Enable(nzRendererParameter renderParameter, bool enable)
|
||||||
|
|
@ -169,16 +149,21 @@ void NzMaterial::EnableAlphaTest(bool alphaTest)
|
||||||
{
|
{
|
||||||
m_alphaTestEnabled = alphaTest;
|
m_alphaTestEnabled = alphaTest;
|
||||||
|
|
||||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
InvalidateShaders();
|
||||||
InvalidatePrograms(nzShaderTarget_Model);
|
|
||||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::EnableLighting(bool lighting)
|
void NzMaterial::EnableLighting(bool lighting)
|
||||||
{
|
{
|
||||||
m_lightingEnabled = lighting;
|
m_lightingEnabled = lighting;
|
||||||
|
|
||||||
InvalidatePrograms(nzShaderTarget_Model);
|
InvalidateShaders();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzMaterial::EnableTransform(bool transform)
|
||||||
|
{
|
||||||
|
m_transformEnabled = transform;
|
||||||
|
|
||||||
|
InvalidateShaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
NzTexture* NzMaterial::GetAlphaMap() const
|
NzTexture* NzMaterial::GetAlphaMap() const
|
||||||
|
|
@ -256,13 +241,17 @@ const NzRenderStates& NzMaterial::GetRenderStates() const
|
||||||
return m_states;
|
return m_states;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NzShaderProgram* NzMaterial::GetShaderProgram(nzShaderTarget target, nzUInt32 flags) const
|
const NzUberShader* NzMaterial::GetShader() const
|
||||||
{
|
{
|
||||||
const ProgramUnit& unit = m_programs[target][flags];
|
return m_uberShader;
|
||||||
if (!unit.program.IsValid())
|
}
|
||||||
GenerateProgram(target, flags);
|
|
||||||
|
|
||||||
return unit.program;
|
const NzUberShaderInstance* NzMaterial::GetShaderInstance(nzUInt32 flags) const
|
||||||
|
{
|
||||||
|
if (!m_shaders[flags].uberInstance)
|
||||||
|
GenerateShader(flags);
|
||||||
|
|
||||||
|
return m_shaders[flags].uberInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
float NzMaterial::GetShininess() const
|
float NzMaterial::GetShininess() const
|
||||||
|
|
@ -300,11 +289,6 @@ bool NzMaterial::HasAlphaMap() const
|
||||||
return m_alphaMap.IsValid();
|
return m_alphaMap.IsValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzMaterial::HasCustomShaderProgram(nzShaderTarget target, nzUInt32 flags) const
|
|
||||||
{
|
|
||||||
return m_programs[target][flags].custom;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzMaterial::HasDiffuseMap() const
|
bool NzMaterial::HasDiffuseMap() const
|
||||||
{
|
{
|
||||||
return m_diffuseMap.IsValid();
|
return m_diffuseMap.IsValid();
|
||||||
|
|
@ -353,6 +337,11 @@ bool NzMaterial::IsLightingEnabled() const
|
||||||
return m_lightingEnabled;
|
return m_lightingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NzMaterial::IsTransformEnabled() const
|
||||||
|
{
|
||||||
|
return m_transformEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
bool NzMaterial::LoadFromFile(const NzString& filePath, const NzMaterialParams& params)
|
bool NzMaterial::LoadFromFile(const NzString& filePath, const NzMaterialParams& params)
|
||||||
{
|
{
|
||||||
return NzMaterialLoader::LoadFromFile(this, filePath, params);
|
return NzMaterialLoader::LoadFromFile(this, filePath, params);
|
||||||
|
|
@ -378,15 +367,10 @@ void NzMaterial::Reset()
|
||||||
m_heightMap.Reset();
|
m_heightMap.Reset();
|
||||||
m_normalMap.Reset();
|
m_normalMap.Reset();
|
||||||
m_specularMap.Reset();
|
m_specularMap.Reset();
|
||||||
|
m_uberShader.Reset();
|
||||||
|
|
||||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
for (ShaderInstance& instance : m_shaders)
|
||||||
{
|
instance.uberInstance = nullptr;
|
||||||
for (ProgramUnit& unit : m_programs[i])
|
|
||||||
{
|
|
||||||
unit.custom = false;
|
|
||||||
unit.program.Reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_alphaThreshold = 0.2f;
|
m_alphaThreshold = 0.2f;
|
||||||
m_alphaTestEnabled = false;
|
m_alphaTestEnabled = false;
|
||||||
|
|
@ -400,6 +384,9 @@ void NzMaterial::Reset()
|
||||||
m_states = NzRenderStates();
|
m_states = NzRenderStates();
|
||||||
m_states.parameters[nzRendererParameter_DepthBuffer] = true;
|
m_states.parameters[nzRendererParameter_DepthBuffer] = true;
|
||||||
m_states.parameters[nzRendererParameter_FaceCulling] = true;
|
m_states.parameters[nzRendererParameter_FaceCulling] = true;
|
||||||
|
m_transformEnabled = true;
|
||||||
|
|
||||||
|
SetShader("Basic");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzMaterial::SetAlphaMap(const NzString& texturePath)
|
bool NzMaterial::SetAlphaMap(const NzString& texturePath)
|
||||||
|
|
@ -423,9 +410,7 @@ void NzMaterial::SetAlphaMap(NzTexture* map)
|
||||||
{
|
{
|
||||||
m_alphaMap = map;
|
m_alphaMap = map;
|
||||||
|
|
||||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
InvalidateShaders();
|
||||||
InvalidatePrograms(nzShaderTarget_Model);
|
|
||||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::SetAlphaThreshold(float alphaThreshold)
|
void NzMaterial::SetAlphaThreshold(float alphaThreshold)
|
||||||
|
|
@ -469,9 +454,7 @@ void NzMaterial::SetDiffuseMap(NzTexture* map)
|
||||||
{
|
{
|
||||||
m_diffuseMap = map;
|
m_diffuseMap = map;
|
||||||
|
|
||||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
InvalidateShaders();
|
||||||
InvalidatePrograms(nzShaderTarget_Model);
|
|
||||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::SetDiffuseSampler(const NzTextureSampler& sampler)
|
void NzMaterial::SetDiffuseSampler(const NzTextureSampler& sampler)
|
||||||
|
|
@ -505,7 +488,7 @@ void NzMaterial::SetEmissiveMap(NzTexture* map)
|
||||||
{
|
{
|
||||||
m_emissiveMap = map;
|
m_emissiveMap = map;
|
||||||
|
|
||||||
InvalidatePrograms(nzShaderTarget_Model);
|
InvalidateShaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::SetFaceCulling(nzFaceSide faceSide)
|
void NzMaterial::SetFaceCulling(nzFaceSide faceSide)
|
||||||
|
|
@ -539,7 +522,7 @@ void NzMaterial::SetHeightMap(NzTexture* map)
|
||||||
{
|
{
|
||||||
m_heightMap = map;
|
m_heightMap = map;
|
||||||
|
|
||||||
InvalidatePrograms(nzShaderTarget_Model);
|
InvalidateShaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzMaterial::SetNormalMap(const NzString& texturePath)
|
bool NzMaterial::SetNormalMap(const NzString& texturePath)
|
||||||
|
|
@ -563,7 +546,7 @@ void NzMaterial::SetNormalMap(NzTexture* map)
|
||||||
{
|
{
|
||||||
m_normalMap = map;
|
m_normalMap = map;
|
||||||
|
|
||||||
InvalidatePrograms(nzShaderTarget_Model);
|
InvalidateShaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::SetRenderStates(const NzRenderStates& states)
|
void NzMaterial::SetRenderStates(const NzRenderStates& states)
|
||||||
|
|
@ -571,12 +554,20 @@ void NzMaterial::SetRenderStates(const NzRenderStates& states)
|
||||||
m_states = states;
|
m_states = states;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::SetShaderProgram(nzShaderTarget target, nzUInt32 flags, const NzShaderProgram* program)
|
void NzMaterial::SetShader(const NzUberShader* uberShader)
|
||||||
{
|
{
|
||||||
ProgramUnit& unit = m_programs[target][flags];
|
m_uberShader = uberShader;
|
||||||
|
InvalidateShaders();
|
||||||
|
}
|
||||||
|
|
||||||
unit.custom = (program != nullptr);
|
bool NzMaterial::SetShader(const NzString& uberShaderName)
|
||||||
unit.program = program;
|
{
|
||||||
|
NzUberShader* uberShader = NzUberShaderLibrary::Get(uberShaderName);
|
||||||
|
if (!uberShader)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
SetShader(uberShader);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::SetShininess(float shininess)
|
void NzMaterial::SetShininess(float shininess)
|
||||||
|
|
@ -610,7 +601,7 @@ void NzMaterial::SetSpecularMap(NzTexture* map)
|
||||||
{
|
{
|
||||||
m_specularMap = map;
|
m_specularMap = map;
|
||||||
|
|
||||||
InvalidatePrograms(nzShaderTarget_Model);
|
InvalidateShaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::SetSpecularSampler(const NzTextureSampler& sampler)
|
void NzMaterial::SetSpecularSampler(const NzTextureSampler& sampler)
|
||||||
|
|
@ -641,19 +632,115 @@ NzMaterial& NzMaterial::operator=(NzMaterial&& material)
|
||||||
material.m_heightMap.Reset();
|
material.m_heightMap.Reset();
|
||||||
material.m_normalMap.Reset();
|
material.m_normalMap.Reset();
|
||||||
material.m_specularMap.Reset();
|
material.m_specularMap.Reset();
|
||||||
|
material.m_uberShader.Reset();
|
||||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
|
||||||
for (ProgramUnit& unit : material.m_programs[i])
|
|
||||||
unit.program.Reset();
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NzMaterial::Initialize()
|
||||||
|
{
|
||||||
|
bool glsl140 = (NzOpenGL::GetGLSLVersion() >= 140);
|
||||||
|
|
||||||
|
// Basic shader
|
||||||
|
{
|
||||||
|
std::unique_ptr<NzUberShaderPreprocessor> uberShader(new NzUberShaderPreprocessor);
|
||||||
|
|
||||||
|
NzString fragmentShader;
|
||||||
|
NzString vertexShader;
|
||||||
|
if (glsl140)
|
||||||
|
{
|
||||||
|
const nzUInt8 coreFragmentShader[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/Basic/core.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 coreVertexShader[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/Basic/core.vert.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
fragmentShader.Set(reinterpret_cast<const char*>(coreFragmentShader), sizeof(coreFragmentShader));
|
||||||
|
vertexShader.Set(reinterpret_cast<const char*>(coreVertexShader), sizeof(coreVertexShader));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const nzUInt8 compatibilityFragmentShader[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/Basic/compatibility.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 compatibilityVertexShader[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/Basic/compatibility.vert.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
fragmentShader.Set(reinterpret_cast<const char*>(compatibilityFragmentShader), sizeof(compatibilityFragmentShader));
|
||||||
|
vertexShader.Set(reinterpret_cast<const char*>(compatibilityVertexShader), sizeof(compatibilityVertexShader));
|
||||||
|
}
|
||||||
|
|
||||||
|
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING");
|
||||||
|
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_INSTANCING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
|
||||||
|
|
||||||
|
NzUberShaderLibrary::Register("Basic", uberShader.get());
|
||||||
|
uberShader.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhongLighting shader
|
||||||
|
{
|
||||||
|
std::unique_ptr<NzUberShaderPreprocessor> uberShader(new NzUberShaderPreprocessor);
|
||||||
|
|
||||||
|
NzString fragmentShader;
|
||||||
|
NzString vertexShader;
|
||||||
|
if (glsl140)
|
||||||
|
{
|
||||||
|
const nzUInt8 coreFragmentShader[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 coreVertexShader[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/core.vert.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
fragmentShader.Set(reinterpret_cast<const char*>(coreFragmentShader), sizeof(coreFragmentShader));
|
||||||
|
vertexShader.Set(reinterpret_cast<const char*>(coreVertexShader), sizeof(coreVertexShader));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const nzUInt8 compatibilityFragmentShader[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/compatibility.frag.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
const nzUInt8 compatibilityVertexShader[] = {
|
||||||
|
#include <Nazara/Graphics/Resources/Shaders/PhongLighting/compatibility.vert.h>
|
||||||
|
};
|
||||||
|
|
||||||
|
fragmentShader.Set(reinterpret_cast<const char*>(compatibilityFragmentShader), sizeof(compatibilityFragmentShader));
|
||||||
|
vertexShader.Set(reinterpret_cast<const char*>(compatibilityVertexShader), sizeof(compatibilityVertexShader));
|
||||||
|
}
|
||||||
|
|
||||||
|
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_DEFERRED ALPHA_MAPPING ALPHA_TEST DIFFUSE_MAPPING EMISSIVE_MAPPING LIGHTING NORMAL_MAPPING PARALLAX_MAPPING SPECULAR_MAPPING");
|
||||||
|
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_DEFERRED FLAG_INSTANCING COMPUTE_TBNMATRIX LIGHTING PARALLAX_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
|
||||||
|
|
||||||
|
NzUberShaderLibrary::Register("PhongLighting", uberShader.get());
|
||||||
|
uberShader.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
s_defaultMaterial = new NzMaterial;
|
||||||
|
s_defaultMaterial->SetPersistent(true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
NzMaterial* NzMaterial::GetDefault()
|
NzMaterial* NzMaterial::GetDefault()
|
||||||
{
|
{
|
||||||
return s_defaultMaterial;
|
return s_defaultMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzMaterial::Uninitialize()
|
||||||
|
{
|
||||||
|
NzUberShaderLibrary::Unregister("PhongLighting");
|
||||||
|
NzUberShaderLibrary::Unregister("Basic");
|
||||||
|
|
||||||
|
s_defaultMaterial->SetPersistent(false, true);
|
||||||
|
s_defaultMaterial = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void NzMaterial::Copy(const NzMaterial& material)
|
void NzMaterial::Copy(const NzMaterial& material)
|
||||||
{
|
{
|
||||||
m_alphaMap.Reset();
|
m_alphaMap.Reset();
|
||||||
|
|
@ -662,10 +749,7 @@ void NzMaterial::Copy(const NzMaterial& material)
|
||||||
m_heightMap.Reset();
|
m_heightMap.Reset();
|
||||||
m_normalMap.Reset();
|
m_normalMap.Reset();
|
||||||
m_specularMap.Reset();
|
m_specularMap.Reset();
|
||||||
|
m_uberShader.Reset();
|
||||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
|
||||||
for (ProgramUnit& unit : m_programs[i])
|
|
||||||
unit.program.Reset();
|
|
||||||
|
|
||||||
std::memcpy(this, &material, sizeof(NzMaterial)); // Autorisé dans notre cas, et bien plus rapide
|
std::memcpy(this, &material, sizeof(NzMaterial)); // Autorisé dans notre cas, et bien plus rapide
|
||||||
|
|
||||||
|
|
@ -676,6 +760,7 @@ void NzMaterial::Copy(const NzMaterial& material)
|
||||||
m_heightMap.Release();
|
m_heightMap.Release();
|
||||||
m_normalMap.Release();
|
m_normalMap.Release();
|
||||||
m_specularMap.Release();
|
m_specularMap.Release();
|
||||||
|
m_uberShader.Release();
|
||||||
|
|
||||||
m_alphaMap = material.m_alphaMap;
|
m_alphaMap = material.m_alphaMap;
|
||||||
m_diffuseMap = material.m_diffuseMap;
|
m_diffuseMap = material.m_diffuseMap;
|
||||||
|
|
@ -683,77 +768,53 @@ void NzMaterial::Copy(const NzMaterial& material)
|
||||||
m_heightMap = material.m_heightMap;
|
m_heightMap = material.m_heightMap;
|
||||||
m_normalMap = material.m_normalMap;
|
m_normalMap = material.m_normalMap;
|
||||||
m_specularMap = material.m_specularMap;
|
m_specularMap = material.m_specularMap;
|
||||||
|
m_uberShader = material.m_uberShader;
|
||||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
|
||||||
{
|
|
||||||
for (unsigned int j = 0; j <= nzShaderFlags_Max; ++j)
|
|
||||||
{
|
|
||||||
NzShaderProgramConstRef& program = m_programs[i][j].program;
|
|
||||||
|
|
||||||
program.Release();
|
|
||||||
program = material.m_programs[i][j].program;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::GenerateProgram(nzShaderTarget target, nzUInt32 flags) const
|
void NzMaterial::GenerateShader(nzUInt32 flags) const
|
||||||
{
|
{
|
||||||
NzShaderProgramManagerParams params;
|
NzParameterList list;
|
||||||
params.target = target;
|
list.SetParameter("ALPHA_MAPPING", m_alphaMap.IsValid());
|
||||||
params.flags = flags;
|
list.SetParameter("ALPHA_TEST", m_alphaTestEnabled);
|
||||||
|
list.SetParameter("COMPUTE_TBNMATRIX", m_normalMap.IsValid() || m_heightMap.IsValid());
|
||||||
|
list.SetParameter("DIFFUSE_MAPPING", m_diffuseMap.IsValid());
|
||||||
|
list.SetParameter("EMISSIVE_MAPPING", m_emissiveMap.IsValid());
|
||||||
|
list.SetParameter("LIGHTING", m_lightingEnabled);
|
||||||
|
list.SetParameter("NORMAL_MAPPING", m_normalMap.IsValid());
|
||||||
|
list.SetParameter("PARALLAX_MAPPING", m_heightMap.IsValid());
|
||||||
|
list.SetParameter("SPECULAR_MAPPING", m_specularMap.IsValid());
|
||||||
|
list.SetParameter("TEXTURE_MAPPING", m_alphaMap.IsValid() || m_diffuseMap.IsValid() || m_emissiveMap.IsValid() ||
|
||||||
|
m_normalMap.IsValid() || m_heightMap.IsValid() || m_specularMap.IsValid());
|
||||||
|
list.SetParameter("TRANSFORM", m_transformEnabled);
|
||||||
|
|
||||||
switch (target)
|
list.SetParameter("FLAG_DEFERRED", static_cast<bool>(flags & nzShaderFlags_Deferred));
|
||||||
{
|
list.SetParameter("FLAG_INSTANCING", static_cast<bool>(flags & nzShaderFlags_Instancing));
|
||||||
case nzShaderTarget_FullscreenQuad:
|
|
||||||
params.fullscreenQuad.alphaMapping = m_alphaMap.IsValid();
|
|
||||||
params.fullscreenQuad.alphaTest = m_alphaTestEnabled;
|
|
||||||
params.fullscreenQuad.diffuseMapping = m_diffuseMap.IsValid();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case nzShaderTarget_Model:
|
ShaderInstance& instance = m_shaders[flags];
|
||||||
params.model.alphaMapping = m_alphaMap.IsValid();
|
instance.uberInstance = m_uberShader->Get(list);
|
||||||
params.model.alphaTest = m_alphaTestEnabled;
|
instance.shader = instance.uberInstance->GetShader();
|
||||||
params.model.diffuseMapping = m_diffuseMap.IsValid();
|
|
||||||
params.model.emissiveMapping = m_emissiveMap.IsValid();
|
|
||||||
params.model.lighting = m_lightingEnabled;
|
|
||||||
params.model.normalMapping = m_normalMap.IsValid();
|
|
||||||
params.model.parallaxMapping = m_heightMap.IsValid();
|
|
||||||
params.model.specularMapping = m_specularMap.IsValid();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case nzShaderTarget_None:
|
#define CacheUniform(name) instance.uniforms[nzMaterialUniform_##name] = instance.shader->GetUniformLocation("Material" #name)
|
||||||
break;
|
|
||||||
|
|
||||||
case nzShaderTarget_Sprite:
|
CacheUniform(AlphaMap);
|
||||||
params.sprite.alphaMapping = m_alphaMap.IsValid();
|
CacheUniform(AlphaThreshold);
|
||||||
params.sprite.alphaTest = m_alphaTestEnabled;
|
CacheUniform(Ambient);
|
||||||
params.sprite.diffuseMapping = m_diffuseMap.IsValid();
|
CacheUniform(Diffuse);
|
||||||
break;
|
CacheUniform(DiffuseMap);
|
||||||
}
|
CacheUniform(EmissiveMap);
|
||||||
|
CacheUniform(HeightMap);
|
||||||
|
CacheUniform(NormalMap);
|
||||||
|
CacheUniform(Shininess);
|
||||||
|
CacheUniform(Specular);
|
||||||
|
CacheUniform(SpecularMap);
|
||||||
|
|
||||||
m_programs[target][flags].program = NzShaderProgramManager::Get(params);
|
#undef CacheUniform
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMaterial::InvalidatePrograms(nzShaderTarget target)
|
void NzMaterial::InvalidateShaders()
|
||||||
{
|
{
|
||||||
for (ProgramUnit& unit : m_programs[target])
|
for (ShaderInstance& instance : m_shaders)
|
||||||
{
|
instance.uberInstance = nullptr;
|
||||||
if (!unit.custom)
|
|
||||||
unit.program.Reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzMaterial::Initialize()
|
|
||||||
{
|
|
||||||
s_defaultMaterial = new NzMaterial;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzMaterial::Uninitialize()
|
|
||||||
{
|
|
||||||
delete s_defaultMaterial;
|
|
||||||
s_defaultMaterial = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NzMaterial* NzMaterial::s_defaultMaterial = nullptr;
|
NzMaterial* NzMaterial::s_defaultMaterial = nullptr;
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||||
#include <Nazara/Graphics/Camera.hpp>
|
#include <Nazara/Graphics/Camera.hpp>
|
||||||
#include <Nazara/Graphics/Config.hpp>
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
|
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -19,6 +20,9 @@ bool NzModelParameters::IsValid() const
|
||||||
if (loadMaterials && !material.IsValid())
|
if (loadMaterials && !material.IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!NzUberShaderLibrary::Has(shaderName))
|
||||||
|
return false;
|
||||||
|
|
||||||
return mesh.IsValid();
|
return mesh.IsValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,6 +60,8 @@ m_skinCount(model.m_skinCount)
|
||||||
if (m_mesh->GetAnimationType() == nzAnimationType_Skeletal)
|
if (m_mesh->GetAnimationType() == nzAnimationType_Skeletal)
|
||||||
m_skeleton = model.m_skeleton;
|
m_skeleton = model.m_skeleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetParent(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
NzModel::~NzModel()
|
NzModel::~NzModel()
|
||||||
|
|
@ -633,9 +639,9 @@ bool NzModel::FrustumCull(const NzFrustumf& frustum)
|
||||||
return frustum.Contains(m_boundingVolume);
|
return frustum.Contains(m_boundingVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzModel::Invalidate()
|
void NzModel::InvalidateNode()
|
||||||
{
|
{
|
||||||
NzSceneNode::Invalidate();
|
NzSceneNode::InvalidateNode();
|
||||||
|
|
||||||
m_boundingVolumeUpdated = false;
|
m_boundingVolumeUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
#version 140
|
|
||||||
|
|
||||||
out vec4 RenderTarget0;
|
|
||||||
|
|
||||||
uniform sampler2D ColorTexture;
|
|
||||||
uniform vec2 InvTargetSize;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
|
||||||
RenderTarget0 = textureLod(ColorTexture, texCoord, 0.0);
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,125,13,10,
|
|
||||||
|
|
@ -2,20 +2,11 @@
|
||||||
|
|
||||||
out vec4 RenderTarget0;
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
struct Light
|
|
||||||
{
|
|
||||||
int type;
|
|
||||||
vec4 ambient;
|
|
||||||
vec4 color;
|
|
||||||
vec2 factors;
|
|
||||||
|
|
||||||
vec4 parameters1;
|
|
||||||
vec4 parameters2;
|
|
||||||
vec2 parameters3;
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform vec3 EyePosition;
|
uniform vec3 EyePosition;
|
||||||
uniform Light Lights[1];
|
|
||||||
|
uniform vec4 LightColor;
|
||||||
|
uniform vec2 LightFactors;
|
||||||
|
uniform vec4 LightDirection;
|
||||||
|
|
||||||
uniform sampler2D GBuffer0;
|
uniform sampler2D GBuffer0;
|
||||||
uniform sampler2D GBuffer1;
|
uniform sampler2D GBuffer1;
|
||||||
|
|
@ -56,15 +47,15 @@ void main()
|
||||||
float depth = ColorToFloat(gVec2.xyz);
|
float depth = ColorToFloat(gVec2.xyz);
|
||||||
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
||||||
|
|
||||||
vec3 lightDir = -Lights[0].parameters1.xyz;
|
vec3 lightDir = -LightDirection.xyz;
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
vec3 lightAmbient = Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
|
vec3 lightAmbient = LightColor.rgb * LightFactors.x * (vec3(1.0) + SceneAmbient.rgb);
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
vec3 lightDiffuse = lambert * Lights[0].color.rgb * Lights[0].factors.y;
|
vec3 lightDiffuse = lambert * LightColor.rgb * LightFactors.y;
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
vec3 lightSpecular;
|
vec3 lightSpecular;
|
||||||
|
|
@ -81,7 +72,7 @@ void main()
|
||||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
specularFactor = pow(specularFactor, shininess);
|
specularFactor = pow(specularFactor, shininess);
|
||||||
|
|
||||||
lightSpecular = specularFactor * Lights[0].color.rgb * specularMultiplier;
|
lightSpecular = specularFactor * LightColor.rgb * specularMultiplier;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
lightSpecular = vec3(0.0);
|
lightSpecular = vec3(0.0);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,21 +1,20 @@
|
||||||
#version 140
|
#version 140
|
||||||
|
|
||||||
|
#define LIGHT_DIRECTIONAL 0
|
||||||
|
#define LIGHT_POINT 1
|
||||||
|
#define LIGHT_SPOT 2
|
||||||
|
|
||||||
out vec4 RenderTarget0;
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
struct Light
|
|
||||||
{
|
|
||||||
int type;
|
|
||||||
vec4 ambient;
|
|
||||||
vec4 color;
|
|
||||||
vec2 factors;
|
|
||||||
|
|
||||||
vec4 parameters1;
|
|
||||||
vec4 parameters2;
|
|
||||||
vec2 parameters3;
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform vec3 EyePosition;
|
uniform vec3 EyePosition;
|
||||||
uniform Light Lights[1];
|
|
||||||
|
uniform int LightType;
|
||||||
|
uniform vec4 LightColor;
|
||||||
|
uniform vec2 LightFactors;
|
||||||
|
uniform vec4 LightDirection;
|
||||||
|
uniform vec4 LightParameters1;
|
||||||
|
uniform vec4 LightParameters2;
|
||||||
|
uniform vec2 LightParameters3;
|
||||||
|
|
||||||
uniform sampler2D GBuffer0;
|
uniform sampler2D GBuffer0;
|
||||||
uniform sampler2D GBuffer1;
|
uniform sampler2D GBuffer1;
|
||||||
|
|
@ -26,7 +25,6 @@ uniform vec2 InvTargetSize;
|
||||||
uniform vec4 SceneAmbient;
|
uniform vec4 SceneAmbient;
|
||||||
|
|
||||||
uniform bool Discard = false;
|
uniform bool Discard = false;
|
||||||
uniform bool SpotLight;
|
|
||||||
|
|
||||||
float ColorToFloat(vec3 color)
|
float ColorToFloat(vec3 color)
|
||||||
{
|
{
|
||||||
|
|
@ -67,28 +65,28 @@ void main()
|
||||||
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||||
worldPos.xyz /= worldPos.w;
|
worldPos.xyz /= worldPos.w;
|
||||||
|
|
||||||
vec3 lightDir = Lights[0].parameters1.xyz - worldPos.xyz;
|
vec3 lightDir = LightParameters1.xyz - worldPos.xyz;
|
||||||
float lightDirLength = length(lightDir);
|
float lightDirLength = length(lightDir);
|
||||||
lightDir /= lightDirLength;
|
lightDir /= lightDirLength;
|
||||||
|
|
||||||
float att = max(Lights[0].parameters1.w - Lights[0].parameters2.w*lightDirLength, 0.0);
|
float att = max(LightParameters1.w - LightParameters2.w*lightDirLength, 0.0);
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
vec3 lightAmbient = att * Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
|
vec3 lightAmbient = att * LightColor.rgb * LightFactors.x * (vec3(1.0) + SceneAmbient.rgb);
|
||||||
|
|
||||||
if (SpotLight)
|
if (LightType == LIGHT_SPOT)
|
||||||
{
|
{
|
||||||
// Modification de l'atténuation pour gérer le spot
|
// Modification de l'atténuation pour gérer le spot
|
||||||
float curAngle = dot(Lights[0].parameters2.xyz, -lightDir);
|
float curAngle = dot(LightParameters2.xyz, -lightDir);
|
||||||
float outerAngle = Lights[0].parameters3.y;
|
float outerAngle = LightParameters3.y;
|
||||||
float innerMinusOuterAngle = Lights[0].parameters3.x - outerAngle;
|
float innerMinusOuterAngle = LightParameters3.x - outerAngle;
|
||||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diffuse
|
// Diffuse
|
||||||
float lambert = max(dot(normal, lightDir), 0.0);
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
vec3 lightDiffuse = att * lambert * Lights[0].color.rgb * Lights[0].factors.y;
|
vec3 lightDiffuse = att * lambert * LightColor.rgb * LightFactors.y;
|
||||||
|
|
||||||
// Specular
|
// Specular
|
||||||
vec3 lightSpecular;
|
vec3 lightSpecular;
|
||||||
|
|
@ -99,7 +97,7 @@ void main()
|
||||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
specularFactor = pow(specularFactor, shininess);
|
specularFactor = pow(specularFactor, shininess);
|
||||||
|
|
||||||
lightSpecular = att * specularFactor * Lights[0].color.rgb * specularMultiplier;
|
lightSpecular = att * specularFactor * LightColor.rgb * specularMultiplier;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
lightSpecular = vec3(0.0);
|
lightSpecular = vec3(0.0);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,82 +0,0 @@
|
||||||
#version 140
|
|
||||||
|
|
||||||
out vec4 RenderTarget0;
|
|
||||||
|
|
||||||
uniform float SSAOBias = 0.0;
|
|
||||||
uniform float SSAOIntensity = 3.0;
|
|
||||||
uniform float SSAOSampleScale = 0.1;
|
|
||||||
uniform float SSAOScale = 1.0;
|
|
||||||
uniform int NoiseTextureSize;
|
|
||||||
uniform mat4 InvViewProjMatrix;
|
|
||||||
uniform sampler2D GBuffer1;
|
|
||||||
uniform sampler2D NoiseTexture;
|
|
||||||
uniform vec2 TargetSize;
|
|
||||||
uniform vec2 InvTargetSize;
|
|
||||||
|
|
||||||
vec3 extractPosition(in float depth, in vec2 texCoord)
|
|
||||||
{
|
|
||||||
depth = depth*2.0 - 1.0;
|
|
||||||
|
|
||||||
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
|
|
||||||
|
|
||||||
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
|
||||||
worldPos.xyz /= worldPos.w;
|
|
||||||
|
|
||||||
return worldPos.xyz;
|
|
||||||
}
|
|
||||||
|
|
||||||
float doAmbientOcclusion(in vec2 texCoord, in vec3 original, in vec3 normal)
|
|
||||||
{
|
|
||||||
vec3 newp = extractPosition(textureLod(GBuffer1, texCoord, 0.0).w, texCoord);
|
|
||||||
vec3 diff = newp - original;
|
|
||||||
float d = length(diff);
|
|
||||||
vec3 v = diff * 1.0/d;
|
|
||||||
d *= SSAOScale;
|
|
||||||
|
|
||||||
return max(0.0, dot(normal, v) - SSAOBias) * (SSAOIntensity / (1.0 + d));
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
const vec2 Kernel[16] = vec2[](
|
|
||||||
vec2(0.53812504, 0.18565957),
|
|
||||||
vec2(0.13790712, 0.24864247),
|
|
||||||
vec2(0.33715037, 0.56794053),
|
|
||||||
vec2(-0.6999805, -0.04511441),
|
|
||||||
vec2(0.06896307, -0.15983082),
|
|
||||||
vec2(0.056099437, 0.006954967),
|
|
||||||
vec2(-0.014653638, 0.14027752),
|
|
||||||
vec2(0.010019933, -0.1924225),
|
|
||||||
vec2(-0.35775623, -0.5301969),
|
|
||||||
vec2(-0.3169221, 0.106360726),
|
|
||||||
vec2(0.010350345, -0.58698344),
|
|
||||||
vec2(-0.08972908, -0.49408212),
|
|
||||||
vec2(0.7119986, -0.0154690035),
|
|
||||||
vec2(-0.053382345, 0.059675813),
|
|
||||||
vec2(0.035267662, -0.063188605),
|
|
||||||
vec2(-0.47761092, 0.2847911));
|
|
||||||
|
|
||||||
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
|
||||||
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
|
|
||||||
|
|
||||||
if (gVec1.w == 1.0)
|
|
||||||
{
|
|
||||||
RenderTarget0 = vec4(1.0, 0.0, 0.0, 0.0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 normal = gVec1.xyz*2.0 - 1.0;
|
|
||||||
|
|
||||||
vec3 viewPos = extractPosition(gVec1.w, texCoord);
|
|
||||||
vec2 randVec = normalize(textureLod(NoiseTexture, texCoord * (TargetSize/NoiseTextureSize), 0.0).xy * 2.0 - 1.0);
|
|
||||||
|
|
||||||
float ao = 0.0;
|
|
||||||
const int ITERATIONS = 16;
|
|
||||||
for (int i = 0; i < ITERATIONS; ++i)
|
|
||||||
{
|
|
||||||
vec2 coord = reflect(Kernel[i], randVec) * SSAOSampleScale;
|
|
||||||
ao += doAmbientOcclusion(texCoord + coord, viewPos, normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderTarget0 = vec4(1.0 - ao/ITERATIONS, 0.0, 0.0, 0.0);
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,17 +0,0 @@
|
||||||
#version 140
|
|
||||||
|
|
||||||
out vec4 RenderTarget0;
|
|
||||||
|
|
||||||
uniform sampler2D ColorTexture;
|
|
||||||
uniform sampler2D SSAOTexture;
|
|
||||||
uniform vec2 InvTargetSize;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
|
||||||
|
|
||||||
vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb;
|
|
||||||
float ssao = textureLod(SSAOTexture, texCoord, 0.0).r;
|
|
||||||
|
|
||||||
RenderTarget0 = vec4(color*ssao, 1.0);
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,83,83,65,79,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,9,102,108,111,97,116,32,115,115,97,111,32,61,32,116,101,120,116,117,114,101,76,111,100,40,83,83,65,79,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,59,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,42,115,115,97,111,44,32,49,46,48,41,59,13,10,125,13,10,
|
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
#if FLAG_DEFERRED
|
|
||||||
#error Deferred Shading needs core profile
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/********************Entrant********************/
|
/********************Entrant********************/
|
||||||
varying vec2 vTexCoord;
|
varying vec2 vTexCoord;
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,50,68,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,50,68,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,118,84,101,120,67,111,111,114,100,41,46,114,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,13,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,13,10,9,9,100,105,115,99,97,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,9,103,108,95,70,114,97,103,67,111,108,111,114,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,13,10,125,
|
||||||
|
|
@ -7,10 +7,7 @@ varying vec2 VertexTexCoord;
|
||||||
varying vec2 vTexCoord;
|
varying vec2 vTexCoord;
|
||||||
|
|
||||||
/********************Uniformes********************/
|
/********************Uniformes********************/
|
||||||
uniform sampler2D MaterialAlphaMap;
|
uniform float VertexDepth;
|
||||||
uniform float MaterialAlphaThreshold;
|
|
||||||
uniform vec4 MaterialDiffuse;
|
|
||||||
uniform sampler2D MaterialDiffuseMap;
|
|
||||||
uniform mat4 ViewProjMatrix;
|
uniform mat4 ViewProjMatrix;
|
||||||
uniform mat4 WorldViewProjMatrix;
|
uniform mat4 WorldViewProjMatrix;
|
||||||
|
|
||||||
|
|
@ -18,16 +15,28 @@ uniform mat4 WorldViewProjMatrix;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
|
#if TRANSFORM
|
||||||
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
#else
|
||||||
|
#if UNIFORM_VERTEX_DEPTH
|
||||||
|
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
|
||||||
|
#else
|
||||||
|
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#if TRANSFORM
|
||||||
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
||||||
|
#else
|
||||||
|
#if UNIFORM_VERTEX_DEPTH
|
||||||
|
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
|
||||||
|
#else
|
||||||
|
gl_Position = vec4(VertexPosition, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING
|
#if TEXTURE_MAPPING
|
||||||
#if FLAG_FLIP_UVS
|
|
||||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
|
||||||
#else
|
|
||||||
vTexCoord = vec2(VertexTexCoord);
|
vTexCoord = vec2(VertexTexCoord);
|
||||||
#endif // FLAG_FLIP_UVS
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,97,114,121,105,110,103,32,109,97,116,52,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,13,10,118,97,114,121,105,110,103,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,13,10,118,97,114,121,105,110,103,32,118,101,99,50,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,97,114,121,105,110,103,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,86,101,114,116,101,120,68,101,112,116,104,59,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,13,10,9,35,105,102,32,84,82,65,78,83,70,79,82,77,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,35,101,108,115,101,13,10,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,9,9,35,101,108,115,101,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,9,35,101,110,100,105,102,13,10,9,35,101,110,100,105,102,13,10,35,101,108,115,101,13,10,9,35,105,102,32,84,82,65,78,83,70,79,82,77,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,35,101,108,115,101,13,10,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,9,9,35,101,108,115,101,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,9,35,101,110,100,105,102,13,10,9,35,101,110,100,105,102,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,84,69,88,84,85,82,69,95,77,65,80,80,73,78,71,13,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,86,101,114,116,101,120,84,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,125,13,10,
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
#if EARLY_FRAGMENT_TESTS && !ALPHA_TEST
|
||||||
|
layout(early_fragment_tests) in;
|
||||||
|
#endif
|
||||||
|
|
||||||
/********************Entrant********************/
|
/********************Entrant********************/
|
||||||
in vec2 vTexCoord;
|
in vec2 vTexCoord;
|
||||||
|
|
||||||
|
|
@ -9,17 +13,25 @@ uniform sampler2D MaterialAlphaMap;
|
||||||
uniform float MaterialAlphaThreshold;
|
uniform float MaterialAlphaThreshold;
|
||||||
uniform vec4 MaterialDiffuse;
|
uniform vec4 MaterialDiffuse;
|
||||||
uniform sampler2D MaterialDiffuseMap;
|
uniform sampler2D MaterialDiffuseMap;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
|
||||||
/********************Fonctions********************/
|
/********************Fonctions********************/
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 fragmentColor = MaterialDiffuse;
|
vec4 fragmentColor = MaterialDiffuse;
|
||||||
|
|
||||||
|
#if AUTO_TEXCOORDS
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
#else
|
||||||
|
vec2 texCoord = vTexCoord;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if DIFFUSE_MAPPING
|
#if DIFFUSE_MAPPING
|
||||||
fragmentColor *= texture(MaterialDiffuseMap, vTexCoord);
|
fragmentColor *= texture(MaterialDiffuseMap, texCoord);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ALPHA_MAPPING
|
#if ALPHA_MAPPING
|
||||||
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
fragmentColor.a *= texture(MaterialAlphaMap, texCoord).r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ALPHA_TEST
|
#if ALPHA_TEST
|
||||||
|
|
@ -27,9 +39,5 @@ void main()
|
||||||
discard;
|
discard;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FLAG_DEFERRED
|
|
||||||
RenderTarget0 = vec4(fragmentColor.rgb, 0.0);
|
|
||||||
#else
|
|
||||||
RenderTarget0 = fragmentColor;
|
RenderTarget0 = fragmentColor;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
35,105,102,32,69,65,82,76,89,95,70,82,65,71,77,69,78,84,95,84,69,83,84,83,32,38,38,32,33,65,76,80,72,65,95,84,69,83,84,13,10,108,97,121,111,117,116,40,101,97,114,108,121,95,102,114,97,103,109,101,110,116,95,116,101,115,116,115,41,32,105,110,59,13,10,35,101,110,100,105,102,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,105,110,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,13,10,35,105,102,32,65,85,84,79,95,84,69,88,67,79,79,82,68,83,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,35,101,108,115,101,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,118,84,101,120,67,111,111,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,116,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,13,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,13,10,9,9,100,105,115,99,97,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,13,10,125,
|
||||||
|
|
@ -7,10 +7,7 @@ in vec2 VertexTexCoord;
|
||||||
out vec2 vTexCoord;
|
out vec2 vTexCoord;
|
||||||
|
|
||||||
/********************Uniformes********************/
|
/********************Uniformes********************/
|
||||||
uniform sampler2D MaterialAlphaMap;
|
uniform float VertexDepth;
|
||||||
uniform float MaterialAlphaThreshold;
|
|
||||||
uniform vec4 MaterialDiffuse;
|
|
||||||
uniform sampler2D MaterialDiffuseMap;
|
|
||||||
uniform mat4 ViewProjMatrix;
|
uniform mat4 ViewProjMatrix;
|
||||||
uniform mat4 WorldViewProjMatrix;
|
uniform mat4 WorldViewProjMatrix;
|
||||||
|
|
||||||
|
|
@ -18,16 +15,28 @@ uniform mat4 WorldViewProjMatrix;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
|
#if TRANSFORM
|
||||||
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
#else
|
||||||
|
#if UNIFORM_VERTEX_DEPTH
|
||||||
|
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
|
||||||
|
#else
|
||||||
|
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#if TRANSFORM
|
||||||
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
||||||
|
#else
|
||||||
|
#if UNIFORM_VERTEX_DEPTH
|
||||||
|
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
|
||||||
|
#else
|
||||||
|
gl_Position = vec4(VertexPosition, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING
|
#if TEXTURE_MAPPING
|
||||||
#if FLAG_FLIP_UVS
|
|
||||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
|
||||||
#else
|
|
||||||
vTexCoord = vec2(VertexTexCoord);
|
vTexCoord = vec2(VertexTexCoord);
|
||||||
#endif // FLAG_FLIP_UVS
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,105,110,32,109,97,116,52,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,13,10,105,110,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,13,10,105,110,32,118,101,99,50,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,111,117,116,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,86,101,114,116,101,120,68,101,112,116,104,59,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,13,10,9,35,105,102,32,84,82,65,78,83,70,79,82,77,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,35,101,108,115,101,13,10,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,9,9,35,101,108,115,101,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,9,35,101,110,100,105,102,13,10,9,35,101,110,100,105,102,13,10,35,101,108,115,101,13,10,9,35,105,102,32,84,82,65,78,83,70,79,82,77,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,35,101,108,115,101,13,10,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,9,9,35,101,108,115,101,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,9,35,101,110,100,105,102,13,10,9,35,101,110,100,105,102,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,84,69,88,84,85,82,69,95,77,65,80,80,73,78,71,13,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,86,101,114,116,101,120,84,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,125,13,10,
|
||||||
|
|
@ -12,6 +12,7 @@ varying vec2 vTexCoord;
|
||||||
varying vec3 vWorldPos;
|
varying vec3 vWorldPos;
|
||||||
|
|
||||||
/********************Uniformes********************/
|
/********************Uniformes********************/
|
||||||
|
uniform float VertexDepth;
|
||||||
uniform mat4 ViewProjMatrix;
|
uniform mat4 ViewProjMatrix;
|
||||||
uniform mat4 WorldMatrix;
|
uniform mat4 WorldMatrix;
|
||||||
uniform mat4 WorldViewProjMatrix;
|
uniform mat4 WorldViewProjMatrix;
|
||||||
|
|
@ -20,11 +21,28 @@ uniform mat4 WorldViewProjMatrix;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
|
#if TRANSFORM
|
||||||
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
#else
|
||||||
|
#if UNIFORM_VERTEX_DEPTH
|
||||||
|
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
|
||||||
|
#else
|
||||||
|
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#if TRANSFORM
|
||||||
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
||||||
|
#else
|
||||||
|
#if UNIFORM_VERTEX_DEPTH
|
||||||
|
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
|
||||||
|
#else
|
||||||
|
gl_Position = vec4(VertexPosition, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if LIGHTING
|
#if LIGHTING
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
mat3 rotationMatrix = mat3(InstanceData0[0].xyz, InstanceData0[1].xyz, InstanceData0[2].xyz);
|
mat3 rotationMatrix = mat3(InstanceData0[0].xyz, InstanceData0[1].xyz, InstanceData0[2].xyz);
|
||||||
|
|
@ -42,15 +60,20 @@ void main()
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING || EMISSIVE_MAPPING || NORMAL_MAPPING || PARALLAX_MAPPING || SPECULAR_MAPPING
|
#if TEXTURE_MAPPING
|
||||||
#if FLAG_FLIP_UVS
|
/* #if FLAG_FLIP_UVS
|
||||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||||
#else
|
#else*/
|
||||||
vTexCoord = VertexTexCoord;
|
vTexCoord = VertexTexCoord;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LIGHTING
|
#if LIGHTING && PARALLAX_MAPPING
|
||||||
|
vViewDir = EyePosition - VertexPosition;
|
||||||
|
vViewDir *= vLightToWorld;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LIGHTING && !FLAG_DEFERRED
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
|
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
|
||||||
#else
|
#else
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +1,7 @@
|
||||||
|
#if EARLY_FRAGMENT_TESTS && !ALPHA_TEST
|
||||||
|
layout(early_fragment_tests) in;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define LIGHT_DIRECTIONAL 0
|
#define LIGHT_DIRECTIONAL 0
|
||||||
#define LIGHT_POINT 1
|
#define LIGHT_POINT 1
|
||||||
#define LIGHT_SPOT 2
|
#define LIGHT_SPOT 2
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -14,6 +14,7 @@ out vec3 vWorldPos;
|
||||||
|
|
||||||
/********************Uniformes********************/
|
/********************Uniformes********************/
|
||||||
uniform vec3 EyePosition;
|
uniform vec3 EyePosition;
|
||||||
|
uniform float VertexDepth;
|
||||||
uniform mat4 ViewProjMatrix;
|
uniform mat4 ViewProjMatrix;
|
||||||
uniform mat4 WorldMatrix;
|
uniform mat4 WorldMatrix;
|
||||||
uniform mat4 WorldViewProjMatrix;
|
uniform mat4 WorldViewProjMatrix;
|
||||||
|
|
@ -22,19 +23,35 @@ uniform mat4 WorldViewProjMatrix;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
|
#if TRANSFORM
|
||||||
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
#else
|
||||||
|
#if UNIFORM_VERTEX_DEPTH
|
||||||
|
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
|
||||||
|
#else
|
||||||
|
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#if TRANSFORM
|
||||||
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
||||||
|
#else
|
||||||
|
#if UNIFORM_VERTEX_DEPTH
|
||||||
|
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
|
||||||
|
#else
|
||||||
|
gl_Position = vec4(VertexPosition, 1.0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LIGHTING
|
//#if LIGHTING
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
mat3 rotationMatrix = mat3(InstanceData0);
|
mat3 rotationMatrix = mat3(InstanceData0);
|
||||||
#else
|
#else
|
||||||
mat3 rotationMatrix = mat3(WorldMatrix);
|
mat3 rotationMatrix = mat3(WorldMatrix);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NORMAL_MAPPING || PARALLAX_MAPPING
|
#if COMPUTE_TBNMATRIX
|
||||||
vec3 binormal = cross(VertexNormal, VertexTangent);
|
vec3 binormal = cross(VertexNormal, VertexTangent);
|
||||||
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
|
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
|
||||||
vLightToWorld[1] = normalize(rotationMatrix * binormal);
|
vLightToWorld[1] = normalize(rotationMatrix * binormal);
|
||||||
|
|
@ -42,14 +59,14 @@ void main()
|
||||||
#else
|
#else
|
||||||
vNormal = normalize(rotationMatrix * VertexNormal);
|
vNormal = normalize(rotationMatrix * VertexNormal);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING || EMISSIVE_MAPPING || NORMAL_MAPPING || PARALLAX_MAPPING || SPECULAR_MAPPING
|
#if TEXTURE_MAPPING
|
||||||
#if FLAG_FLIP_UVS
|
/* #if FLAG_FLIP_UVS
|
||||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||||
#else
|
#else*/
|
||||||
vTexCoord = VertexTexCoord;
|
vTexCoord = VertexTexCoord;
|
||||||
#endif
|
// #endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LIGHTING && PARALLAX_MAPPING
|
#if LIGHTING && PARALLAX_MAPPING
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -48,13 +48,6 @@ NzScene::NzScene()
|
||||||
|
|
||||||
NzScene::~NzScene()
|
NzScene::~NzScene()
|
||||||
{
|
{
|
||||||
const std::vector<NzNode*>& childs = m_impl->root.GetChilds();
|
|
||||||
for (NzNode* child : childs)
|
|
||||||
{
|
|
||||||
if (child->GetNodeType() == nzNodeType_Scene)
|
|
||||||
static_cast<NzSceneNode*>(child)->SetScene(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete m_impl;
|
delete m_impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include <Nazara/Graphics/Scene.hpp>
|
#include <Nazara/Graphics/Scene.hpp>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
///FIXME: Constructeur de copie
|
||||||
|
|
||||||
NzSceneNode::NzSceneNode() :
|
NzSceneNode::NzSceneNode() :
|
||||||
m_scene(nullptr),
|
m_scene(nullptr),
|
||||||
m_drawingEnabled(true),
|
m_drawingEnabled(true),
|
||||||
|
|
@ -15,7 +17,8 @@ m_visible(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
NzSceneNode::NzSceneNode(const NzSceneNode& sceneNode) :
|
NzSceneNode::NzSceneNode(const NzSceneNode& sceneNode) :
|
||||||
NzNode(sceneNode), // La scène est affectée via le parenting du node
|
NzNode(sceneNode),
|
||||||
|
m_scene(nullptr),
|
||||||
m_drawingEnabled(sceneNode.m_drawingEnabled),
|
m_drawingEnabled(sceneNode.m_drawingEnabled),
|
||||||
m_visible(false)
|
m_visible(false)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace
|
||||||
return indexBuffer.release();
|
return indexBuffer.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
NzShaderProgram* BuildProgram()
|
NzShader* BuildShader()
|
||||||
{
|
{
|
||||||
const char* fragmentSource110 =
|
const char* fragmentSource110 =
|
||||||
"#version 110\n"
|
"#version 110\n"
|
||||||
|
|
@ -106,33 +106,39 @@ namespace
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
///TODO: Remplacer ça par des ShaderNode
|
///TODO: Remplacer ça par des ShaderNode
|
||||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
std::unique_ptr<NzShader> shader(new NzShader);
|
||||||
program->SetPersistent(false);
|
shader->SetPersistent(false);
|
||||||
|
|
||||||
|
if (!shader->Create())
|
||||||
|
{
|
||||||
|
NazaraError("Failed to create shader");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool useGLSL140 = (NzOpenGL::GetVersion() >= 310);
|
bool useGLSL140 = (NzOpenGL::GetVersion() >= 310);
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Fragment, (useGLSL140) ? fragmentSource140 : fragmentSource110))
|
if (!shader->AttachStageFromSource(nzShaderStage_Fragment, (useGLSL140) ? fragmentSource140 : fragmentSource110))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to load fragment shader");
|
NazaraError("Failed to load fragment shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!program->LoadShader(nzShaderType_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110))
|
if (!shader->AttachStageFromSource(nzShaderStage_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to load vertex shader");
|
NazaraError("Failed to load vertex shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!program->Compile())
|
if (!shader->Link())
|
||||||
{
|
{
|
||||||
NazaraError("Failed to compile program");
|
NazaraError("Failed to link shader");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
program->SendInteger(program->GetUniformLocation("Skybox"), 0);
|
shader->SendInteger(shader->GetUniformLocation("Skybox"), 0);
|
||||||
program->SendFloat(program->GetUniformLocation(nzShaderUniform_VertexDepth), 1.f);
|
shader->SendFloat(shader->GetUniformLocation("VertexDepth"), 1.f);
|
||||||
|
|
||||||
return program.release();
|
return shader.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
NzRenderStates BuildRenderStates()
|
NzRenderStates BuildRenderStates()
|
||||||
|
|
@ -174,7 +180,7 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
static NzIndexBuffer* s_indexBuffer = nullptr;
|
static NzIndexBuffer* s_indexBuffer = nullptr;
|
||||||
static NzShaderProgram* s_program = nullptr;
|
static NzShader* s_shader = nullptr;
|
||||||
static NzVertexBuffer* s_vertexBuffer = nullptr;
|
static NzVertexBuffer* s_vertexBuffer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,15 +189,15 @@ NzSkyboxBackground::NzSkyboxBackground()
|
||||||
if (!s_indexBuffer)
|
if (!s_indexBuffer)
|
||||||
s_indexBuffer = BuildIndexBuffer();
|
s_indexBuffer = BuildIndexBuffer();
|
||||||
|
|
||||||
if (!s_program)
|
if (!s_shader)
|
||||||
s_program = BuildProgram();
|
s_shader = BuildShader();
|
||||||
|
|
||||||
if (!s_vertexBuffer)
|
if (!s_vertexBuffer)
|
||||||
s_vertexBuffer = BuildVertexBuffer();
|
s_vertexBuffer = BuildVertexBuffer();
|
||||||
|
|
||||||
m_indexBuffer = s_indexBuffer;
|
m_indexBuffer = s_indexBuffer;
|
||||||
m_program = s_program;
|
|
||||||
m_sampler.SetWrapMode(nzSamplerWrap_Clamp); // Nécessaire pour ne pas voir les côtés
|
m_sampler.SetWrapMode(nzSamplerWrap_Clamp); // Nécessaire pour ne pas voir les côtés
|
||||||
|
m_shader = s_shader;
|
||||||
m_vertexBuffer = s_vertexBuffer;
|
m_vertexBuffer = s_vertexBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,8 +212,8 @@ NzSkyboxBackground::~NzSkyboxBackground()
|
||||||
if (m_indexBuffer.Reset())
|
if (m_indexBuffer.Reset())
|
||||||
s_indexBuffer = nullptr;
|
s_indexBuffer = nullptr;
|
||||||
|
|
||||||
if (m_program.Reset())
|
if (m_shader.Reset())
|
||||||
s_program = nullptr;
|
s_shader = nullptr;
|
||||||
|
|
||||||
if (m_vertexBuffer.Reset())
|
if (m_vertexBuffer.Reset())
|
||||||
s_vertexBuffer = nullptr;
|
s_vertexBuffer = nullptr;
|
||||||
|
|
@ -226,7 +232,7 @@ void NzSkyboxBackground::Draw(const NzScene* scene) const
|
||||||
NzRenderer::SetMatrix(nzMatrixType_View, skyboxMatrix);
|
NzRenderer::SetMatrix(nzMatrixType_View, skyboxMatrix);
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Scale(NzVector3f(viewer->GetZNear())));
|
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Scale(NzVector3f(viewer->GetZNear())));
|
||||||
NzRenderer::SetRenderStates(states);
|
NzRenderer::SetRenderStates(states);
|
||||||
NzRenderer::SetShaderProgram(s_program);
|
NzRenderer::SetShader(m_shader);
|
||||||
NzRenderer::SetTexture(0, m_texture);
|
NzRenderer::SetTexture(0, m_texture);
|
||||||
NzRenderer::SetTextureSampler(0, m_sampler);
|
NzRenderer::SetTextureSampler(0, m_sampler);
|
||||||
NzRenderer::SetVertexBuffer(m_vertexBuffer);
|
NzRenderer::SetVertexBuffer(m_vertexBuffer);
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ m_textureCoords(sprite.m_textureCoords),
|
||||||
m_size(sprite.m_size),
|
m_size(sprite.m_size),
|
||||||
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated)
|
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated)
|
||||||
{
|
{
|
||||||
|
SetParent(sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
NzSprite::NzSprite(NzSprite&& sprite) :
|
NzSprite::NzSprite(NzSprite&& sprite) :
|
||||||
|
|
@ -161,9 +162,9 @@ bool NzSprite::FrustumCull(const NzFrustumf& frustum)
|
||||||
return frustum.Contains(m_boundingVolume);
|
return frustum.Contains(m_boundingVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzSprite::Invalidate()
|
void NzSprite::InvalidateNode()
|
||||||
{
|
{
|
||||||
NzSceneNode::Invalidate();
|
NzSceneNode::InvalidateNode();
|
||||||
|
|
||||||
m_boundingVolumeUpdated = false;
|
m_boundingVolumeUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <Nazara/Graphics/TextureBackground.hpp>
|
#include <Nazara/Graphics/TextureBackground.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
|
@ -25,14 +25,19 @@ namespace
|
||||||
|
|
||||||
NzTextureBackground::NzTextureBackground()
|
NzTextureBackground::NzTextureBackground()
|
||||||
{
|
{
|
||||||
NzShaderProgramManagerParams params;
|
m_uberShader = NzUberShaderLibrary::Get("Basic");
|
||||||
params.target = nzShaderTarget_FullscreenQuad;
|
|
||||||
params.flags = 0;
|
|
||||||
params.fullscreenQuad.alphaMapping = false;
|
|
||||||
params.fullscreenQuad.alphaTest = false;
|
|
||||||
params.fullscreenQuad.diffuseMapping = true;
|
|
||||||
|
|
||||||
m_program = NzShaderProgramManager::Get(params);
|
NzParameterList list;
|
||||||
|
list.SetParameter("DIFFUSE_MAPPING", true);
|
||||||
|
list.SetParameter("TEXTURE_MAPPING", true);
|
||||||
|
list.SetParameter("UNIFORM_VERTEX_DEPTH", true);
|
||||||
|
|
||||||
|
m_uberShaderInstance = m_uberShader->Get(list);
|
||||||
|
|
||||||
|
const NzShader* shader = m_uberShaderInstance->GetShader();
|
||||||
|
m_materialDiffuseUniform = shader->GetUniformLocation("MaterialDiffuse");
|
||||||
|
m_materialDiffuseMapUniform = shader->GetUniformLocation("MaterialDiffuseMap");
|
||||||
|
m_vertexDepthUniform = shader->GetUniformLocation("VertexDepth");
|
||||||
}
|
}
|
||||||
|
|
||||||
NzTextureBackground::NzTextureBackground(NzTexture* texture) :
|
NzTextureBackground::NzTextureBackground(NzTexture* texture) :
|
||||||
|
|
@ -48,12 +53,14 @@ void NzTextureBackground::Draw(const NzScene* scene) const
|
||||||
static NzRenderStates states(BuildRenderStates());
|
static NzRenderStates states(BuildRenderStates());
|
||||||
|
|
||||||
NzRenderer::SetRenderStates(states);
|
NzRenderer::SetRenderStates(states);
|
||||||
NzRenderer::SetShaderProgram(m_program);
|
|
||||||
NzRenderer::SetTexture(0, m_texture);
|
NzRenderer::SetTexture(0, m_texture);
|
||||||
|
|
||||||
m_program->SendColor(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), NzColor::White);
|
m_uberShaderInstance->Activate();
|
||||||
m_program->SendFloat(m_program->GetUniformLocation(nzShaderUniform_VertexDepth), 1.f);
|
|
||||||
m_program->SendInteger(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuseMap), 0);
|
const NzShader* shader = m_uberShaderInstance->GetShader();
|
||||||
|
shader->SendColor(m_materialDiffuseUniform, NzColor::White);
|
||||||
|
shader->SendFloat(m_vertexDepthUniform, 1.f);
|
||||||
|
shader->SendInteger(m_materialDiffuseMapUniform, 0);
|
||||||
|
|
||||||
NzRenderer::DrawFullscreenQuad();
|
NzRenderer::DrawFullscreenQuad();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue