Skip to content

Commit 8c2adbd

Browse files
committed
GITechDemo:
*added sanity checks for textures that are required to generate GBuffer *moved sky pass after SSR in order to avoid reflecting the sun and sky *removed lens distortion effect due to blurring *updated Sponza model with some geometry to make volumetric lighting more prominent
1 parent 94f004c commit 8c2adbd

File tree

7 files changed

+870163
-546513
lines changed

7 files changed

+870163
-546513
lines changed

GITechDemo/Code/AppMain/GITechDemo/RenderScheme/DirectionalLightPass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void DirectionalLightPass::Update(const float fDeltaTime)
9393

9494
texIrradianceMap = IrradianceTexture.GetTextureIndex();
9595
texEnvMap = EnvironmentTexture.GetTextureIndex();
96+
97+
nBRDFModel = gmtl::Math::clamp(nBRDFModel.GetCurrentValue(), (int)BLINN_PHONG, (int)BRDF_MODEL_MAX - 1);
9698
}
9799

98100
void DirectionalLightPass::Draw()

GITechDemo/Code/AppMain/GITechDemo/RenderScheme/GBufferPass.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void GBufferPass::Update(const float fDeltaTime)
9797
ResourceMgr->GetTexture(LinearFullDepthBuffer.GetRenderTarget()->GetColorBuffer())->SetFilter(SF_MIN_MAG_POINT_MIP_NONE);
9898
ResourceMgr->GetTexture(LinearQuarterDepthBuffer.GetRenderTarget()->GetColorBuffer())->SetFilter(SF_MIN_MAG_POINT_MIP_NONE);
9999
ResourceMgr->GetTexture(HyperbolicQuarterDepthBuffer.GetRenderTarget()->GetColorBuffer())->SetFilter(SF_MIN_MAG_POINT_MIP_NONE);
100+
101+
DIFFUSE_ANISOTROPY = Math::clamp(DIFFUSE_ANISOTROPY, 1, (int)MAX_ANISOTROPY);
100102
}
101103

102104
void GBufferPass::Draw()
@@ -151,27 +153,33 @@ void GBufferPass::Draw()
151153
{
152154
PUSH_PROFILE_MARKER(SponzaScene.GetModel()->arrMaterial[SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx]->szName.c_str());
153155

154-
DIFFUSE_ANISOTROPY = Math::clamp(DIFFUSE_ANISOTROPY, 1, (int)MAX_ANISOTROPY);
155-
RenderContext->GetResourceManager()->GetTexture(
156-
SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_DIFFUSE, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx)
157-
)->SetAnisotropy((unsigned int)DIFFUSE_ANISOTROPY);
156+
const unsigned int diffuseTexIdx = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_DIFFUSE, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
157+
const unsigned int normalTexIdx = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_HEIGHT, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
158+
const unsigned int specTexIdx = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_SPECULAR, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
159+
const unsigned int matTexIdx = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_AMBIENT, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
160+
const unsigned int roughnessTexIdx = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_SHININESS, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
161+
162+
if (diffuseTexIdx != ~0u && ((texMatType != ~0u && texRoughness != ~0u) || nBRDFModel == BLINN_PHONG))
163+
{
164+
RenderContext->GetResourceManager()->GetTexture(diffuseTexIdx)->SetAnisotropy((unsigned int)DIFFUSE_ANISOTROPY);
158165

159-
texDiffuse = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_DIFFUSE, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
160-
texNormal = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_HEIGHT, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
161-
bHasNormalMap = (texNormal != -1) && GBUFFER_USE_NORMAL_MAPS;
166+
texDiffuse = diffuseTexIdx;
167+
texNormal = normalTexIdx;
168+
bHasNormalMap = (texNormal != -1) && GBUFFER_USE_NORMAL_MAPS;
162169

163-
// For Blinn-Phong BRDF
164-
texSpec = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_SPECULAR, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
165-
bHasSpecMap = (texSpec != -1);
166-
fSpecIntensity = SponzaScene.GetModel()->arrMaterial[SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx]->fShininessStrength;
170+
// For Blinn-Phong BRDF
171+
texSpec = (nBRDFModel == BLINN_PHONG ? specTexIdx : ~0u);
172+
bHasSpecMap = (texSpec != -1);
173+
fSpecIntensity = SponzaScene.GetModel()->arrMaterial[SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx]->fShininessStrength;
167174

168-
// For Cook-Torrance BRDF
169-
texMatType = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_AMBIENT, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
170-
texRoughness = SponzaScene.GetTexture(Synesthesia3D::Model::TextureDesc::TT_SHININESS, SponzaScene.GetModel()->arrMesh[mesh]->nMaterialIdx);
175+
// For Cook-Torrance BRDF
176+
texMatType = (nBRDFModel == COOK_TORRANCE_GGX || nBRDFModel == COOK_TORRANCE_BECKMANN ? matTexIdx : ~0u);
177+
texRoughness = (nBRDFModel == COOK_TORRANCE_GGX || nBRDFModel == COOK_TORRANCE_BECKMANN ? roughnessTexIdx : ~0u);
171178

172-
GBufferGenerationShader.Enable();
173-
RenderContext->DrawVertexBuffer(SponzaScene.GetModel()->arrMesh[mesh]->pVertexBuffer);
174-
GBufferGenerationShader.Disable();
179+
GBufferGenerationShader.Enable();
180+
RenderContext->DrawVertexBuffer(SponzaScene.GetModel()->arrMesh[mesh]->pVertexBuffer);
181+
GBufferGenerationShader.Disable();
182+
}
175183

176184
POP_PROFILE_MARKER();
177185
}

GITechDemo/Code/AppMain/GITechDemo/RenderScheme/RenderScheme.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ CREATE_ROOT_PASS()
6363
// Screen space ambient occlusion (done here so as not to affect indirect and volumetric lights)
6464
#include "SSAOPass.h"
6565
ADD_RENDER_PASS(SSAO_PASS, SSAOPass, "SSAO", LIGHTING_PASS)
66-
67-
// Render the sky box (moved after SSAO so as to avoid halo artifacts on the sky)
68-
#include "SkyPass.h"
69-
ADD_RENDER_PASS(SKY_PASS, SkyPass, "Sky", LIGHTING_PASS)
7066

7167
// Compute indirect light contribution from the directional light (1 unoccluded bounce)
7268
#include "DirectionalIndirectLightPass.h"
@@ -75,6 +71,10 @@ CREATE_ROOT_PASS()
7571
// Screen space reflection
7672
#include "ScreenSpaceReflectionPass.h"
7773
ADD_RENDER_PASS(SCREEN_SPACE_REFLECTION_PASS, ScreenSpaceReflectionPass, "Screen Space Reflection", LIGHTING_PASS)
74+
75+
// Render the sky box (moved after SSAO so as to avoid halo artifacts on the sky; moved after SSR to avoid reflecting sun or sky)
76+
#include "SkyPass.h"
77+
ADD_RENDER_PASS(SKY_PASS, SkyPass, "Sky", LIGHTING_PASS)
7878

7979
// Downsample the light accumulation buffer here, because we don't want the volumetric light to be bloomed
8080
#include "HDRDownsampleForBloomPass.h"

GITechDemo/Code/AppMain/GITechDemo/Resources/AppResources.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ namespace GITechDemoApp
447447
CREATE_SHADER_CONSTANT_OBJECT(fVignIn, float, 0.f );
448448
CREATE_SHADER_CONSTANT_OBJECT(fVignFade, float, 22.f );
449449
CREATE_SHADER_CONSTANT_OBJECT(fChromaShiftAmount, float, 3.f );
450-
CREATE_SHADER_CONSTANT_OBJECT(fQuarticDistortionCoef, float, -0.02f );
451-
CREATE_SHADER_CONSTANT_OBJECT(fCubicDistortionModifier, float, -0.03f );
450+
CREATE_SHADER_CONSTANT_OBJECT(fQuarticDistortionCoef, float, 0.f );
451+
CREATE_SHADER_CONSTANT_OBJECT(fCubicDistortionModifier, float, 0.f );
452452
CREATE_SHADER_CONSTANT_OBJECT(fDistortionScale, float, 1.f );
453453
// Motion blur
454454
CREATE_SHADER_CONSTANT_OBJECT(fMotionBlurIntensity, float, 0.01f );

GITechDemo/Code/AppMain/GITechDemo/Resources/AppResources.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ namespace GITechDemoApp
373373
{
374374
BLINN_PHONG = 0,
375375
COOK_TORRANCE_GGX,
376-
COOK_TORRANCE_BECKMANN
376+
COOK_TORRANCE_BECKMANN,
377+
BRDF_MODEL_MAX
377378
};
378379
}
379380

GITechDemo/Data/shaders/ScreenSpaceReflection.hlsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ void psmain(VSOut input, out float4 f4Color : SV_TARGET)
7171
{
7272
float2 f2HitTexelCoord; float3 f3HitPoint; f4Color = 0;
7373

74+
const float fDepth = tex2D(texLinDepthBuffer, input.f2TexCoord).r;
75+
DEPTH_KILL(fDepth, fZFar * 0.999f);
76+
7477
const float3 f3ViewDir = normalize(input.f3ViewVec);
75-
const float fDepth = tex2D(texLinDepthBuffer, input.f2TexCoord).r;
7678
const float3 f3Normal = DecodeNormal(tex2D(texNormalBuffer, input.f2TexCoord));
7779
const float3 f3RayStartPosVS = input.f3ViewVec * fDepth + f3Normal * max(0.01f * fDepth, 0.001f);
7880
const float3 f3ReflectedRayDir = reflect(f3ViewDir, f3Normal);

0 commit comments

Comments
 (0)