Graphics: Add basic reflection mapping

This commit is contained in:
Lynix
2016-12-18 01:18:48 +01:00
parent 459c5e7a09
commit 37d36a89a6
10 changed files with 104 additions and 26 deletions

View File

@@ -214,8 +214,15 @@ namespace Nz
s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData1, ComponentType_Float4, NazaraOffsetOf(ForwardRenderQueue::BillboardData, size)); // Englobe sincos
s_billboardInstanceDeclaration.EnableComponent(VertexComponent_InstanceData2, ComponentType_Color, NazaraOffsetOf(ForwardRenderQueue::BillboardData, color));
s_reflectionSampler.SetFilterMode(SamplerFilter_Bilinear);
s_reflectionSampler.SetWrapMode(SamplerWrap_Clamp);
s_shadowSampler.SetFilterMode(SamplerFilter_Bilinear);
s_shadowSampler.SetWrapMode(SamplerWrap_Clamp);
std::array<UInt8, 6> whitePixels = { { 255, 255, 255, 255, 255, 255 } };
s_dummyReflection.Create(ImageType_Cubemap, PixelFormatType_L8, 1, 1);
s_dummyReflection.Update(whitePixels.data());
}
catch (const std::exception& e)
{
@@ -232,6 +239,7 @@ namespace Nz
void ForwardRenderTechnique::Uninitialize()
{
s_dummyReflection.Destroy();
s_quadIndexBuffer.Reset();
s_quadVertexBuffer.Reset();
}
@@ -583,6 +591,10 @@ namespace Nz
const Shader* lastShader = nullptr;
const ShaderUniforms* shaderUniforms = nullptr;
Texture* reflectionMap = sceneData.globalReflectionTexture;
if (!reflectionMap)
reflectionMap = &s_dummyReflection;
for (auto& pipelinePair : layer.opaqueModels)
{
const MaterialPipeline* pipeline = pipelinePair.first;
@@ -618,6 +630,15 @@ namespace Nz
{
material->Apply(pipelineInstance);
if (shaderUniforms->reflectionMap != -1)
{
unsigned int textureUnit = Material::GetTextureUnit(TextureMap_ReflectionCube);
shader->SendInteger(shaderUniforms->reflectionMap, textureUnit);
Renderer::SetTexture(textureUnit, reflectionMap);
Renderer::SetTextureSampler(textureUnit, s_reflectionSampler);
}
ForwardRenderQueue::MeshInstanceContainer& meshInstances = matEntry.meshMap;
// Meshes
@@ -895,6 +916,7 @@ namespace Nz
uniforms.shaderUniformInvalidatedSlot.Connect(shader->OnShaderUniformInvalidated, this, &ForwardRenderTechnique::OnShaderInvalidated);
uniforms.eyePosition = shader->GetUniformLocation("EyePosition");
uniforms.reflectionMap = shader->GetUniformLocation("ReflectionMap");
uniforms.sceneAmbient = shader->GetUniformLocation("SceneAmbient");
uniforms.textureOverlay = shader->GetUniformLocation("TextureOverlay");
@@ -1037,6 +1059,8 @@ namespace Nz
}
IndexBuffer ForwardRenderTechnique::s_quadIndexBuffer;
Texture ForwardRenderTechnique::s_dummyReflection;
TextureSampler ForwardRenderTechnique::s_reflectionSampler;
TextureSampler ForwardRenderTechnique::s_shadowSampler;
VertexBuffer ForwardRenderTechnique::s_quadVertexBuffer;
VertexDeclaration ForwardRenderTechnique::s_billboardInstanceDeclaration;