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:
@@ -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
|
||||
@@ -1,15 +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_LOADERS_TEXTURE_HPP
|
||||
#define NAZARA_LOADERS_TEXTURE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
void NzLoaders_Texture_Register();
|
||||
void NzLoaders_Texture_Unregister();
|
||||
|
||||
#endif // NAZARA_LOADERS_TEXTURE_HPP
|
||||
@@ -1,50 +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/Renderer/Loaders/Texture.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
nzTernary Check(NzInputStream& stream, const NzMaterialParams& parameters)
|
||||
{
|
||||
NazaraUnused(stream);
|
||||
NazaraUnused(parameters);
|
||||
|
||||
return nzTernary_Unknown;
|
||||
}
|
||||
|
||||
bool Load(NzMaterial* material, NzInputStream& stream, const NzMaterialParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
texture->SetPersistent(false);
|
||||
|
||||
if (!texture->LoadFromStream(stream))
|
||||
{
|
||||
NazaraError("Failed to load diffuse map");
|
||||
return false;
|
||||
}
|
||||
|
||||
material->Reset();
|
||||
material->SetDiffuseMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void NzLoaders_Texture_Register()
|
||||
{
|
||||
NzMaterialLoader::RegisterLoader(NzImageLoader::IsExtensionSupported, Check, Load);
|
||||
}
|
||||
|
||||
void NzLoaders_Texture_Unregister()
|
||||
{
|
||||
NzMaterialLoader::UnregisterLoader(NzImageLoader::IsExtensionSupported, Check, Load);
|
||||
}
|
||||
@@ -1,760 +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/Renderer/Material.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgram.hpp>
|
||||
#include <Nazara/Renderer/ShaderProgramManager.hpp>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
bool NzMaterialParams::IsValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
NzMaterial::NzMaterial()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
NzMaterial::NzMaterial(const NzMaterial& material) :
|
||||
NzResource()
|
||||
{
|
||||
Copy(material);
|
||||
}
|
||||
|
||||
NzMaterial::NzMaterial(NzMaterial&& material)
|
||||
{
|
||||
Copy(material);
|
||||
|
||||
// Nous "volons" la référence du matériau
|
||||
material.m_alphaMap.Reset();
|
||||
material.m_diffuseMap.Reset();
|
||||
material.m_emissiveMap.Reset();
|
||||
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();
|
||||
}
|
||||
|
||||
NzMaterial::~NzMaterial()
|
||||
{
|
||||
NotifyDestroy();
|
||||
}
|
||||
|
||||
void NzMaterial::Apply(const NzShaderProgram* program) 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);
|
||||
|
||||
if (m_alphaMap)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
if (m_emissiveMap)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
if (m_heightMap)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
if (m_normalMap)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
if (shininessLocation != -1)
|
||||
program->SendFloat(shininessLocation, m_shininess);
|
||||
|
||||
if (specularColorLocation != -1)
|
||||
program->SendColor(specularColorLocation, m_specularColor);
|
||||
|
||||
if (m_specularMap)
|
||||
{
|
||||
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::SetRenderStates(m_states);
|
||||
}
|
||||
|
||||
void NzMaterial::Enable(nzRendererParameter renderParameter, bool enable)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (renderParameter > nzRendererParameter_Max)
|
||||
{
|
||||
NazaraError("Renderer parameter out of enum");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_states.parameters[renderParameter] = enable;
|
||||
}
|
||||
|
||||
void NzMaterial::EnableAlphaTest(bool alphaTest)
|
||||
{
|
||||
m_alphaTestEnabled = alphaTest;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
||||
}
|
||||
|
||||
void NzMaterial::EnableLighting(bool lighting)
|
||||
{
|
||||
m_lightingEnabled = lighting;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
}
|
||||
|
||||
NzTexture* NzMaterial::GetAlphaMap() const
|
||||
{
|
||||
return m_alphaMap;
|
||||
}
|
||||
|
||||
float NzMaterial::GetAlphaThreshold() const
|
||||
{
|
||||
return m_alphaThreshold;
|
||||
}
|
||||
|
||||
NzColor NzMaterial::GetAmbientColor() const
|
||||
{
|
||||
return m_ambientColor;
|
||||
}
|
||||
|
||||
nzRendererComparison NzMaterial::GetDepthFunc() const
|
||||
{
|
||||
return m_states.depthFunc;
|
||||
}
|
||||
|
||||
NzColor NzMaterial::GetDiffuseColor() const
|
||||
{
|
||||
return m_diffuseColor;
|
||||
}
|
||||
|
||||
NzTextureSampler& NzMaterial::GetDiffuseSampler()
|
||||
{
|
||||
return m_diffuseSampler;
|
||||
}
|
||||
|
||||
const NzTextureSampler& NzMaterial::GetDiffuseSampler() const
|
||||
{
|
||||
return m_diffuseSampler;
|
||||
}
|
||||
|
||||
NzTexture* NzMaterial::GetDiffuseMap() const
|
||||
{
|
||||
return m_diffuseMap;
|
||||
}
|
||||
|
||||
nzBlendFunc NzMaterial::GetDstBlend() const
|
||||
{
|
||||
return m_states.dstBlend;
|
||||
}
|
||||
|
||||
NzTexture* NzMaterial::GetEmissiveMap() const
|
||||
{
|
||||
return m_emissiveMap;
|
||||
}
|
||||
|
||||
nzFaceSide NzMaterial::GetFaceCulling() const
|
||||
{
|
||||
return m_states.faceCulling;
|
||||
}
|
||||
|
||||
nzFaceFilling NzMaterial::GetFaceFilling() const
|
||||
{
|
||||
return m_states.faceFilling;
|
||||
}
|
||||
|
||||
NzTexture* NzMaterial::GetHeightMap() const
|
||||
{
|
||||
return m_heightMap;
|
||||
}
|
||||
|
||||
NzTexture* NzMaterial::GetNormalMap() const
|
||||
{
|
||||
return m_normalMap;
|
||||
}
|
||||
|
||||
const NzRenderStates& NzMaterial::GetRenderStates() const
|
||||
{
|
||||
return m_states;
|
||||
}
|
||||
|
||||
const NzShaderProgram* NzMaterial::GetShaderProgram(nzShaderTarget target, nzUInt32 flags) const
|
||||
{
|
||||
const ProgramUnit& unit = m_programs[target][flags];
|
||||
if (!unit.program.IsValid())
|
||||
GenerateProgram(target, flags);
|
||||
|
||||
return unit.program;
|
||||
}
|
||||
|
||||
float NzMaterial::GetShininess() const
|
||||
{
|
||||
return m_shininess;
|
||||
}
|
||||
|
||||
NzColor NzMaterial::GetSpecularColor() const
|
||||
{
|
||||
return m_specularColor;
|
||||
}
|
||||
|
||||
NzTexture* NzMaterial::GetSpecularMap() const
|
||||
{
|
||||
return m_specularMap;
|
||||
}
|
||||
|
||||
NzTextureSampler& NzMaterial::GetSpecularSampler()
|
||||
{
|
||||
return m_specularSampler;
|
||||
}
|
||||
|
||||
const NzTextureSampler& NzMaterial::GetSpecularSampler() const
|
||||
{
|
||||
return m_specularSampler;
|
||||
}
|
||||
|
||||
nzBlendFunc NzMaterial::GetSrcBlend() const
|
||||
{
|
||||
return m_states.srcBlend;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
bool NzMaterial::HasEmissiveMap() const
|
||||
{
|
||||
return m_emissiveMap.IsValid();
|
||||
}
|
||||
|
||||
bool NzMaterial::HasHeightMap() const
|
||||
{
|
||||
return m_heightMap.IsValid();
|
||||
}
|
||||
|
||||
bool NzMaterial::HasNormalMap() const
|
||||
{
|
||||
return m_normalMap.IsValid();
|
||||
}
|
||||
|
||||
bool NzMaterial::HasSpecularMap() const
|
||||
{
|
||||
return m_specularMap.IsValid();
|
||||
}
|
||||
|
||||
bool NzMaterial::IsAlphaTestEnabled() const
|
||||
{
|
||||
return m_alphaTestEnabled;
|
||||
}
|
||||
|
||||
bool NzMaterial::IsEnabled(nzRendererParameter parameter) const
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (parameter > nzRendererParameter_Max)
|
||||
{
|
||||
NazaraError("Renderer parameter out of enum");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_states.parameters[parameter];
|
||||
}
|
||||
|
||||
bool NzMaterial::IsLightingEnabled() const
|
||||
{
|
||||
return m_lightingEnabled;
|
||||
}
|
||||
|
||||
bool NzMaterial::LoadFromFile(const NzString& filePath, const NzMaterialParams& params)
|
||||
{
|
||||
return NzMaterialLoader::LoadFromFile(this, filePath, params);
|
||||
}
|
||||
|
||||
bool NzMaterial::LoadFromMemory(const void* data, std::size_t size, const NzMaterialParams& params)
|
||||
{
|
||||
return NzMaterialLoader::LoadFromMemory(this, data, size, params);
|
||||
}
|
||||
|
||||
bool NzMaterial::LoadFromStream(NzInputStream& stream, const NzMaterialParams& params)
|
||||
{
|
||||
return NzMaterialLoader::LoadFromStream(this, stream, params);
|
||||
}
|
||||
|
||||
void NzMaterial::Reset()
|
||||
{
|
||||
NotifyDestroy();
|
||||
|
||||
m_alphaMap.Reset();
|
||||
m_diffuseMap.Reset();
|
||||
m_emissiveMap.Reset();
|
||||
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.custom = false;
|
||||
unit.program.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
m_alphaThreshold = 0.2f;
|
||||
m_alphaTestEnabled = false;
|
||||
m_ambientColor = NzColor(128, 128, 128);
|
||||
m_diffuseColor = NzColor::White;
|
||||
m_diffuseSampler = NzTextureSampler();
|
||||
m_lightingEnabled = true;
|
||||
m_shininess = 50.f;
|
||||
m_specularColor = NzColor::White;
|
||||
m_specularSampler = NzTextureSampler();
|
||||
m_states = NzRenderStates();
|
||||
m_states.parameters[nzRendererParameter_DepthBuffer] = true;
|
||||
m_states.parameters[nzRendererParameter_FaceCulling] = true;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetAlphaMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetAlphaMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetAlphaMap(NzTexture* map)
|
||||
{
|
||||
m_alphaMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
||||
}
|
||||
|
||||
void NzMaterial::SetAlphaThreshold(float alphaThreshold)
|
||||
{
|
||||
m_alphaThreshold = alphaThreshold;
|
||||
}
|
||||
|
||||
void NzMaterial::SetAmbientColor(const NzColor& ambient)
|
||||
{
|
||||
m_ambientColor = ambient;
|
||||
}
|
||||
|
||||
void NzMaterial::SetDepthFunc(nzRendererComparison depthFunc)
|
||||
{
|
||||
m_states.depthFunc = depthFunc;
|
||||
}
|
||||
|
||||
void NzMaterial::SetDiffuseColor(const NzColor& diffuse)
|
||||
{
|
||||
m_diffuseColor = diffuse;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetDiffuseMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetDiffuseMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetDiffuseMap(NzTexture* map)
|
||||
{
|
||||
m_diffuseMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_FullscreenQuad);
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
InvalidatePrograms(nzShaderTarget_Sprite);
|
||||
}
|
||||
|
||||
void NzMaterial::SetDiffuseSampler(const NzTextureSampler& sampler)
|
||||
{
|
||||
m_diffuseSampler = sampler;
|
||||
}
|
||||
|
||||
void NzMaterial::SetDstBlend(nzBlendFunc func)
|
||||
{
|
||||
m_states.dstBlend = func;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetEmissiveMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetEmissiveMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetEmissiveMap(NzTexture* map)
|
||||
{
|
||||
m_emissiveMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
}
|
||||
|
||||
void NzMaterial::SetFaceCulling(nzFaceSide faceSide)
|
||||
{
|
||||
m_states.faceCulling = faceSide;
|
||||
}
|
||||
|
||||
void NzMaterial::SetFaceFilling(nzFaceFilling filling)
|
||||
{
|
||||
m_states.faceFilling = filling;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetHeightMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetHeightMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetHeightMap(NzTexture* map)
|
||||
{
|
||||
m_heightMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
}
|
||||
|
||||
bool NzMaterial::SetNormalMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetNormalMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetNormalMap(NzTexture* map)
|
||||
{
|
||||
m_normalMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
}
|
||||
|
||||
void NzMaterial::SetRenderStates(const NzRenderStates& states)
|
||||
{
|
||||
m_states = states;
|
||||
}
|
||||
|
||||
void NzMaterial::SetShaderProgram(nzShaderTarget target, nzUInt32 flags, const NzShaderProgram* program)
|
||||
{
|
||||
ProgramUnit& unit = m_programs[target][flags];
|
||||
|
||||
unit.custom = (program != nullptr);
|
||||
unit.program = program;
|
||||
}
|
||||
|
||||
void NzMaterial::SetShininess(float shininess)
|
||||
{
|
||||
m_shininess = shininess;
|
||||
}
|
||||
|
||||
void NzMaterial::SetSpecularColor(const NzColor& specular)
|
||||
{
|
||||
m_specularColor = specular;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetSpecularMap(const NzString& texturePath)
|
||||
{
|
||||
std::unique_ptr<NzTexture> texture(new NzTexture);
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
SetSpecularMap(texture.get());
|
||||
texture.release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMaterial::SetSpecularMap(NzTexture* map)
|
||||
{
|
||||
m_specularMap = map;
|
||||
|
||||
InvalidatePrograms(nzShaderTarget_Model);
|
||||
}
|
||||
|
||||
void NzMaterial::SetSpecularSampler(const NzTextureSampler& sampler)
|
||||
{
|
||||
m_specularSampler = sampler;
|
||||
}
|
||||
|
||||
void NzMaterial::SetSrcBlend(nzBlendFunc func)
|
||||
{
|
||||
m_states.srcBlend = func;
|
||||
}
|
||||
|
||||
NzMaterial& NzMaterial::operator=(const NzMaterial& material)
|
||||
{
|
||||
Copy(material);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzMaterial& NzMaterial::operator=(NzMaterial&& material)
|
||||
{
|
||||
Copy(material);
|
||||
|
||||
// Comme ça nous volons la référence du matériau
|
||||
material.m_alphaMap.Reset();
|
||||
material.m_diffuseMap.Reset();
|
||||
material.m_emissiveMap.Reset();
|
||||
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();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzMaterial* NzMaterial::GetDefault()
|
||||
{
|
||||
return s_defaultMaterial;
|
||||
}
|
||||
|
||||
void NzMaterial::Copy(const NzMaterial& material)
|
||||
{
|
||||
m_alphaMap.Reset();
|
||||
m_diffuseMap.Reset();
|
||||
m_emissiveMap.Reset();
|
||||
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();
|
||||
|
||||
std::memcpy(this, &material, sizeof(NzMaterial)); // Autorisé dans notre cas, et bien plus rapide
|
||||
|
||||
// Ensuite une petite astuce pour récupérer correctement les références
|
||||
m_alphaMap.Release();
|
||||
m_diffuseMap.Release();
|
||||
m_emissiveMap.Release();
|
||||
m_heightMap.Release();
|
||||
m_normalMap.Release();
|
||||
m_specularMap.Release();
|
||||
|
||||
m_alphaMap = material.m_alphaMap;
|
||||
m_diffuseMap = material.m_diffuseMap;
|
||||
m_emissiveMap = material.m_emissiveMap;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NzMaterial::GenerateProgram(nzShaderTarget target, nzUInt32 flags) const
|
||||
{
|
||||
NzShaderProgramManagerParams params;
|
||||
params.target = target;
|
||||
params.flags = flags;
|
||||
|
||||
switch (target)
|
||||
{
|
||||
case nzShaderTarget_FullscreenQuad:
|
||||
params.fullscreenQuad.alphaMapping = m_alphaMap.IsValid();
|
||||
params.fullscreenQuad.alphaTest = m_alphaTestEnabled;
|
||||
params.fullscreenQuad.diffuseMapping = m_diffuseMap.IsValid();
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
case nzShaderTarget_None:
|
||||
break;
|
||||
|
||||
case nzShaderTarget_Sprite:
|
||||
params.sprite.alphaMapping = m_alphaMap.IsValid();
|
||||
params.sprite.alphaTest = m_alphaTestEnabled;
|
||||
params.sprite.diffuseMapping = m_diffuseMap.IsValid();
|
||||
break;
|
||||
}
|
||||
|
||||
m_programs[target][flags].program = NzShaderProgramManager::Get(params);
|
||||
}
|
||||
|
||||
void NzMaterial::InvalidatePrograms(nzShaderTarget target)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
NzMaterial* NzMaterial::s_defaultMaterial = nullptr;
|
||||
NzMaterialLoader::LoaderList NzMaterial::s_loaders;
|
||||
@@ -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,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,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,
|
||||
@@ -1,226 +0,0 @@
|
||||
#if FLAG_DEFERRED
|
||||
#error Deferred Shading needs core profile
|
||||
#endif
|
||||
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
#define LIGHT_SPOT 2
|
||||
|
||||
/********************Entrant********************/
|
||||
varying mat3 vLightToWorld;
|
||||
varying vec3 vNormal;
|
||||
varying vec2 vTexCoord;
|
||||
varying vec3 vWorldPos;
|
||||
|
||||
/********************Uniformes********************/
|
||||
struct Light
|
||||
{
|
||||
int type;
|
||||
vec4 color;
|
||||
vec2 factors;
|
||||
|
||||
vec4 parameters1;
|
||||
vec4 parameters2;
|
||||
vec2 parameters3;
|
||||
};
|
||||
|
||||
uniform vec3 EyePosition;
|
||||
uniform Light Lights[3];
|
||||
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialAmbient;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
uniform sampler2D MaterialEmissiveMap;
|
||||
uniform sampler2D MaterialNormalMap;
|
||||
uniform float MaterialShininess;
|
||||
uniform vec4 MaterialSpecular;
|
||||
uniform sampler2D MaterialSpecularMap;
|
||||
|
||||
uniform vec4 SceneAmbient;
|
||||
|
||||
/********************Fonctions********************/
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseColor = MaterialDiffuse;
|
||||
#if DIFFUSE_MAPPING
|
||||
diffuseColor *= texture(MaterialDiffuseMap, vTexCoord);
|
||||
#endif
|
||||
|
||||
#if ALPHA_MAPPING
|
||||
diffuseColor.a *= texture(MaterialAlphaMap, vTexCoord).r;
|
||||
#endif
|
||||
|
||||
#if ALPHA_TEST
|
||||
if (diffuseColor.a < MaterialAlphaThreshold)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
vec3 lightAmbient = vec3(0.0);
|
||||
vec3 lightDiffuse = vec3(0.0);
|
||||
vec3 lightSpecular = vec3(0.0);
|
||||
|
||||
#if NORMAL_MAPPING
|
||||
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, vTexCoord)) - 1.0));
|
||||
#else
|
||||
vec3 normal = normalize(vNormal);
|
||||
#endif
|
||||
|
||||
if (MaterialShininess > 0.0)
|
||||
{
|
||||
vec3 eyeVec = normalize(EyePosition - vWorldPos);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (Lights[i].type == LIGHT_DIRECTIONAL)
|
||||
{
|
||||
vec3 lightDir = -Lights[i].parameters1.xyz;
|
||||
|
||||
// Ambient
|
||||
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
|
||||
// Specular
|
||||
vec3 reflection = reflect(-lightDir, normal);
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, MaterialShininess);
|
||||
|
||||
lightSpecular += specularFactor * Lights[i].color.rgb;
|
||||
}
|
||||
else if (Lights[i].type == LIGHT_POINT)
|
||||
{
|
||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength; // Normalisation
|
||||
|
||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
|
||||
// Specular
|
||||
vec3 reflection = reflect(-lightDir, normal);
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, MaterialShininess);
|
||||
|
||||
lightSpecular += att * specularFactor * Lights[i].color.rgb;
|
||||
}
|
||||
else if (Lights[i].type == LIGHT_SPOT)
|
||||
{
|
||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength; // Normalisation
|
||||
|
||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
// Modification de l'atténuation pour gérer le spot
|
||||
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
||||
float outerAngle = Lights[i].parameters3.y;
|
||||
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||
|
||||
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
|
||||
// Specular
|
||||
vec3 reflection = reflect(-lightDir, normal);
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, MaterialShininess);
|
||||
|
||||
lightSpecular += att * specularFactor * Lights[i].color.rgb;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (Lights[i].type == LIGHT_DIRECTIONAL)
|
||||
{
|
||||
vec3 lightDir = -Lights[i].parameters1.xyz;
|
||||
|
||||
// Ambient
|
||||
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
}
|
||||
else if (Lights[i].type == LIGHT_POINT)
|
||||
{
|
||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength; // Normalisation
|
||||
|
||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
}
|
||||
else if (Lights[i].type == LIGHT_SPOT)
|
||||
{
|
||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength; // Normalisation
|
||||
|
||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
// Modification de l'atténuation pour gérer le spot
|
||||
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
||||
float outerAngle = Lights[i].parameters3.y;
|
||||
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||
|
||||
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lightSpecular *= MaterialSpecular.rgb;
|
||||
#if SPECULAR_MAPPING
|
||||
lightSpecular *= texture(MaterialSpecularMap, vTexCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
|
||||
#endif
|
||||
|
||||
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
|
||||
vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor;
|
||||
|
||||
#if EMISSIVE_MAPPING
|
||||
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
|
||||
|
||||
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, vTexCoord).rgb;
|
||||
RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
|
||||
#else
|
||||
RenderTarget0 = fragmentColor;
|
||||
#endif // EMISSIVE_MAPPING
|
||||
#else
|
||||
RenderTarget0 = diffuseColor;
|
||||
#endif // LIGHTING
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,60 +0,0 @@
|
||||
/********************Entrant********************/
|
||||
varying mat4 InstanceData0;
|
||||
varying vec3 VertexPosition;
|
||||
varying vec3 VertexNormal;
|
||||
varying vec3 VertexTangent;
|
||||
varying vec2 VertexTexCoord;
|
||||
|
||||
/********************Sortant********************/
|
||||
varying mat3 vLightToWorld;
|
||||
varying vec3 vNormal;
|
||||
varying vec2 vTexCoord;
|
||||
varying vec3 vWorldPos;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform mat4 ViewProjMatrix;
|
||||
uniform mat4 WorldMatrix;
|
||||
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
|
||||
|
||||
#if LIGHTING
|
||||
#if FLAG_INSTANCING
|
||||
mat3 rotationMatrix = mat3(InstanceData0[0].xyz, InstanceData0[1].xyz, InstanceData0[2].xyz);
|
||||
#else
|
||||
mat3 rotationMatrix = mat3(WorldMatrix[0].xyz, WorldMatrix[1].xyz, WorldMatrix[2].xyz);
|
||||
#endif
|
||||
|
||||
#if NORMAL_MAPPING
|
||||
vec3 binormal = cross(VertexNormal, VertexTangent);
|
||||
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
|
||||
vLightToWorld[1] = normalize(rotationMatrix * binormal);
|
||||
vLightToWorld[2] = normalize(rotationMatrix * VertexNormal);
|
||||
#else
|
||||
vNormal = normalize(rotationMatrix * VertexNormal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING || EMISSIVE_MAPPING || NORMAL_MAPPING || PARALLAX_MAPPING || SPECULAR_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||
#else
|
||||
vTexCoord = VertexTexCoord;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
#if FLAG_INSTANCING
|
||||
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
|
||||
#else
|
||||
vWorldPos = vec3(WorldMatrix * vec4(VertexPosition, 1.0));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,320 +0,0 @@
|
||||
#define LIGHT_DIRECTIONAL 0
|
||||
#define LIGHT_POINT 1
|
||||
#define LIGHT_SPOT 2
|
||||
|
||||
/********************Entrant********************/
|
||||
in mat3 vLightToWorld;
|
||||
in vec3 vNormal;
|
||||
in vec2 vTexCoord;
|
||||
in vec3 vViewDir;
|
||||
in vec3 vWorldPos;
|
||||
|
||||
/********************Sortant********************/
|
||||
out vec4 RenderTarget0;
|
||||
out vec4 RenderTarget1;
|
||||
out vec4 RenderTarget2;
|
||||
|
||||
/********************Uniformes********************/
|
||||
struct Light
|
||||
{
|
||||
int type;
|
||||
vec4 color;
|
||||
vec2 factors;
|
||||
|
||||
vec4 parameters1;
|
||||
vec4 parameters2;
|
||||
vec2 parameters3;
|
||||
};
|
||||
|
||||
uniform vec3 EyePosition;
|
||||
uniform Light Lights[3];
|
||||
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialAmbient;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
uniform sampler2D MaterialEmissiveMap;
|
||||
uniform sampler2D MaterialHeightMap;
|
||||
uniform sampler2D MaterialNormalMap;
|
||||
uniform float MaterialShininess;
|
||||
uniform vec4 MaterialSpecular;
|
||||
uniform sampler2D MaterialSpecularMap;
|
||||
|
||||
uniform float ParallaxBias = -0.03;
|
||||
uniform float ParallaxScale = 0.02;
|
||||
uniform vec4 SceneAmbient;
|
||||
|
||||
/********************Fonctions********************/
|
||||
vec3 FloatToColor(float f)
|
||||
{
|
||||
vec3 color;
|
||||
|
||||
f *= 256.0;
|
||||
color.x = floor(f);
|
||||
|
||||
f = (f - color.x) * 256.0;
|
||||
color.y = floor(f);
|
||||
|
||||
color.z = f - color.y;
|
||||
color.xy *= 0.00390625; // *= 1.0/256
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#define kPI 3.1415926536
|
||||
|
||||
vec4 EncodeNormal(in vec3 normal)
|
||||
{
|
||||
//return vec4(normal*0.5 + 0.5, 0.0);
|
||||
return vec4(vec2(atan(normal.y, normal.x)/kPI, normal.z), 0.0, 0.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseColor = MaterialDiffuse;
|
||||
vec2 texCoord = vTexCoord;
|
||||
#if LIGHTING && PARALLAX_MAPPING
|
||||
float height = texture(MaterialHeightMap, texCoord).r;
|
||||
float v = height*ParallaxScale + ParallaxBias;
|
||||
|
||||
vec3 viewDir = normalize(vViewDir);
|
||||
texCoord += v * viewDir.xy;
|
||||
#endif
|
||||
|
||||
#if DIFFUSE_MAPPING
|
||||
diffuseColor *= texture(MaterialDiffuseMap, texCoord);
|
||||
#endif
|
||||
|
||||
#if FLAG_DEFERRED
|
||||
#if ALPHA_TEST
|
||||
#if ALPHA_MAPPING // Inutile de faire de l'alpha-mapping sans alpha-test en Deferred (l'alpha n'est pas sauvegardé)
|
||||
diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r;
|
||||
#endif
|
||||
|
||||
if (diffuseColor.a < MaterialAlphaThreshold)
|
||||
discard;
|
||||
#endif // ALPHA_TEST
|
||||
|
||||
#if LIGHTING
|
||||
#if NORMAL_MAPPING
|
||||
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0));
|
||||
#else
|
||||
vec3 normal = normalize(vNormal);
|
||||
#endif // NORMAL_MAPPING
|
||||
|
||||
vec3 specularColor = MaterialSpecular.rgb;
|
||||
#if SPECULAR_MAPPING
|
||||
specularColor *= texture(MaterialSpecularMap, texCoord).rgb;
|
||||
#endif
|
||||
|
||||
/*
|
||||
Texture0: Diffuse Color + Specular
|
||||
Texture1: Normal + Specular
|
||||
Texture2: Encoded depth + Shininess
|
||||
*/
|
||||
RenderTarget0 = vec4(diffuseColor.rgb, dot(specularColor, vec3(0.3, 0.59, 0.11)));
|
||||
RenderTarget1 = vec4(EncodeNormal(normal));
|
||||
RenderTarget2 = vec4(FloatToColor(gl_FragCoord.z), (MaterialShininess == 0.0) ? 0.0 : max(log2(MaterialShininess), 0.1)/10.5); // http://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf
|
||||
#else // LIGHTING
|
||||
RenderTarget0 = vec4(diffuseColor.rgb, 0.0);
|
||||
#endif
|
||||
#else // FLAG_DEFERRED
|
||||
#if ALPHA_MAPPING
|
||||
diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r;
|
||||
#endif
|
||||
|
||||
#if ALPHA_TEST
|
||||
if (diffuseColor.a < MaterialAlphaThreshold)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
#if LIGHTING
|
||||
vec3 lightAmbient = vec3(0.0);
|
||||
vec3 lightDiffuse = vec3(0.0);
|
||||
vec3 lightSpecular = vec3(0.0);
|
||||
|
||||
#if NORMAL_MAPPING
|
||||
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0));
|
||||
#else
|
||||
vec3 normal = normalize(vNormal);
|
||||
#endif
|
||||
|
||||
if (MaterialShininess > 0.0)
|
||||
{
|
||||
vec3 eyeVec = normalize(EyePosition - vWorldPos);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
switch (Lights[i].type)
|
||||
{
|
||||
case LIGHT_DIRECTIONAL:
|
||||
{
|
||||
vec3 lightDir = -Lights[i].parameters1.xyz;
|
||||
|
||||
// Ambient
|
||||
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
|
||||
// Specular
|
||||
vec3 reflection = reflect(-lightDir, normal);
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, MaterialShininess);
|
||||
|
||||
lightSpecular += specularFactor * Lights[i].color.rgb;
|
||||
break;
|
||||
}
|
||||
|
||||
case LIGHT_POINT:
|
||||
{
|
||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength; // Normalisation
|
||||
|
||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
|
||||
// Specular
|
||||
vec3 reflection = reflect(-lightDir, normal);
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, MaterialShininess);
|
||||
|
||||
lightSpecular += att * specularFactor * Lights[i].color.rgb;
|
||||
break;
|
||||
}
|
||||
|
||||
case LIGHT_SPOT:
|
||||
{
|
||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength; // Normalisation
|
||||
|
||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Modification de l'atténuation pour gérer le spot
|
||||
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
||||
float outerAngle = Lights[i].parameters3.y;
|
||||
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
|
||||
// Specular
|
||||
vec3 reflection = reflect(-lightDir, normal);
|
||||
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||
specularFactor = pow(specularFactor, MaterialShininess);
|
||||
|
||||
lightSpecular += att * specularFactor * Lights[i].color.rgb;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
switch (Lights[i].type)
|
||||
{
|
||||
case LIGHT_DIRECTIONAL:
|
||||
{
|
||||
vec3 lightDir = normalize(-Lights[i].parameters1.xyz);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
break;
|
||||
}
|
||||
|
||||
case LIGHT_POINT:
|
||||
{
|
||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength; // Normalisation
|
||||
|
||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
break;
|
||||
}
|
||||
|
||||
case LIGHT_SPOT:
|
||||
{
|
||||
vec3 lightDir = Lights[i].parameters1.xyz - vWorldPos;
|
||||
float lightDirLength = length(lightDir);
|
||||
lightDir /= lightDirLength; // Normalisation
|
||||
|
||||
float att = max(Lights[i].parameters1.w - Lights[i].parameters2.w*lightDirLength, 0.0);
|
||||
|
||||
// Ambient
|
||||
lightAmbient += att * Lights[i].color.rgb * Lights[i].factors.x * (MaterialAmbient.rgb + SceneAmbient.rgb);
|
||||
|
||||
// Modification de l'atténuation pour gérer le spot
|
||||
float curAngle = dot(Lights[i].parameters2.xyz, -lightDir);
|
||||
float outerAngle = Lights[i].parameters3.y;
|
||||
float innerMinusOuterAngle = Lights[i].parameters3.x - outerAngle;
|
||||
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||
|
||||
// Diffuse
|
||||
float lambert = max(dot(normal, lightDir), 0.0);
|
||||
|
||||
lightDiffuse += att * lambert * Lights[i].color.rgb * Lights[i].factors.y;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lightSpecular *= MaterialSpecular.rgb;
|
||||
#if SPECULAR_MAPPING
|
||||
lightSpecular *= texture(MaterialSpecularMap, texCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
|
||||
#endif
|
||||
|
||||
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
|
||||
vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor;
|
||||
|
||||
#if EMISSIVE_MAPPING
|
||||
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
|
||||
|
||||
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, texCoord).rgb;
|
||||
RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
|
||||
#else
|
||||
RenderTarget0 = fragmentColor;
|
||||
#endif // EMISSIVE_MAPPING
|
||||
#else
|
||||
RenderTarget0 = diffuseColor;
|
||||
#endif // LIGHTING
|
||||
#endif // FLAG_DEFERRED
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,67 +0,0 @@
|
||||
/********************Entrant********************/
|
||||
in mat4 InstanceData0;
|
||||
in vec3 VertexPosition;
|
||||
in vec3 VertexNormal;
|
||||
in vec3 VertexTangent;
|
||||
in vec2 VertexTexCoord;
|
||||
|
||||
/********************Sortant********************/
|
||||
out mat3 vLightToWorld;
|
||||
out vec3 vNormal;
|
||||
out vec2 vTexCoord;
|
||||
out vec3 vViewDir;
|
||||
out vec3 vWorldPos;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform vec3 EyePosition;
|
||||
uniform mat4 ViewProjMatrix;
|
||||
uniform mat4 WorldMatrix;
|
||||
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
|
||||
|
||||
#if LIGHTING
|
||||
#if FLAG_INSTANCING
|
||||
mat3 rotationMatrix = mat3(InstanceData0);
|
||||
#else
|
||||
mat3 rotationMatrix = mat3(WorldMatrix);
|
||||
#endif
|
||||
|
||||
#if NORMAL_MAPPING || PARALLAX_MAPPING
|
||||
vec3 binormal = cross(VertexNormal, VertexTangent);
|
||||
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
|
||||
vLightToWorld[1] = normalize(rotationMatrix * binormal);
|
||||
vLightToWorld[2] = normalize(rotationMatrix * VertexNormal);
|
||||
#else
|
||||
vNormal = normalize(rotationMatrix * VertexNormal);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING || EMISSIVE_MAPPING || NORMAL_MAPPING || PARALLAX_MAPPING || SPECULAR_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||
#else
|
||||
vTexCoord = VertexTexCoord;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#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
|
||||
vWorldPos = vec3(WorldMatrix * vec4(VertexPosition, 1.0));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
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,33 +0,0 @@
|
||||
/********************Entrant********************/
|
||||
varying mat4 InstanceData0;
|
||||
varying vec3 VertexPosition;
|
||||
varying vec2 VertexTexCoord;
|
||||
|
||||
/********************Sortant********************/
|
||||
varying vec2 vTexCoord;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
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
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||
#else
|
||||
vTexCoord = vec2(VertexTexCoord);
|
||||
#endif // FLAG_FLIP_UVS
|
||||
#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,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,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,33 +0,0 @@
|
||||
/********************Entrant********************/
|
||||
in mat4 InstanceData0;
|
||||
in vec3 VertexPosition;
|
||||
in vec2 VertexTexCoord;
|
||||
|
||||
/********************Sortant********************/
|
||||
out vec2 vTexCoord;
|
||||
|
||||
/********************Uniformes********************/
|
||||
uniform sampler2D MaterialAlphaMap;
|
||||
uniform float MaterialAlphaThreshold;
|
||||
uniform vec4 MaterialDiffuse;
|
||||
uniform sampler2D MaterialDiffuseMap;
|
||||
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
|
||||
|
||||
#if ALPHA_MAPPING || DIFFUSE_MAPPING
|
||||
#if FLAG_FLIP_UVS
|
||||
vTexCoord = vec2(VertexTexCoord.x, 1.0 - VertexTexCoord.y);
|
||||
#else
|
||||
vTexCoord = vec2(VertexTexCoord);
|
||||
#endif // FLAG_FLIP_UVS
|
||||
#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,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;
|
||||
}
|
||||
Reference in New Issue
Block a user