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:
@@ -222,9 +222,9 @@ void NzCamera::ApplyView() const
|
||||
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
|
||||
m_frustumUpdated = false;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <Nazara/Graphics/ColorBackGround.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
@@ -26,14 +26,15 @@ namespace
|
||||
NzColorBackground::NzColorBackground(const NzColor& color) :
|
||||
m_color(color)
|
||||
{
|
||||
NzShaderProgramManagerParams params;
|
||||
params.target = nzShaderTarget_FullscreenQuad;
|
||||
params.flags = 0;
|
||||
params.fullscreenQuad.alphaMapping = false;
|
||||
params.fullscreenQuad.alphaTest = false;
|
||||
params.fullscreenQuad.diffuseMapping = false;
|
||||
m_uberShader = NzUberShaderLibrary::Get("Basic");
|
||||
|
||||
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
|
||||
@@ -43,10 +44,12 @@ void NzColorBackground::Draw(const NzScene* scene) const
|
||||
static NzRenderStates states(BuildRenderStates());
|
||||
|
||||
NzRenderer::SetRenderStates(states);
|
||||
NzRenderer::SetShaderProgram(m_program);
|
||||
|
||||
m_program->SendColor(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), m_color);
|
||||
m_program->SendFloat(m_program->GetUniformLocation(nzShaderUniform_VertexDepth), 1.f);
|
||||
m_uberShaderInstance->Activate();
|
||||
|
||||
const NzShader* shader = m_uberShaderInstance->GetShader();
|
||||
shader->SendColor(m_materialDiffuseUniform, m_color);
|
||||
shader->SendFloat(m_vertexDepthUniform, 1.f);
|
||||
|
||||
NzRenderer::DrawFullscreenQuad();
|
||||
}
|
||||
@@ -64,6 +67,5 @@ NzColor NzColorBackground::GetColor() const
|
||||
void NzColorBackground::SetColor(const NzColor& 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/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#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() :
|
||||
m_uniformUpdated(false),
|
||||
m_brightLuminance(0.8),
|
||||
@@ -151,23 +19,17 @@ m_blurPassCount(5)
|
||||
m_bilinearSampler.SetFilterMode(nzSamplerFilter_Bilinear);
|
||||
m_bilinearSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
||||
|
||||
m_bloomBrightProgram = BuildBloomBrightProgram();
|
||||
m_bloomBrightProgram->SendInteger(m_bloomBrightProgram->GetUniformLocation("ColorTexture"), 0);
|
||||
|
||||
m_bloomFinalProgram = BuildBloomFinalProgram();
|
||||
m_bloomFinalProgram->SendInteger(m_bloomFinalProgram->GetUniformLocation("BloomTexture"), 1);
|
||||
m_bloomFinalProgram->SendInteger(m_bloomFinalProgram->GetUniformLocation("ColorTexture"), 0);
|
||||
|
||||
m_bloomBrightShader = NzShaderLibrary::Get("DeferredBloomBright");
|
||||
m_bloomFinalShader = NzShaderLibrary::Get("DeferredBloomFinal");
|
||||
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)
|
||||
{
|
||||
m_bloomTextures[i] = new NzTexture;
|
||||
m_bloomTextures[i]->SetPersistent(false);
|
||||
}
|
||||
|
||||
m_gaussianBlurProgram = BuildGaussianBlurProgram();
|
||||
m_gaussianBlurProgramFilterLocation = m_gaussianBlurProgram->GetUniformLocation("Filter");
|
||||
}
|
||||
|
||||
NzDeferredBloomPass::~NzDeferredBloomPass() = default;
|
||||
@@ -217,12 +79,12 @@ bool NzDeferredBloomPass::Process(const NzScene* scene, unsigned int firstWorkTe
|
||||
NzRenderer::SetTarget(m_workRTT);
|
||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
||||
|
||||
NzRenderer::SetShaderProgram(m_bloomBrightProgram);
|
||||
NzRenderer::SetShader(m_bloomBrightShader);
|
||||
if (!m_uniformUpdated)
|
||||
{
|
||||
m_bloomBrightProgram->SendFloat(m_bloomBrightProgram->GetUniformLocation("BrightLuminance"), m_brightLuminance);
|
||||
m_bloomBrightProgram->SendFloat(m_bloomBrightProgram->GetUniformLocation("BrightMiddleGrey"), m_brightMiddleGrey);
|
||||
m_bloomBrightProgram->SendFloat(m_bloomBrightProgram->GetUniformLocation("BrightThreshold"), m_brightThreshold);
|
||||
m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightLuminance"), m_brightLuminance);
|
||||
m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightMiddleGrey"), m_brightMiddleGrey);
|
||||
m_bloomBrightShader->SendFloat(m_bloomBrightShader->GetUniformLocation("BrightThreshold"), m_brightThreshold);
|
||||
|
||||
m_uniformUpdated = true;
|
||||
}
|
||||
@@ -233,20 +95,20 @@ bool NzDeferredBloomPass::Process(const NzScene* scene, unsigned int firstWorkTe
|
||||
NzRenderer::SetTarget(&m_bloomRTT);
|
||||
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)
|
||||
{
|
||||
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::DrawFullscreenQuad();
|
||||
|
||||
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::DrawFullscreenQuad();
|
||||
@@ -256,7 +118,7 @@ bool NzDeferredBloomPass::Process(const NzScene* scene, unsigned int firstWorkTe
|
||||
NzRenderer::SetTarget(m_workRTT);
|
||||
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(1, m_workTextures[secondWorkTexture]);
|
||||
NzRenderer::DrawFullscreenQuad();
|
||||
|
||||
@@ -7,13 +7,14 @@
|
||||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
// http://digitalerr0r.wordpress.com/2009/05/16/xna-shader-programming-tutorial-20-depth-of-field/
|
||||
NzShaderProgram* BuildDepthOfFieldProgram()
|
||||
NzShader* BuildDepthOfFieldShader()
|
||||
{
|
||||
const char* fragmentSource =
|
||||
"#version 140\n"
|
||||
@@ -62,84 +63,46 @@ namespace
|
||||
"}\n";
|
||||
|
||||
///TODO: Remplacer ça par des ShaderNode
|
||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
||||
program->SetPersistent(false);
|
||||
std::unique_ptr<NzShader> shader(new NzShader);
|
||||
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");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
||||
if (!shader->AttachStageFromSource(nzShaderStage_Vertex, vertexSource))
|
||||
{
|
||||
NazaraError("Failed to load vertex shader");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!program->Compile())
|
||||
if (!shader->Link())
|
||||
{
|
||||
NazaraError("Failed to compile program");
|
||||
NazaraError("Failed to link shader");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return program.release();
|
||||
return shader.release();
|
||||
}
|
||||
}
|
||||
|
||||
NzDeferredDOFPass::NzDeferredDOFPass()
|
||||
{
|
||||
m_blurProgram = BuildGaussianBlurProgram();
|
||||
m_blurProgram->SendInteger(m_blurProgram->GetUniformLocation("ColorTexture"), 0);
|
||||
m_dofShader = BuildDepthOfFieldShader();
|
||||
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_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);
|
||||
m_gaussianBlurShader = NzShaderLibrary::Get("DeferredGaussianBlur");
|
||||
m_gaussianBlurShaderFilterLocation = m_gaussianBlurShader->GetUniformLocation("Filter");
|
||||
|
||||
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::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;
|
||||
for (unsigned int i = 0; i < dofBlurPass; ++i)
|
||||
{
|
||||
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::DrawFullscreenQuad();
|
||||
|
||||
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::DrawFullscreenQuad();
|
||||
@@ -193,7 +156,7 @@ bool NzDeferredDOFPass::Process(const NzScene* scene, unsigned int firstWorkText
|
||||
NzRenderer::SetTarget(m_workRTT);
|
||||
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(1, m_dofTextures[1]);
|
||||
NzRenderer::SetTexture(2, m_GBuffer[1]);
|
||||
|
||||
@@ -5,57 +5,13 @@
|
||||
#include <Nazara/Graphics/DeferredFXAAPass.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#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()
|
||||
{
|
||||
m_fxaaProgram = BuildFXAAProgram();
|
||||
m_fxaaProgram->SendInteger(m_fxaaProgram->GetUniformLocation("ColorTexture"), 0);
|
||||
m_fxaaShader = NzShaderLibrary::Get("DeferredFXAA");
|
||||
|
||||
m_pointSampler.SetAnisotropyLevel(1);
|
||||
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::SetRenderStates(m_states);
|
||||
NzRenderer::SetShaderProgram(m_fxaaProgram);
|
||||
NzRenderer::SetShader(m_fxaaShader);
|
||||
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
||||
NzRenderer::SetTextureSampler(0, m_pointSampler);
|
||||
NzRenderer::DrawFullscreenQuad();
|
||||
|
||||
@@ -6,64 +6,30 @@
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#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()
|
||||
{
|
||||
m_program = BuildBlitProgram();
|
||||
m_program->SendInteger(m_program->GetUniformLocation("ColorTexture"), 0);
|
||||
|
||||
m_pointSampler.SetAnisotropyLevel(1);
|
||||
m_pointSampler.SetFilterMode(nzSamplerFilter_Nearest);
|
||||
m_pointSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
||||
|
||||
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;
|
||||
@@ -75,10 +41,15 @@ bool NzDeferredFinalPass::Process(const NzScene* scene, unsigned int firstWorkTe
|
||||
scene->GetViewer()->ApplyView();
|
||||
|
||||
NzRenderer::SetRenderStates(m_states);
|
||||
NzRenderer::SetShaderProgram(m_program);
|
||||
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
||||
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();
|
||||
|
||||
return false;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
NzShaderProgram* BuildFogProgram()
|
||||
NzShader* BuildFogShader()
|
||||
{
|
||||
/*const nzUInt8 fragmentSource[] = {
|
||||
#include <Nazara/Graphics/Resources/DeferredShading/Shaders/FXAA.frag.h>
|
||||
@@ -84,41 +84,48 @@ namespace
|
||||
"}\n";
|
||||
|
||||
///TODO: Remplacer ça par des ShaderNode
|
||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
||||
program->SetPersistent(false);
|
||||
std::unique_ptr<NzShader> shader(new NzShader);
|
||||
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");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
||||
if (!shader->AttachStageFromSource(nzShaderStage_Vertex, vertexSource))
|
||||
{
|
||||
NazaraError("Failed to load vertex shader");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!program->Compile())
|
||||
if (!shader->Link())
|
||||
{
|
||||
NazaraError("Failed to compile program");
|
||||
NazaraError("Failed to link shader");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return program.release();
|
||||
shader->SendInteger(shader->GetUniformLocation("ColorTexture"), 0);
|
||||
shader->SendInteger(shader->GetUniformLocation("GBuffer2"), 1);
|
||||
|
||||
return shader.release();
|
||||
}
|
||||
}
|
||||
|
||||
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.SetFilterMode(nzSamplerFilter_Nearest);
|
||||
m_pointSampler.SetWrapMode(nzSamplerWrap_Clamp);
|
||||
|
||||
m_shader = BuildFogShader();
|
||||
|
||||
m_states.parameters[nzRendererParameter_DepthBuffer] = false;
|
||||
}
|
||||
|
||||
@@ -130,8 +137,8 @@ bool NzDeferredFogPass::Process(const NzScene* scene, unsigned int firstWorkText
|
||||
NzRenderer::SetTarget(m_workRTT);
|
||||
NzRenderer::SetViewport(NzRecti(0, 0, m_dimensions.x, m_dimensions.y));
|
||||
|
||||
NzRenderer::SetShaderProgram(m_program);
|
||||
m_program->SendVector(m_program->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||
NzRenderer::SetShader(m_shader);
|
||||
m_shader->SendVector(m_shader->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||
|
||||
NzRenderer::SetRenderStates(m_states);
|
||||
NzRenderer::SetTexture(0, m_workTextures[secondWorkTexture]);
|
||||
|
||||
@@ -6,63 +6,20 @@
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
#include <memory>
|
||||
#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()
|
||||
{
|
||||
m_clearProgram = BuildClearProgram();
|
||||
m_clearShader = NzShaderLibrary::Get("DeferredGBufferClear");
|
||||
m_clearStates.parameters[nzRendererParameter_DepthBuffer] = true;
|
||||
m_clearStates.parameters[nzRendererParameter_FaceCulling] = 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::SetRenderStates(m_clearStates);
|
||||
NzRenderer::SetShaderProgram(m_clearProgram);
|
||||
NzRenderer::SetShader(m_clearShader);
|
||||
NzRenderer::DrawFullscreenQuad();
|
||||
|
||||
|
||||
NzRenderer::SetMatrix(nzMatrixType_Projection, viewer->GetProjectionMatrix());
|
||||
NzRenderer::SetMatrix(nzMatrixType_View, viewer->GetViewMatrix());
|
||||
|
||||
const NzShaderProgram* lastProgram = nullptr;
|
||||
const NzShader* lastShader = nullptr;
|
||||
|
||||
for (auto& matIt : m_renderQueue->opaqueModels)
|
||||
{
|
||||
@@ -118,23 +75,19 @@ bool NzDeferredGeometryPass::Process(const NzScene* scene, unsigned int firstWor
|
||||
if (useInstancing)
|
||||
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
|
||||
if (program != lastProgram)
|
||||
if (shader != lastShader)
|
||||
{
|
||||
NzRenderer::SetShaderProgram(program);
|
||||
|
||||
// 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
|
||||
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
|
||||
/*if (!skeletalContainer.empty())
|
||||
{
|
||||
|
||||
@@ -2,122 +2,45 @@
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// 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/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/OpenGL.hpp> // Supprimer
|
||||
#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() :
|
||||
m_lightMeshesDrawing(false)
|
||||
{
|
||||
m_directionalLightProgram = BuildDirectionalLightProgram();
|
||||
m_pointSpotLightProgram = BuildPointSpotLightProgram();
|
||||
m_directionalLightShader = NzShaderLibrary::Get("DeferredDirectionnalLight");
|
||||
|
||||
m_pointSpotLightProgramDiscardLocation = m_pointSpotLightProgram->GetUniformLocation("Discard");
|
||||
m_pointSpotLightProgramSpotLightLocation = m_pointSpotLightProgram->GetUniformLocation("SpotLight");
|
||||
m_directionalLightUniforms.ubo = false;
|
||||
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.SetFilterMode(nzSamplerFilter_Nearest);
|
||||
@@ -177,13 +100,13 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||
if (!m_renderQueue->directionalLights.empty())
|
||||
{
|
||||
NzRenderer::SetRenderStates(lightStates);
|
||||
NzRenderer::SetShaderProgram(m_directionalLightProgram);
|
||||
m_directionalLightProgram->SendColor(m_directionalLightProgram->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||
m_directionalLightProgram->SendVector(m_directionalLightProgram->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||
NzRenderer::SetShader(m_directionalLightShader);
|
||||
m_directionalLightShader->SendColor(m_directionalLightShader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||
m_directionalLightShader->SendVector(m_directionalLightShader->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||
|
||||
for (const NzLight* light : m_renderQueue->directionalLights)
|
||||
{
|
||||
light->Enable(m_directionalLightProgram, 0);
|
||||
light->Enable(m_directionalLightShader, m_directionalLightUniforms);
|
||||
NzRenderer::DrawFullscreenQuad();
|
||||
}
|
||||
}
|
||||
@@ -207,23 +130,21 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||
|
||||
NzRenderer::SetRenderStates(lightStates);
|
||||
|
||||
NzRenderer::SetShaderProgram(m_pointSpotLightProgram);
|
||||
m_pointSpotLightProgram->SendColor(m_pointSpotLightProgram->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||
m_pointSpotLightProgram->SendVector(m_pointSpotLightProgram->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||
NzRenderer::SetShader(m_pointSpotLightShader);
|
||||
m_pointSpotLightShader->SendColor(m_pointSpotLightShader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||
m_pointSpotLightShader->SendVector(m_pointSpotLightShader->GetUniformLocation(nzShaderUniform_EyePosition), scene->GetViewer()->GetEyePosition());
|
||||
|
||||
NzMatrix4f lightMatrix;
|
||||
lightMatrix.MakeIdentity();
|
||||
if (!m_renderQueue->pointLights.empty())
|
||||
{
|
||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramSpotLightLocation, false);
|
||||
|
||||
const NzIndexBuffer* indexBuffer = m_sphereMesh->GetIndexBuffer();
|
||||
NzRenderer::SetIndexBuffer(indexBuffer);
|
||||
NzRenderer::SetVertexBuffer(m_sphereMesh->GetVertexBuffer());
|
||||
|
||||
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.SetTranslation(light->GetPosition());
|
||||
|
||||
@@ -235,7 +156,7 @@ bool NzDeferredPhongLightingPass::Process(const NzScene* scene, unsigned int fir
|
||||
NzRenderer::Enable(nzRendererParameter_FaceCulling, false);
|
||||
NzRenderer::SetStencilCompareFunction(nzRendererComparison_Always);
|
||||
|
||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramDiscardLocation, true);
|
||||
m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, true);
|
||||
|
||||
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::SetStencilPassOperation(nzStencilOperation_Zero, nzFaceSide_Back);
|
||||
|
||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramDiscardLocation, false);
|
||||
m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, false);
|
||||
|
||||
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::SetFaceFilling(nzFaceFilling_Line);
|
||||
|
||||
NzShaderProgramManagerParams params;
|
||||
params.flags = nzShaderFlags_None;
|
||||
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);
|
||||
const NzShader* shader = NzShaderLibrary::Get("DebugSimple");
|
||||
NzRenderer::SetShader(shader);
|
||||
for (const NzLight* light : m_renderQueue->pointLights)
|
||||
{
|
||||
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);
|
||||
|
||||
program->SendColor(program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), light->GetColor());
|
||||
shader->SendColor(0, light->GetColor());
|
||||
|
||||
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())
|
||||
{
|
||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramSpotLightLocation, true);
|
||||
|
||||
const NzIndexBuffer* indexBuffer = m_coneMesh->GetIndexBuffer();
|
||||
NzRenderer::SetIndexBuffer(indexBuffer);
|
||||
NzRenderer::SetVertexBuffer(m_coneMesh->GetVertexBuffer());
|
||||
|
||||
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;
|
||||
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::SetStencilCompareFunction(nzRendererComparison_Always);
|
||||
|
||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramDiscardLocation, true);
|
||||
m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, true);
|
||||
|
||||
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::SetStencilPassOperation(nzStencilOperation_Zero, nzFaceSide_Back);
|
||||
|
||||
m_pointSpotLightProgram->SendBoolean(m_pointSpotLightProgramDiscardLocation, false);
|
||||
m_pointSpotLightShader->SendBoolean(m_pointSpotLightShaderDiscardLocation, false);
|
||||
|
||||
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::SetFaceFilling(nzFaceFilling_Line);
|
||||
|
||||
NzShaderProgramManagerParams params;
|
||||
params.flags = nzShaderFlags_None;
|
||||
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);
|
||||
const NzShader* shader = NzShaderLibrary::Get("DebugSimple");
|
||||
NzRenderer::SetShader(shader);
|
||||
for (const NzLight* light : m_renderQueue->spotLights)
|
||||
{
|
||||
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);
|
||||
|
||||
program->SendColor(program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), light->GetColor());
|
||||
shader->SendColor(0, light->GetColor());
|
||||
|
||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, indexBuffer->GetIndexCount());
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include <Nazara/Graphics/Camera.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.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)
|
||||
{
|
||||
nzUInt32 possibleFlags[] = {
|
||||
nzShaderFlags_Deferred,
|
||||
nzShaderFlags_Deferred | nzShaderFlags_Instancing
|
||||
};
|
||||
const NzUberShader* uberShader1 = mat1->GetShader();
|
||||
const NzUberShader* uberShader2 = mat2->GetShader();
|
||||
if (uberShader1 != uberShader2)
|
||||
return uberShader1 < uberShader2;
|
||||
|
||||
for (nzUInt32 flag : possibleFlags)
|
||||
{
|
||||
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||
const NzShader* shader1 = mat1->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||
const NzShader* shader2 = mat2->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||
|
||||
if (program1 != program2)
|
||||
return program1 < program2;
|
||||
}
|
||||
if (shader1 != shader2)
|
||||
return shader1 < shader2;
|
||||
|
||||
const NzTexture* diffuseMap1 = mat1->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)
|
||||
{
|
||||
nzUInt32 possibleFlags[] = {
|
||||
nzShaderFlags_Deferred
|
||||
};
|
||||
const NzUberShader* uberShader1 = mat1->GetShader();
|
||||
const NzUberShader* uberShader2 = mat2->GetShader();
|
||||
if (uberShader1 != uberShader2)
|
||||
return uberShader1 < uberShader2;
|
||||
|
||||
for (nzUInt32 flag : possibleFlags)
|
||||
{
|
||||
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||
const NzShader* shader1 = mat1->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||
const NzShader* shader2 = mat2->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||
|
||||
if (program1 != program2)
|
||||
return program1 < program2;
|
||||
}
|
||||
if (shader1 != shader2)
|
||||
return shader1 < shader2;
|
||||
|
||||
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
||||
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// 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/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||
@@ -16,12 +20,14 @@
|
||||
#include <Nazara/Graphics/DeferredPhongLightingPass.hpp>
|
||||
#include <Nazara/Graphics/Drawable.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.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 <memory>
|
||||
#include <random>
|
||||
@@ -43,6 +49,37 @@ namespace
|
||||
};
|
||||
|
||||
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() :
|
||||
@@ -67,7 +104,6 @@ m_GBufferSize(0U)
|
||||
try
|
||||
{
|
||||
NzErrorFlags errFlags(nzErrorFlag_ThrowException);
|
||||
std::unique_ptr<NzDeferredRenderPass> smartPtr; // Nous évite un leak en cas d'exception
|
||||
|
||||
ResetPass(nzRenderPassType_Final, 0);
|
||||
ResetPass(nzRenderPassType_Geometry, 0);
|
||||
@@ -343,14 +379,186 @@ void NzDeferredRenderTechnique::SetPass(nzRenderPassType relativeTo, int positio
|
||||
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()
|
||||
{
|
||||
// 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::GetMaxColorAttachments() >= 4 &&
|
||||
NzRenderer::GetMaxRenderTargets() >= 4 &&
|
||||
NzTexture::IsFormatSupported(nzPixelFormat_RGBA32F);
|
||||
NzRenderer::GetMaxRenderTargets() >= 4;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
@@ -186,8 +186,7 @@ void NzForwardRenderQueue::AddSubMesh(const NzMaterial* material, const NzSubMes
|
||||
unsigned int instanceCount = staticDataContainer.size() + 1;
|
||||
|
||||
// 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 >= 10)
|
||||
if (instanceCount >= NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT)
|
||||
enableInstancing = true; // Apparemment oui, activons l'instancing avec ce matériau
|
||||
|
||||
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)
|
||||
{
|
||||
nzUInt32 possibleFlags[] = {
|
||||
nzShaderFlags_None,
|
||||
nzShaderFlags_Instancing
|
||||
};
|
||||
const NzUberShader* uberShader1 = mat1->GetShader();
|
||||
const NzUberShader* uberShader2 = mat2->GetShader();
|
||||
if (uberShader1 != uberShader2)
|
||||
return uberShader1 < uberShader2;
|
||||
|
||||
for (nzUInt32 flag : possibleFlags)
|
||||
{
|
||||
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||
const NzShader* shader1 = mat1->GetShaderInstance()->GetShader();
|
||||
const NzShader* shader2 = mat2->GetShaderInstance()->GetShader();
|
||||
|
||||
if (program1 != program2)
|
||||
return program1 < program2;
|
||||
}
|
||||
if (shader1 != shader2)
|
||||
return shader1 < shader2;
|
||||
|
||||
const NzTexture* diffuseMap1 = mat1->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)
|
||||
{
|
||||
nzUInt32 possibleFlags[] = {
|
||||
nzShaderFlags_None
|
||||
};
|
||||
const NzUberShader* uberShader1 = mat1->GetShader();
|
||||
const NzUberShader* uberShader2 = mat2->GetShader();
|
||||
if (uberShader1 != uberShader2)
|
||||
return uberShader1 < uberShader2;
|
||||
|
||||
for (nzUInt32 flag : possibleFlags)
|
||||
{
|
||||
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||
const NzShader* shader1 = mat1->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||
const NzShader* shader2 = mat2->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
||||
|
||||
if (program1 != program2)
|
||||
return program1 < program2;
|
||||
}
|
||||
if (shader1 != shader2)
|
||||
return shader1 < shader2;
|
||||
|
||||
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
||||
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <Nazara/Graphics/Camera.hpp>
|
||||
#include <Nazara/Graphics/Drawable.hpp>
|
||||
#include <Nazara/Graphics/Light.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
@@ -21,7 +21,6 @@
|
||||
namespace
|
||||
{
|
||||
static NzIndexBuffer* s_indexBuffer = nullptr;
|
||||
unsigned int s_maxLightPerPass = 3; ///TODO: Constante sur le nombre maximum de lumières
|
||||
unsigned int s_maxSprites = 8192;
|
||||
|
||||
NzIndexBuffer* BuildIndexBuffer()
|
||||
@@ -164,7 +163,8 @@ void NzForwardRenderTechnique::SetMaxLightPassPerObject(unsigned int passCount)
|
||||
void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||
{
|
||||
NzAbstractViewer* viewer = scene->GetViewer();
|
||||
const NzShaderProgram* lastProgram = nullptr;
|
||||
const LightUniforms* lightUniforms = nullptr;
|
||||
const NzShader* lastShader = nullptr;
|
||||
|
||||
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)
|
||||
bool instancing = m_instancingEnabled && (!material->IsLightingEnabled() || m_lights.IsEmpty()) && renderQueueInstancing;
|
||||
|
||||
// On commence par récupérer le programme du matériau
|
||||
const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Model, (instancing) ? nzShaderFlags_Instancing : 0);
|
||||
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||
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
|
||||
if (program != lastProgram)
|
||||
if (shader != lastShader)
|
||||
{
|
||||
NzRenderer::SetShaderProgram(program);
|
||||
|
||||
// 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
|
||||
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
|
||||
/*if (!skeletalContainer.empty())
|
||||
@@ -260,10 +260,10 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||
unsigned int lightIndex = 0;
|
||||
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)
|
||||
{
|
||||
unsigned int renderedLightCount = std::min(lightCount, s_maxLightPerPass);
|
||||
unsigned int renderedLightCount = std::min(lightCount, NAZARA_GRAPHICS_MAX_LIGHTPERPASS);
|
||||
lightCount -= renderedLightCount;
|
||||
|
||||
if (pass == 1)
|
||||
@@ -278,10 +278,10 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||
}
|
||||
|
||||
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)
|
||||
NzLight::Disable(program, i);
|
||||
for (unsigned int i = renderedLightCount; i < NAZARA_GRAPHICS_MAX_LIGHTPERPASS; ++i)
|
||||
NzLight::Disable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||
|
||||
const NzForwardRenderQueue::StaticData* data = &staticData[0];
|
||||
unsigned int instanceCount = staticData.size();
|
||||
@@ -317,7 +317,7 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||
for (const NzForwardRenderQueue::StaticData& data : staticData)
|
||||
{
|
||||
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;
|
||||
|
||||
NzRenderer::SetMatrix(nzMatrixType_World, data.transformMatrix);
|
||||
@@ -325,10 +325,10 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||
unsigned int otherLightIndex = 0;
|
||||
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)
|
||||
{
|
||||
unsigned int renderedLightCount = std::min(lightCount, s_maxLightPerPass);
|
||||
unsigned int renderedLightCount = std::min(lightCount, NAZARA_GRAPHICS_MAX_LIGHTPERPASS);
|
||||
lightCount -= renderedLightCount;
|
||||
|
||||
if (pass == 1)
|
||||
@@ -345,13 +345,13 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||
for (unsigned int i = 0; i < renderedLightCount; ++i)
|
||||
{
|
||||
if (directionalLightIndex >= directionalLightCount)
|
||||
m_lights.GetResult(otherLightIndex++)->Enable(program, i);
|
||||
m_lights.GetResult(otherLightIndex++)->Enable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||
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)
|
||||
NzLight::Disable(program, i);
|
||||
for (unsigned int i = renderedLightCount; i < NAZARA_GRAPHICS_MAX_LIGHTPERPASS; ++i)
|
||||
NzLight::Disable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||
|
||||
DrawFunc(primitiveMode, 0, indexCount);
|
||||
}
|
||||
@@ -375,7 +375,7 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||
void NzForwardRenderTechnique::DrawSprites(const NzScene* scene) const
|
||||
{
|
||||
NzAbstractViewer* viewer = scene->GetViewer();
|
||||
const NzShaderProgram* lastProgram = nullptr;
|
||||
const NzShader* lastShader = nullptr;
|
||||
|
||||
NzRenderer::SetIndexBuffer(m_indexBuffer);
|
||||
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Identity());
|
||||
@@ -389,24 +389,20 @@ void NzForwardRenderTechnique::DrawSprites(const NzScene* scene) const
|
||||
unsigned int spriteCount = spriteVector.size();
|
||||
if (spriteCount > 0)
|
||||
{
|
||||
// On commence par récupérer le programme du matériau
|
||||
const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Sprite, 0);
|
||||
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||
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
|
||||
if (program != lastProgram)
|
||||
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
||||
if (shader != lastShader)
|
||||
{
|
||||
NzRenderer::SetShaderProgram(program);
|
||||
|
||||
// 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
|
||||
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];
|
||||
do
|
||||
{
|
||||
@@ -455,7 +451,8 @@ void NzForwardRenderTechnique::DrawSprites(const NzScene* scene) const
|
||||
void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
||||
{
|
||||
NzAbstractViewer* viewer = scene->GetViewer();
|
||||
const NzShaderProgram* lastProgram = nullptr;
|
||||
const LightUniforms* lightUniforms = nullptr;
|
||||
const NzShader* lastShader = nullptr;
|
||||
unsigned int lightCount = 0;
|
||||
|
||||
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.transparentSkeletalModels[pair.first].material;
|
||||
|
||||
// On commence par récupérer le shader du matériau
|
||||
const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Model, 0);
|
||||
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||
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
|
||||
if (program != lastProgram)
|
||||
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
||||
if (shader != lastShader)
|
||||
{
|
||||
NzRenderer::SetShaderProgram(program);
|
||||
|
||||
// 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
|
||||
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)
|
||||
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)
|
||||
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
|
||||
if (pair.second)
|
||||
{
|
||||
@@ -518,15 +514,15 @@ void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
||||
NzRenderer::SetVertexBuffer(vertexBuffer);
|
||||
|
||||
// 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)
|
||||
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)
|
||||
NzLight::Disable(program, i);
|
||||
for (unsigned int i = lightCount; i < NAZARA_GRAPHICS_MAX_LIGHTPERPASS; ++i)
|
||||
NzLight::Disable(shader, lightUniforms->uniforms, lightUniforms->offset*i);
|
||||
|
||||
NzRenderer::SetMatrix(nzMatrixType_World, matrix);
|
||||
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/DeferredRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
||||
#include <Nazara/Graphics/Loaders/OBJ.hpp>
|
||||
#include <Nazara/Graphics/Loaders/Texture.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
@@ -35,17 +37,27 @@ bool NzGraphics::Initialize()
|
||||
// Initialisation du module
|
||||
NzCallOnExit onExit(NzGraphics::Uninitialize);
|
||||
|
||||
if (!NzMaterial::Initialize())
|
||||
{
|
||||
NazaraError("Failed to create material");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Loaders
|
||||
NzLoaders_OBJ_Register();
|
||||
|
||||
// Loader générique
|
||||
// Loaders génériques
|
||||
NzLoaders_Mesh_Register();
|
||||
NzLoaders_Texture_Register();
|
||||
|
||||
// RenderTechniques
|
||||
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_BasicForward), 0, []() -> NzAbstractRenderTechnique* { return new NzForwardRenderTechnique; });
|
||||
|
||||
if (NzDeferredRenderTechnique::IsSupported())
|
||||
{
|
||||
NzDeferredRenderTechnique::Initialize();
|
||||
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_DeferredShading), 20, []() -> NzAbstractRenderTechnique* { return new NzDeferredRenderTechnique; });
|
||||
}
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
@@ -75,6 +87,11 @@ void NzGraphics::Uninitialize()
|
||||
// Loaders
|
||||
NzLoaders_Mesh_Unregister();
|
||||
NzLoaders_OBJ_Unregister();
|
||||
NzLoaders_Texture_Unregister();
|
||||
|
||||
NzMaterial::Uninitialize();
|
||||
|
||||
NzDeferredRenderTechnique::Uninitialize();
|
||||
|
||||
NazaraNotice("Uninitialized: Graphics module");
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <cstring>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
@@ -41,6 +41,7 @@ m_innerAngle(light.m_innerAngle),
|
||||
m_outerAngle(light.m_outerAngle),
|
||||
m_radius(light.m_radius)
|
||||
{
|
||||
SetParent(light);
|
||||
}
|
||||
|
||||
void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
||||
@@ -48,7 +49,7 @@ void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
||||
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
|
||||
@@ -75,31 +76,9 @@ void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) con
|
||||
-P3: float cosInnerAngle + float cosOuterAngle
|
||||
*/
|
||||
|
||||
///TODO: Optimiser
|
||||
int typeLocation = program->GetUniformLocation("Lights[0].type");
|
||||
int colorLocation = program->GetUniformLocation("Lights[0].color");
|
||||
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));
|
||||
shader->SendInteger(uniforms.locations.type + offset, m_type);
|
||||
shader->SendColor(uniforms.locations.color + offset, m_color);
|
||||
shader->SendVector(uniforms.locations.factors + offset, NzVector2f(m_ambientFactor, m_diffuseFactor));
|
||||
|
||||
if (!m_derivedUpdated)
|
||||
UpdateDerived();
|
||||
@@ -107,18 +86,18 @@ void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) con
|
||||
switch (m_type)
|
||||
{
|
||||
case nzLightType_Directional:
|
||||
program->SendVector(parameters1Location, NzVector4f(m_derivedRotation * NzVector3f::Forward()));
|
||||
shader->SendVector(uniforms.locations.parameters1 + offset, NzVector4f(m_derivedRotation * NzVector3f::Forward()));
|
||||
break;
|
||||
|
||||
case nzLightType_Point:
|
||||
program->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation));
|
||||
program->SendVector(parameters2Location, NzVector4f(0.f, 0.f, 0.f, 1.f/m_radius));
|
||||
shader->SendVector(uniforms.locations.parameters1 + offset, NzVector4f(m_derivedPosition, m_attenuation));
|
||||
shader->SendVector(uniforms.locations.parameters2 + offset, NzVector4f(0.f, 0.f, 0.f, 1.f/m_radius));
|
||||
break;
|
||||
|
||||
case nzLightType_Spot:
|
||||
program->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation));
|
||||
program->SendVector(parameters2Location, 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.parameters1 + offset, NzVector4f(m_derivedPosition, m_attenuation));
|
||||
shader->SendVector(uniforms.locations.parameters2 + offset, NzVector4f(m_derivedRotation * NzVector3f::Forward(), 1.f/m_radius));
|
||||
shader->SendVector(uniforms.locations.parameters3 + offset, NzVector2f(std::cos(NzDegreeToRadian(m_innerAngle)), std::cos(NzDegreeToRadian(m_outerAngle))));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -245,10 +224,9 @@ NzLight& NzLight::operator=(const NzLight& light)
|
||||
return *this;
|
||||
}
|
||||
|
||||
void NzLight::Disable(const NzShaderProgram* program, unsigned int lightUnit)
|
||||
void NzLight::Disable(const NzShader* shader, const NzLightUniforms& uniforms, int offset)
|
||||
{
|
||||
///TODO: Optimiser
|
||||
program->SendInteger(program->GetUniformLocation("Lights[" + NzString::Number(lightUnit) + "].type"), -1);
|
||||
shader->SendInteger(uniforms.locations.type + offset, -1);
|
||||
}
|
||||
|
||||
bool NzLight::FrustumCull(const NzFrustumf& frustum)
|
||||
@@ -276,9 +254,9 @@ bool NzLight::FrustumCull(const NzFrustumf& frustum)
|
||||
return false;
|
||||
}
|
||||
|
||||
void NzLight::Invalidate()
|
||||
void NzLight::InvalidateNode()
|
||||
{
|
||||
NzSceneNode::Invalidate();
|
||||
NzSceneNode::InvalidateNode();
|
||||
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
@@ -63,8 +63,11 @@ namespace
|
||||
{
|
||||
std::unique_ptr<NzMaterial> material(new NzMaterial);
|
||||
material->SetPersistent(false);
|
||||
|
||||
if (material->LoadFromFile(mat, parameters.material))
|
||||
{
|
||||
material->SetShader(parameters.shaderName);
|
||||
|
||||
model->SetMaterial(i, material.get());
|
||||
material.release();
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.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/OBJParser.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/IndexMapper.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
@@ -212,6 +212,8 @@ namespace
|
||||
std::unique_ptr<NzMaterial> material(new NzMaterial);
|
||||
material->SetPersistent(false);
|
||||
|
||||
material->SetShader(parameters.shaderName);
|
||||
|
||||
nzUInt8 alphaValue = static_cast<nzUInt8>(mtlMat->alpha*255.f);
|
||||
|
||||
NzColor ambientColor(mtlMat->ambient);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
@@ -1,12 +1,12 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Renderer/Loaders/Texture.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Graphics/Loaders/Texture.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -1,17 +1,25 @@
|
||||
// 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
|
||||
|
||||
#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/ShaderProgram.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <Nazara/Renderer/UberShaderPreprocessor.hpp>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
bool NzMaterialParams::IsValid() const
|
||||
{
|
||||
if (!NzUberShaderLibrary::Has(shaderName))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,10 +45,7 @@ NzMaterial::NzMaterial(NzMaterial&& material)
|
||||
material.m_heightMap.Reset();
|
||||
material.m_normalMap.Reset();
|
||||
material.m_specularMap.Reset();
|
||||
|
||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
||||
for (ProgramUnit& unit : material.m_programs[i])
|
||||
unit.program.Reset();
|
||||
material.m_uberShader.Reset();
|
||||
}
|
||||
|
||||
NzMaterial::~NzMaterial()
|
||||
@@ -48,108 +53,83 @@ NzMaterial::~NzMaterial()
|
||||
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);
|
||||
int ambientColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialAmbient);
|
||||
int diffuseColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialDiffuse);
|
||||
int shininessLocation = program->GetUniformLocation(nzShaderUniform_MaterialShininess);
|
||||
int specularColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialSpecular);
|
||||
const ShaderInstance& instance = m_shaders[shaderFlags];
|
||||
if (!instance.uberInstance)
|
||||
GenerateShader(shaderFlags);
|
||||
|
||||
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);
|
||||
if (alphaMapLocation != -1)
|
||||
{
|
||||
nzUInt8 textureUnit;
|
||||
if (program->SendTexture(alphaMapLocation, m_alphaMap, &textureUnit))
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
else
|
||||
NazaraWarning("Failed to send diffuse map");
|
||||
}
|
||||
NzRenderer::SetTexture(textureUnit, m_alphaMap);
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_AlphaMap], textureUnit);
|
||||
textureUnit++;
|
||||
}
|
||||
|
||||
if (alphaThresholdLocation != -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)
|
||||
if (m_diffuseMap && instance.uniforms[nzMaterialUniform_DiffuseMap] != -1)
|
||||
{
|
||||
int diffuseMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialDiffuseMap);
|
||||
if (diffuseMapLocation != -1)
|
||||
{
|
||||
nzUInt8 textureUnit;
|
||||
if (program->SendTexture(diffuseMapLocation, m_diffuseMap, &textureUnit))
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
else
|
||||
NazaraWarning("Failed to send diffuse map");
|
||||
}
|
||||
NzRenderer::SetTexture(textureUnit, m_diffuseMap);
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_DiffuseMap], textureUnit);
|
||||
textureUnit++;
|
||||
}
|
||||
|
||||
if (m_emissiveMap)
|
||||
if (m_emissiveMap && instance.uniforms[nzMaterialUniform_EmissiveMap] != -1)
|
||||
{
|
||||
int emissiveMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialEmissiveMap);
|
||||
if (emissiveMapLocation != -1)
|
||||
{
|
||||
nzUInt8 textureUnit;
|
||||
if (program->SendTexture(emissiveMapLocation, m_emissiveMap, &textureUnit))
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
else
|
||||
NazaraWarning("Failed to send emissive map");
|
||||
}
|
||||
NzRenderer::SetTexture(textureUnit, m_emissiveMap);
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_EmissiveMap], textureUnit);
|
||||
textureUnit++;
|
||||
}
|
||||
|
||||
if (m_heightMap)
|
||||
if (m_heightMap && instance.uniforms[nzMaterialUniform_HeightMap] != -1)
|
||||
{
|
||||
int heightMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialHeightMap);
|
||||
if (heightMapLocation != -1)
|
||||
{
|
||||
nzUInt8 textureUnit;
|
||||
if (program->SendTexture(heightMapLocation, m_heightMap, &textureUnit))
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
else
|
||||
NazaraWarning("Failed to send height map");
|
||||
}
|
||||
NzRenderer::SetTexture(textureUnit, m_heightMap);
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_HeightMap], textureUnit);
|
||||
textureUnit++;
|
||||
}
|
||||
|
||||
if (m_normalMap)
|
||||
if (m_normalMap && instance.uniforms[nzMaterialUniform_NormalMap] != -1)
|
||||
{
|
||||
int normalMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialNormalMap);
|
||||
if (normalMapLocation != -1)
|
||||
{
|
||||
nzUInt8 textureUnit;
|
||||
if (program->SendTexture(normalMapLocation, m_normalMap, &textureUnit))
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
else
|
||||
NazaraWarning("Failed to send normal map");
|
||||
}
|
||||
NzRenderer::SetTexture(textureUnit, m_normalMap);
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler);
|
||||
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_NormalMap], textureUnit);
|
||||
textureUnit++;
|
||||
}
|
||||
|
||||
if (shininessLocation != -1)
|
||||
program->SendFloat(shininessLocation, m_shininess);
|
||||
|
||||
if (specularColorLocation != -1)
|
||||
program->SendColor(specularColorLocation, m_specularColor);
|
||||
|
||||
if (m_specularMap)
|
||||
if (m_specularMap && instance.uniforms[nzMaterialUniform_SpecularMap] != -1)
|
||||
{
|
||||
int specularMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialSpecularMap);
|
||||
if (specularMapLocation != -1)
|
||||
{
|
||||
nzUInt8 textureUnit;
|
||||
if (program->SendTexture(specularMapLocation, m_specularMap, &textureUnit))
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_specularSampler);
|
||||
else
|
||||
NazaraWarning("Failed to send specular map");
|
||||
}
|
||||
NzRenderer::SetTexture(textureUnit, m_specularMap);
|
||||
NzRenderer::SetTextureSampler(textureUnit, m_specularSampler);
|
||||
instance.shader->SendInteger(instance.uniforms[nzMaterialUniform_SpecularMap], textureUnit);
|
||||
textureUnit++;
|
||||
}
|
||||
|
||||
NzRenderer::SetRenderStates(m_states);
|
||||
|
||||
if (lastUsedUnit)
|
||||
*lastUsedUnit = textureUnit;
|
||||
|
||||
return instance.shader;
|
||||
}
|
||||
|
||||
void NzMaterial::Enable(nzRendererParameter renderParameter, bool enable)
|
||||
@@ -169,16 +149,21 @@ void NzMaterial::EnableAlphaTest(bool alphaTest)
|
||||
{
|
||||
m_alphaTestEnabled = alphaTest;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
void NzMaterial::EnableLighting(bool lighting)
|
||||
{
|
||||
m_lightingEnabled = lighting;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
void NzMaterial::EnableTransform(bool transform)
|
||||
{
|
||||
m_transformEnabled = transform;
|
||||
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
NzTexture* NzMaterial::GetAlphaMap() const
|
||||
@@ -256,13 +241,17 @@ const NzRenderStates& NzMaterial::GetRenderStates() const
|
||||
return m_states;
|
||||
}
|
||||
|
||||
const NzShaderProgram* NzMaterial::GetShaderProgram(nzShaderTarget target, nzUInt32 flags) const
|
||||
const NzUberShader* NzMaterial::GetShader() const
|
||||
{
|
||||
const ProgramUnit& unit = m_programs[target][flags];
|
||||
if (!unit.program.IsValid())
|
||||
GenerateProgram(target, flags);
|
||||
return m_uberShader;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -300,11 +289,6 @@ bool NzMaterial::HasAlphaMap() const
|
||||
return m_alphaMap.IsValid();
|
||||
}
|
||||
|
||||
bool NzMaterial::HasCustomShaderProgram(nzShaderTarget target, nzUInt32 flags) const
|
||||
{
|
||||
return m_programs[target][flags].custom;
|
||||
}
|
||||
|
||||
bool NzMaterial::HasDiffuseMap() const
|
||||
{
|
||||
return m_diffuseMap.IsValid();
|
||||
@@ -353,6 +337,11 @@ bool NzMaterial::IsLightingEnabled() const
|
||||
return m_lightingEnabled;
|
||||
}
|
||||
|
||||
bool NzMaterial::IsTransformEnabled() const
|
||||
{
|
||||
return m_transformEnabled;
|
||||
}
|
||||
|
||||
bool NzMaterial::LoadFromFile(const NzString& filePath, const NzMaterialParams& params)
|
||||
{
|
||||
return NzMaterialLoader::LoadFromFile(this, filePath, params);
|
||||
@@ -378,15 +367,10 @@ void NzMaterial::Reset()
|
||||
m_heightMap.Reset();
|
||||
m_normalMap.Reset();
|
||||
m_specularMap.Reset();
|
||||
m_uberShader.Reset();
|
||||
|
||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
||||
{
|
||||
for (ProgramUnit& unit : m_programs[i])
|
||||
{
|
||||
unit.custom = false;
|
||||
unit.program.Reset();
|
||||
}
|
||||
}
|
||||
for (ShaderInstance& instance : m_shaders)
|
||||
instance.uberInstance = nullptr;
|
||||
|
||||
m_alphaThreshold = 0.2f;
|
||||
m_alphaTestEnabled = false;
|
||||
@@ -400,6 +384,9 @@ void NzMaterial::Reset()
|
||||
m_states = NzRenderStates();
|
||||
m_states.parameters[nzRendererParameter_DepthBuffer] = true;
|
||||
m_states.parameters[nzRendererParameter_FaceCulling] = true;
|
||||
m_transformEnabled = true;
|
||||
|
||||
SetShader("Basic");
|
||||
}
|
||||
|
||||
bool NzMaterial::SetAlphaMap(const NzString& texturePath)
|
||||
@@ -423,9 +410,7 @@ void NzMaterial::SetAlphaMap(NzTexture* map)
|
||||
{
|
||||
m_alphaMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
void NzMaterial::SetAlphaThreshold(float alphaThreshold)
|
||||
@@ -469,9 +454,7 @@ void NzMaterial::SetDiffuseMap(NzTexture* map)
|
||||
{
|
||||
m_diffuseMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
void NzMaterial::SetDiffuseSampler(const NzTextureSampler& sampler)
|
||||
@@ -505,7 +488,7 @@ void NzMaterial::SetEmissiveMap(NzTexture* map)
|
||||
{
|
||||
m_emissiveMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
void NzMaterial::SetFaceCulling(nzFaceSide faceSide)
|
||||
@@ -539,7 +522,7 @@ void NzMaterial::SetHeightMap(NzTexture* map)
|
||||
{
|
||||
m_heightMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
bool NzMaterial::SetNormalMap(const NzString& texturePath)
|
||||
@@ -563,7 +546,7 @@ void NzMaterial::SetNormalMap(NzTexture* map)
|
||||
{
|
||||
m_normalMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
void NzMaterial::SetRenderStates(const NzRenderStates& states)
|
||||
@@ -571,12 +554,20 @@ void NzMaterial::SetRenderStates(const NzRenderStates& 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);
|
||||
unit.program = program;
|
||||
bool NzMaterial::SetShader(const NzString& uberShaderName)
|
||||
{
|
||||
NzUberShader* uberShader = NzUberShaderLibrary::Get(uberShaderName);
|
||||
if (!uberShader)
|
||||
return false;
|
||||
|
||||
SetShader(uberShader);
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetShininess(float shininess)
|
||||
@@ -610,7 +601,7 @@ void NzMaterial::SetSpecularMap(NzTexture* map)
|
||||
{
|
||||
m_specularMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidateShaders();
|
||||
}
|
||||
|
||||
void NzMaterial::SetSpecularSampler(const NzTextureSampler& sampler)
|
||||
@@ -641,19 +632,115 @@ NzMaterial& NzMaterial::operator=(NzMaterial&& material)
|
||||
material.m_heightMap.Reset();
|
||||
material.m_normalMap.Reset();
|
||||
material.m_specularMap.Reset();
|
||||
|
||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
||||
for (ProgramUnit& unit : material.m_programs[i])
|
||||
unit.program.Reset();
|
||||
material.m_uberShader.Reset();
|
||||
|
||||
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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_alphaMap.Reset();
|
||||
@@ -662,10 +749,7 @@ void NzMaterial::Copy(const NzMaterial& material)
|
||||
m_heightMap.Reset();
|
||||
m_normalMap.Reset();
|
||||
m_specularMap.Reset();
|
||||
|
||||
for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i)
|
||||
for (ProgramUnit& unit : m_programs[i])
|
||||
unit.program.Reset();
|
||||
m_uberShader.Reset();
|
||||
|
||||
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_normalMap.Release();
|
||||
m_specularMap.Release();
|
||||
m_uberShader.Release();
|
||||
|
||||
m_alphaMap = material.m_alphaMap;
|
||||
m_diffuseMap = material.m_diffuseMap;
|
||||
@@ -683,77 +768,53 @@ void NzMaterial::Copy(const NzMaterial& material)
|
||||
m_heightMap = material.m_heightMap;
|
||||
m_normalMap = material.m_normalMap;
|
||||
m_specularMap = material.m_specularMap;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
m_uberShader = material.m_uberShader;
|
||||
}
|
||||
|
||||
void NzMaterial::GenerateProgram(nzShaderTarget target, nzUInt32 flags) const
|
||||
void NzMaterial::GenerateShader(nzUInt32 flags) const
|
||||
{
|
||||
NzShaderProgramManagerParams params;
|
||||
params.target = target;
|
||||
params.flags = flags;
|
||||
NzParameterList list;
|
||||
list.SetParameter("ALPHA_MAPPING", m_alphaMap.IsValid());
|
||||
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)
|
||||
{
|
||||
case nzShaderTarget_FullscreenQuad:
|
||||
params.fullscreenQuad.alphaMapping = m_alphaMap.IsValid();
|
||||
params.fullscreenQuad.alphaTest = m_alphaTestEnabled;
|
||||
params.fullscreenQuad.diffuseMapping = m_diffuseMap.IsValid();
|
||||
break;
|
||||
list.SetParameter("FLAG_DEFERRED", static_cast<bool>(flags & nzShaderFlags_Deferred));
|
||||
list.SetParameter("FLAG_INSTANCING", static_cast<bool>(flags & nzShaderFlags_Instancing));
|
||||
|
||||
case nzShaderTarget_Model:
|
||||
params.model.alphaMapping = m_alphaMap.IsValid();
|
||||
params.model.alphaTest = m_alphaTestEnabled;
|
||||
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;
|
||||
ShaderInstance& instance = m_shaders[flags];
|
||||
instance.uberInstance = m_uberShader->Get(list);
|
||||
instance.shader = instance.uberInstance->GetShader();
|
||||
|
||||
case nzShaderTarget_None:
|
||||
break;
|
||||
#define CacheUniform(name) instance.uniforms[nzMaterialUniform_##name] = instance.shader->GetUniformLocation("Material" #name)
|
||||
|
||||
case nzShaderTarget_Sprite:
|
||||
params.sprite.alphaMapping = m_alphaMap.IsValid();
|
||||
params.sprite.alphaTest = m_alphaTestEnabled;
|
||||
params.sprite.diffuseMapping = m_diffuseMap.IsValid();
|
||||
break;
|
||||
}
|
||||
CacheUniform(AlphaMap);
|
||||
CacheUniform(AlphaThreshold);
|
||||
CacheUniform(Ambient);
|
||||
CacheUniform(Diffuse);
|
||||
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])
|
||||
{
|
||||
if (!unit.custom)
|
||||
unit.program.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool NzMaterial::Initialize()
|
||||
{
|
||||
s_defaultMaterial = new NzMaterial;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::Uninitialize()
|
||||
{
|
||||
delete s_defaultMaterial;
|
||||
s_defaultMaterial = nullptr;
|
||||
for (ShaderInstance& instance : m_shaders)
|
||||
instance.uberInstance = nullptr;
|
||||
}
|
||||
|
||||
NzMaterial* NzMaterial::s_defaultMaterial = nullptr;
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||
#include <Nazara/Graphics/Camera.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
#include <memory>
|
||||
@@ -19,6 +20,9 @@ bool NzModelParameters::IsValid() const
|
||||
if (loadMaterials && !material.IsValid())
|
||||
return false;
|
||||
|
||||
if (!NzUberShaderLibrary::Has(shaderName))
|
||||
return false;
|
||||
|
||||
return mesh.IsValid();
|
||||
}
|
||||
|
||||
@@ -56,6 +60,8 @@ m_skinCount(model.m_skinCount)
|
||||
if (m_mesh->GetAnimationType() == nzAnimationType_Skeletal)
|
||||
m_skeleton = model.m_skeleton;
|
||||
}
|
||||
|
||||
SetParent(model);
|
||||
}
|
||||
|
||||
NzModel::~NzModel()
|
||||
@@ -633,9 +639,9 @@ bool NzModel::FrustumCull(const NzFrustumf& frustum)
|
||||
return frustum.Contains(m_boundingVolume);
|
||||
}
|
||||
|
||||
void NzModel::Invalidate()
|
||||
void NzModel::InvalidateNode()
|
||||
{
|
||||
NzSceneNode::Invalidate();
|
||||
NzSceneNode::InvalidateNode();
|
||||
|
||||
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;
|
||||
|
||||
struct Light
|
||||
{
|
||||
int type;
|
||||
vec4 ambient;
|
||||
vec4 color;
|
||||
vec2 factors;
|
||||
|
||||
vec4 parameters1;
|
||||
vec4 parameters2;
|
||||
vec2 parameters3;
|
||||
};
|
||||
|
||||
uniform vec3 EyePosition;
|
||||
uniform Light Lights[1];
|
||||
|
||||
uniform vec4 LightColor;
|
||||
uniform vec2 LightFactors;
|
||||
uniform vec4 LightDirection;
|
||||
|
||||
uniform sampler2D GBuffer0;
|
||||
uniform sampler2D GBuffer1;
|
||||
@@ -56,15 +47,15 @@ void main()
|
||||
float depth = ColorToFloat(gVec2.xyz);
|
||||
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
||||
|
||||
vec3 lightDir = -Lights[0].parameters1.xyz;
|
||||
vec3 lightDir = -LightDirection.xyz;
|
||||
|
||||
// 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
|
||||
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
|
||||
vec3 lightSpecular;
|
||||
@@ -81,7 +72,7 @@ void main()
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, shininess);
|
||||
|
||||
lightSpecular = specularFactor * Lights[0].color.rgb * specularMultiplier;
|
||||
lightSpecular = specularFactor * LightColor.rgb * specularMultiplier;
|
||||
}
|
||||
else
|
||||
lightSpecular = vec3(0.0);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,21 +1,20 @@
|
||||
#version 140
|
||||
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
#define LIGHT_SPOT 2
|
||||
|
||||
out vec4 RenderTarget0;
|
||||
|
||||
struct Light
|
||||
{
|
||||
int type;
|
||||
vec4 ambient;
|
||||
vec4 color;
|
||||
vec2 factors;
|
||||
|
||||
vec4 parameters1;
|
||||
vec4 parameters2;
|
||||
vec2 parameters3;
|
||||
};
|
||||
|
||||
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 GBuffer1;
|
||||
@@ -26,7 +25,6 @@ uniform vec2 InvTargetSize;
|
||||
uniform vec4 SceneAmbient;
|
||||
|
||||
uniform bool Discard = false;
|
||||
uniform bool SpotLight;
|
||||
|
||||
float ColorToFloat(vec3 color)
|
||||
{
|
||||
@@ -67,28 +65,28 @@ void main()
|
||||
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||
worldPos.xyz /= worldPos.w;
|
||||
|
||||
vec3 lightDir = Lights[0].parameters1.xyz - worldPos.xyz;
|
||||
vec3 lightDir = LightParameters1.xyz - worldPos.xyz;
|
||||
float lightDirLength = length(lightDir);
|
||||
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
|
||||
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
|
||||
float curAngle = dot(Lights[0].parameters2.xyz, -lightDir);
|
||||
float outerAngle = Lights[0].parameters3.y;
|
||||
float innerMinusOuterAngle = Lights[0].parameters3.x - outerAngle;
|
||||
float curAngle = dot(LightParameters2.xyz, -lightDir);
|
||||
float outerAngle = LightParameters3.y;
|
||||
float innerMinusOuterAngle = LightParameters3.x - outerAngle;
|
||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||
}
|
||||
|
||||
// Diffuse
|
||||
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
|
||||
vec3 lightSpecular;
|
||||
@@ -99,7 +97,7 @@ void main()
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, shininess);
|
||||
|
||||
lightSpecular = att * specularFactor * Lights[0].color.rgb * specularMultiplier;
|
||||
lightSpecular = att * specularFactor * LightColor.rgb * specularMultiplier;
|
||||
}
|
||||
else
|
||||
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********************/
|
||||
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;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
uniform float VertexDepth;
|
||||
uniform mat4 ViewProjMatrix;
|
||||
uniform mat4 WorldViewProjMatrix;
|
||||
|
||||
@@ -18,16 +15,28 @@ uniform mat4 WorldViewProjMatrix;
|
||||
void main()
|
||||
{
|
||||
#if FLAG_INSTANCING
|
||||
#if TRANSFORM
|
||||
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
|
||||
#if TRANSFORM
|
||||
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
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||
#else
|
||||
#if TEXTURE_MAPPING
|
||||
vTexCoord = vec2(VertexTexCoord);
|
||||
#endif // FLAG_FLIP_UVS
|
||||
#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********************/
|
||||
in vec2 vTexCoord;
|
||||
|
||||
@@ -9,17 +13,25 @@ uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
uniform vec2 InvTargetSize;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
vec4 fragmentColor = MaterialDiffuse;
|
||||
|
||||
#if AUTO_TEXCOORDS
|
||||
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||
#else
|
||||
vec2 texCoord = vTexCoord;
|
||||
#endif
|
||||
|
||||
#if DIFFUSE_MAPPING
|
||||
fragmentColor *= texture(MaterialDiffuseMap, vTexCoord);
|
||||
fragmentColor *= texture(MaterialDiffuseMap, texCoord);
|
||||
#endif
|
||||
|
||||
#if ALPHA_MAPPING
|
||||
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
||||
fragmentColor.a *= texture(MaterialAlphaMap, texCoord).r;
|
||||
#endif
|
||||
|
||||
#if ALPHA_TEST
|
||||
@@ -27,9 +39,5 @@ void main()
|
||||
discard;
|
||||
#endif
|
||||
|
||||
#if FLAG_DEFERRED
|
||||
RenderTarget0 = vec4(fragmentColor.rgb, 0.0);
|
||||
#else
|
||||
RenderTarget0 = fragmentColor;
|
||||
#endif
|
||||
}
|
||||
1
src/Nazara/Graphics/Resources/Shaders/Basic/core.frag.h
Normal file
1
src/Nazara/Graphics/Resources/Shaders/Basic/core.frag.h
Normal file
@@ -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;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
uniform float VertexDepth;
|
||||
uniform mat4 ViewProjMatrix;
|
||||
uniform mat4 WorldViewProjMatrix;
|
||||
|
||||
@@ -18,16 +15,28 @@ uniform mat4 WorldViewProjMatrix;
|
||||
void main()
|
||||
{
|
||||
#if FLAG_INSTANCING
|
||||
#if TRANSFORM
|
||||
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
|
||||
#if TRANSFORM
|
||||
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
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||
#else
|
||||
#if TEXTURE_MAPPING
|
||||
vTexCoord = vec2(VertexTexCoord);
|
||||
#endif // FLAG_FLIP_UVS
|
||||
#endif
|
||||
}
|
||||
1
src/Nazara/Graphics/Resources/Shaders/Basic/core.vert.h
Normal file
1
src/Nazara/Graphics/Resources/Shaders/Basic/core.vert.h
Normal file
@@ -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;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform float VertexDepth;
|
||||
uniform mat4 ViewProjMatrix;
|
||||
uniform mat4 WorldMatrix;
|
||||
uniform mat4 WorldViewProjMatrix;
|
||||
@@ -20,11 +21,28 @@ uniform mat4 WorldViewProjMatrix;
|
||||
void main()
|
||||
{
|
||||
#if FLAG_INSTANCING
|
||||
#if TRANSFORM
|
||||
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
|
||||
#if TRANSFORM
|
||||
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
|
||||
|
||||
|
||||
#if LIGHTING
|
||||
#if FLAG_INSTANCING
|
||||
mat3 rotationMatrix = mat3(InstanceData0[0].xyz, InstanceData0[1].xyz, InstanceData0[2].xyz);
|
||||
@@ -42,15 +60,20 @@ void main()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING || EMISSIVE_MAPPING || NORMAL_MAPPING || PARALLAX_MAPPING || SPECULAR_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
#if TEXTURE_MAPPING
|
||||
/* #if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||
#else
|
||||
#else*/
|
||||
vTexCoord = VertexTexCoord;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
#if LIGHTING && PARALLAX_MAPPING
|
||||
vViewDir = EyePosition - VertexPosition;
|
||||
vViewDir *= vLightToWorld;
|
||||
#endif
|
||||
|
||||
#if LIGHTING && !FLAG_DEFERRED
|
||||
#if FLAG_INSTANCING
|
||||
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
|
||||
#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_POINT 1
|
||||
#define LIGHT_SPOT 2
|
||||
File diff suppressed because one or more lines are too long
@@ -14,6 +14,7 @@ out vec3 vWorldPos;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform vec3 EyePosition;
|
||||
uniform float VertexDepth;
|
||||
uniform mat4 ViewProjMatrix;
|
||||
uniform mat4 WorldMatrix;
|
||||
uniform mat4 WorldViewProjMatrix;
|
||||
@@ -22,19 +23,35 @@ uniform mat4 WorldViewProjMatrix;
|
||||
void main()
|
||||
{
|
||||
#if FLAG_INSTANCING
|
||||
#if TRANSFORM
|
||||
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
|
||||
#if TRANSFORM
|
||||
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
|
||||
|
||||
#if LIGHTING
|
||||
//#if LIGHTING
|
||||
#if FLAG_INSTANCING
|
||||
mat3 rotationMatrix = mat3(InstanceData0);
|
||||
#else
|
||||
mat3 rotationMatrix = mat3(WorldMatrix);
|
||||
#endif
|
||||
|
||||
#if NORMAL_MAPPING || PARALLAX_MAPPING
|
||||
#if COMPUTE_TBNMATRIX
|
||||
vec3 binormal = cross(VertexNormal, VertexTangent);
|
||||
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
|
||||
vLightToWorld[1] = normalize(rotationMatrix * binormal);
|
||||
@@ -42,14 +59,14 @@ void main()
|
||||
#else
|
||||
vNormal = normalize(rotationMatrix * VertexNormal);
|
||||
#endif
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING || EMISSIVE_MAPPING || NORMAL_MAPPING || PARALLAX_MAPPING || SPECULAR_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
#if TEXTURE_MAPPING
|
||||
/* #if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||
#else
|
||||
#else*/
|
||||
vTexCoord = VertexTexCoord;
|
||||
#endif
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
#if LIGHTING && PARALLAX_MAPPING
|
||||
File diff suppressed because one or more lines are too long
@@ -48,13 +48,6 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
///FIXME: Constructeur de copie
|
||||
|
||||
NzSceneNode::NzSceneNode() :
|
||||
m_scene(nullptr),
|
||||
m_drawingEnabled(true),
|
||||
@@ -15,7 +17,8 @@ m_visible(false)
|
||||
}
|
||||
|
||||
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_visible(false)
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace
|
||||
return indexBuffer.release();
|
||||
}
|
||||
|
||||
NzShaderProgram* BuildProgram()
|
||||
NzShader* BuildShader()
|
||||
{
|
||||
const char* fragmentSource110 =
|
||||
"#version 110\n"
|
||||
@@ -106,33 +106,39 @@ namespace
|
||||
"}\n";
|
||||
|
||||
///TODO: Remplacer ça par des ShaderNode
|
||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram(nzShaderLanguage_GLSL));
|
||||
program->SetPersistent(false);
|
||||
std::unique_ptr<NzShader> shader(new NzShader);
|
||||
shader->SetPersistent(false);
|
||||
|
||||
if (!shader->Create())
|
||||
{
|
||||
NazaraError("Failed to create shader");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!program->LoadShader(nzShaderType_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110))
|
||||
if (!shader->AttachStageFromSource(nzShaderStage_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110))
|
||||
{
|
||||
NazaraError("Failed to load vertex shader");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!program->Compile())
|
||||
if (!shader->Link())
|
||||
{
|
||||
NazaraError("Failed to compile program");
|
||||
NazaraError("Failed to link shader");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
program->SendInteger(program->GetUniformLocation("Skybox"), 0);
|
||||
program->SendFloat(program->GetUniformLocation(nzShaderUniform_VertexDepth), 1.f);
|
||||
shader->SendInteger(shader->GetUniformLocation("Skybox"), 0);
|
||||
shader->SendFloat(shader->GetUniformLocation("VertexDepth"), 1.f);
|
||||
|
||||
return program.release();
|
||||
return shader.release();
|
||||
}
|
||||
|
||||
NzRenderStates BuildRenderStates()
|
||||
@@ -174,7 +180,7 @@ namespace
|
||||
}
|
||||
|
||||
static NzIndexBuffer* s_indexBuffer = nullptr;
|
||||
static NzShaderProgram* s_program = nullptr;
|
||||
static NzShader* s_shader = nullptr;
|
||||
static NzVertexBuffer* s_vertexBuffer = nullptr;
|
||||
}
|
||||
|
||||
@@ -183,15 +189,15 @@ NzSkyboxBackground::NzSkyboxBackground()
|
||||
if (!s_indexBuffer)
|
||||
s_indexBuffer = BuildIndexBuffer();
|
||||
|
||||
if (!s_program)
|
||||
s_program = BuildProgram();
|
||||
if (!s_shader)
|
||||
s_shader = BuildShader();
|
||||
|
||||
if (!s_vertexBuffer)
|
||||
s_vertexBuffer = BuildVertexBuffer();
|
||||
|
||||
m_indexBuffer = s_indexBuffer;
|
||||
m_program = s_program;
|
||||
m_sampler.SetWrapMode(nzSamplerWrap_Clamp); // Nécessaire pour ne pas voir les côtés
|
||||
m_shader = s_shader;
|
||||
m_vertexBuffer = s_vertexBuffer;
|
||||
}
|
||||
|
||||
@@ -206,8 +212,8 @@ NzSkyboxBackground::~NzSkyboxBackground()
|
||||
if (m_indexBuffer.Reset())
|
||||
s_indexBuffer = nullptr;
|
||||
|
||||
if (m_program.Reset())
|
||||
s_program = nullptr;
|
||||
if (m_shader.Reset())
|
||||
s_shader = nullptr;
|
||||
|
||||
if (m_vertexBuffer.Reset())
|
||||
s_vertexBuffer = nullptr;
|
||||
@@ -226,7 +232,7 @@ void NzSkyboxBackground::Draw(const NzScene* scene) const
|
||||
NzRenderer::SetMatrix(nzMatrixType_View, skyboxMatrix);
|
||||
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Scale(NzVector3f(viewer->GetZNear())));
|
||||
NzRenderer::SetRenderStates(states);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(m_shader);
|
||||
NzRenderer::SetTexture(0, m_texture);
|
||||
NzRenderer::SetTextureSampler(0, m_sampler);
|
||||
NzRenderer::SetVertexBuffer(m_vertexBuffer);
|
||||
|
||||
@@ -46,6 +46,7 @@ m_textureCoords(sprite.m_textureCoords),
|
||||
m_size(sprite.m_size),
|
||||
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated)
|
||||
{
|
||||
SetParent(sprite);
|
||||
}
|
||||
|
||||
NzSprite::NzSprite(NzSprite&& sprite) :
|
||||
@@ -161,9 +162,9 @@ bool NzSprite::FrustumCull(const NzFrustumf& frustum)
|
||||
return frustum.Contains(m_boundingVolume);
|
||||
}
|
||||
|
||||
void NzSprite::Invalidate()
|
||||
void NzSprite::InvalidateNode()
|
||||
{
|
||||
NzSceneNode::Invalidate();
|
||||
NzSceneNode::InvalidateNode();
|
||||
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <Nazara/Graphics/TextureBackground.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
@@ -25,14 +25,19 @@ namespace
|
||||
|
||||
NzTextureBackground::NzTextureBackground()
|
||||
{
|
||||
NzShaderProgramManagerParams params;
|
||||
params.target = nzShaderTarget_FullscreenQuad;
|
||||
params.flags = 0;
|
||||
params.fullscreenQuad.alphaMapping = false;
|
||||
params.fullscreenQuad.alphaTest = false;
|
||||
params.fullscreenQuad.diffuseMapping = true;
|
||||
m_uberShader = NzUberShaderLibrary::Get("Basic");
|
||||
|
||||
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) :
|
||||
@@ -48,12 +53,14 @@ void NzTextureBackground::Draw(const NzScene* scene) const
|
||||
static NzRenderStates states(BuildRenderStates());
|
||||
|
||||
NzRenderer::SetRenderStates(states);
|
||||
NzRenderer::SetShaderProgram(m_program);
|
||||
NzRenderer::SetTexture(0, m_texture);
|
||||
|
||||
m_program->SendColor(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), NzColor::White);
|
||||
m_program->SendFloat(m_program->GetUniformLocation(nzShaderUniform_VertexDepth), 1.f);
|
||||
m_program->SendInteger(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuseMap), 0);
|
||||
m_uberShaderInstance->Activate();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -207,9 +207,9 @@ void NzView::ApplyView() const
|
||||
NzRenderer::SetViewport(m_viewport);
|
||||
}
|
||||
|
||||
void NzView::Invalidate()
|
||||
void NzView::InvalidateNode()
|
||||
{
|
||||
NzNode::Invalidate();
|
||||
NzNode::InvalidateNode();
|
||||
|
||||
// Le frustum et la view matrix dépendent des paramètres du node, invalidons-les
|
||||
m_frustumUpdated = false;
|
||||
|
||||
@@ -1,72 +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_ABSTRACTSHADERPROGRAM_HPP
|
||||
#define NAZARA_ABSTRACTSHADERPROGRAM_HPP
|
||||
|
||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
||||
|
||||
class NzAbstractShaderProgram
|
||||
{
|
||||
friend class NzRenderer;
|
||||
|
||||
public:
|
||||
NzAbstractShaderProgram() = default;
|
||||
virtual ~NzAbstractShaderProgram();
|
||||
|
||||
virtual bool Bind() = 0;
|
||||
virtual bool BindTextures() = 0;
|
||||
|
||||
virtual bool Compile() = 0;
|
||||
virtual bool Create() = 0;
|
||||
|
||||
virtual void Destroy() = 0;
|
||||
|
||||
virtual NzByteArray GetBinary() const = 0;
|
||||
virtual NzString GetLog() const = 0;
|
||||
virtual nzShaderLanguage GetLanguage() const = 0;
|
||||
virtual NzString GetSourceCode(nzShaderType type) const = 0;
|
||||
virtual int GetUniformLocation(const NzString& name) const = 0;
|
||||
virtual int GetUniformLocation(nzShaderUniform uniform) const = 0;
|
||||
|
||||
virtual bool IsBinaryRetrievable() const = 0;
|
||||
virtual bool IsLoaded(nzShaderType type) const = 0;
|
||||
|
||||
virtual bool LoadFromBinary(const void* buffer, unsigned int size) = 0;
|
||||
virtual bool LoadShader(nzShaderType type, const NzString& source) = 0;
|
||||
|
||||
virtual bool SendBoolean(int location, bool value) = 0;
|
||||
virtual bool SendColor(int location, const NzColor& color) = 0;
|
||||
virtual bool SendDouble(int location, double value) = 0;
|
||||
virtual bool SendDoubleArray(int location, const double* values, unsigned int count) = 0;
|
||||
virtual bool SendFloat(int location, float value) = 0;
|
||||
virtual bool SendFloatArray(int location, const float* values, unsigned int count) = 0;
|
||||
virtual bool SendInteger(int location, int value) = 0;
|
||||
virtual bool SendIntegerArray(int location, const int* value, unsigned int count) = 0;
|
||||
virtual bool SendMatrix(int location, const NzMatrix4d& matrix) = 0;
|
||||
virtual bool SendMatrix(int location, const NzMatrix4f& matrix) = 0;
|
||||
virtual bool SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit = nullptr) = 0;
|
||||
virtual bool SendVector(int location, const NzVector2d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector2f& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector2i& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector3d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector3f& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector3i& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector4d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector4f& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector4i& vector) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector2d* vectors, unsigned int count) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector2f* vectors, unsigned int count) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector2i* vectors, unsigned int count) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector3d* vectors, unsigned int count) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector3f* vectors, unsigned int count) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector3i* vectors, unsigned int count) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector4d* vectors, unsigned int count) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector4f* vectors, unsigned int count) = 0;
|
||||
virtual bool SendVectorArray(int location, const NzVector4i* vectors, unsigned int count) = 0;
|
||||
};
|
||||
|
||||
#endif // NAZARA_ABSTRACTSHADERPROGRAM_HPP
|
||||
@@ -3,26 +3,28 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/DebugDrawer.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
///TODO: Améliorer
|
||||
|
||||
namespace
|
||||
{
|
||||
static std::unique_ptr<NzShader> s_shader = nullptr;
|
||||
static NzColor s_primaryColor;
|
||||
static NzColor s_secondaryColor;
|
||||
static NzRenderStates s_renderStates;
|
||||
static const NzShaderProgram* s_program = nullptr;
|
||||
static NzVertexBuffer s_vertexBuffer;
|
||||
static bool s_initialized = false;
|
||||
static int s_colorLocation = -1;
|
||||
@@ -126,10 +128,10 @@ void NzDebugDrawer::Draw(const NzBoxf& box)
|
||||
mapper.Unmap();
|
||||
|
||||
NzRenderer::SetRenderStates(s_renderStates);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(s_shader.get());
|
||||
NzRenderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_primaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24);
|
||||
}
|
||||
@@ -213,10 +215,10 @@ void NzDebugDrawer::Draw(const NzFrustumf& frustum)
|
||||
mapper.Unmap();
|
||||
|
||||
NzRenderer::SetRenderStates(s_renderStates);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(s_shader.get());
|
||||
NzRenderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_primaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24);
|
||||
}
|
||||
@@ -295,10 +297,10 @@ void NzDebugDrawer::Draw(const NzOrientedBoxf& orientedBox)
|
||||
mapper.Unmap();
|
||||
|
||||
NzRenderer::SetRenderStates(s_renderStates);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(s_shader.get());
|
||||
NzRenderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_primaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24);
|
||||
}
|
||||
@@ -343,13 +345,13 @@ void NzDebugDrawer::Draw(const NzSkeleton* skeleton)
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
NzRenderer::SetRenderStates(s_renderStates);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(s_shader.get());
|
||||
NzRenderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_primaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, vertexCount);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_secondaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_secondaryColor);
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_PointList, 0, vertexCount);
|
||||
}
|
||||
}
|
||||
@@ -393,10 +395,10 @@ void NzDebugDrawer::DrawBinormals(const NzStaticMesh* subMesh)
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
NzRenderer::SetRenderStates(s_renderStates);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(s_shader.get());
|
||||
NzRenderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_primaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, vertexCount);
|
||||
}
|
||||
}
|
||||
@@ -469,10 +471,10 @@ void NzDebugDrawer::DrawCone(const NzVector3f& origin, const NzQuaternionf& rota
|
||||
mapper.Unmap();
|
||||
|
||||
NzRenderer::SetRenderStates(s_renderStates);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(s_shader.get());
|
||||
NzRenderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_primaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 16);
|
||||
}
|
||||
@@ -516,10 +518,10 @@ void NzDebugDrawer::DrawNormals(const NzStaticMesh* subMesh)
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
NzRenderer::SetRenderStates(s_renderStates);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(s_shader.get());
|
||||
NzRenderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_primaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, vertexCount);
|
||||
}
|
||||
}
|
||||
@@ -563,10 +565,10 @@ void NzDebugDrawer::DrawTangents(const NzStaticMesh* subMesh)
|
||||
if (vertexCount > 0)
|
||||
{
|
||||
NzRenderer::SetRenderStates(s_renderStates);
|
||||
NzRenderer::SetShaderProgram(s_program);
|
||||
NzRenderer::SetShader(s_shader.get());
|
||||
NzRenderer::SetVertexBuffer(&s_vertexBuffer);
|
||||
|
||||
s_program->SendColor(s_colorLocation, s_primaryColor);
|
||||
s_shader->SendColor(s_colorLocation, s_primaryColor);
|
||||
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, vertexCount);
|
||||
}
|
||||
}
|
||||
@@ -600,35 +602,85 @@ bool NzDebugDrawer::Initialize()
|
||||
{
|
||||
if (!s_initialized)
|
||||
{
|
||||
// s_program
|
||||
// s_shader
|
||||
{
|
||||
NzShaderProgramManagerParams params;
|
||||
params.target = nzShaderTarget_Model;
|
||||
params.flags = 0;
|
||||
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 char* fragmentSource110 =
|
||||
"#version 110\n"
|
||||
"uniform vec3 color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = vec4(color, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
s_program = NzShaderProgramManager::Get(params);
|
||||
if (!s_program)
|
||||
const char* fragmentSource140 =
|
||||
"#version 140\n"
|
||||
"uniform vec3 color;\n"
|
||||
"out vec4 RenderTarget0;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" RenderTarget0 = vec4(color, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
const char* vertexSource110 =
|
||||
"#version 110\n"
|
||||
"attribute vec3 Position;\n"
|
||||
"uniform mat4 WorldViewProjMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjMatrix * vec4(Position, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
const char* vertexSource140 =
|
||||
"#version 140\n"
|
||||
"in vec3 Position;\n"
|
||||
"uniform mat4 WorldViewProjMatrix;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = WorldViewProjMatrix * vec4(Position, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
bool useGLSL140 = (NzOpenGL::GetVersion() >= 310);
|
||||
|
||||
s_shader.reset(new NzShader);
|
||||
if (!s_shader->Create())
|
||||
{
|
||||
NazaraError("Failed to build debug s_program");
|
||||
|
||||
Uninitialize();
|
||||
|
||||
NazaraError("Failed to create shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
s_colorLocation = s_program->GetUniformLocation(nzShaderUniform_MaterialDiffuse);
|
||||
if (!s_shader->AttachStageFromSource(nzShaderStage_Fragment, (useGLSL140) ? fragmentSource140 : fragmentSource110))
|
||||
{
|
||||
Uninitialize();
|
||||
|
||||
NazaraError("Failed to load fragment shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!s_shader->AttachStageFromSource(nzShaderStage_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110))
|
||||
{
|
||||
Uninitialize();
|
||||
|
||||
NazaraError("Failed to load vertex shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!s_shader->Link())
|
||||
{
|
||||
Uninitialize();
|
||||
|
||||
NazaraError("Failed to link shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
s_colorLocation = s_shader->GetUniformLocation("color");
|
||||
}
|
||||
|
||||
// s_vertexBuffer
|
||||
try
|
||||
{
|
||||
NzErrorFlags flags(nzErrorFlag_ThrowException);
|
||||
s_vertexBuffer.Reset(NzVertexDeclaration::Get(nzVertexLayout_XYZ), 65365, nzBufferStorage_Hardware, nzBufferUsage_Dynamic);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
@@ -676,6 +728,7 @@ void NzDebugDrawer::SetSecondaryColor(const NzColor& color)
|
||||
|
||||
void NzDebugDrawer::Uninitialize()
|
||||
{
|
||||
s_shader.reset();
|
||||
s_vertexBuffer.Reset();
|
||||
s_initialized = false;
|
||||
}
|
||||
|
||||
@@ -1,101 +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_GLSLPROGRAM_HPP
|
||||
#define NAZARA_GLSLPROGRAM_HPP
|
||||
|
||||
#include <Nazara/Core/ResourceListener.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/AbstractShaderProgram.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
class NzResource;
|
||||
|
||||
class NzGLSLProgram : public NzAbstractShaderProgram, NzResourceListener
|
||||
{
|
||||
public:
|
||||
NzGLSLProgram(NzShaderProgram* parent);
|
||||
~NzGLSLProgram() = default;
|
||||
|
||||
bool Bind();
|
||||
bool BindTextures();
|
||||
|
||||
bool Compile();
|
||||
|
||||
bool Create();
|
||||
void Destroy();
|
||||
|
||||
NzByteArray GetBinary() const;
|
||||
NzString GetLog() const;
|
||||
nzShaderLanguage GetLanguage() const;
|
||||
NzString GetSourceCode(nzShaderType type) const;
|
||||
int GetUniformLocation(const NzString& name) const;
|
||||
int GetUniformLocation(nzShaderUniform uniform) const;
|
||||
|
||||
bool IsBinaryRetrievable() const;
|
||||
bool IsLoaded(nzShaderType type) const;
|
||||
|
||||
bool LoadFromBinary(const void* buffer, unsigned int size);
|
||||
bool LoadShader(nzShaderType type, const NzString& source);
|
||||
|
||||
bool SendBoolean(int location, bool value);
|
||||
bool SendColor(int location, const NzColor& color);
|
||||
bool SendDouble(int location, double value);
|
||||
bool SendDoubleArray(int location, const double* values, unsigned int count);
|
||||
bool SendFloat(int location, float value);
|
||||
bool SendFloatArray(int location, const float* values, unsigned int count);
|
||||
bool SendInteger(int location, int value);
|
||||
bool SendIntegerArray(int location, const int* values, unsigned int count);
|
||||
bool SendMatrix(int location, const NzMatrix4d& matrix);
|
||||
bool SendMatrix(int location, const NzMatrix4f& matrix);
|
||||
bool SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit = nullptr);
|
||||
bool SendVector(int location, const NzVector2d& vector);
|
||||
bool SendVector(int location, const NzVector2f& vector);
|
||||
bool SendVector(int location, const NzVector2i& vector);
|
||||
bool SendVector(int location, const NzVector3d& vector);
|
||||
bool SendVector(int location, const NzVector3f& vector);
|
||||
bool SendVector(int location, const NzVector3i& vector);
|
||||
bool SendVector(int location, const NzVector4d& vector);
|
||||
bool SendVector(int location, const NzVector4f& vector);
|
||||
bool SendVector(int location, const NzVector4i& vector);
|
||||
bool SendVectorArray(int location, const NzVector2d* vectors, unsigned int count);
|
||||
bool SendVectorArray(int location, const NzVector2f* vectors, unsigned int count);
|
||||
bool SendVectorArray(int location, const NzVector2i* vectors, unsigned int count);
|
||||
bool SendVectorArray(int location, const NzVector3d* vectors, unsigned int count);
|
||||
bool SendVectorArray(int location, const NzVector3f* vectors, unsigned int count);
|
||||
bool SendVectorArray(int location, const NzVector3i* vectors, unsigned int count);
|
||||
bool SendVectorArray(int location, const NzVector4d* vectors, unsigned int count);
|
||||
bool SendVectorArray(int location, const NzVector4f* vectors, unsigned int count);
|
||||
bool SendVectorArray(int location, const NzVector4i* vectors, unsigned int count);
|
||||
|
||||
private:
|
||||
bool OnResourceCreated(const NzResource* resource, int index) override;
|
||||
bool OnResourceDestroy(const NzResource* resource, int index) override;
|
||||
void OnResourceReleased(const NzResource* resource, int index) override;
|
||||
void PreLinkage();
|
||||
bool PostLinkage();
|
||||
|
||||
struct TextureSlot
|
||||
{
|
||||
bool enabled;
|
||||
bool updated = false;
|
||||
nzUInt8 unit;
|
||||
const NzTexture* texture;
|
||||
};
|
||||
|
||||
mutable std::unordered_map<NzString, GLint> m_idCache;
|
||||
std::map<GLint, TextureSlot> m_textures;
|
||||
GLuint m_program;
|
||||
GLuint m_shaders[nzShaderType_Max+1];
|
||||
NzShaderProgram* m_parent;
|
||||
NzString m_log;
|
||||
int m_uniformLocations[nzShaderUniform_Max+1];
|
||||
};
|
||||
|
||||
#endif // NAZARA_GLSLPROGRAM_HPP
|
||||
@@ -822,6 +822,7 @@ bool NzOpenGL::Initialize()
|
||||
glGenBuffers = reinterpret_cast<PFNGLGENBUFFERSPROC>(LoadEntry("glGenBuffers"));
|
||||
glGenQueries = reinterpret_cast<PFNGLGENQUERIESPROC>(LoadEntry("glGenQueries"));
|
||||
glGenTextures = reinterpret_cast<PFNGLGENTEXTURESPROC>(LoadEntry("glGenTextures"));
|
||||
glGetActiveUniform = reinterpret_cast<PFNGLGETACTIVEUNIFORMPROC>(LoadEntry("glGetActiveUniform"));
|
||||
glGetBooleanv = reinterpret_cast<PFNGLGETBOOLEANVPROC>(LoadEntry("glGetBooleanv"));
|
||||
glGetBufferParameteriv = reinterpret_cast<PFNGLGETBUFFERPARAMETERIVPROC>(LoadEntry("glGetBufferParameteriv"));
|
||||
glGetError = reinterpret_cast<PFNGLGETERRORPROC>(LoadEntry("glGetError"));
|
||||
@@ -1742,16 +1743,16 @@ void NzOpenGL::Uninitialize()
|
||||
}
|
||||
}
|
||||
|
||||
void NzOpenGL::OnContextDestruction(const NzContext* context)
|
||||
{
|
||||
s_contexts.erase(context);
|
||||
}
|
||||
|
||||
void NzOpenGL::OnContextChange(const NzContext* newContext)
|
||||
{
|
||||
s_contextStates = (newContext) ? &s_contexts[newContext] : nullptr;
|
||||
}
|
||||
|
||||
void NzOpenGL::OnContextDestruction(const NzContext* context)
|
||||
{
|
||||
s_contexts.erase(context);
|
||||
}
|
||||
|
||||
GLenum NzOpenGL::Attachment[] =
|
||||
{
|
||||
GL_COLOR_ATTACHMENT0, // nzAttachmentPoint_Color
|
||||
@@ -1962,14 +1963,14 @@ GLenum NzOpenGL::SamplerWrapMode[] =
|
||||
|
||||
static_assert(sizeof(NzOpenGL::SamplerWrapMode)/sizeof(GLenum) == nzSamplerWrap_Max+1, "Sampler wrap mode array is incomplete");
|
||||
|
||||
GLenum NzOpenGL::ShaderType[] =
|
||||
GLenum NzOpenGL::ShaderStage[] =
|
||||
{
|
||||
GL_FRAGMENT_SHADER, // nzShaderType_Fragment
|
||||
GL_GEOMETRY_SHADER, // nzShaderType_Geometry
|
||||
GL_VERTEX_SHADER // nzShaderType_Vertex
|
||||
GL_FRAGMENT_SHADER, // nzShaderStage_Fragment
|
||||
GL_GEOMETRY_SHADER, // nzShaderStage_Geometry
|
||||
GL_VERTEX_SHADER // nzShaderStage_Vertex
|
||||
};
|
||||
|
||||
static_assert(sizeof(NzOpenGL::ShaderType)/sizeof(GLenum) == nzShaderType_Max+1, "Shader type array is incomplete");
|
||||
static_assert(sizeof(NzOpenGL::ShaderStage)/sizeof(GLenum) == nzShaderStage_Max+1, "Shader stage array is incomplete");
|
||||
|
||||
GLenum NzOpenGL::StencilOperation[] =
|
||||
{
|
||||
@@ -2091,6 +2092,7 @@ PFNGLGENQUERIESPROC glGenQueries = nullptr;
|
||||
PFNGLGENSAMPLERSPROC glGenSamplers = nullptr;
|
||||
PFNGLGENTEXTURESPROC glGenTextures = nullptr;
|
||||
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr;
|
||||
PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform = nullptr;
|
||||
PFNGLGETBOOLEANVPROC glGetBooleanv = nullptr;
|
||||
PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr;
|
||||
PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr;
|
||||
|
||||
@@ -8,17 +8,16 @@
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Renderer/AbstractShaderProgram.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/DebugDrawer.hpp>
|
||||
#include <Nazara/Renderer/HardwareBuffer.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
||||
#include <Nazara/Renderer/Loaders/Texture.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
@@ -48,7 +47,7 @@ namespace
|
||||
Update_None = 0,
|
||||
|
||||
Update_Matrices = 0x1,
|
||||
Update_Program = 0x2,
|
||||
Update_Shader = 0x2,
|
||||
Update_Textures = 0x4,
|
||||
Update_VAO = 0x8
|
||||
};
|
||||
@@ -84,7 +83,7 @@ namespace
|
||||
nzUInt32 s_updateFlags;
|
||||
const NzIndexBuffer* s_indexBuffer;
|
||||
const NzRenderTarget* s_target;
|
||||
const NzShaderProgram* s_program;
|
||||
const NzShader* s_shader;
|
||||
const NzVertexBuffer* s_vertexBuffer;
|
||||
const NzVertexDeclaration* s_instancingDeclaration;
|
||||
bool s_capabilities[nzRendererCap_Max+1];
|
||||
@@ -605,9 +604,9 @@ NzRecti NzRenderer::GetScissorRect()
|
||||
return NzOpenGL::GetCurrentScissorBox();
|
||||
}
|
||||
|
||||
const NzShaderProgram* NzRenderer::GetShaderProgram()
|
||||
const NzShader* NzRenderer::GetShader()
|
||||
{
|
||||
return s_program;
|
||||
return s_shader;
|
||||
}
|
||||
|
||||
const NzRenderTarget* NzRenderer::GetTarget()
|
||||
@@ -734,14 +733,14 @@ bool NzRenderer::Initialize()
|
||||
s_states = NzRenderStates();
|
||||
|
||||
s_indexBuffer = nullptr;
|
||||
s_program = nullptr;
|
||||
s_shader = nullptr;
|
||||
s_target = nullptr;
|
||||
s_targetSize.Set(0U);
|
||||
s_textureUnits.resize(s_maxTextureUnit);
|
||||
s_useSamplerObjects = NzOpenGL::IsSupported(nzOpenGLExtension_SamplerObjects);
|
||||
s_useVertexArrayObjects = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObjects);
|
||||
s_updateFlags = (Update_Matrices | Update_Shader | Update_VAO);
|
||||
s_vertexBuffer = nullptr;
|
||||
s_updateFlags = (Update_Matrices | Update_Program | Update_VAO);
|
||||
|
||||
s_fullscreenQuadBuffer.Reset(NzVertexDeclaration::Get(nzVertexLayout_XY), 4, nzBufferStorage_Hardware, nzBufferUsage_Static);
|
||||
|
||||
@@ -769,19 +768,15 @@ bool NzRenderer::Initialize()
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
s_capabilities[nzRendererCap_Instancing] = false;
|
||||
NazaraError("Failed to create instancing buffer: " + NzString(e.what())); ///TODO: Noexcept
|
||||
|
||||
NzErrorFlags flags(nzErrorFlag_ThrowExceptionDisabled);
|
||||
NazaraError("Failed to create instancing buffer: " + NzString(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!NzMaterial::Initialize())
|
||||
if (!NzShaderLibrary::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize materials");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NzShaderProgramManager::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize shader program manager");
|
||||
NazaraError("Failed to initialize shader library");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -791,8 +786,77 @@ bool NzRenderer::Initialize()
|
||||
return false;
|
||||
}
|
||||
|
||||
// Loaders
|
||||
NzLoaders_Texture_Register();
|
||||
if (!NzUberShaderLibrary::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize uber shader library");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Création du shader de Debug
|
||||
std::unique_ptr<NzShader> shader(new NzShader);
|
||||
shader->SetPersistent(false);
|
||||
|
||||
if (!shader->Create())
|
||||
{
|
||||
NazaraError("Failed to create debug shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
const nzUInt8 coreFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Debug/core.frag.h>
|
||||
};
|
||||
|
||||
const nzUInt8 coreVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Debug/core.vert.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Debug/compatibility.frag.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Debug/compatibility.vert.h>
|
||||
};
|
||||
|
||||
const char* fragmentShader;
|
||||
const char* vertexShader;
|
||||
unsigned int fragmentShaderLength;
|
||||
unsigned int vertexShaderLength;
|
||||
if (NzOpenGL::GetGLSLVersion() >= 140)
|
||||
{
|
||||
fragmentShader = reinterpret_cast<const char*>(coreFragmentShader);
|
||||
fragmentShaderLength = sizeof(coreFragmentShader);
|
||||
vertexShader = reinterpret_cast<const char*>(coreVertexShader);
|
||||
vertexShaderLength = sizeof(coreVertexShader);
|
||||
}
|
||||
else
|
||||
{
|
||||
fragmentShader = reinterpret_cast<const char*>(compatibilityFragmentShader);
|
||||
fragmentShaderLength = sizeof(compatibilityFragmentShader);
|
||||
vertexShader = reinterpret_cast<const char*>(compatibilityVertexShader);
|
||||
vertexShaderLength = sizeof(compatibilityVertexShader);
|
||||
}
|
||||
|
||||
if (!shader->AttachStageFromSource(nzShaderStage_Fragment, fragmentShader, fragmentShaderLength))
|
||||
{
|
||||
NazaraError("Failed to attach fragment stage");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shader->AttachStageFromSource(nzShaderStage_Vertex, vertexShader, vertexShaderLength))
|
||||
{
|
||||
NazaraError("Failed to attach vertex stage");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shader->Link())
|
||||
{
|
||||
NazaraError("Failed to link shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
NzShaderLibrary::Register("DebugSimple", shader.get());
|
||||
shader.release();
|
||||
|
||||
onExit.Reset();
|
||||
|
||||
@@ -1051,20 +1115,23 @@ void NzRenderer::SetScissorRect(const NzRecti& rect)
|
||||
NzOpenGL::BindScissorBox(rect);
|
||||
}
|
||||
|
||||
void NzRenderer::SetShaderProgram(const NzShaderProgram* program)
|
||||
void NzRenderer::SetShader(const NzShader* shader)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (program && !program->IsCompiled())
|
||||
if (shader)
|
||||
{
|
||||
NazaraError("Shader program is not compiled");
|
||||
return;
|
||||
if (!shader->IsValid() || !shader->IsLinked())
|
||||
{
|
||||
NazaraError("Invalid shader");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (s_program != program)
|
||||
if (s_shader != shader)
|
||||
{
|
||||
s_program = program;
|
||||
s_updateFlags |= Update_Program;
|
||||
s_shader = shader;
|
||||
s_updateFlags |= Update_Shader;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1373,16 +1440,15 @@ void NzRenderer::Uninitialize()
|
||||
// Libération du module
|
||||
s_moduleReferenceCounter = 0;
|
||||
|
||||
s_textureUnits.clear();
|
||||
|
||||
// Loaders
|
||||
NzLoaders_Texture_Unregister();
|
||||
NzShaderLibrary::Unregister("DebugSimple");
|
||||
|
||||
NzUberShaderLibrary::Uninitialize();
|
||||
NzTextureSampler::Uninitialize();
|
||||
NzShaderProgramManager::Uninitialize();
|
||||
NzMaterial::Uninitialize();
|
||||
NzShaderLibrary::Uninitialize();
|
||||
NzDebugDrawer::Uninitialize();
|
||||
|
||||
s_textureUnits.clear();
|
||||
|
||||
// Libération des buffers
|
||||
s_fullscreenQuadBuffer.Reset();
|
||||
s_instanceBuffer.Reset();
|
||||
@@ -1447,9 +1513,9 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
#endif
|
||||
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!s_program)
|
||||
if (!s_shader)
|
||||
{
|
||||
NazaraError("No shader program");
|
||||
NazaraError("No shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1462,49 +1528,46 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
|
||||
s_target->EnsureTargetUpdated();
|
||||
|
||||
NzAbstractShaderProgram* programImpl = s_program->m_impl;
|
||||
programImpl->Bind(); // Active le programme si ce n'est pas déjà le cas
|
||||
s_shader->Bind(); // Active le programme si ce n'est pas déjà le cas
|
||||
|
||||
// Si le programme a été changé depuis la dernière fois
|
||||
if (s_updateFlags & Update_Program)
|
||||
if (s_updateFlags & Update_Shader)
|
||||
{
|
||||
// Récupération des indices des variables uniformes (-1 si la variable n'existe pas)
|
||||
s_matrices[nzMatrixType_Projection].location = programImpl->GetUniformLocation(nzShaderUniform_ProjMatrix);
|
||||
s_matrices[nzMatrixType_View].location = programImpl->GetUniformLocation(nzShaderUniform_ViewMatrix);
|
||||
s_matrices[nzMatrixType_World].location = programImpl->GetUniformLocation(nzShaderUniform_WorldMatrix);
|
||||
s_matrices[nzMatrixType_Projection].location = s_shader->GetUniformLocation(nzShaderUniform_ProjMatrix);
|
||||
s_matrices[nzMatrixType_View].location = s_shader->GetUniformLocation(nzShaderUniform_ViewMatrix);
|
||||
s_matrices[nzMatrixType_World].location = s_shader->GetUniformLocation(nzShaderUniform_WorldMatrix);
|
||||
|
||||
s_matrices[nzMatrixType_ViewProj].location = programImpl->GetUniformLocation(nzShaderUniform_ViewProjMatrix);
|
||||
s_matrices[nzMatrixType_WorldView].location = programImpl->GetUniformLocation(nzShaderUniform_WorldViewMatrix);
|
||||
s_matrices[nzMatrixType_WorldViewProj].location = programImpl->GetUniformLocation(nzShaderUniform_WorldViewProjMatrix);
|
||||
s_matrices[nzMatrixType_ViewProj].location = s_shader->GetUniformLocation(nzShaderUniform_ViewProjMatrix);
|
||||
s_matrices[nzMatrixType_WorldView].location = s_shader->GetUniformLocation(nzShaderUniform_WorldViewMatrix);
|
||||
s_matrices[nzMatrixType_WorldViewProj].location = s_shader->GetUniformLocation(nzShaderUniform_WorldViewProjMatrix);
|
||||
|
||||
s_matrices[nzMatrixType_InvProjection].location = programImpl->GetUniformLocation(nzShaderUniform_InvProjMatrix);
|
||||
s_matrices[nzMatrixType_InvView].location = programImpl->GetUniformLocation(nzShaderUniform_InvViewMatrix);
|
||||
s_matrices[nzMatrixType_InvViewProj].location = programImpl->GetUniformLocation(nzShaderUniform_InvViewProjMatrix);
|
||||
s_matrices[nzMatrixType_InvWorld].location = programImpl->GetUniformLocation(nzShaderUniform_InvWorldMatrix);
|
||||
s_matrices[nzMatrixType_InvWorldView].location = programImpl->GetUniformLocation(nzShaderUniform_InvWorldViewMatrix);
|
||||
s_matrices[nzMatrixType_InvWorldViewProj].location = programImpl->GetUniformLocation(nzShaderUniform_InvWorldViewProjMatrix);
|
||||
s_matrices[nzMatrixType_InvProjection].location = s_shader->GetUniformLocation(nzShaderUniform_InvProjMatrix);
|
||||
s_matrices[nzMatrixType_InvView].location = s_shader->GetUniformLocation(nzShaderUniform_InvViewMatrix);
|
||||
s_matrices[nzMatrixType_InvViewProj].location = s_shader->GetUniformLocation(nzShaderUniform_InvViewProjMatrix);
|
||||
s_matrices[nzMatrixType_InvWorld].location = s_shader->GetUniformLocation(nzShaderUniform_InvWorldMatrix);
|
||||
s_matrices[nzMatrixType_InvWorldView].location = s_shader->GetUniformLocation(nzShaderUniform_InvWorldViewMatrix);
|
||||
s_matrices[nzMatrixType_InvWorldViewProj].location = s_shader->GetUniformLocation(nzShaderUniform_InvWorldViewProjMatrix);
|
||||
|
||||
s_targetSize.Set(0U); // On force l'envoi des uniformes
|
||||
s_updateFlags |= Update_Matrices; // Changement de programme, on renvoie toutes les matrices demandées
|
||||
|
||||
s_updateFlags &= ~Update_Program;
|
||||
s_updateFlags &= ~Update_Shader;
|
||||
}
|
||||
|
||||
programImpl->BindTextures();
|
||||
|
||||
// Envoi des uniformes liées au Renderer
|
||||
NzVector2ui targetSize(s_target->GetWidth(), s_target->GetHeight());
|
||||
if (s_targetSize != targetSize)
|
||||
{
|
||||
int location;
|
||||
|
||||
location = programImpl->GetUniformLocation(nzShaderUniform_InvTargetSize);
|
||||
location = s_shader->GetUniformLocation(nzShaderUniform_InvTargetSize);
|
||||
if (location != -1)
|
||||
programImpl->SendVector(location, 1.f/NzVector2f(targetSize));
|
||||
s_shader->SendVector(location, 1.f/NzVector2f(targetSize));
|
||||
|
||||
location = programImpl->GetUniformLocation(nzShaderUniform_TargetSize);
|
||||
location = s_shader->GetUniformLocation(nzShaderUniform_TargetSize);
|
||||
if (location != -1)
|
||||
programImpl->SendVector(location, NzVector2f(targetSize));
|
||||
s_shader->SendVector(location, NzVector2f(targetSize));
|
||||
|
||||
s_targetSize.Set(targetSize);
|
||||
}
|
||||
@@ -1570,7 +1633,7 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
if (!unit.updated)
|
||||
UpdateMatrix(static_cast<nzMatrixType>(i));
|
||||
|
||||
programImpl->SendMatrix(unit.location, unit.matrix);
|
||||
s_shader->SendMatrix(unit.location, unit.matrix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1744,7 +1807,7 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
glBindVertexArray(s_currentVAO);
|
||||
|
||||
// On vérifie que les textures actuellement bindées sont bien nos textures
|
||||
// Ceci à cause du fait qu'il est possible que des opérations sur les textures ait eu lieu
|
||||
// Ceci à cause du fait qu'il est possible que des opérations sur les textures aient eu lieu
|
||||
// entre le dernier rendu et maintenant
|
||||
for (unsigned int i = 0; i < s_maxTextureUnit; ++i)
|
||||
{
|
||||
@@ -1753,18 +1816,18 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
NzOpenGL::BindTexture(i, texture->GetType(), texture->GetOpenGLID());
|
||||
}
|
||||
|
||||
// Et on termine par envoyer nos états à OpenGL
|
||||
// Et on termine par envoyer nos états au driver
|
||||
NzOpenGL::ApplyStates(s_states);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzRenderer::OnProgramReleased(const NzShaderProgram* program)
|
||||
void NzRenderer::OnShaderReleased(const NzShader* shader)
|
||||
{
|
||||
if (s_program == program)
|
||||
if (s_shader == shader)
|
||||
{
|
||||
s_program = nullptr;
|
||||
s_updateFlags |= Update_Program;
|
||||
s_shader = nullptr;
|
||||
s_updateFlags |= Update_Shader;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#version 110
|
||||
|
||||
/********************Uniformes********************/
|
||||
layout(location = 0) uniform vec4 Color;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = Color;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
35,118,101,114,115,105,111,110,32,49,49,48,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,108,97,121,111,117,116,40,108,111,99,97,116,105,111,110,32,61,32,48,41,32,117,110,105,102,111,114,109,32,118,101,99,52,32,67,111,108,111,114,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,103,108,95,70,114,97,103,67,111,108,111,114,32,61,32,67,111,108,111,114,59,13,10,125,
|
||||
@@ -1,17 +1,13 @@
|
||||
#version 110
|
||||
|
||||
/********************Entrant********************/
|
||||
varying mat4 InstanceData0;
|
||||
varying vec3 VertexPosition;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform mat4 ViewProjMatrix;
|
||||
uniform mat4 WorldViewProjMatrix;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
#if FLAG_INSTANCING
|
||||
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
||||
#else
|
||||
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
35,118,101,114,115,105,111,110,32,49,49,48,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,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,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,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,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,125,13,10,
|
||||
13
src/Nazara/Renderer/Resources/Shaders/Debug/core.frag
Normal file
13
src/Nazara/Renderer/Resources/Shaders/Debug/core.frag
Normal file
@@ -0,0 +1,13 @@
|
||||
#version 140
|
||||
|
||||
/********************Sortant********************/
|
||||
out vec4 RenderTarget0;
|
||||
|
||||
/********************Uniformes********************/
|
||||
layout(location = 0) uniform vec4 Color;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
RenderTarget0 = Color;
|
||||
}
|
||||
1
src/Nazara/Renderer/Resources/Shaders/Debug/core.frag.h
Normal file
1
src/Nazara/Renderer/Resources/Shaders/Debug/core.frag.h
Normal file
@@ -0,0 +1 @@
|
||||
35,118,101,114,115,105,111,110,32,49,52,48,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,108,97,121,111,117,116,40,108,111,99,97,116,105,111,110,32,61,32,48,41,32,117,110,105,102,111,114,109,32,118,101,99,52,32,67,111,108,111,114,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,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,67,111,108,111,114,59,13,10,125,
|
||||
@@ -1,17 +1,13 @@
|
||||
#version 140
|
||||
|
||||
/********************Entrant********************/
|
||||
in mat4 InstanceData0;
|
||||
in vec3 VertexPosition;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform mat4 ViewProjMatrix;
|
||||
uniform mat4 WorldViewProjMatrix;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
#if FLAG_INSTANCING
|
||||
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
||||
#else
|
||||
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
|
||||
#endif
|
||||
}
|
||||
1
src/Nazara/Renderer/Resources/Shaders/Debug/core.vert.h
Normal file
1
src/Nazara/Renderer/Resources/Shaders/Debug/core.vert.h
Normal file
@@ -0,0 +1 @@
|
||||
35,118,101,114,115,105,111,110,32,49,52,48,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,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,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,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,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,125,13,10,
|
||||
@@ -1 +0,0 @@
|
||||
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,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,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,
|
||||
@@ -1,30 +0,0 @@
|
||||
#if FLAG_DEFERRED
|
||||
#error Deferred Shading needs core profile
|
||||
#endif
|
||||
|
||||
/********************Entrant********************/
|
||||
varying vec2 VertexPosition;
|
||||
|
||||
/********************Sortant********************/
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
uniform float VertexDepth;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(VertexPosition, VertexDepth, 1.0);
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, 0.5 - VertexPosition.y*0.5;
|
||||
#else
|
||||
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, (VertexPosition.y + 1.0)*0.5);
|
||||
#endif // FLAG_FLIP_UVS
|
||||
#endif
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,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,118,97,114,121,105,110,103,32,118,101,99,50,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,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,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,102,108,111,97,116,32,86,101,114,116,101,120,68,101,112,116,104,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,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,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,13,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,32,124,124,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,35,105,102,32,70,76,65,71,95,70,76,73,80,95,85,86,83,13,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,48,46,53,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,48,46,53,59,13,10,9,35,101,108,115,101,13,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,32,43,32,49,46,48,41,42,48,46,53,41,59,13,10,9,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,70,76,73,80,95,85,86,83,13,10,35,101,110,100,105,102,13,10,125,13,10,
|
||||
@@ -1,35 +0,0 @@
|
||||
/********************Entrant********************/
|
||||
in vec2 vTexCoord;
|
||||
|
||||
/********************Sortant********************/
|
||||
out vec4 RenderTarget0;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
vec4 fragmentColor = MaterialDiffuse;
|
||||
#if DIFFUSE_MAPPING
|
||||
fragmentColor *= texture(MaterialDiffuseMap, vTexCoord);
|
||||
#endif
|
||||
|
||||
#if ALPHA_MAPPING
|
||||
fragmentColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
||||
#endif
|
||||
|
||||
#if ALPHA_TEST
|
||||
if (fragmentColor.a < MaterialAlphaThreshold)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
#if FLAG_DEFERRED
|
||||
RenderTarget0 = vec4(fragmentColor.rgb, 0.0);
|
||||
#else
|
||||
RenderTarget0 = fragmentColor;
|
||||
#endif
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
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,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,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,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,35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,114,103,98,44,32,48,46,48,41,59,13,10,35,101,108,115,101,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,35,101,110,100,105,102,13,10,125,
|
||||
@@ -1,30 +0,0 @@
|
||||
#if FLAG_DEFERRED
|
||||
#error Deferred Shading needs core profile
|
||||
#endif
|
||||
|
||||
/********************Entrant********************/
|
||||
in vec2 VertexPosition;
|
||||
|
||||
/********************Sortant********************/
|
||||
out vec2 vTexCoord;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
uniform float VertexDepth;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(VertexPosition, VertexDepth, 1.0);
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, 0.5 - VertexPosition.y*0.5;
|
||||
#else
|
||||
vTexCoord = vec2((VertexPosition.x + 1.0)*0.5, (VertexPosition.y + 1.0)*0.5);
|
||||
#endif // FLAG_FLIP_UVS
|
||||
#endif
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,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,86,101,114,116,101,120,80,111,115,105,116,105,111,110,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,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,102,108,111,97,116,32,86,101,114,116,101,120,68,101,112,116,104,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,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,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,13,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,32,124,124,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,35,105,102,32,70,76,65,71,95,70,76,73,80,95,85,86,83,13,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,48,46,53,32,45,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,42,48,46,53,59,13,10,9,35,101,108,115,101,13,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,32,43,32,49,46,48,41,42,48,46,53,44,32,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,121,32,43,32,49,46,48,41,42,48,46,53,41,59,13,10,9,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,70,76,73,80,95,85,86,83,13,10,35,101,110,100,105,102,13,10,125,13,10,
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,18 +0,0 @@
|
||||
#if FLAG_DEFERRED
|
||||
#error Deferred Shading needs core profile
|
||||
#endif
|
||||
|
||||
/********************Entrant********************/
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = MaterialDiffuse;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,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,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,103,108,95,70,114,97,103,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,125,
|
||||
@@ -1 +0,0 @@
|
||||
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,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,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,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,35,101,108,115,101,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,35,101,110,100,105,102,13,10,125,13,10,
|
||||
@@ -1,21 +0,0 @@
|
||||
/********************Entrant********************/
|
||||
in vec2 vTexCoord;
|
||||
|
||||
/********************Sortant********************/
|
||||
out vec4 RenderTarget0;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
#if FLAG_DEFERRED
|
||||
RenderTarget0 = vec4(MaterialDiffuse.rgb, 0.0);
|
||||
#else
|
||||
RenderTarget0 = MaterialDiffuse;
|
||||
#endif
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
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,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,68,69,70,69,82,82,69,68,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,46,114,103,98,44,32,48,46,48,41,59,13,10,35,101,108,115,101,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,35,101,110,100,105,102,13,10,125,
|
||||
@@ -1 +0,0 @@
|
||||
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,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,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,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,35,101,108,115,101,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,35,101,110,100,105,102,13,10,125,13,10,
|
||||
@@ -1,32 +0,0 @@
|
||||
#if FLAG_DEFERRED
|
||||
#error Deferred Shading needs core profile
|
||||
#endif
|
||||
|
||||
/********************Entrant********************/
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
vec4 fragmentColor = MaterialDiffuse;
|
||||
#if DIFFUSE_MAPPING
|
||||
fragmentColor *= texture2D(MaterialDiffuseMap, vTexCoord);
|
||||
#endif
|
||||
|
||||
#if ALPHA_MAPPING
|
||||
fragmentColor.a *= texture2D(MaterialAlphaMap, vTexCoord).r;
|
||||
#endif
|
||||
|
||||
#if ALPHA_TEST
|
||||
if (fragmentColor.a < MaterialAlphaThreshold)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
gl_FragColor = fragmentColor;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,35,101,114,114,111,114,32,68,101,102,101,114,114,101,100,32,83,104,97,100,105,110,103,32,110,101,101,100,115,32,99,111,114,101,32,112,114,111,102,105,108,101,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,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,
|
||||
@@ -1 +0,0 @@
|
||||
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,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,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,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,35,101,108,115,101,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,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,32,124,124,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,35,105,102,32,70,76,65,71,95,70,76,73,80,95,85,86,83,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,46,120,44,32,49,46,48,32,45,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,46,121,41,59,13,10,9,35,101,108,115,101,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,9,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,70,76,73,80,95,85,86,83,13,10,35,101,110,100,105,102,13,10,125,13,10,
|
||||
@@ -1 +0,0 @@
|
||||
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,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,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,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,35,105,102,32,70,76,65,71,95,68,69,70,69,82,82,69,68,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,114,103,98,44,32,48,46,48,41,59,13,10,35,101,108,115,101,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,35,101,110,100,105,102,13,10,125,
|
||||
@@ -1 +0,0 @@
|
||||
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,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,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,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,35,101,108,115,101,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,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,32,124,124,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,35,105,102,32,70,76,65,71,95,70,76,73,80,95,85,86,83,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,46,120,44,32,49,46,48,32,45,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,46,121,41,59,13,10,9,35,101,108,115,101,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,9,35,101,110,100,105,102,32,47,47,32,70,76,65,71,95,70,76,73,80,95,85,86,83,13,10,35,101,110,100,105,102,13,10,125,13,10,
|
||||
@@ -2,60 +2,141 @@
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/GLSLProgram.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||
#include <Nazara/Renderer/ShaderStage.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzGLSLProgram::NzGLSLProgram(NzShaderProgram* parent) :
|
||||
m_parent(parent)
|
||||
NzShader::NzShader() :
|
||||
m_linked(false),
|
||||
m_program(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::Bind()
|
||||
NzShader::NzShader(NzShader&& shader) :
|
||||
m_linked(shader.m_linked),
|
||||
m_program(shader.m_program)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (NzContext::GetCurrent() == nullptr)
|
||||
for (unsigned int i = 0; i <= nzShaderStage_Max; ++i)
|
||||
m_attachedShaders[i] = std::move(shader.m_attachedShaders[i]);
|
||||
|
||||
shader.m_linked = false;
|
||||
shader.m_program = 0;
|
||||
}
|
||||
|
||||
NzShader::~NzShader()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void NzShader::AttachStage(nzShaderStage stage, const NzShaderStage& shaderStage)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_program)
|
||||
{
|
||||
NazaraError("No active context");
|
||||
return false;
|
||||
NazaraError("Invalid program");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shaderStage.IsValid())
|
||||
{
|
||||
NazaraError("Invalid shader stage");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shaderStage.IsCompiled())
|
||||
{
|
||||
NazaraError("Shader stage must be compiled");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
unsigned int shader = shaderStage.GetOpenGLID();
|
||||
|
||||
return true;
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (std::find(m_attachedShaders[stage].begin(), m_attachedShaders[stage].end(), shader) != m_attachedShaders[stage].end())
|
||||
{
|
||||
NazaraError("Shader stage is already attached");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
glAttachShader(m_program, shader);
|
||||
m_attachedShaders[stage].push_back(shader);
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::BindTextures()
|
||||
bool NzShader::AttachStageFromFile(nzShaderStage stage, const NzString& filePath)
|
||||
{
|
||||
for (const std::pair<GLint, TextureSlot>& pair : m_textures)
|
||||
NzShaderStage shaderStage(stage);
|
||||
if (!shaderStage.IsValid())
|
||||
{
|
||||
const TextureSlot& slot = pair.second;
|
||||
if (slot.enabled)
|
||||
NzRenderer::SetTexture(slot.unit, slot.texture);
|
||||
NazaraError("Failed to create shader stage");
|
||||
return false;
|
||||
}
|
||||
|
||||
shaderStage.SetSourceFromFile(filePath);
|
||||
|
||||
if (!shaderStage.Compile())
|
||||
{
|
||||
NazaraError("Failed to compile stage: " + shaderStage.GetLog());
|
||||
return false;
|
||||
}
|
||||
|
||||
AttachStage(stage, shaderStage);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::Compile()
|
||||
bool NzShader::AttachStageFromSource(nzShaderStage stage, const char* source, unsigned int length)
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
NzShaderStage shaderStage(stage);
|
||||
if (!shaderStage.IsValid())
|
||||
{
|
||||
NazaraError("Failed to create shader stage");
|
||||
return false;
|
||||
}
|
||||
|
||||
PreLinkage();
|
||||
shaderStage.SetSource(source, length);
|
||||
|
||||
glLinkProgram(m_program);
|
||||
if (!shaderStage.Compile())
|
||||
{
|
||||
NazaraError("Failed to compile stage: " + shaderStage.GetLog());
|
||||
return false;
|
||||
}
|
||||
|
||||
return PostLinkage();
|
||||
AttachStage(stage, shaderStage);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::Create()
|
||||
bool NzShader::AttachStageFromSource(nzShaderStage stage, const NzString& source)
|
||||
{
|
||||
NzShaderStage shaderStage(stage);
|
||||
if (!shaderStage.IsValid())
|
||||
{
|
||||
NazaraError("Failed to create shader stage");
|
||||
return false;
|
||||
}
|
||||
|
||||
shaderStage.SetSource(source);
|
||||
|
||||
if (!shaderStage.Compile())
|
||||
{
|
||||
NazaraError("Failed to compile stage: " + shaderStage.GetLog());
|
||||
return false;
|
||||
}
|
||||
|
||||
AttachStage(stage, shaderStage);
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzShader::Bind() const
|
||||
{
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
}
|
||||
|
||||
bool NzShader::Create()
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
@@ -66,6 +147,8 @@ bool NzGLSLProgram::Create()
|
||||
return false;
|
||||
}
|
||||
|
||||
m_linked = false;
|
||||
|
||||
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData0], "InstanceData0");
|
||||
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData1], "InstanceData1");
|
||||
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzAttributeUsage_InstanceData2], "InstanceData2");
|
||||
@@ -96,26 +179,20 @@ bool NzGLSLProgram::Create()
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= nzShaderType_Max; ++i)
|
||||
m_shaders[i] = 0;
|
||||
|
||||
if (NzOpenGL::IsSupported(nzOpenGLExtension_GetProgramBinary))
|
||||
glProgramParameteri(m_program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzGLSLProgram::Destroy()
|
||||
void NzShader::Destroy()
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
for (auto it = m_textures.begin(); it != m_textures.end(); ++it)
|
||||
it->second.texture->RemoveResourceListener(this);
|
||||
|
||||
NzOpenGL::DeleteProgram(m_program);
|
||||
}
|
||||
|
||||
NzByteArray NzGLSLProgram::GetBinary() const
|
||||
NzByteArray NzShader::GetBinary() const
|
||||
{
|
||||
NzByteArray byteArray;
|
||||
|
||||
@@ -140,66 +217,114 @@ NzByteArray NzGLSLProgram::GetBinary() const
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
NzString NzGLSLProgram::GetLog() const
|
||||
NzString NzShader::GetLog() const
|
||||
{
|
||||
return m_log;
|
||||
}
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_program)
|
||||
{
|
||||
NazaraError("Shader is not initialized");
|
||||
return NzString();
|
||||
}
|
||||
#endif
|
||||
|
||||
nzShaderLanguage NzGLSLProgram::GetLanguage() const
|
||||
{
|
||||
return nzShaderLanguage_GLSL;
|
||||
}
|
||||
|
||||
NzString NzGLSLProgram::GetSourceCode(nzShaderType type) const
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
NzString source;
|
||||
NzString log;
|
||||
|
||||
GLint length = 0;
|
||||
glGetShaderiv(m_shaders[type], GL_SHADER_SOURCE_LENGTH, &length);
|
||||
if (length > 1)
|
||||
glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length);
|
||||
if (length > 1) // Le caractère de fin faisant partie du compte
|
||||
{
|
||||
source.Resize(length-1); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
glGetShaderSource(m_shaders[type], length, nullptr, &source[0]);
|
||||
log.Resize(length - 1); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
glGetProgramInfoLog(m_program, length, nullptr, &log[0]);
|
||||
}
|
||||
else
|
||||
log = "No log.";
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
NzString NzShader::GetSourceCode(nzShaderStage stage) const
|
||||
{
|
||||
if (!HasStage(stage))
|
||||
return NzString();
|
||||
|
||||
NzContext::EnsureContext();
|
||||
|
||||
static const char sep[] = "\n////////////////////////////////////////////////////////////////////////////////\n\n";
|
||||
|
||||
unsigned int totalLength = 0;
|
||||
for (unsigned int shader : m_attachedShaders[stage])
|
||||
{
|
||||
GLint length;
|
||||
glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &length);
|
||||
|
||||
totalLength += length - 1;
|
||||
}
|
||||
|
||||
totalLength += (m_attachedShaders[stage].size()-1)*(sizeof(sep)/sizeof(char));
|
||||
|
||||
NzString source;
|
||||
source.Resize(totalLength);
|
||||
|
||||
unsigned int offset = 0;
|
||||
for (unsigned int shader : m_attachedShaders[stage])
|
||||
{
|
||||
if (offset > 0)
|
||||
{
|
||||
std::memcpy(&source[offset], sep, sizeof(sep)/sizeof(char));
|
||||
offset += sizeof(sep)/sizeof(char);
|
||||
}
|
||||
|
||||
GLint length;
|
||||
glGetShaderSource(shader, totalLength, &length, &source[offset]);
|
||||
|
||||
offset += length;
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
int NzGLSLProgram::GetUniformLocation(const NzString& name) const
|
||||
int NzShader::GetUniformLocation(const NzString& name) const
|
||||
{
|
||||
auto it = m_idCache.find(name);
|
||||
GLint id;
|
||||
if (it == m_idCache.end())
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
NzContext::EnsureContext();
|
||||
|
||||
id = glGetUniformLocation(m_program, name.GetConstBuffer());
|
||||
m_idCache[name] = id;
|
||||
}
|
||||
else
|
||||
id = it->second;
|
||||
|
||||
return id;
|
||||
return glGetUniformLocation(m_program, name.GetConstBuffer());
|
||||
}
|
||||
|
||||
int NzGLSLProgram::GetUniformLocation(nzShaderUniform uniform) const
|
||||
int NzShader::GetUniformLocation(nzShaderUniform shaderUniform) const
|
||||
{
|
||||
return m_uniformLocations[uniform];
|
||||
return m_uniformLocations[shaderUniform];
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::IsBinaryRetrievable() const
|
||||
bool NzShader::HasStage(nzShaderStage stage) const
|
||||
{
|
||||
return !m_attachedShaders[stage].empty();
|
||||
}
|
||||
|
||||
bool NzShader::IsBinaryRetrievable() const
|
||||
{
|
||||
return NzOpenGL::IsSupported(nzOpenGLExtension_GetProgramBinary);
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::IsLoaded(nzShaderType type) const
|
||||
bool NzShader::IsLinked() const
|
||||
{
|
||||
return m_shaders[type] != 0;
|
||||
return m_linked;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::LoadFromBinary(const void* buffer, unsigned int size)
|
||||
bool NzShader::IsValid() const
|
||||
{
|
||||
return m_program != 0;
|
||||
}
|
||||
|
||||
bool NzShader::Link()
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
glLinkProgram(m_program);
|
||||
|
||||
return PostLinkage();
|
||||
}
|
||||
|
||||
bool NzShader::LoadFromBinary(const void* buffer, unsigned int size)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!glProgramBinary)
|
||||
@@ -207,6 +332,12 @@ bool NzGLSLProgram::LoadFromBinary(const void* buffer, unsigned int size)
|
||||
NazaraError("GL_ARB_get_program_binary not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!buffer || size < sizeof(nzUInt64))
|
||||
{
|
||||
NazaraError("Invalid buffer");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
NzContext::EnsureContext();
|
||||
@@ -218,73 +349,17 @@ bool NzGLSLProgram::LoadFromBinary(const void* buffer, unsigned int size)
|
||||
GLenum binaryFormat = static_cast<GLenum>(*reinterpret_cast<const nzUInt64*>(&ptr[0]));
|
||||
ptr += sizeof(nzUInt64);
|
||||
|
||||
PreLinkage();
|
||||
|
||||
glProgramBinary(m_program, binaryFormat, ptr, size-sizeof(nzUInt64));
|
||||
glProgramBinary(m_program, binaryFormat, ptr, size - sizeof(nzUInt64));
|
||||
|
||||
return PostLinkage();
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::LoadShader(nzShaderType type, const NzString& source)
|
||||
bool NzShader::LoadFromBinary(const NzByteArray& byteArray)
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
GLuint shader = glCreateShader(NzOpenGL::ShaderType[type]);
|
||||
if (!shader)
|
||||
{
|
||||
m_log = "Failed to create shader object";
|
||||
NazaraError(m_log);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* tmp = source.GetConstBuffer();
|
||||
GLint length = source.GetSize();
|
||||
glShaderSource(shader, 1, &tmp, &length);
|
||||
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint success;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
|
||||
if (success == GL_TRUE)
|
||||
{
|
||||
glAttachShader(m_program, shader); // On attache le shader au programme
|
||||
glDeleteShader(shader); // On le marque pour suppression (Lors de l'appel à glDeleteProgram)
|
||||
|
||||
m_shaders[type] = shader;
|
||||
|
||||
static NzString successStr("Compilation successful");
|
||||
m_log = successStr;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// On remplit le log avec l'erreur de compilation
|
||||
length = 0;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
|
||||
if (length > 1)
|
||||
{
|
||||
m_log.Clear(true);
|
||||
m_log.Reserve(length+19-2); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
m_log.Prepend("Compilation error: ");
|
||||
m_log.Resize(length+19-2); // Extension du buffer d'écriture pour ajouter le log
|
||||
|
||||
glGetShaderInfoLog(shader, length-1, nullptr, &m_log[19]);
|
||||
}
|
||||
else
|
||||
m_log = "Compilation failed but no info log found";
|
||||
|
||||
NazaraError(m_log);
|
||||
|
||||
glDeleteShader(shader);
|
||||
|
||||
return false;
|
||||
}
|
||||
return LoadFromBinary(byteArray.GetConstBuffer(), byteArray.GetSize());
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendBoolean(int location, bool value)
|
||||
void NzShader::SendBoolean(int location, bool value) const
|
||||
{
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, location, value);
|
||||
@@ -293,11 +368,9 @@ bool NzGLSLProgram::SendBoolean(int location, bool value)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform1i(location, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendColor(int location, const NzColor& color)
|
||||
void NzShader::SendColor(int location, const NzColor& color) const
|
||||
{
|
||||
NzVector4f vecColor(color.r/255.f, color.g/255.f, color.b/255.f, color.a/255.f);
|
||||
|
||||
@@ -308,11 +381,9 @@ bool NzGLSLProgram::SendColor(int location, const NzColor& color)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform4fv(location, 1, vecColor);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendDouble(int location, double value)
|
||||
void NzShader::SendDouble(int location, double value) const
|
||||
{
|
||||
if (glProgramUniform1d)
|
||||
glProgramUniform1d(m_program, location, value);
|
||||
@@ -321,11 +392,9 @@ bool NzGLSLProgram::SendDouble(int location, double value)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform1d(location, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendDoubleArray(int location, const double* values, unsigned int count)
|
||||
void NzShader::SendDoubleArray(int location, const double* values, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform1dv)
|
||||
glProgramUniform1dv(m_program, location, count, values);
|
||||
@@ -334,11 +403,9 @@ bool NzGLSLProgram::SendDoubleArray(int location, const double* values, unsigned
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform1dv(location, count, values);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendFloat(int location, float value)
|
||||
void NzShader::SendFloat(int location, float value) const
|
||||
{
|
||||
if (glProgramUniform1f)
|
||||
glProgramUniform1f(m_program, location, value);
|
||||
@@ -347,11 +414,9 @@ bool NzGLSLProgram::SendFloat(int location, float value)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform1f(location, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendFloatArray(int location, const float* values, unsigned int count)
|
||||
void NzShader::SendFloatArray(int location, const float* values, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform1fv)
|
||||
glProgramUniform1fv(m_program, location, count, values);
|
||||
@@ -360,11 +425,9 @@ bool NzGLSLProgram::SendFloatArray(int location, const float* values, unsigned i
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform1fv(location, count, values);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendInteger(int location, int value)
|
||||
void NzShader::SendInteger(int location, int value) const
|
||||
{
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, location, value);
|
||||
@@ -373,11 +436,9 @@ bool NzGLSLProgram::SendInteger(int location, int value)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform1i(location, value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendIntegerArray(int location, const int* values, unsigned int count)
|
||||
void NzShader::SendIntegerArray(int location, const int* values, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform1iv)
|
||||
glProgramUniform1iv(m_program, location, count, values);
|
||||
@@ -386,11 +447,9 @@ bool NzGLSLProgram::SendIntegerArray(int location, const int* values, unsigned i
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform1iv(location, count, values);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendMatrix(int location, const NzMatrix4d& matrix)
|
||||
void NzShader::SendMatrix(int location, const NzMatrix4d& matrix) const
|
||||
{
|
||||
if (glProgramUniformMatrix4dv)
|
||||
glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix);
|
||||
@@ -399,11 +458,9 @@ bool NzGLSLProgram::SendMatrix(int location, const NzMatrix4d& matrix)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniformMatrix4dv(location, 1, GL_FALSE, matrix);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendMatrix(int location, const NzMatrix4f& matrix)
|
||||
void NzShader::SendMatrix(int location, const NzMatrix4f& matrix) const
|
||||
{
|
||||
if (glProgramUniformMatrix4fv)
|
||||
glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix);
|
||||
@@ -412,76 +469,9 @@ bool NzGLSLProgram::SendMatrix(int location, const NzMatrix4f& matrix)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, matrix);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit)
|
||||
{
|
||||
auto it = m_textures.find(location);
|
||||
if (it != m_textures.end())
|
||||
{
|
||||
// Slot déjà utilisé
|
||||
TextureSlot& slot = it->second;
|
||||
if (slot.texture != texture)
|
||||
{
|
||||
slot.texture->RemoveResourceListener(this);
|
||||
|
||||
if (texture)
|
||||
{
|
||||
slot.texture = texture;
|
||||
slot.texture->AddResourceListener(this, location);
|
||||
|
||||
slot.updated = false;
|
||||
|
||||
if (textureUnit)
|
||||
*textureUnit = slot.unit;
|
||||
}
|
||||
else
|
||||
slot.enabled = false;
|
||||
}
|
||||
else if (textureUnit)
|
||||
*textureUnit = slot.unit;
|
||||
}
|
||||
else if (texture)
|
||||
{
|
||||
unsigned int maxUnits = NzRenderer::GetMaxTextureUnits();
|
||||
unsigned int unitUsed = m_textures.size();
|
||||
if (unitUsed >= maxUnits)
|
||||
{
|
||||
NazaraError("Unable to use texture for shader: all available texture units are in use");
|
||||
return false;
|
||||
}
|
||||
|
||||
// À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre
|
||||
|
||||
TextureSlot slot;
|
||||
slot.enabled = texture->IsValid();
|
||||
slot.unit = unitUsed+1;
|
||||
slot.texture = texture;
|
||||
|
||||
if (slot.enabled)
|
||||
{
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, location, slot.unit);
|
||||
else
|
||||
{
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform1i(location, slot.unit);
|
||||
}
|
||||
}
|
||||
|
||||
m_textures[location] = slot;
|
||||
texture->AddResourceListener(this, location);
|
||||
|
||||
if (textureUnit)
|
||||
*textureUnit = slot.unit;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector2d& vector)
|
||||
void NzShader::SendVector(int location, const NzVector2d& vector) const
|
||||
{
|
||||
if (glProgramUniform2dv)
|
||||
glProgramUniform2dv(m_program, location, 1, vector);
|
||||
@@ -490,11 +480,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector2d& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform2dv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector2f& vector)
|
||||
void NzShader::SendVector(int location, const NzVector2f& vector) const
|
||||
{
|
||||
if (glProgramUniform2fv)
|
||||
glProgramUniform2fv(m_program, location, 1, vector);
|
||||
@@ -503,11 +491,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector2f& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform2fv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector2i& vector)
|
||||
void NzShader::SendVector(int location, const NzVector2i& vector) const
|
||||
{
|
||||
if (glProgramUniform2fv)
|
||||
glProgramUniform2iv(m_program, location, 1, vector);
|
||||
@@ -516,11 +502,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector2i& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform2iv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector3d& vector)
|
||||
void NzShader::SendVector(int location, const NzVector3d& vector) const
|
||||
{
|
||||
if (glProgramUniform3dv)
|
||||
glProgramUniform3dv(m_program, location, 1, vector);
|
||||
@@ -529,11 +513,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector3d& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform3dv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector3f& vector)
|
||||
void NzShader::SendVector(int location, const NzVector3f& vector) const
|
||||
{
|
||||
if (glProgramUniform3fv)
|
||||
glProgramUniform3fv(m_program, location, 1, vector);
|
||||
@@ -542,11 +524,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector3f& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform3fv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector3i& vector)
|
||||
void NzShader::SendVector(int location, const NzVector3i& vector) const
|
||||
{
|
||||
if (glProgramUniform3iv)
|
||||
glProgramUniform3iv(m_program, location, 1, vector);
|
||||
@@ -555,11 +535,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector3i& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform3iv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector4d& vector)
|
||||
void NzShader::SendVector(int location, const NzVector4d& vector) const
|
||||
{
|
||||
if (glProgramUniform4dv)
|
||||
glProgramUniform4dv(m_program, location, 1, vector);
|
||||
@@ -568,11 +546,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector4d& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform4dv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector4f& vector)
|
||||
void NzShader::SendVector(int location, const NzVector4f& vector) const
|
||||
{
|
||||
if (glProgramUniform4fv)
|
||||
glProgramUniform4fv(m_program, location, 1, vector);
|
||||
@@ -581,11 +557,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector4f& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform4fv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVector(int location, const NzVector4i& vector)
|
||||
void NzShader::SendVector(int location, const NzVector4i& vector) const
|
||||
{
|
||||
if (glProgramUniform4iv)
|
||||
glProgramUniform4iv(m_program, location, 1, vector);
|
||||
@@ -594,11 +568,9 @@ bool NzGLSLProgram::SendVector(int location, const NzVector4i& vector)
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform4iv(location, 1, vector);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector2d* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector2d* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform2dv)
|
||||
glProgramUniform2dv(m_program, location, count, reinterpret_cast<const double*>(vectors));
|
||||
@@ -607,11 +579,9 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector2d* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform2dv(location, count, reinterpret_cast<const double*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector2f* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector2f* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform2fv)
|
||||
glProgramUniform2fv(m_program, location, count, reinterpret_cast<const float*>(vectors));
|
||||
@@ -620,11 +590,9 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector2f* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform2fv(location, count, reinterpret_cast<const float*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector2i* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector2i* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform2iv)
|
||||
glProgramUniform2iv(m_program, location, count, reinterpret_cast<const int*>(vectors));
|
||||
@@ -633,11 +601,9 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector2i* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform2iv(location, count, reinterpret_cast<const int*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector3d* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector3d* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform3dv)
|
||||
glProgramUniform3dv(m_program, location, count, reinterpret_cast<const double*>(vectors));
|
||||
@@ -646,11 +612,9 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector3d* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform3dv(location, count, reinterpret_cast<const double*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector3f* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector3f* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform3fv)
|
||||
glProgramUniform3fv(m_program, location, count, reinterpret_cast<const float*>(vectors));
|
||||
@@ -659,11 +623,9 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector3f* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform3fv(location, count, reinterpret_cast<const float*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector3i* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector3i* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform3iv)
|
||||
glProgramUniform3iv(m_program, location, count, reinterpret_cast<const int*>(vectors));
|
||||
@@ -672,11 +634,9 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector3i* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform3iv(location, count, reinterpret_cast<const int*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector4d* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector4d* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform4dv)
|
||||
glProgramUniform4dv(m_program, location, count, reinterpret_cast<const double*>(vectors));
|
||||
@@ -685,11 +645,9 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector4d* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform4dv(location, count, reinterpret_cast<const double*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector4f* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector4f* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform4fv)
|
||||
glProgramUniform4fv(m_program, location, count, reinterpret_cast<const float*>(vectors));
|
||||
@@ -698,11 +656,9 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector4f* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform4fv(location, count, reinterpret_cast<const float*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::SendVectorArray(int location, const NzVector4i* vectors, unsigned int count)
|
||||
void NzShader::SendVectorArray(int location, const NzVector4i* vectors, unsigned int count) const
|
||||
{
|
||||
if (glProgramUniform4iv)
|
||||
glProgramUniform4iv(m_program, location, count, reinterpret_cast<const int*>(vectors));
|
||||
@@ -711,94 +667,44 @@ bool NzGLSLProgram::SendVectorArray(int location, const NzVector4i* vectors, uns
|
||||
NzOpenGL::BindProgram(m_program);
|
||||
glUniform4iv(location, count, reinterpret_cast<const int*>(vectors));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::OnResourceCreated(const NzResource* resource, int index)
|
||||
unsigned int NzShader::GetOpenGLID() const
|
||||
{
|
||||
NazaraUnused(resource);
|
||||
|
||||
auto it = m_textures.find(index);
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (it == m_textures.end())
|
||||
{
|
||||
NazaraInternalError("Invalid index (" + NzString::Number(index) + ')');
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
TextureSlot& slot = it->second;
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (slot.texture != resource)
|
||||
{
|
||||
NazaraInternalError("Wrong texture at location #" + NzString::Number(index));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
slot.enabled = true;
|
||||
slot.updated = false;
|
||||
|
||||
return true;
|
||||
return m_program;
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::OnResourceDestroy(const NzResource* resource, int index)
|
||||
NzShader& NzShader::operator=(NzShader&& shader)
|
||||
{
|
||||
NazaraUnused(resource);
|
||||
Destroy();
|
||||
|
||||
auto it = m_textures.find(index);
|
||||
for (unsigned int i = 0; i <= nzShaderStage_Max; ++i)
|
||||
m_attachedShaders[i] = std::move(shader.m_attachedShaders[i]);
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (it == m_textures.end())
|
||||
{
|
||||
NazaraInternalError("Invalid index (" + NzString::Number(index) + ')');
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
m_linked = shader.m_linked;
|
||||
m_program = shader.m_program;
|
||||
|
||||
TextureSlot& slot = it->second;
|
||||
shader.m_linked = false;
|
||||
shader.m_program = 0;
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (slot.texture != resource)
|
||||
{
|
||||
NazaraInternalError("Wrong texture at location #" + NzString::Number(index));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
slot.enabled = false;
|
||||
|
||||
return true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void NzGLSLProgram::OnResourceReleased(const NzResource* resource, int index)
|
||||
bool NzShader::IsStageSupported(nzShaderStage stage)
|
||||
{
|
||||
if (m_textures.erase(index) == 0)
|
||||
NazaraInternalError("Texture " + NzString::Pointer(resource) + " not found");
|
||||
return NzShaderStage::IsSupported(stage);
|
||||
}
|
||||
|
||||
void NzGLSLProgram::PreLinkage()
|
||||
bool NzShader::PostLinkage()
|
||||
{
|
||||
m_idCache.clear();
|
||||
m_textures.clear();
|
||||
}
|
||||
|
||||
bool NzGLSLProgram::PostLinkage()
|
||||
{
|
||||
// On suppose qu'un contexte OpenGL est actif à l'appel de cette fonction
|
||||
GLint success;
|
||||
glGetProgramiv(m_program, GL_LINK_STATUS, &success);
|
||||
|
||||
if (success == GL_TRUE)
|
||||
m_linked = (success == GL_TRUE);
|
||||
if (m_linked)
|
||||
{
|
||||
static NzString successStr("Linkage successful");
|
||||
m_log = successStr;
|
||||
|
||||
// Pour éviter de se tromper entre le nom et la constante
|
||||
#define CacheUniform(name) m_uniformLocations[nzShaderUniform_##name] = GetUniformLocation(#name)
|
||||
#define CacheUniform(name) m_uniformLocations[nzShaderUniform_##name] = glGetUniformLocation(m_program, #name)
|
||||
|
||||
CacheUniform(EyePosition);
|
||||
CacheUniform(InvProjMatrix);
|
||||
@@ -808,21 +714,9 @@ bool NzGLSLProgram::PostLinkage()
|
||||
CacheUniform(InvWorldMatrix);
|
||||
CacheUniform(InvWorldViewMatrix);
|
||||
CacheUniform(InvWorldViewProjMatrix);
|
||||
CacheUniform(MaterialAlphaMap);
|
||||
CacheUniform(MaterialAlphaThreshold);
|
||||
CacheUniform(MaterialAmbient);
|
||||
CacheUniform(MaterialDiffuse);
|
||||
CacheUniform(MaterialDiffuseMap);
|
||||
CacheUniform(MaterialEmissiveMap);
|
||||
CacheUniform(MaterialHeightMap);
|
||||
CacheUniform(MaterialNormalMap);
|
||||
CacheUniform(MaterialShininess);
|
||||
CacheUniform(MaterialSpecular);
|
||||
CacheUniform(MaterialSpecularMap);
|
||||
CacheUniform(ProjMatrix);
|
||||
CacheUniform(SceneAmbient);
|
||||
CacheUniform(TargetSize);
|
||||
CacheUniform(VertexDepth);
|
||||
CacheUniform(ViewMatrix);
|
||||
CacheUniform(ViewProjMatrix);
|
||||
CacheUniform(WorldMatrix);
|
||||
@@ -835,23 +729,7 @@ bool NzGLSLProgram::PostLinkage()
|
||||
}
|
||||
else
|
||||
{
|
||||
// On remplit le log avec l'erreur de compilation
|
||||
GLint length = 0;
|
||||
glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length);
|
||||
if (length > 1)
|
||||
{
|
||||
m_log.Clear(true);
|
||||
m_log.Reserve(length+15-2); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
m_log.Prepend("Linkage error: ");
|
||||
m_log.Resize(length+15-2); // Extension du buffer d'écriture pour ajouter le log
|
||||
|
||||
glGetProgramInfoLog(m_program, length-1, nullptr, &m_log[19]);
|
||||
}
|
||||
else
|
||||
m_log = "Linkage failed but no info log found";
|
||||
|
||||
NazaraError(m_log);
|
||||
|
||||
NazaraError("Failed to compile shader stage: " + GetLog());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
51
src/Nazara/Renderer/ShaderLibrary.cpp
Normal file
51
src/Nazara/Renderer/ShaderLibrary.cpp
Normal file
@@ -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
|
||||
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzShader* NzShaderLibrary::Get(const NzString& name)
|
||||
{
|
||||
auto it = s_library.find(name);
|
||||
if (it != s_library.end())
|
||||
return it->second;
|
||||
else
|
||||
{
|
||||
NazaraError("Shader \"" + name + "\" is not present");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzShaderLibrary::Has(const NzString& name)
|
||||
{
|
||||
return s_library.find(name) != s_library.end();
|
||||
}
|
||||
|
||||
bool NzShaderLibrary::Initialize()
|
||||
{
|
||||
return true; // Que faire
|
||||
}
|
||||
|
||||
void NzShaderLibrary::Register(const NzString& name, NzShader* shader)
|
||||
{
|
||||
s_library.emplace(name, shader);
|
||||
NazaraDebug("Shader \"" + name + "\" registred");
|
||||
}
|
||||
|
||||
void NzShaderLibrary::Uninitialize()
|
||||
{
|
||||
for (auto it : s_library)
|
||||
NazaraWarning("Shader \"" + it.first + "\" has not been unregistred");
|
||||
|
||||
s_library.clear();
|
||||
}
|
||||
|
||||
void NzShaderLibrary::Unregister(const NzString& name)
|
||||
{
|
||||
s_library.erase(name);
|
||||
NazaraDebug("Shader \"" + name + "\" unregistred");
|
||||
}
|
||||
|
||||
std::unordered_map<NzString, NzShaderRef> NzShaderLibrary::s_library;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,658 +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
|
||||
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Core/Directory.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ParamsHash
|
||||
{
|
||||
std::size_t operator()(const NzShaderProgramManagerParams& params) const
|
||||
{
|
||||
static_assert(nzShaderTarget_Max < 0x4, "Maximum shader target takes more than 2 bits");
|
||||
|
||||
std::size_t h = (params.target << 0) | // 2 bits
|
||||
(params.flags << 2); // 8 bits
|
||||
|
||||
switch (params.target)
|
||||
{
|
||||
case nzShaderTarget_FullscreenQuad:
|
||||
h |= (params.fullscreenQuad.alphaMapping << 10) | // 1 bit
|
||||
(params.fullscreenQuad.alphaTest << 11) | // 1 bit
|
||||
(params.fullscreenQuad.diffuseMapping << 12); // 1 bit
|
||||
break;
|
||||
|
||||
case nzShaderTarget_Model:
|
||||
h |= (params.model.alphaMapping << 10) | // 1 bit
|
||||
(params.model.alphaTest << 11) | // 1 bit
|
||||
(params.model.diffuseMapping << 12) | // 1 bit
|
||||
(params.model.emissiveMapping << 13) | // 1 bit
|
||||
(params.model.lighting << 14) | // 1 bit
|
||||
(params.model.normalMapping << 15) | // 1 bit
|
||||
(params.model.parallaxMapping << 16) | // 1 bit
|
||||
(params.model.specularMapping << 17); // 1 bit
|
||||
break;
|
||||
|
||||
case nzShaderTarget_None:
|
||||
break;
|
||||
|
||||
case nzShaderTarget_Sprite:
|
||||
h |= (params.sprite.alphaMapping << 10) | // 1 bit
|
||||
(params.sprite.alphaTest << 11) | // 1 bit
|
||||
(params.sprite.diffuseMapping << 12); // 1 bit
|
||||
break;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
struct ParamsEquality
|
||||
{
|
||||
bool operator()(const NzShaderProgramManagerParams& first, const NzShaderProgramManagerParams& second) const
|
||||
{
|
||||
if (first.target != second.target || first.flags != second.flags)
|
||||
return false;
|
||||
|
||||
switch (first.target)
|
||||
{
|
||||
case nzShaderTarget_FullscreenQuad:
|
||||
return std::memcmp(&first.fullscreenQuad, &second.fullscreenQuad, sizeof(NzShaderProgramManagerParams::FullscreenQuad)) == 0;
|
||||
|
||||
case nzShaderTarget_Model:
|
||||
return std::memcmp(&first.model, &second.model, sizeof(NzShaderProgramManagerParams::Model)) == 0;
|
||||
|
||||
case nzShaderTarget_None:
|
||||
return true;
|
||||
|
||||
case nzShaderTarget_Sprite:
|
||||
return std::memcmp(&first.sprite, &second.sprite, sizeof(NzShaderProgramManagerParams::Sprite)) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
std::unordered_map<NzShaderProgramManagerParams, NzShaderProgramRef, ParamsHash, ParamsEquality> s_programs;
|
||||
NzString s_cacheDirectory("shaderCache");
|
||||
bool s_cacheEnabled = false;
|
||||
bool s_earlyFragmentTest;
|
||||
bool s_glsl140;
|
||||
//bool s_loadCachedPrograms = true;
|
||||
unsigned int s_glslVersion;
|
||||
}
|
||||
|
||||
const NzShaderProgram* NzShaderProgramManager::Get(const NzShaderProgramManagerParams& params)
|
||||
{
|
||||
auto it = s_programs.find(params);
|
||||
if (it == s_programs.end())
|
||||
{
|
||||
// Alors nous générons le programme
|
||||
std::unique_ptr<NzShaderProgram> program;
|
||||
|
||||
if (s_cacheEnabled)
|
||||
{
|
||||
NzString programFileName = NzNumberToString(ParamsHash()(params), 36) + ".nsb"; // Nazara Shader Binary, très original, je sais
|
||||
NazaraDebug("Checking cache for program file \"" + programFileName + "\"...");
|
||||
|
||||
NzFile shaderFile(s_cacheDirectory + NAZARA_DIRECTORY_SEPARATOR + programFileName);
|
||||
if (shaderFile.Open(NzFile::ReadOnly))
|
||||
{
|
||||
NazaraDebug("File found");
|
||||
|
||||
unsigned int size = static_cast<unsigned int>(shaderFile.GetSize());
|
||||
|
||||
NzByteArray binary;
|
||||
binary.Resize(size);
|
||||
|
||||
if (shaderFile.Read(&binary[0], size) != size)
|
||||
{
|
||||
NazaraError("Failed to read program binary");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shaderFile.Close();
|
||||
|
||||
program.reset(new NzShaderProgram);
|
||||
if (!program->LoadFromBinary(binary))
|
||||
{
|
||||
NazaraWarning("Program \"" + programFileName + "\" loading failed, this is mostly due to a driver/video card "
|
||||
"update or a file corruption, regenerating program...");
|
||||
|
||||
program.reset(GenerateProgram(params));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (shaderFile.Exists())
|
||||
NazaraWarning("Program file exists but couldn't be opened");
|
||||
|
||||
program.reset(GenerateProgram(params));
|
||||
if (program)
|
||||
{
|
||||
if (program->IsBinaryRetrievable())
|
||||
{
|
||||
NazaraDebug("Program \"" + programFileName + "\" (re)generated, saving it into program cache directory...");
|
||||
|
||||
NzByteArray programBinary = program->GetBinary();
|
||||
if (!programBinary.IsEmpty())
|
||||
{
|
||||
if (!shaderFile.Open(NzFile::Truncate | NzFile::WriteOnly) || !shaderFile.Write(programBinary))
|
||||
NazaraWarning("Failed to save program binary to file \"" + programFileName + '"');
|
||||
}
|
||||
else
|
||||
NazaraWarning("Failed to retrieve shader program binary");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
program.reset(GenerateProgram(params));
|
||||
|
||||
if (program)
|
||||
s_programs[params] = program.get();
|
||||
else
|
||||
{
|
||||
NazaraWarning("Failed to build program, using default one...");
|
||||
|
||||
NzShaderProgramManagerParams defaultParams;
|
||||
defaultParams.flags = params.flags;
|
||||
defaultParams.target = nzShaderTarget_None;
|
||||
|
||||
program.reset(s_programs[defaultParams]); // Shader par défaut
|
||||
}
|
||||
|
||||
return program.release();
|
||||
}
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
NzString NzShaderProgramManager::BuildFragmentCode(const NzShaderProgramManagerParams& params)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (params.target > nzShaderTarget_Max)
|
||||
{
|
||||
NazaraError("Shader target out of enum");
|
||||
return NzString();
|
||||
}
|
||||
#endif
|
||||
|
||||
NzString source;
|
||||
|
||||
/********************Header********************/
|
||||
source.Reserve(14 + 24 + 24 + 26 + 1);
|
||||
source += "#version ";
|
||||
source += NzString::Number(s_glslVersion);
|
||||
source += "\n\n";
|
||||
|
||||
source += "#define FLAG_DEFERRED ";
|
||||
source += (params.flags & nzShaderFlags_Deferred) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define FLAG_FLIP_UVS ";
|
||||
source += (params.flags & nzShaderFlags_FlipUVs) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define FLAG_INSTANCING ";
|
||||
source += (params.flags & nzShaderFlags_Instancing) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += '\n';
|
||||
|
||||
switch (params.target)
|
||||
{
|
||||
case nzShaderTarget_FullscreenQuad:
|
||||
{
|
||||
const nzUInt8 coreFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/FullscreenQuad/core.frag.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/FullscreenQuad/compatibility.frag.h>
|
||||
};
|
||||
|
||||
const char* shaderSource = reinterpret_cast<const char*>((s_glsl140) ? coreFragmentShader : compatibilityFragmentShader);
|
||||
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreFragmentShader) : sizeof(compatibilityFragmentShader);
|
||||
|
||||
source.Reserve(source.GetCapacity() + 34 + 24 + 21 + 26 + 1 + shaderSourceSize);
|
||||
|
||||
// "discard" ne s'entend pas bien avec les early fragment tests
|
||||
if (s_earlyFragmentTest && !params.fullscreenQuad.alphaTest)
|
||||
source += "layout(early_fragment_tests) in;\n\n";
|
||||
|
||||
source += "#define ALPHA_MAPPING ";
|
||||
source += (params.fullscreenQuad.alphaMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define ALPHA_TEST ";
|
||||
source += (params.fullscreenQuad.alphaTest) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define DIFFUSE_MAPPING ";
|
||||
source += (params.fullscreenQuad.diffuseMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += '\n';
|
||||
|
||||
source.Append(shaderSource, shaderSourceSize);
|
||||
break;
|
||||
}
|
||||
|
||||
case nzShaderTarget_Model:
|
||||
{
|
||||
const nzUInt8 coreFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Model/core.frag.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Model/compatibility.frag.h>
|
||||
};
|
||||
|
||||
const char* shaderSource = reinterpret_cast<const char*>((s_glsl140) ? coreFragmentShader : compatibilityFragmentShader);
|
||||
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreFragmentShader) : sizeof(compatibilityFragmentShader);
|
||||
|
||||
source.Reserve(source.GetCapacity() + 34 + 24 + 21 + 26 + 27 + 19 + 25 + 27 + 27 + 1 + shaderSourceSize);
|
||||
|
||||
if (s_earlyFragmentTest && !params.model.alphaTest)
|
||||
source += "layout(early_fragment_tests) in;\n\n";
|
||||
|
||||
source += "#define ALPHA_MAPPING ";
|
||||
source += (params.model.alphaMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define ALPHA_TEST ";
|
||||
source += (params.model.alphaTest) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define DIFFUSE_MAPPING ";
|
||||
source += (params.model.diffuseMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define EMISSIVE_MAPPING ";
|
||||
source += (params.model.emissiveMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define LIGHTING ";
|
||||
source += (params.model.lighting) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define NORMAL_MAPPING ";
|
||||
source += (params.model.normalMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define PARALLAX_MAPPING ";
|
||||
source += (params.model.parallaxMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define SPECULAR_MAPPING ";
|
||||
source += (params.model.specularMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += '\n';
|
||||
|
||||
source.Append(shaderSource, shaderSourceSize);
|
||||
break;
|
||||
}
|
||||
|
||||
case nzShaderTarget_None:
|
||||
{
|
||||
const nzUInt8 coreFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/None/core.frag.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/None/compatibility.frag.h>
|
||||
};
|
||||
|
||||
const char* shaderSource = reinterpret_cast<const char*>((s_glsl140) ? coreFragmentShader : compatibilityFragmentShader);
|
||||
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreFragmentShader) : sizeof(compatibilityFragmentShader);
|
||||
|
||||
source.Reserve(source.GetCapacity() + 34 + shaderSourceSize);
|
||||
|
||||
if (s_earlyFragmentTest)
|
||||
source += "layout(early_fragment_tests) in;\n\n";
|
||||
|
||||
source.Append(shaderSource, shaderSourceSize);
|
||||
break;
|
||||
}
|
||||
|
||||
case nzShaderTarget_Sprite:
|
||||
{
|
||||
const nzUInt8 coreFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Sprite/core.frag.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityFragmentShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Sprite/compatibility.frag.h>
|
||||
};
|
||||
|
||||
const char* shaderSource = reinterpret_cast<const char*>((s_glsl140) ? coreFragmentShader : compatibilityFragmentShader);
|
||||
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreFragmentShader) : sizeof(compatibilityFragmentShader);
|
||||
|
||||
source.Reserve(source.GetCapacity() + 34 + 24 + 21 + 26 + 1 + shaderSourceSize);
|
||||
|
||||
// "discard" ne s'entend pas bien avec les early fragment tests
|
||||
if (s_earlyFragmentTest && !params.sprite.alphaTest)
|
||||
source += "layout(early_fragment_tests) in;\n\n";
|
||||
|
||||
source += "#define ALPHA_MAPPING ";
|
||||
source += (params.sprite.alphaMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define ALPHA_TEST ";
|
||||
source += (params.sprite.alphaTest) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define DIFFUSE_MAPPING ";
|
||||
source += (params.sprite.diffuseMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += '\n';
|
||||
|
||||
source.Append(shaderSource, shaderSourceSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
NzString NzShaderProgramManager::BuildVertexCode(const NzShaderProgramManagerParams& params)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (params.target > nzShaderTarget_Max)
|
||||
{
|
||||
NazaraError("Shader target out of enum");
|
||||
return NzString();
|
||||
}
|
||||
#endif
|
||||
|
||||
NzString source;
|
||||
|
||||
/********************Header********************/
|
||||
source.Reserve(14 + 24 + 24 + 26 + 1);
|
||||
source += "#version ";
|
||||
source += NzString::Number(s_glslVersion);
|
||||
source += "\n\n";
|
||||
|
||||
source += "#define FLAG_DEFERRED ";
|
||||
source += (params.flags & nzShaderFlags_Deferred) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define FLAG_FLIP_UVS ";
|
||||
source += (params.flags & nzShaderFlags_FlipUVs) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define FLAG_INSTANCING ";
|
||||
source += (params.flags & nzShaderFlags_Instancing) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += '\n';
|
||||
|
||||
switch (params.target)
|
||||
{
|
||||
case nzShaderTarget_FullscreenQuad:
|
||||
{
|
||||
const nzUInt8 coreVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/FullscreenQuad/core.vert.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/FullscreenQuad/compatibility.vert.h>
|
||||
};
|
||||
|
||||
const char* shaderSource = reinterpret_cast<const char*>((s_glsl140) ? coreVertexShader : compatibilityVertexShader);
|
||||
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreVertexShader) : sizeof(compatibilityVertexShader);
|
||||
|
||||
source.Reserve(source.GetCapacity() + 24 + 21 + 26 + 1 + shaderSourceSize);
|
||||
|
||||
source += "#define ALPHA_MAPPING ";
|
||||
source += (params.fullscreenQuad.alphaMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define ALPHA_TEST ";
|
||||
source += (params.fullscreenQuad.alphaTest) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define DIFFUSE_MAPPING ";
|
||||
source += (params.fullscreenQuad.diffuseMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += '\n';
|
||||
|
||||
source.Append(shaderSource, shaderSourceSize);
|
||||
break;
|
||||
}
|
||||
|
||||
case nzShaderTarget_Model:
|
||||
{
|
||||
const nzUInt8 coreVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Model/core.vert.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Model/compatibility.vert.h>
|
||||
};
|
||||
|
||||
const char* shaderSource = reinterpret_cast<const char*>((s_glsl140) ? coreVertexShader : compatibilityVertexShader);
|
||||
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreVertexShader) : sizeof(compatibilityVertexShader);
|
||||
|
||||
source.Reserve(source.GetCapacity() + 24 + 21 + 26 + 27 + 19 + 25 + 27 + 27 + 1 + shaderSourceSize);
|
||||
|
||||
source += "#define ALPHA_MAPPING ";
|
||||
source += (params.model.alphaMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define ALPHA_TEST ";
|
||||
source += (params.model.alphaTest) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define DIFFUSE_MAPPING ";
|
||||
source += (params.model.diffuseMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define EMISSIVE_MAPPING ";
|
||||
source += (params.model.emissiveMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define LIGHTING ";
|
||||
source += (params.model.lighting) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define NORMAL_MAPPING ";
|
||||
source += (params.model.normalMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define PARALLAX_MAPPING ";
|
||||
source += (params.model.parallaxMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define SPECULAR_MAPPING ";
|
||||
source += (params.model.specularMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += '\n';
|
||||
|
||||
source.Append(shaderSource, shaderSourceSize);
|
||||
break;
|
||||
}
|
||||
|
||||
case nzShaderTarget_None:
|
||||
{
|
||||
const nzUInt8 coreVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/None/core.vert.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/None/compatibility.vert.h>
|
||||
};
|
||||
|
||||
const char* shaderSource = reinterpret_cast<const char*>((s_glsl140) ? coreVertexShader : compatibilityVertexShader);
|
||||
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreVertexShader) : sizeof(compatibilityVertexShader);
|
||||
|
||||
source.Append(shaderSource, shaderSourceSize);
|
||||
break;
|
||||
}
|
||||
|
||||
case nzShaderTarget_Sprite:
|
||||
{
|
||||
const nzUInt8 coreVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Sprite/core.vert.h>
|
||||
};
|
||||
|
||||
const nzUInt8 compatibilityVertexShader[] = {
|
||||
#include <Nazara/Renderer/Resources/Shaders/Sprite/compatibility.vert.h>
|
||||
};
|
||||
|
||||
const char* shaderSource = reinterpret_cast<const char*>((s_glsl140) ? coreVertexShader : compatibilityVertexShader);
|
||||
unsigned int shaderSourceSize = (s_glsl140) ? sizeof(coreVertexShader) : sizeof(compatibilityVertexShader);
|
||||
|
||||
source.Reserve(source.GetCapacity() + 24 + 21 + 26 + 1 + shaderSourceSize);
|
||||
|
||||
source += "#define ALPHA_MAPPING ";
|
||||
source += (params.fullscreenQuad.alphaMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define ALPHA_TEST ";
|
||||
source += (params.fullscreenQuad.alphaTest) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += "#define DIFFUSE_MAPPING ";
|
||||
source += (params.fullscreenQuad.diffuseMapping) ? '1' : '0';
|
||||
source += '\n';
|
||||
|
||||
source += '\n';
|
||||
|
||||
source.Append(shaderSource, shaderSourceSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
NzShaderProgram* NzShaderProgramManager::GenerateProgram(const NzShaderProgramManagerParams& params)
|
||||
{
|
||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram);
|
||||
program->SetPersistent(false);
|
||||
|
||||
if (!program->Create(nzShaderLanguage_GLSL))
|
||||
{
|
||||
NazaraError("Failed to create program");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NzString fragmentSource = BuildFragmentCode(params);
|
||||
if (!program->LoadShader(nzShaderType_Fragment, fragmentSource))
|
||||
{
|
||||
NazaraError("Failed to load fragment shader: " + program->GetLog());
|
||||
NazaraNotice("Source:\n" + fragmentSource);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NzString vertexSource = BuildVertexCode(params);
|
||||
if (!program->LoadShader(nzShaderType_Vertex, vertexSource))
|
||||
{
|
||||
NazaraError("Failed to load vertex shader: " + program->GetLog());
|
||||
NazaraNotice("Source:\n" + vertexSource);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!program->Compile())
|
||||
{
|
||||
NazaraError("Failed to compile program: " + program->GetLog());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return program.release();
|
||||
}
|
||||
|
||||
bool NzShaderProgramManager::Initialize()
|
||||
{
|
||||
s_glslVersion = NzOpenGL::GetGLSLVersion();
|
||||
s_earlyFragmentTest = (s_glslVersion >= 420 || NzOpenGL::IsSupported(nzOpenGLExtension_Shader_ImageLoadStore));
|
||||
s_glsl140 = (s_glslVersion >= 140);
|
||||
|
||||
NzShaderProgramManagerParams params;
|
||||
params.target = nzShaderTarget_None;
|
||||
for (unsigned int i = 0; i <= nzShaderFlags_Max; ++i)
|
||||
{
|
||||
params.flags = i;
|
||||
|
||||
NzShaderProgram* program = GenerateProgram(params);
|
||||
if (!program)
|
||||
{
|
||||
NazaraError("Failed to generate default program (flags: 0x" + NzString::Number(i, 16) + ')');
|
||||
Uninitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
s_programs[params] = program;
|
||||
}
|
||||
|
||||
/*if (s_loadCachedPrograms)
|
||||
{
|
||||
NzDirectory cacheDirectory(s_cacheDirectory);
|
||||
cacheDirectory.SetPattern("*.nsb");
|
||||
|
||||
if (cacheDirectory.Open())
|
||||
{
|
||||
while (cacheDirectory.NextResult(true))
|
||||
{
|
||||
long long hash;
|
||||
if (cacheDirectory.GetResultName().SubStringTo(".nsb", -1, true, false).ToInteger(&hash, 32))
|
||||
{
|
||||
std::size_t hashCode = static_cast<std::size_t>(hash);
|
||||
|
||||
if (s_programs.find(hashCode) == s_programs.end())
|
||||
{
|
||||
NzFile shaderFile(cacheDirectory.GetResultPath());
|
||||
if (shaderFile.Open(NzFile::ReadOnly))
|
||||
{
|
||||
unsigned int size = cacheDirectory.GetResultSize();
|
||||
|
||||
NzByteArray binary;
|
||||
binary.Resize(size);
|
||||
|
||||
if (shaderFile.Read(&binary[0], size) != size)
|
||||
{
|
||||
NazaraError("Failed to read program binary");
|
||||
return false;
|
||||
}
|
||||
|
||||
shaderFile.Close();
|
||||
|
||||
std::unique_ptr<NzShaderProgram> program(new NzShaderProgram);
|
||||
if (program->LoadFromBinary(binary))
|
||||
s_programs[hashCode] = binary.release();
|
||||
else
|
||||
NazaraWarning("Program binary \"" + cacheDirectory.GetResultName() + "\" loading failed, this is mostly due to a driver/video card "
|
||||
"update or a file corruption, regenerating program..."); }
|
||||
}
|
||||
}
|
||||
else
|
||||
NazaraWarning("Failed to parse program file name (" + cacheDirectory.GetResultName() + ')');
|
||||
}
|
||||
}
|
||||
else if (cacheDirectory.Exists())
|
||||
NazaraWarning("Failed to open shader cache directory");
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzShaderProgramManager::Uninitialize()
|
||||
{
|
||||
s_programs.clear();
|
||||
}
|
||||
231
src/Nazara/Renderer/ShaderStage.cpp
Normal file
231
src/Nazara/Renderer/ShaderStage.cpp
Normal file
@@ -0,0 +1,231 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Renderer/ShaderStage.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzShaderStage::NzShaderStage() :
|
||||
m_compiled(false),
|
||||
m_id(0)
|
||||
{
|
||||
}
|
||||
|
||||
NzShaderStage::NzShaderStage(nzShaderStage stage) :
|
||||
NzShaderStage()
|
||||
{
|
||||
Create(stage);
|
||||
}
|
||||
|
||||
NzShaderStage::NzShaderStage(NzShaderStage&& stage) :
|
||||
m_stage(stage.m_stage),
|
||||
m_compiled(stage.m_compiled),
|
||||
m_id(stage.m_id)
|
||||
{
|
||||
stage.m_id = 0;
|
||||
}
|
||||
|
||||
NzShaderStage::~NzShaderStage()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool NzShaderStage::Compile()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_id)
|
||||
{
|
||||
NazaraError("Shader stage is not initialized");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
glCompileShader(m_id);
|
||||
|
||||
GLint success;
|
||||
glGetShaderiv(m_id, GL_COMPILE_STATUS, &success);
|
||||
|
||||
m_compiled = (success == GL_TRUE);
|
||||
if (m_compiled)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
NazaraError("Failed to compile shader stage: " + GetLog());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzShaderStage::Create(nzShaderStage stage)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_id = glCreateShader(NzOpenGL::ShaderStage[stage]);
|
||||
m_stage = stage;
|
||||
|
||||
return (m_id != 0);
|
||||
}
|
||||
|
||||
void NzShaderStage::Destroy()
|
||||
{
|
||||
m_compiled = false;
|
||||
if (m_id)
|
||||
glDeleteShader(m_id);
|
||||
}
|
||||
|
||||
NzString NzShaderStage::GetLog() const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_id)
|
||||
{
|
||||
NazaraError("Shader stage is not initialized");
|
||||
return NzString();
|
||||
}
|
||||
#endif
|
||||
|
||||
NzString log;
|
||||
|
||||
GLint length = 0;
|
||||
glGetShaderiv(m_id, GL_INFO_LOG_LENGTH, &length);
|
||||
if (length > 1) // Le caractère de fin faisant partie du compte
|
||||
{
|
||||
log.Resize(length - 1); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
glGetShaderInfoLog(m_id, length, nullptr, &log[0]);
|
||||
}
|
||||
else
|
||||
log = "No log.";
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
NzString NzShaderStage::GetSource() const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_id)
|
||||
{
|
||||
NazaraError("Shader stage is not initialized");
|
||||
return NzString();
|
||||
}
|
||||
#endif
|
||||
|
||||
NzString source;
|
||||
|
||||
GLint length = 0;
|
||||
glGetShaderiv(m_id, GL_SHADER_SOURCE_LENGTH, &length);
|
||||
if (length > 1) // Le caractère de fin compte
|
||||
{
|
||||
source.Resize(length - 1); // La taille retournée est celle du buffer (Avec caractère de fin)
|
||||
glGetShaderSource(m_id, length, nullptr, &source[0]);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
bool NzShaderStage::IsCompiled() const
|
||||
{
|
||||
return m_compiled;
|
||||
}
|
||||
|
||||
bool NzShaderStage::IsValid() const
|
||||
{
|
||||
return m_id != 0;
|
||||
}
|
||||
|
||||
void NzShaderStage::SetSource(const char* source, unsigned int length)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_id)
|
||||
{
|
||||
NazaraError("Shader stage is not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
glShaderSource(m_id, 1, &source, reinterpret_cast<const GLint*>(&length));
|
||||
}
|
||||
|
||||
void NzShaderStage::SetSource(const NzString& source)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_id)
|
||||
{
|
||||
NazaraError("Shader stage is not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
const char* tmp = source.GetConstBuffer();
|
||||
GLint length = source.GetSize();
|
||||
glShaderSource(m_id, 1, &tmp, &length);
|
||||
}
|
||||
|
||||
bool NzShaderStage::SetSourceFromFile(const NzString& filePath)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_id)
|
||||
{
|
||||
NazaraError("Shader stage is not initialized");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
NzFile file(filePath);
|
||||
if (!file.Open(NzFile::ReadOnly | NzFile::Text))
|
||||
{
|
||||
NazaraError("Failed to open \"" + filePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int length = static_cast<unsigned int>(file.GetSize());
|
||||
|
||||
NzString source;
|
||||
source.Resize(length);
|
||||
|
||||
if (file.Read(&source[0], length) != length)
|
||||
{
|
||||
NazaraError("Failed to read program file");
|
||||
return false;
|
||||
}
|
||||
|
||||
file.Close();
|
||||
|
||||
SetSource(source);
|
||||
return true;
|
||||
}
|
||||
|
||||
NzShaderStage& NzShaderStage::operator=(NzShaderStage&& shader)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_compiled = shader.m_compiled;
|
||||
m_id = shader.m_id;
|
||||
m_stage = shader.m_stage;
|
||||
|
||||
shader.m_id = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int NzShaderStage::GetOpenGLID() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
bool NzShaderStage::IsSupported(nzShaderStage stage)
|
||||
{
|
||||
switch (stage)
|
||||
{
|
||||
case nzShaderStage_Fragment:
|
||||
case nzShaderStage_Vertex:
|
||||
return true;
|
||||
|
||||
case nzShaderStage_Geometry:
|
||||
return NzOpenGL::GetVersion() >= 320;
|
||||
|
||||
default:
|
||||
NazaraError("Shader stage not handled (0x" + NzString::Number(stage, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/AbstractShaderProgram.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzAbstractShaderProgram::~NzAbstractShaderProgram() = default;
|
||||
NzUberShader::~NzUberShader() = default;
|
||||
19
src/Nazara/Renderer/UberShaderInstance.cpp
Normal file
19
src/Nazara/Renderer/UberShaderInstance.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||
#include <algorithm>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzUberShaderInstance::NzUberShaderInstance(const NzShader* shader) :
|
||||
m_shader(shader)
|
||||
{
|
||||
}
|
||||
|
||||
NzUberShaderInstance::~NzUberShaderInstance() = default;
|
||||
|
||||
const NzShader* NzUberShaderInstance::GetShader() const
|
||||
{
|
||||
return m_shader;
|
||||
}
|
||||
21
src/Nazara/Renderer/UberShaderInstancePreprocessor.cpp
Normal file
21
src/Nazara/Renderer/UberShaderInstancePreprocessor.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Renderer/UberShaderInstancePreprocessor.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzUberShaderInstancePreprocessor::NzUberShaderInstancePreprocessor(const NzShader* shader) :
|
||||
NzUberShaderInstance(shader)
|
||||
{
|
||||
}
|
||||
|
||||
NzUberShaderInstancePreprocessor::~NzUberShaderInstancePreprocessor() = default;
|
||||
|
||||
bool NzUberShaderInstancePreprocessor::Activate() const
|
||||
{
|
||||
NzRenderer::SetShader(m_shader);
|
||||
|
||||
return true;
|
||||
}
|
||||
51
src/Nazara/Renderer/UberShaderLibrary.cpp
Normal file
51
src/Nazara/Renderer/UberShaderLibrary.cpp
Normal file
@@ -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
|
||||
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzUberShader* NzUberShaderLibrary::Get(const NzString& name)
|
||||
{
|
||||
auto it = s_library.find(name);
|
||||
if (it != s_library.end())
|
||||
return it->second;
|
||||
else
|
||||
{
|
||||
NazaraError("UberShader \"" + name + "\" is not present");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzUberShaderLibrary::Has(const NzString& name)
|
||||
{
|
||||
return s_library.find(name) != s_library.end();
|
||||
}
|
||||
|
||||
bool NzUberShaderLibrary::Initialize()
|
||||
{
|
||||
return true; // Que faire
|
||||
}
|
||||
|
||||
void NzUberShaderLibrary::Register(const NzString& name, NzUberShader* uberShader)
|
||||
{
|
||||
s_library.emplace(name, uberShader);
|
||||
NazaraDebug("UberShader \"" + name + "\" registred");
|
||||
}
|
||||
|
||||
void NzUberShaderLibrary::Uninitialize()
|
||||
{
|
||||
for (auto it : s_library)
|
||||
NazaraWarning("UberShader \"" + it.first + "\" has not been unregistred");
|
||||
|
||||
s_library.clear();
|
||||
}
|
||||
|
||||
void NzUberShaderLibrary::Unregister(const NzString& name)
|
||||
{
|
||||
s_library.erase(name);
|
||||
NazaraDebug("UberShader \"" + name + "\" unregistred");
|
||||
}
|
||||
|
||||
std::unordered_map<NzString, NzUberShaderRef> NzUberShaderLibrary::s_library;
|
||||
155
src/Nazara/Renderer/UberShaderPreprocessor.cpp
Normal file
155
src/Nazara/Renderer/UberShaderPreprocessor.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Renderer/UberShaderPreprocessor.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzUberShaderInstance* NzUberShaderPreprocessor::Get(const NzParameterList& parameters) const
|
||||
{
|
||||
// Première étape, transformer les paramètres en un flag
|
||||
nzUInt32 flags = 0;
|
||||
for (auto it = m_flags.begin(); it != m_flags.end(); ++it)
|
||||
{
|
||||
if (parameters.HasParameter(it->first))
|
||||
{
|
||||
bool value;
|
||||
if (parameters.GetBooleanParameter(it->first, &value) && value)
|
||||
flags |= it->second;
|
||||
}
|
||||
}
|
||||
|
||||
// Le shader fait-il partie du cache ?
|
||||
auto shaderIt = m_cache.find(flags);
|
||||
|
||||
// Si non, il nous faut le construire
|
||||
if (shaderIt == m_cache.end())
|
||||
{
|
||||
try
|
||||
{
|
||||
NzErrorFlags errFlags(nzErrorFlag_Silent | nzErrorFlag_ThrowException);
|
||||
|
||||
std::unique_ptr<NzShader> shader(new NzShader);
|
||||
shader->Create();
|
||||
|
||||
for (unsigned int i = 0; i <= nzShaderStage_Max; ++i)
|
||||
{
|
||||
const Shader& shaderStage = m_shaders[i];
|
||||
|
||||
if (shaderStage.present)
|
||||
{
|
||||
nzUInt32 stageFlags = 0;
|
||||
for (auto it = shaderStage.flags.begin(); it != shaderStage.flags.end(); ++it)
|
||||
{
|
||||
if (parameters.HasParameter(it->first))
|
||||
{
|
||||
bool value;
|
||||
if (parameters.GetBooleanParameter(it->first, &value) && value)
|
||||
stageFlags |= it->second;
|
||||
}
|
||||
}
|
||||
|
||||
auto stageIt = shaderStage.cache.find(stageFlags);
|
||||
if (stageIt == shaderStage.cache.end())
|
||||
{
|
||||
NzShaderStage stage;
|
||||
stage.Create(static_cast<nzShaderStage>(i));
|
||||
|
||||
unsigned int glslVersion = NzOpenGL::GetGLSLVersion();
|
||||
|
||||
NzStringStream code;
|
||||
code << "#version " << glslVersion << "\n\n";
|
||||
|
||||
code << "#define GLSL_VERSION " << glslVersion << "\n\n";
|
||||
|
||||
code << "#define EARLY_FRAGMENT_TEST " << (glslVersion >= 420 || NzOpenGL::IsSupported(nzOpenGLExtension_Shader_ImageLoadStore)) << "\n\n";
|
||||
|
||||
for (auto it = shaderStage.flags.begin(); it != shaderStage.flags.end(); ++it)
|
||||
code << "#define " << it->first << ' ' << ((stageFlags & it->second) ? '1' : '0') << '\n';
|
||||
|
||||
code << "\n#line 1\n";
|
||||
code << shaderStage.source;
|
||||
|
||||
stage.SetSource(code);
|
||||
stage.Compile();
|
||||
|
||||
shader->AttachStage(static_cast<nzShaderStage>(i), stage);
|
||||
|
||||
shaderStage.cache.emplace(flags, std::move(stage));
|
||||
}
|
||||
else
|
||||
shader->AttachStage(static_cast<nzShaderStage>(i), stageIt->second);
|
||||
}
|
||||
}
|
||||
|
||||
shader->Link();
|
||||
|
||||
auto pair = m_cache.emplace(flags, shader.get());
|
||||
shader.release();
|
||||
|
||||
return &(pair.first)->second;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NzErrorFlags errFlags(nzErrorFlag_ThrowExceptionDisabled);
|
||||
|
||||
NazaraError("Failed to build uber shader instance: " + NzError::GetLastError());
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
return &shaderIt->second;
|
||||
}
|
||||
|
||||
void NzUberShaderPreprocessor::SetShader(nzShaderStage stage, const NzString& source, const NzString& flagString)
|
||||
{
|
||||
Shader& shader = m_shaders[stage];
|
||||
shader.present = true;
|
||||
shader.source = source;
|
||||
|
||||
std::vector<NzString> flags;
|
||||
flagString.Split(flags, ' ');
|
||||
|
||||
for (NzString& flag : flags)
|
||||
{
|
||||
auto it = m_flags.find(flag);
|
||||
if (it == m_flags.end())
|
||||
m_flags[flag] = 1U << m_flags.size();
|
||||
|
||||
auto it2 = shader.flags.find(flag);
|
||||
if (it2 == shader.flags.end())
|
||||
shader.flags[flag] = 1U << shader.flags.size();
|
||||
}
|
||||
}
|
||||
|
||||
bool NzUberShaderPreprocessor::SetShaderFromFile(nzShaderStage stage, const NzString& filePath, const NzString& flags)
|
||||
{
|
||||
NzFile file(filePath);
|
||||
if (!file.Open(NzFile::ReadOnly | NzFile::Text))
|
||||
{
|
||||
NazaraError("Failed to open \"" + filePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int length = static_cast<unsigned int>(file.GetSize());
|
||||
|
||||
NzString source;
|
||||
source.Resize(length);
|
||||
|
||||
if (file.Read(&source[0], length) != length)
|
||||
{
|
||||
NazaraError("Failed to read program file");
|
||||
return false;
|
||||
}
|
||||
|
||||
file.Close();
|
||||
|
||||
SetShader(stage, source, flags);
|
||||
return true;
|
||||
}
|
||||
@@ -28,15 +28,14 @@ m_initialPosition(node.m_initialPosition),
|
||||
m_initialScale(node.m_initialScale),
|
||||
m_position(node.m_position),
|
||||
m_scale(node.m_scale),
|
||||
m_parent(node.m_parent),
|
||||
m_parent(nullptr),
|
||||
m_derivedUpdated(false),
|
||||
m_inheritPosition(node.m_inheritPosition),
|
||||
m_inheritRotation(node.m_inheritRotation),
|
||||
m_inheritScale(node.m_inheritScale),
|
||||
m_transformMatrixUpdated(false)
|
||||
{
|
||||
if (m_parent)
|
||||
m_parent->AddChild(this);
|
||||
SetParent(node.m_parent, false);
|
||||
}
|
||||
|
||||
NzNode::~NzNode()
|
||||
@@ -247,7 +246,7 @@ NzNode& NzNode::Interpolate(const NzNode& nodeA, const NzNode& nodeB, float inte
|
||||
break;
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -275,7 +274,7 @@ NzNode& NzNode::Move(const NzVector3f& movement, nzCoordSys coordSys)
|
||||
break;
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -308,7 +307,7 @@ NzNode& NzNode::Rotate(const NzQuaternionf& rotation, nzCoordSys coordSys)
|
||||
|
||||
m_rotation.Normalize();
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -316,7 +315,7 @@ NzNode& NzNode::Scale(const NzVector3f& scale)
|
||||
{
|
||||
m_scale *= scale;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -324,7 +323,7 @@ NzNode& NzNode::Scale(float scale)
|
||||
{
|
||||
m_scale *= scale;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -334,7 +333,7 @@ NzNode& NzNode::Scale(float scaleX, float scaleY, float scaleZ)
|
||||
m_scale.y *= scaleY;
|
||||
m_scale.z *= scaleZ;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -345,7 +344,7 @@ void NzNode::SetInheritPosition(bool inheritPosition)
|
||||
{
|
||||
m_inheritPosition = inheritPosition;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,7 +355,7 @@ void NzNode::SetInheritRotation(bool inheritRotation)
|
||||
{
|
||||
m_inheritRotation = inheritRotation;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +366,7 @@ void NzNode::SetInheritScale(bool inheritScale)
|
||||
{
|
||||
m_inheritScale = inheritScale;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,14 +374,14 @@ void NzNode::SetInitialPosition(const NzVector3f& position)
|
||||
{
|
||||
m_initialPosition = position;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetInitialPosition(float positionX, float positionY, float positionZ)
|
||||
{
|
||||
m_initialPosition.Set(positionX, positionY, positionZ);
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetInitialRotation(const NzQuaternionf& rotation)
|
||||
@@ -390,28 +389,28 @@ void NzNode::SetInitialRotation(const NzQuaternionf& rotation)
|
||||
m_initialRotation = rotation;
|
||||
m_initialRotation.Normalize(); // Évitons toute mauvaise surprise ...
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetInitialScale(const NzVector3f& scale)
|
||||
{
|
||||
m_initialScale = scale;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetInitialScale(float scale)
|
||||
{
|
||||
m_initialScale.Set(scale);
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetInitialScale(float scaleX, float scaleY, float scaleZ)
|
||||
{
|
||||
m_initialScale.Set(scaleX, scaleY, scaleZ);
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetName(const NzString& name)
|
||||
@@ -457,7 +456,7 @@ void NzNode::SetParent(const NzNode* node, bool keepDerived)
|
||||
if (m_parent)
|
||||
m_parent->AddChild(this);
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
OnParenting(node);
|
||||
@@ -489,7 +488,7 @@ void NzNode::SetPosition(const NzVector3f& position, nzCoordSys coordSys)
|
||||
break;
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetPosition(float positionX, float positionY, float positionZ, nzCoordSys coordSys)
|
||||
@@ -522,7 +521,7 @@ void NzNode::SetRotation(const NzQuaternionf& rotation, nzCoordSys coordSys)
|
||||
break;
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetScale(const NzVector3f& scale, nzCoordSys coordSys)
|
||||
@@ -541,7 +540,7 @@ void NzNode::SetScale(const NzVector3f& scale, nzCoordSys coordSys)
|
||||
break;
|
||||
}
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::SetScale(float scale, nzCoordSys coordSys)
|
||||
@@ -627,7 +626,7 @@ NzNode& NzNode::operator=(const NzNode& node)
|
||||
m_rotation = node.m_rotation;
|
||||
m_scale = node.m_scale;
|
||||
|
||||
Invalidate();
|
||||
InvalidateNode();
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -645,13 +644,13 @@ void NzNode::AddChild(NzNode* node) const
|
||||
m_childs.push_back(node);
|
||||
}
|
||||
|
||||
void NzNode::Invalidate()
|
||||
void NzNode::InvalidateNode()
|
||||
{
|
||||
m_derivedUpdated = false;
|
||||
m_transformMatrixUpdated = false;
|
||||
|
||||
for (NzNode* node : m_childs)
|
||||
node->Invalidate();
|
||||
node->InvalidateNode();
|
||||
}
|
||||
|
||||
void NzNode::OnParenting(const NzNode* parent)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user