Added Deferred Shading
Former-commit-id: 926022d6306144e2f87cd293291928bda44c7a87
This commit is contained in:
parent
d363e29e15
commit
b7b65d7119
|
|
@ -0,0 +1,89 @@
|
||||||
|
// Copyright (C) 2013 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_DEFERREDRENDERQUEUE_HPP
|
||||||
|
#define NAZARA_DEFERREDRENDERQUEUE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/Color.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListener.hpp>
|
||||||
|
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||||
|
#include <Nazara/Math/Box.hpp>
|
||||||
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
#include <map>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
class NzForwardRenderQueue;
|
||||||
|
class NzMaterial;
|
||||||
|
class NzSkeletalMesh;
|
||||||
|
class NzStaticMesh;
|
||||||
|
|
||||||
|
class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourceListener
|
||||||
|
{
|
||||||
|
friend class NzDeferredRenderTechnique;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NzDeferredRenderQueue(NzForwardRenderQueue* forwardQueue);
|
||||||
|
~NzDeferredRenderQueue();
|
||||||
|
|
||||||
|
void AddDrawable(const NzDrawable* drawable);
|
||||||
|
void AddLight(const NzLight* light);
|
||||||
|
void AddModel(const NzModel* model);
|
||||||
|
void AddSprite(const NzSprite* sprite);
|
||||||
|
void AddSubMesh(const NzMaterial* material, const NzSubMesh* subMesh, const NzMatrix4f& transformMatrix);
|
||||||
|
|
||||||
|
void Clear(bool fully);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool OnResourceDestroy(const NzResource* resource, int index) override;
|
||||||
|
void OnResourceReleased(const NzResource* resource, int index) override;
|
||||||
|
|
||||||
|
struct SkeletalData
|
||||||
|
{
|
||||||
|
///TODO
|
||||||
|
NzMatrix4f transformMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct StaticData
|
||||||
|
{
|
||||||
|
NzMatrix4f transformMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BatchedModelMaterialComparator
|
||||||
|
{
|
||||||
|
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BatchedSpriteMaterialComparator
|
||||||
|
{
|
||||||
|
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BatchedSkeletalMeshComparator
|
||||||
|
{
|
||||||
|
bool operator()(const NzSkeletalMesh* subMesh1, const NzSkeletalMesh* subMesh2);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BatchedStaticMeshComparator
|
||||||
|
{
|
||||||
|
bool operator()(const NzStaticMesh* subMesh1, const NzStaticMesh* subMesh2);
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<const NzSkeletalMesh*, std::vector<SkeletalData>, BatchedSkeletalMeshComparator> BatchedSkeletalMeshContainer;
|
||||||
|
typedef std::map<const NzStaticMesh*, std::vector<StaticData>, BatchedStaticMeshComparator> BatchedStaticMeshContainer;
|
||||||
|
typedef std::map<const NzMaterial*, std::tuple<bool, bool, BatchedSkeletalMeshContainer, BatchedStaticMeshContainer>, BatchedModelMaterialComparator> BatchedModelContainer;
|
||||||
|
typedef std::map<const NzMaterial*, std::vector<const NzSprite*>> BatchedSpriteContainer;
|
||||||
|
typedef std::vector<const NzLight*> LightContainer;
|
||||||
|
|
||||||
|
BatchedModelContainer opaqueModels;
|
||||||
|
BatchedSpriteContainer sprites;
|
||||||
|
LightContainer directionalLights;
|
||||||
|
LightContainer pointLights;
|
||||||
|
LightContainer spotLights;
|
||||||
|
NzForwardRenderQueue* m_forwardQueue;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_DEFERREDRENDERQUEUE_HPP
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
// Copyright (C) 2013 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_DEFERREDRENDERTECHNIQUE_HPP
|
||||||
|
#define NAZARA_DEFERREDRENDERTECHNIQUE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Graphics/AbstractRenderTechnique.hpp>
|
||||||
|
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
|
||||||
|
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderStates.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderProgram.hpp>
|
||||||
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
|
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||||
|
#include <Nazara/Utility/Mesh.hpp>
|
||||||
|
|
||||||
|
class NAZARA_API NzDeferredRenderTechnique : public NzAbstractRenderTechnique, public NzRenderTarget::Listener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzDeferredRenderTechnique();
|
||||||
|
~NzDeferredRenderTechnique();
|
||||||
|
|
||||||
|
void Clear(const NzScene* scene);
|
||||||
|
bool Draw(const NzScene* scene);
|
||||||
|
|
||||||
|
NzTexture* GetGBuffer(unsigned int i) const;
|
||||||
|
NzAbstractRenderQueue* GetRenderQueue() override;
|
||||||
|
nzRenderTechniqueType GetType() const override;
|
||||||
|
NzTexture* GetWorkTexture(unsigned int i) const;
|
||||||
|
|
||||||
|
static bool IsSupported();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void GeomPass(const NzScene* scene);
|
||||||
|
void DirectionalLightPass(const NzScene* scene);
|
||||||
|
void PointLightPass(const NzScene* scene);
|
||||||
|
void SpotLightPass(const NzScene* scene);
|
||||||
|
bool UpdateTextures() const;
|
||||||
|
|
||||||
|
NzForwardRenderTechnique m_forwardTechnique; // Doit être initialisé avant la RenderQueue
|
||||||
|
NzDeferredRenderQueue m_renderQueue;
|
||||||
|
NzMeshRef m_sphere;
|
||||||
|
NzStaticMesh* m_sphereMesh;
|
||||||
|
mutable NzRenderTexture m_bloomRTT;
|
||||||
|
mutable NzRenderTexture m_dofRTT;
|
||||||
|
mutable NzRenderTexture m_geometryRTT;
|
||||||
|
mutable NzRenderTexture m_ssaoRTT;
|
||||||
|
NzRenderStates m_clearStates;
|
||||||
|
NzShaderProgramRef m_aaProgram;
|
||||||
|
NzShaderProgramRef m_blitProgram;
|
||||||
|
NzShaderProgramRef m_bloomBrightProgram;
|
||||||
|
NzShaderProgramRef m_bloomFinalProgram;
|
||||||
|
NzShaderProgramRef m_clearProgram;
|
||||||
|
NzShaderProgramRef m_directionalLightProgram;
|
||||||
|
NzShaderProgramRef m_depthOfFieldProgram;
|
||||||
|
NzShaderProgramRef m_gaussianBlurProgram;
|
||||||
|
NzShaderProgramRef m_pointLightProgram;
|
||||||
|
NzShaderProgramRef m_ssaoProgram;
|
||||||
|
NzShaderProgramRef m_ssaoFinalProgram;
|
||||||
|
NzShaderProgramRef m_spotLightProgram;
|
||||||
|
mutable NzTextureRef m_bloomTextureA;
|
||||||
|
mutable NzTextureRef m_bloomTextureB;
|
||||||
|
mutable NzTextureRef m_dofTextureA;
|
||||||
|
mutable NzTextureRef m_dofTextureB;
|
||||||
|
mutable NzTextureRef m_GBuffer[4];
|
||||||
|
mutable NzTextureRef m_ssaoTextureA;
|
||||||
|
mutable NzTextureRef m_ssaoTextureB;
|
||||||
|
mutable NzTextureRef m_ssaoNoiseTexture;
|
||||||
|
mutable NzTextureRef m_workTextureA;
|
||||||
|
mutable NzTextureRef m_workTextureB;
|
||||||
|
NzTextureSampler m_bilinearSampler;
|
||||||
|
NzTextureSampler m_pointSampler;
|
||||||
|
NzTextureSampler m_ssaoSampler;
|
||||||
|
NzVector2ui m_GBufferSize;
|
||||||
|
const NzRenderTarget* m_viewerTarget;
|
||||||
|
mutable bool m_texturesUpdated;
|
||||||
|
int m_gaussianBlurProgramFilterLocation;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_FORWARDRENDERTECHNIQUE_HPP
|
||||||
|
|
@ -0,0 +1,334 @@
|
||||||
|
// Copyright (C) 2013 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
|
||||||
|
#include <Nazara/Graphics/Camera.hpp>
|
||||||
|
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
||||||
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
|
#include <Nazara/Renderer/Material.hpp>
|
||||||
|
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||||
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
enum ResourceType
|
||||||
|
{
|
||||||
|
ResourceType_Material,
|
||||||
|
ResourceType_SkeletalMesh,
|
||||||
|
ResourceType_StaticMesh
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
NzDeferredRenderQueue::NzDeferredRenderQueue(NzForwardRenderQueue* forwardQueue) :
|
||||||
|
m_forwardQueue(forwardQueue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NzDeferredRenderQueue::~NzDeferredRenderQueue()
|
||||||
|
{
|
||||||
|
Clear(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzDeferredRenderQueue::AddDrawable(const NzDrawable* drawable)
|
||||||
|
{
|
||||||
|
m_forwardQueue->AddDrawable(drawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzDeferredRenderQueue::AddLight(const NzLight* light)
|
||||||
|
{
|
||||||
|
#if NAZARA_GRAPHICS_SAFE
|
||||||
|
if (!light)
|
||||||
|
{
|
||||||
|
NazaraError("Invalid light");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (light->GetLightType())
|
||||||
|
{
|
||||||
|
case nzLightType_Directional:
|
||||||
|
directionalLights.push_back(light);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case nzLightType_Point:
|
||||||
|
pointLights.push_back(light);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case nzLightType_Spot:
|
||||||
|
spotLights.push_back(light);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_forwardQueue->AddLight(light);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzDeferredRenderQueue::AddModel(const NzModel* model)
|
||||||
|
{
|
||||||
|
#if NAZARA_GRAPHICS_SAFE
|
||||||
|
if (!model)
|
||||||
|
{
|
||||||
|
NazaraError("Invalid model");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!model->IsDrawable())
|
||||||
|
{
|
||||||
|
NazaraError("Model is not drawable");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const NzMatrix4f& transformMatrix = model->GetTransformMatrix();
|
||||||
|
|
||||||
|
NzMesh* mesh = model->GetMesh();
|
||||||
|
unsigned int submeshCount = mesh->GetSubMeshCount();
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < submeshCount; ++i)
|
||||||
|
{
|
||||||
|
NzSubMesh* subMesh = mesh->GetSubMesh(i);
|
||||||
|
NzMaterial* material = model->GetMaterial(subMesh->GetMaterialIndex());
|
||||||
|
|
||||||
|
AddSubMesh(material, subMesh, transformMatrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzDeferredRenderQueue::AddSprite(const NzSprite* sprite)
|
||||||
|
{
|
||||||
|
#if NAZARA_GRAPHICS_SAFE
|
||||||
|
if (!sprite)
|
||||||
|
{
|
||||||
|
NazaraError("Invalid sprite");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sprite->IsDrawable())
|
||||||
|
{
|
||||||
|
NazaraError("Sprite is not drawable");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NzMaterial* material = sprite->GetMaterial();
|
||||||
|
if (material->IsEnabled(nzRendererParameter_Blend))
|
||||||
|
m_forwardQueue->AddSprite(sprite);
|
||||||
|
else
|
||||||
|
sprites[material].push_back(sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzDeferredRenderQueue::AddSubMesh(const NzMaterial* material, const NzSubMesh* subMesh, const NzMatrix4f& transformMatrix)
|
||||||
|
{
|
||||||
|
switch (subMesh->GetAnimationType())
|
||||||
|
{
|
||||||
|
case nzAnimationType_Skeletal:
|
||||||
|
{
|
||||||
|
///TODO
|
||||||
|
/*
|
||||||
|
** Il y a ici deux choses importantes à gérer:
|
||||||
|
** -Pour commencer, la mise en cache de std::vector suffisamment grands pour contenir le résultat du skinning
|
||||||
|
** l'objectif ici est d'éviter une allocation à chaque frame, donc de réutiliser un tableau existant
|
||||||
|
** Note: Il faudrait évaluer aussi la possibilité de conserver le buffer d'une frame à l'autre.
|
||||||
|
** Ceci permettant de ne pas skinner inutilement ce qui ne bouge pas, ou de skinner partiellement un mesh.
|
||||||
|
** Il faut cependant voir où stocker ce set de buffers, qui doit être communs à toutes les RQ d'une même scène.
|
||||||
|
**
|
||||||
|
** -Ensuite, la possibilité de regrouper les modèles skinnés identiques, une centaine de soldats marchant au pas
|
||||||
|
** ne devrait requérir qu'un skinning.
|
||||||
|
*/
|
||||||
|
NazaraError("Skeletal mesh not supported yet, sorry");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case nzAnimationType_Static:
|
||||||
|
{
|
||||||
|
if (material->IsEnabled(nzRendererParameter_Blend))
|
||||||
|
m_forwardQueue->AddSubMesh(material, subMesh, transformMatrix);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const NzStaticMesh* staticMesh = static_cast<const NzStaticMesh*>(subMesh);
|
||||||
|
|
||||||
|
auto pair = opaqueModels.insert(std::make_pair(material, BatchedModelContainer::mapped_type()));
|
||||||
|
if (pair.second)
|
||||||
|
material->AddResourceListener(this, ResourceType_Material);
|
||||||
|
|
||||||
|
bool& used = std::get<0>(pair.first->second);
|
||||||
|
bool& enableInstancing = std::get<1>(pair.first->second);
|
||||||
|
|
||||||
|
used = true;
|
||||||
|
|
||||||
|
auto& meshMap = std::get<3>(pair.first->second);
|
||||||
|
|
||||||
|
auto pair2 = meshMap.insert(std::make_pair(staticMesh, BatchedStaticMeshContainer::mapped_type()));
|
||||||
|
if (pair2.second)
|
||||||
|
staticMesh->AddResourceListener(this, ResourceType_StaticMesh);
|
||||||
|
|
||||||
|
std::vector<StaticData>& staticDataContainer = pair2.first->second;
|
||||||
|
|
||||||
|
unsigned int instanceCount = staticDataContainer.size() + 1;
|
||||||
|
|
||||||
|
// Avons-nous suffisamment d'instances pour que le coût d'utilisation de l'instancing soit payé ?
|
||||||
|
if (instanceCount >= NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT)
|
||||||
|
enableInstancing = true; // Apparemment oui, activons l'instancing avec ce matériau
|
||||||
|
|
||||||
|
staticDataContainer.resize(instanceCount);
|
||||||
|
StaticData& data = staticDataContainer.back();
|
||||||
|
data.transformMatrix = transformMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzDeferredRenderQueue::Clear(bool fully)
|
||||||
|
{
|
||||||
|
directionalLights.clear();
|
||||||
|
pointLights.clear();
|
||||||
|
spotLights.clear();
|
||||||
|
|
||||||
|
if (fully)
|
||||||
|
{
|
||||||
|
for (auto& matIt : opaqueModels)
|
||||||
|
{
|
||||||
|
const NzMaterial* material = matIt.first;
|
||||||
|
material->RemoveResourceListener(this);
|
||||||
|
|
||||||
|
BatchedSkeletalMeshContainer& skeletalContainer = std::get<2>(matIt.second);
|
||||||
|
for (auto& meshIt : skeletalContainer)
|
||||||
|
{
|
||||||
|
const NzSkeletalMesh* skeletalMesh = meshIt.first;
|
||||||
|
skeletalMesh->RemoveResourceListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
BatchedStaticMeshContainer& staticContainer = std::get<3>(matIt.second);
|
||||||
|
for (auto& meshIt : staticContainer)
|
||||||
|
{
|
||||||
|
const NzStaticMesh* staticMesh = meshIt.first;
|
||||||
|
staticMesh->RemoveResourceListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
opaqueModels.clear();
|
||||||
|
sprites.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_forwardQueue->Clear(fully);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NzDeferredRenderQueue::OnResourceDestroy(const NzResource* resource, int index)
|
||||||
|
{
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case ResourceType_Material:
|
||||||
|
opaqueModels.erase(static_cast<const NzMaterial*>(resource));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ResourceType_SkeletalMesh:
|
||||||
|
{
|
||||||
|
for (auto& pair : opaqueModels)
|
||||||
|
std::get<2>(pair.second).erase(static_cast<const NzSkeletalMesh*>(resource));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ResourceType_StaticMesh:
|
||||||
|
{
|
||||||
|
for (auto& pair : opaqueModels)
|
||||||
|
std::get<3>(pair.second).erase(static_cast<const NzStaticMesh*>(resource));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // Nous ne voulons plus recevoir d'évènement de cette ressource
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzDeferredRenderQueue::OnResourceReleased(const NzResource* resource, int index)
|
||||||
|
{
|
||||||
|
OnResourceDestroy(resource, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NzDeferredRenderQueue::BatchedModelMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
||||||
|
{
|
||||||
|
nzUInt32 possibleFlags[] = {
|
||||||
|
nzShaderFlags_Deferred,
|
||||||
|
nzShaderFlags_Deferred | nzShaderFlags_Instancing
|
||||||
|
};
|
||||||
|
|
||||||
|
for (nzUInt32 flag : possibleFlags)
|
||||||
|
{
|
||||||
|
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||||
|
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||||
|
|
||||||
|
if (program1 != program2)
|
||||||
|
return program1 < program2;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
||||||
|
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
||||||
|
if (diffuseMap1 != diffuseMap2)
|
||||||
|
return diffuseMap1 < diffuseMap2;
|
||||||
|
|
||||||
|
return mat1 < mat2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NzDeferredRenderQueue::BatchedSpriteMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
||||||
|
{
|
||||||
|
nzUInt32 possibleFlags[] = {
|
||||||
|
nzShaderFlags_Deferred
|
||||||
|
};
|
||||||
|
|
||||||
|
for (nzUInt32 flag : possibleFlags)
|
||||||
|
{
|
||||||
|
const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||||
|
const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, flag);
|
||||||
|
|
||||||
|
if (program1 != program2)
|
||||||
|
return program1 < program2;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
||||||
|
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
||||||
|
if (diffuseMap1 != diffuseMap2)
|
||||||
|
return diffuseMap1 < diffuseMap2;
|
||||||
|
|
||||||
|
return mat1 < mat2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NzDeferredRenderQueue::BatchedSkeletalMeshComparator::operator()(const NzSkeletalMesh* subMesh1, const NzSkeletalMesh* subMesh2)
|
||||||
|
{
|
||||||
|
const NzIndexBuffer* iBuffer1 = subMesh1->GetIndexBuffer();
|
||||||
|
const NzBuffer* buffer1 = (iBuffer1) ? iBuffer1->GetBuffer() : nullptr;
|
||||||
|
|
||||||
|
const NzIndexBuffer* iBuffer2 = subMesh1->GetIndexBuffer();
|
||||||
|
const NzBuffer* buffer2 = (iBuffer2) ? iBuffer2->GetBuffer() : nullptr;
|
||||||
|
|
||||||
|
if (buffer1 == buffer2)
|
||||||
|
return subMesh1 < subMesh2;
|
||||||
|
else
|
||||||
|
return buffer2 < buffer2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NzDeferredRenderQueue::BatchedStaticMeshComparator::operator()(const NzStaticMesh* subMesh1, const NzStaticMesh* subMesh2)
|
||||||
|
{
|
||||||
|
const NzIndexBuffer* iBuffer1 = subMesh1->GetIndexBuffer();
|
||||||
|
const NzBuffer* buffer1 = (iBuffer1) ? iBuffer1->GetBuffer() : nullptr;
|
||||||
|
|
||||||
|
const NzIndexBuffer* iBuffer2 = subMesh2->GetIndexBuffer();
|
||||||
|
const NzBuffer* buffer2 = (iBuffer2) ? iBuffer2->GetBuffer() : nullptr;
|
||||||
|
|
||||||
|
if (buffer1 == buffer2)
|
||||||
|
{
|
||||||
|
buffer1 = subMesh1->GetVertexBuffer()->GetBuffer();
|
||||||
|
buffer2 = subMesh2->GetVertexBuffer()->GetBuffer();
|
||||||
|
|
||||||
|
if (buffer1 == buffer2)
|
||||||
|
return subMesh1 < subMesh2;
|
||||||
|
else
|
||||||
|
return buffer1 < buffer2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return buffer1 < buffer2;
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -6,6 +6,7 @@
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Core/Log.hpp>
|
#include <Nazara/Core/Log.hpp>
|
||||||
#include <Nazara/Graphics/Config.hpp>
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
|
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
|
||||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||||
#include <Nazara/Graphics/RenderTechniques.hpp>
|
#include <Nazara/Graphics/RenderTechniques.hpp>
|
||||||
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
#include <Nazara/Graphics/Loaders/Mesh.hpp>
|
||||||
|
|
@ -38,6 +39,9 @@ bool NzGraphics::Initialize()
|
||||||
// RenderTechniques
|
// RenderTechniques
|
||||||
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_BasicForward), 0, []() -> NzAbstractRenderTechnique* { return new NzForwardRenderTechnique; });
|
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_BasicForward), 0, []() -> NzAbstractRenderTechnique* { return new NzForwardRenderTechnique; });
|
||||||
|
|
||||||
|
if (NzDeferredRenderTechnique::IsSupported())
|
||||||
|
NzRenderTechniques::Register(NzRenderTechniques::ToString(nzRenderTechniqueType_DeferredShading), 20, []() -> NzAbstractRenderTechnique* { return new NzDeferredRenderTechnique; });
|
||||||
|
|
||||||
NazaraNotice("Initialized: Graphics module");
|
NazaraNotice("Initialized: Graphics module");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
uniform sampler2D ColorTexture;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
RenderTarget0 = textureLod(ColorTexture, texCoord, 0.0);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,59,13,10,125,13,10,
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
uniform float BrightLuminance = 0.8;
|
||||||
|
uniform float BrightMiddleGrey = 0.5;
|
||||||
|
uniform float BrightThreshold = 0.8;
|
||||||
|
uniform sampler2D ColorTexture;
|
||||||
|
uniform sampler2D BloomTexture;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
|
||||||
|
vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb;
|
||||||
|
|
||||||
|
color *= BrightMiddleGrey/BrightLuminance;
|
||||||
|
color *= 1.0 + (color / (BrightThreshold*BrightThreshold));
|
||||||
|
color -= 0.5;
|
||||||
|
color /= (1.0 + color);
|
||||||
|
|
||||||
|
RenderTarget0 = vec4(color, 1.0);
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,76,117,109,105,110,97,110,99,101,32,61,32,48,46,56,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,77,105,100,100,108,101,71,114,101,121,32,61,32,48,46,53,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,32,61,32,48,46,56,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,66,108,111,111,109,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,13,10,9,99,111,108,111,114,32,42,61,32,66,114,105,103,104,116,77,105,100,100,108,101,71,114,101,121,47,66,114,105,103,104,116,76,117,109,105,110,97,110,99,101,59,13,10,9,99,111,108,111,114,32,42,61,32,49,46,48,32,43,32,40,99,111,108,111,114,32,47,32,40,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,42,66,114,105,103,104,116,84,104,114,101,115,104,111,108,100,41,41,59,13,10,9,99,111,108,111,114,32,45,61,32,48,46,53,59,13,10,9,99,111,108,111,114,32,47,61,32,40,49,46,48,32,43,32,99,111,108,111,114,41,59,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,44,32,49,46,48,41,59,13,10,125,59,13,10,
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
uniform sampler2D BloomTexture;
|
||||||
|
uniform sampler2D ColorTexture;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
|
||||||
|
vec3 bloomColor = textureLod(BloomTexture, texCoord, 0.0).rgb;
|
||||||
|
vec3 originalColor = textureLod(ColorTexture, texCoord, 0.0).rgb;
|
||||||
|
|
||||||
|
RenderTarget0 = vec4(originalColor + bloomColor, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,66,108,111,111,109,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,9,118,101,99,51,32,98,108,111,111,109,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,66,108,111,111,109,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,9,118,101,99,51,32,111,114,105,103,105,110,97,108,67,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,111,114,105,103,105,110,97,108,67,111,108,111,114,32,43,32,98,108,111,111,109,67,111,108,111,114,44,32,49,46,48,41,59,13,10,125,13,10,
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
out vec4 RenderTarget1;
|
||||||
|
out vec4 RenderTarget2;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
RenderTarget0 = vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
|
RenderTarget1 = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
RenderTarget2 = vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
|
gl_FragDepth = 1.0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,49,59,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,50,59,13,10,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,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,49,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,49,46,48,41,59,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,50,32,61,32,118,101,99,52,40,48,46,48,44,32,48,46,48,44,32,48,46,48,44,32,48,46,48,41,59,13,10,9,103,108,95,70,114,97,103,68,101,112,116,104,32,61,32,49,46,48,59,13,10,125,13,10,
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
struct Light
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
vec4 ambient;
|
||||||
|
vec4 color;
|
||||||
|
vec2 factors;
|
||||||
|
|
||||||
|
vec4 parameters1;
|
||||||
|
vec4 parameters2;
|
||||||
|
vec2 parameters3;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform vec3 EyePosition;
|
||||||
|
uniform Light Lights[1];
|
||||||
|
|
||||||
|
uniform sampler2D GBuffer0;
|
||||||
|
uniform sampler2D GBuffer1;
|
||||||
|
uniform sampler2D GBuffer2;
|
||||||
|
|
||||||
|
uniform mat4 InvViewProjMatrix;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
uniform vec4 SceneAmbient;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0);
|
||||||
|
if (gVec0.w == 0.0)
|
||||||
|
{
|
||||||
|
RenderTarget0 = vec4(gVec0.xyz, 1.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
|
||||||
|
vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);
|
||||||
|
|
||||||
|
vec3 diffuseColor = gVec0.xyz;
|
||||||
|
vec3 normal = gVec1.xyz*2.0 - 1.0;
|
||||||
|
vec3 specularColor = gVec2.xyz;
|
||||||
|
float depth = gVec1.w*2.0 - 1.0;
|
||||||
|
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
||||||
|
|
||||||
|
vec3 lightDir = -Lights[0].parameters1.xyz;
|
||||||
|
|
||||||
|
// Ambient
|
||||||
|
vec3 lightAmbient = Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
|
||||||
|
|
||||||
|
// Diffuse
|
||||||
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
|
vec3 lightDiffuse = lambert * Lights[0].color.rgb * Lights[0].factors.y;
|
||||||
|
|
||||||
|
// Specular
|
||||||
|
vec3 lightSpecular = vec3(0.0);
|
||||||
|
if (shininess > 0.0)
|
||||||
|
{
|
||||||
|
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
|
||||||
|
|
||||||
|
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||||
|
worldPos.xyz /= worldPos.w;
|
||||||
|
|
||||||
|
vec3 eyeVec = normalize(EyePosition - worldPos.xyz);
|
||||||
|
|
||||||
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, shininess);
|
||||||
|
|
||||||
|
lightSpecular = specularFactor * Lights[0].color.rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
lightSpecular *= specularColor;
|
||||||
|
|
||||||
|
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
|
||||||
|
vec4 fragmentColor = vec4(lightColor * diffuseColor, 1.0);
|
||||||
|
|
||||||
|
RenderTarget0 = fragmentColor;
|
||||||
|
};
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,47 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
uniform float FXAAReduceMul = 0.0; // 1.0/8.0
|
||||||
|
uniform float FXAASpanMax = 8.0;
|
||||||
|
uniform sampler2D ColorTexture;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
#define FXAA_REDUCE_MIN (1.0/128.0)
|
||||||
|
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
|
||||||
|
vec3 rgbNW = textureLod(ColorTexture, texCoord, 0.0).rgb;
|
||||||
|
vec3 rgbNE = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(1,0)).rgb;
|
||||||
|
vec3 rgbSW = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(0,1)).rgb;
|
||||||
|
vec3 rgbSE = textureLodOffset(ColorTexture, texCoord, 0.0, ivec2(1,1)).rgb;
|
||||||
|
vec3 rgbM = textureLod(ColorTexture, texCoord, 0.0).rgb;
|
||||||
|
|
||||||
|
vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||||
|
float lumaNW = dot(rgbNW, luma);
|
||||||
|
float lumaNE = dot(rgbNE, luma);
|
||||||
|
float lumaSW = dot(rgbSW, luma);
|
||||||
|
float lumaSE = dot(rgbSE, luma);
|
||||||
|
float lumaM = dot(rgbM, luma);
|
||||||
|
|
||||||
|
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
|
||||||
|
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
|
||||||
|
|
||||||
|
vec2 dir;
|
||||||
|
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
|
||||||
|
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
|
||||||
|
|
||||||
|
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAAReduceMul), FXAA_REDUCE_MIN);
|
||||||
|
float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);
|
||||||
|
dir = min(vec2(FXAASpanMax, FXAASpanMax), max(vec2(-FXAASpanMax, -FXAASpanMax), dir * rcpDirMin)) * InvTargetSize;
|
||||||
|
|
||||||
|
vec3 rgbA = (1.0/2.0) * (textureLod(ColorTexture, texCoord + dir * (1.0/3.0 - 0.5), 0.0).rgb + textureLod(ColorTexture, texCoord + dir * (2.0/3.0 - 0.5), 0.0).rgb);
|
||||||
|
vec3 rgbB = rgbA * 1.0/2.0 + 1.0/4.0 * (textureLod(ColorTexture, texCoord + dir * (0.0/3.0 - 0.5), 0.0).rgb + textureLod(ColorTexture, texCoord + dir * (3.0/3.0 - 0.5), 0.0).rgb);
|
||||||
|
float lumaB = dot(rgbB, luma);
|
||||||
|
|
||||||
|
vec3 fragmentColor = (lumaB < lumaMin || lumaB > lumaMax) ? rgbA : rgbB;
|
||||||
|
|
||||||
|
RenderTarget0 = vec4(fragmentColor, 1.0);
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,25 @@
|
||||||
|
// http://www.geeks3d.com/20100909/shader-library-gaussian-blur-post-processing-filter-in-glsl/
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
uniform sampler2D ColorTexture;
|
||||||
|
uniform vec2 Filter;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
|
||||||
|
float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
|
||||||
|
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb * weight[0];
|
||||||
|
|
||||||
|
for (int i = 1; i < 3; i++)
|
||||||
|
{
|
||||||
|
color += textureLod(ColorTexture, texCoord + Filter*vec2(offset[i])*InvTargetSize, 0.0).rgb * weight[i];
|
||||||
|
color += textureLod(ColorTexture, texCoord - Filter*vec2(offset[i])*InvTargetSize, 0.0).rgb * weight[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderTarget0 = vec4(color, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
47,47,32,104,116,116,112,58,47,47,119,119,119,46,103,101,101,107,115,51,100,46,99,111,109,47,50,48,49,48,48,57,48,57,47,115,104,97,100,101,114,45,108,105,98,114,97,114,121,45,103,97,117,115,115,105,97,110,45,98,108,117,114,45,112,111,115,116,45,112,114,111,99,101,115,115,105,110,103,45,102,105,108,116,101,114,45,105,110,45,103,108,115,108,47,13,10,35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,70,105,108,116,101,114,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,102,108,111,97,116,32,111,102,102,115,101,116,91,51,93,32,61,32,102,108,111,97,116,91,93,40,48,46,48,44,32,49,46,51,56,52,54,49,53,51,56,52,54,44,32,51,46,50,51,48,55,54,57,50,51,48,56,41,59,13,10,102,108,111,97,116,32,119,101,105,103,104,116,91,51,93,32,61,32,102,108,111,97,116,91,93,40,48,46,50,50,55,48,50,55,48,50,55,48,44,32,48,46,51,49,54,50,49,54,50,49,54,50,44,32,48,46,48,55,48,50,55,48,50,55,48,51,41,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,48,93,59,13,10,13,10,9,102,111,114,32,40,105,110,116,32,105,32,61,32,49,59,32,105,32,60,32,51,59,32,105,43,43,41,13,10,9,123,13,10,9,9,99,111,108,111,114,32,43,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,43,32,70,105,108,116,101,114,42,118,101,99,50,40,111,102,102,115,101,116,91,105,93,41,42,73,110,118,84,97,114,103,101,116,83,105,122,101,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,105,93,59,13,10,9,9,99,111,108,111,114,32,43,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,32,45,32,70,105,108,116,101,114,42,118,101,99,50,40,111,102,102,115,101,116,91,105,93,41,42,73,110,118,84,97,114,103,101,116,83,105,122,101,44,32,48,46,48,41,46,114,103,98,32,42,32,119,101,105,103,104,116,91,105,93,59,13,10,9,125,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,44,32,49,46,48,41,59,13,10,125,13,10,
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
struct Light
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
vec4 ambient;
|
||||||
|
vec4 color;
|
||||||
|
vec2 factors;
|
||||||
|
|
||||||
|
vec4 parameters1;
|
||||||
|
vec4 parameters2;
|
||||||
|
vec2 parameters3;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform vec3 EyePosition;
|
||||||
|
uniform Light Lights[1];
|
||||||
|
|
||||||
|
uniform sampler2D GBuffer0;
|
||||||
|
uniform sampler2D GBuffer1;
|
||||||
|
uniform sampler2D GBuffer2;
|
||||||
|
|
||||||
|
uniform mat4 InvViewProjMatrix;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
uniform vec4 SceneAmbient;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0);
|
||||||
|
if (gVec0.w == 0.0)
|
||||||
|
{
|
||||||
|
RenderTarget0 = vec4(gVec0.xyz, 1.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
|
||||||
|
vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);
|
||||||
|
|
||||||
|
vec3 diffuseColor = gVec0.xyz;
|
||||||
|
vec3 normal = gVec1.xyz*2.0 - 1.0;
|
||||||
|
vec3 specularColor = gVec2.xyz;
|
||||||
|
float depth = gVec1.w*2.0 - 1.0;
|
||||||
|
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
||||||
|
|
||||||
|
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
|
||||||
|
|
||||||
|
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||||
|
worldPos.xyz /= worldPos.w;
|
||||||
|
|
||||||
|
vec3 lightDir = Lights[0].parameters1.xyz - worldPos.xyz;
|
||||||
|
float lightDirLength = length(lightDir);
|
||||||
|
lightDir /= lightDirLength;
|
||||||
|
|
||||||
|
float att = max(Lights[0].parameters1.w - Lights[0].parameters2.x*lightDirLength, 0.0);
|
||||||
|
|
||||||
|
// Ambient
|
||||||
|
vec3 lightAmbient = att * Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
|
||||||
|
|
||||||
|
// Diffuse
|
||||||
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
|
vec3 lightDiffuse = att * lambert * Lights[0].color.rgb * Lights[0].factors.y;
|
||||||
|
|
||||||
|
// Specular
|
||||||
|
vec3 lightSpecular = vec3(0.0);
|
||||||
|
if (shininess > 0.0)
|
||||||
|
{
|
||||||
|
vec3 eyeVec = normalize(EyePosition - worldPos.xyz);
|
||||||
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, shininess);
|
||||||
|
|
||||||
|
lightSpecular = att * specularFactor * Lights[0].color.rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
lightSpecular *= specularColor;
|
||||||
|
|
||||||
|
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
|
||||||
|
vec4 fragmentColor = vec4(lightColor * diffuseColor, 1.0);
|
||||||
|
|
||||||
|
RenderTarget0 = fragmentColor;
|
||||||
|
};
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,82 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
uniform float SSAOBias = 0.0;
|
||||||
|
uniform float SSAOIntensity = 3.0;
|
||||||
|
uniform float SSAOSampleScale = 0.1;
|
||||||
|
uniform float SSAOScale = 1.0;
|
||||||
|
uniform int NoiseTextureSize;
|
||||||
|
uniform mat4 InvViewProjMatrix;
|
||||||
|
uniform sampler2D GBuffer1;
|
||||||
|
uniform sampler2D NoiseTexture;
|
||||||
|
uniform vec2 TargetSize;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
|
||||||
|
vec3 extractPosition(in float depth, in vec2 texCoord)
|
||||||
|
{
|
||||||
|
depth = depth*2.0 - 1.0;
|
||||||
|
|
||||||
|
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
|
||||||
|
|
||||||
|
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||||
|
worldPos.xyz /= worldPos.w;
|
||||||
|
|
||||||
|
return worldPos.xyz;
|
||||||
|
}
|
||||||
|
|
||||||
|
float doAmbientOcclusion(in vec2 texCoord, in vec3 original, in vec3 normal)
|
||||||
|
{
|
||||||
|
vec3 newp = extractPosition(textureLod(GBuffer1, texCoord, 0.0).w, texCoord);
|
||||||
|
vec3 diff = newp - original;
|
||||||
|
float d = length(diff);
|
||||||
|
vec3 v = diff * 1.0/d;
|
||||||
|
d *= SSAOScale;
|
||||||
|
|
||||||
|
return max(0.0, dot(normal, v) - SSAOBias) * (SSAOIntensity / (1.0 + d));
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
const vec2 Kernel[16] = vec2[](
|
||||||
|
vec2(0.53812504, 0.18565957),
|
||||||
|
vec2(0.13790712, 0.24864247),
|
||||||
|
vec2(0.33715037, 0.56794053),
|
||||||
|
vec2(-0.6999805, -0.04511441),
|
||||||
|
vec2(0.06896307, -0.15983082),
|
||||||
|
vec2(0.056099437, 0.006954967),
|
||||||
|
vec2(-0.014653638, 0.14027752),
|
||||||
|
vec2(0.010019933, -0.1924225),
|
||||||
|
vec2(-0.35775623, -0.5301969),
|
||||||
|
vec2(-0.3169221, 0.106360726),
|
||||||
|
vec2(0.010350345, -0.58698344),
|
||||||
|
vec2(-0.08972908, -0.49408212),
|
||||||
|
vec2(0.7119986, -0.0154690035),
|
||||||
|
vec2(-0.053382345, 0.059675813),
|
||||||
|
vec2(0.035267662, -0.063188605),
|
||||||
|
vec2(-0.47761092, 0.2847911));
|
||||||
|
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
|
||||||
|
|
||||||
|
if (gVec1.w == 1.0)
|
||||||
|
{
|
||||||
|
RenderTarget0 = vec4(1.0, 0.0, 0.0, 0.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 normal = gVec1.xyz*2.0 - 1.0;
|
||||||
|
|
||||||
|
vec3 viewPos = extractPosition(gVec1.w, texCoord);
|
||||||
|
vec2 randVec = normalize(textureLod(NoiseTexture, texCoord * (TargetSize/NoiseTextureSize), 0.0).xy * 2.0 - 1.0);
|
||||||
|
|
||||||
|
float ao = 0.0;
|
||||||
|
const int ITERATIONS = 16;
|
||||||
|
for (int i = 0; i < ITERATIONS; ++i)
|
||||||
|
{
|
||||||
|
vec2 coord = reflect(Kernel[i], randVec) * SSAOSampleScale;
|
||||||
|
ao += doAmbientOcclusion(texCoord + coord, viewPos, normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderTarget0 = vec4(1.0 - ao/ITERATIONS, 0.0, 0.0, 0.0);
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,17 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
uniform sampler2D ColorTexture;
|
||||||
|
uniform sampler2D SSAOTexture;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
|
||||||
|
vec3 color = textureLod(ColorTexture, texCoord, 0.0).rgb;
|
||||||
|
float ssao = textureLod(SSAOTexture, texCoord, 0.0).r;
|
||||||
|
|
||||||
|
RenderTarget0 = vec4(color*ssao, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
35,118,101,114,115,105,111,110,32,49,52,48,13,10,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,67,111,108,111,114,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,83,83,65,79,84,101,120,116,117,114,101,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,9,118,101,99,51,32,99,111,108,111,114,32,61,32,116,101,120,116,117,114,101,76,111,100,40,67,111,108,111,114,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,103,98,59,13,10,9,102,108,111,97,116,32,115,115,97,111,32,61,32,116,101,120,116,117,114,101,76,111,100,40,83,83,65,79,84,101,120,116,117,114,101,44,32,116,101,120,67,111,111,114,100,44,32,48,46,48,41,46,114,59,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,118,101,99,52,40,99,111,108,111,114,42,115,115,97,111,44,32,49,46,48,41,59,13,10,125,13,10,
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
#version 140
|
||||||
|
|
||||||
|
out vec4 RenderTarget0;
|
||||||
|
|
||||||
|
struct Light
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
vec4 ambient;
|
||||||
|
vec4 color;
|
||||||
|
vec2 factors;
|
||||||
|
|
||||||
|
vec4 parameters1;
|
||||||
|
vec4 parameters2;
|
||||||
|
vec2 parameters3;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform vec3 EyePosition;
|
||||||
|
uniform Light Lights[1];
|
||||||
|
|
||||||
|
uniform sampler2D GBuffer0;
|
||||||
|
uniform sampler2D GBuffer1;
|
||||||
|
uniform sampler2D GBuffer2;
|
||||||
|
|
||||||
|
uniform mat4 InvViewProjMatrix;
|
||||||
|
uniform vec2 InvTargetSize;
|
||||||
|
uniform vec4 SceneAmbient;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
vec4 gVec0 = textureLod(GBuffer0, texCoord, 0.0);
|
||||||
|
if (gVec0.w == 0.0)
|
||||||
|
{
|
||||||
|
RenderTarget0 = vec4(gVec0.xyz, 1.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 gVec1 = textureLod(GBuffer1, texCoord, 0.0);
|
||||||
|
vec4 gVec2 = textureLod(GBuffer2, texCoord, 0.0);
|
||||||
|
|
||||||
|
vec3 diffuseColor = gVec0.xyz;
|
||||||
|
vec3 normal = gVec1.xyz*2.0 - 1.0;
|
||||||
|
vec3 specularColor = gVec2.xyz;
|
||||||
|
float depth = gVec1.w*2.0 - 1.0;
|
||||||
|
float shininess = (gVec2.w == 0.0) ? 0.0 : exp2(gVec2.w*10.5);
|
||||||
|
|
||||||
|
vec3 viewSpace = vec3(texCoord*2.0 - 1.0, depth);
|
||||||
|
|
||||||
|
vec4 worldPos = InvViewProjMatrix * vec4(viewSpace, 1.0);
|
||||||
|
worldPos.xyz /= worldPos.w;
|
||||||
|
|
||||||
|
vec3 lightDir = Lights[0].parameters1.xyz - worldPos.xyz;
|
||||||
|
float lightDirLength = length(lightDir);
|
||||||
|
lightDir /= lightDirLength;
|
||||||
|
|
||||||
|
float att = max(Lights[0].parameters1.w - Lights[0].parameters2.w*lightDirLength, 0.0);
|
||||||
|
|
||||||
|
// Ambient
|
||||||
|
vec3 lightAmbient = att * Lights[0].color.rgb * Lights[0].factors.x * (vec3(1.0) + SceneAmbient.rgb);
|
||||||
|
|
||||||
|
// Modification de l'atténuation pour gérer le spot
|
||||||
|
float curAngle = dot(Lights[0].parameters2.xyz, -lightDir);
|
||||||
|
float outerAngle = Lights[0].parameters3.y;
|
||||||
|
float innerMinusOuterAngle = Lights[0].parameters3.x - outerAngle;
|
||||||
|
att *= max((curAngle - outerAngle) / innerMinusOuterAngle, 0.0);
|
||||||
|
|
||||||
|
// Diffuse
|
||||||
|
float lambert = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
|
vec3 lightDiffuse = att * lambert * Lights[0].color.rgb * Lights[0].factors.y;
|
||||||
|
|
||||||
|
// Specular
|
||||||
|
vec3 lightSpecular = vec3(0.0);
|
||||||
|
if (shininess > 0.0)
|
||||||
|
{
|
||||||
|
vec3 eyeVec = normalize(EyePosition - worldPos.xyz);
|
||||||
|
vec3 reflection = reflect(-lightDir, normal);
|
||||||
|
float specularFactor = max(dot(reflection, eyeVec), 0.0);
|
||||||
|
specularFactor = pow(specularFactor, shininess);
|
||||||
|
|
||||||
|
lightSpecular = att * specularFactor * Lights[0].color.rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
lightSpecular *= specularColor;
|
||||||
|
|
||||||
|
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
|
||||||
|
vec4 fragmentColor = vec4(lightColor * diffuseColor, 1.0);
|
||||||
|
|
||||||
|
RenderTarget0 = fragmentColor;
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue