Skip to content

Commit

Permalink
bugifx: resolve rendering artifacts
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Apr 15, 2023
1 parent 452903f commit 97d09e3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion HPL2/core/include/graphics/RendererDeferred.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ namespace hpl {

std::array<std::unique_ptr<iVertexBuffer>, eDeferredShapeQuality_LastEnum> m_shapeSphere;
std::unique_ptr<iVertexBuffer> m_shapePyramid;
std::array<absl::InlinedVector<ShadowMapData, 10>, eShadowMapResolution_LastEnum> m_shadowMapData;
std::array<absl::InlinedVector<ShadowMapData, 15>, eShadowMapResolution_LastEnum> m_shadowMapData;

int m_maxBatchLights;
int mlMaxBatchVertices;
Expand Down
1 change: 0 additions & 1 deletion HPL2/core/resource/fs_basic_translucent_material.sc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,5 @@ void main()
vFinalColor.xyz += vReflectionColor.xyz * fRimLight * fFinalAlpha * u_lightLevel;
}
#endif

gl_FragColor = vFinalColor;
}
5 changes: 2 additions & 3 deletions HPL2/core/sources/graphics/MaterialType_Water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ namespace hpl {
}

program.m_uniforms.push_back({ m_u_param, &params, 4 });
cMatrixf mtxInvView = hasCubeMap ? ([&] {
const cMatrixf mtxInvView = ([&] {
cMatrixf mtxInvView = apRenderer->GetCurrentFrustum()->GetViewMatrix().GetTranspose();
return mtxInvView.GetRotation().GetTranspose();
})()
: cMatrixf::Identity;
})();
program.m_uniforms.push_back({ m_u_mtxInvViewRotation, &mtxInvView.v });
program.m_uniforms.push_back({ m_u_fogColor, &fogColor.v });
program.m_handle = m_waterVariant.GetVariant(flags);
Expand Down
42 changes: 20 additions & 22 deletions HPL2/core/sources/graphics/RendererDeferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ namespace hpl {
eMaterialRenderMode_Diffuse,
[&context,
view, &arg](iRenderable* obj, GraphicsContext::LayoutStream& layoutInput, GraphicsContext::ShaderProgram& shaderInput) {
shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual;
shaderInput.m_configuration.m_depthTest = DepthTest::Equal;
shaderInput.m_configuration.m_write = Write::RGBA;
shaderInput.m_configuration.m_cull = Cull::CounterClockwise;

Expand Down Expand Up @@ -662,7 +662,7 @@ namespace hpl {
eMaterialRenderMode_Diffuse,
[&context, view, &args](iRenderable* obj, GraphicsContext::LayoutStream& layoutInput, GraphicsContext::ShaderProgram& shaderInput) {
shaderInput.m_configuration.m_depthTest = DepthTest::LessEqual;
shaderInput.m_configuration.m_write = Write::RGBA;
shaderInput.m_configuration.m_write = Write::RGB;

cMaterial* pMaterial = obj->GetMaterial();
shaderInput.m_configuration.m_rgbBlendFunc = CreateFromMaterialBlendMode(pMaterial->GetBlendMode());
Expand Down Expand Up @@ -1099,13 +1099,13 @@ namespace hpl {
};
};

for (size_t i = 0; i < 1; ++i) {
for (size_t i = 0; i < 10; ++i) {
m_shadowMapData[eShadowMapResolution_High].emplace_back(createShadowMap(vShadowSize[lStartSize + eShadowMapResolution_High]));
}
for (size_t i = 0; i < 4; ++i) {
for (size_t i = 0; i < 15; ++i) {
m_shadowMapData[eShadowMapResolution_Medium].emplace_back(createShadowMap(vShadowSize[lStartSize + eShadowMapResolution_Medium]));
}
for (size_t i = 0; i < 6; ++i) {
for (size_t i = 0; i < 20; ++i) {
m_shadowMapData[eShadowMapResolution_Low].emplace_back(createShadowMap(vShadowSize[lStartSize + eShadowMapResolution_Low]));
}

Expand Down Expand Up @@ -1661,7 +1661,7 @@ namespace hpl {
GraphicsContext::ShaderProgram shaderProgram;
shaderProgram.m_configuration.m_cull = Cull::Clockwise;
shaderProgram.m_configuration.m_depthTest = DepthTest::GreaterEqual;
shaderProgram.m_configuration.m_write = Write::RGBA;
shaderProgram.m_configuration.m_write = Write::RGB;
shaderProgram.m_configuration.m_frontStencilTest = CreateStencilTest(
StencilFunction::Equal, StencilFail::Zero, StencilDepthFail::Zero, StencilDepthPass::Zero, 0xff, 0xff);
drawBoxLight(boxStencilPass, shaderProgram, light);
Expand All @@ -1677,7 +1677,7 @@ namespace hpl {
GraphicsContext::ShaderProgram shaderProgram;
shaderProgram.m_configuration.m_cull = Cull::Clockwise;
shaderProgram.m_configuration.m_depthTest = DepthTest::GreaterEqual;
shaderProgram.m_configuration.m_write = Write::RGBA;
shaderProgram.m_configuration.m_write = Write::RGB;
drawBoxLight(boxLightBackPass, shaderProgram, light);
}
}
Expand Down Expand Up @@ -1778,10 +1778,15 @@ namespace hpl {
} else {
shaderProgram.m_textures.push_back({ m_s_spotFalloffMap, spotFallOffImage->GetHandle(), 5 });
}
auto& currentLight = apLightData->m_light;
BX_ASSERT(currentLight->GetLightType() == eLightType_Spot, "Only spot lights are supported for shadow rendering")

cLightSpot* pSpotLight = static_cast<cLightSpot*>(currentLight);
cFrustum* pLightFrustum = pSpotLight->GetFrustum();

std::vector<iRenderable*> shadowCasters;
if (apLightData->m_castShadows &&
detail::SetupShadowMapRendering(shadowCasters, apWorld, apFrustum, pLightSpot, mvCurrentOcclusionPlanes)) {
detail::SetupShadowMapRendering(shadowCasters, apWorld, pLightFrustum, pLightSpot, mvCurrentOcclusionPlanes)) {
flags |= rendering::detail::SpotlightVariant_UseShadowMap;
eShadowMapResolution shadowMapRes = apLightData->m_shadowResolution;

Expand Down Expand Up @@ -1809,7 +1814,6 @@ namespace hpl {
}
return nullptr;
};
auto& currentLight = apLightData->m_light;
auto* shadowMapData = findBestShadowMap(shadowMapRes, currentLight);
if (!shadowMapData) {
// No shadow map available
Expand All @@ -1825,8 +1829,8 @@ namespace hpl {
}

if (currentLight->GetLightType() == eLightType_Spot &&
(static_cast<cLightSpot*>(currentLight)->GetAspect() != shadowMapData->m_aspect ||
static_cast<cLightSpot*>(currentLight)->GetFOV() != shadowMapData->m_fov)) {
(pSpotLight->GetAspect() != shadowMapData->m_aspect ||
pSpotLight->GetFOV() != shadowMapData->m_fov)) {
return true;
}
return !currentLight->ShadowCastersAreUnchanged(shadowCasters);
Expand All @@ -1836,17 +1840,11 @@ namespace hpl {
shadowMapData->m_radius = currentLight->GetRadius();

if (currentLight->GetLightType() == eLightType_Spot) {
cLightSpot* pSpotLight = static_cast<cLightSpot*>(currentLight);
shadowMapData->m_aspect = pSpotLight->GetAspect();
shadowMapData->m_fov = pSpotLight->GetFOV();
}
currentLight->SetShadowCasterCacheFromVec(shadowCasters);

BX_ASSERT(
currentLight->GetLightType() == eLightType_Spot, "Only spot lights are supported for shadow rendering")
cLightSpot* pSpotLight = static_cast<cLightSpot*>(currentLight);
cFrustum* pLightFrustum = pSpotLight->GetFrustum();

GraphicsContext::ViewConfiguration shadowPassViewConfig{ shadowMapData->m_target };
shadowPassViewConfig.m_clear = { 0, 1.0, 0, ClearOp::Depth };
shadowPassViewConfig.m_view = pLightFrustum->GetViewMatrix().GetTranspose();
Expand Down Expand Up @@ -1919,7 +1917,7 @@ namespace hpl {
{
GraphicsContext::ShaderProgram shaderProgram;
shaderProgram.m_configuration.m_cull = Cull::Clockwise;
shaderProgram.m_configuration.m_write = Write::RGBA;
shaderProgram.m_configuration.m_write = Write::RGB;
shaderProgram.m_configuration.m_depthTest = DepthTest::GreaterEqual;
shaderProgram.m_configuration.m_frontStencilTest = CreateStencilTest(
StencilFunction::Equal, StencilFail::Zero, StencilDepthFail::Zero, StencilDepthPass::Zero, 0xff, 0xff);
Expand All @@ -1943,7 +1941,7 @@ namespace hpl {
for (auto& light : deferredLightRenderBack) {
GraphicsContext::ShaderProgram shaderProgram;
shaderProgram.m_configuration.m_cull = Cull::Clockwise;
shaderProgram.m_configuration.m_write = Write::RGBA;
shaderProgram.m_configuration.m_write = Write::RGB;
shaderProgram.m_configuration.m_depthTest = DepthTest::GreaterEqual;
shaderProgram.m_configuration.m_rgbBlendFunc =
CreateBlendFunction(BlendOperator::Add, BlendOperand::One, BlendOperand::One);
Expand Down Expand Up @@ -2457,12 +2455,12 @@ namespace hpl {

shaderInput.m_configuration.m_depthTest = pMaterial->GetDepthTest() ? DepthTest::LessEqual : DepthTest::None;
shaderInput.m_configuration.m_write = Write::RGB;
shaderInput.m_configuration.m_cull = Cull::None;
shaderInput.m_configuration.m_cull = Cull::CounterClockwise;

shaderInput.m_modelTransform = pMatrix ? pMatrix->GetTranspose() : cMatrixf::Identity;

if (pMaterial->HasRefraction()) {
shaderInput.m_configuration.m_rgbBlendFunc = CreateFromMaterialBlendMode(eMaterialBlendMode_Add);
shaderInput.m_configuration.m_rgbBlendFunc = CreateBlendFunction(BlendOperator::Add, BlendOperand::SrcAlpha, BlendOperand::One);
shaderInput.m_configuration.m_alphaBlendFunc = CreateFromMaterialBlendMode(eMaterialBlendMode_Add);
} else {
shaderInput.m_configuration.m_rgbBlendFunc = CreateFromMaterialBlendMode(pMaterial->GetBlendMode());
Expand All @@ -2487,7 +2485,7 @@ namespace hpl {

shaderInput.m_configuration.m_depthTest = pMaterial->GetDepthTest() ? DepthTest::LessEqual : DepthTest::None;
shaderInput.m_configuration.m_write = Write::RGB;
shaderInput.m_configuration.m_cull = Cull::None;
shaderInput.m_configuration.m_cull = Cull::CounterClockwise;

shaderInput.m_configuration.m_rgbBlendFunc = CreateFromMaterialBlendMode(eMaterialBlendMode_Add);
shaderInput.m_configuration.m_alphaBlendFunc = CreateFromMaterialBlendMode(eMaterialBlendMode_Add);
Expand Down

0 comments on commit 97d09e3

Please sign in to comment.