Skip to content

Commit

Permalink
chore: address compiling problems and box light
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <mpollind@gmail.com>
  • Loading branch information
pollend committed Apr 15, 2023
1 parent 146f2fe commit 452903f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion HPL2/core/resource/fs_basic_translucent_material.sc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void main()
#endif
#ifdef USE_BLEND_MODE_MULX2
float fBlendMulAlpha = u_lightLevel * fFinalAlpha;
vFinalColor.xyz = mul(vFinalColor.xyz, fBlendMulAlpha) + mul(vec3(0.5,0.5,0.5), vec3(1.0 - fBlendMulAlpha));
vFinalColor.xyz = mul(vFinalColor.xyz, fBlendMulAlpha) + mul(vec3(0.5,0.5,0.5), (1.0 - fBlendMulAlpha));
#endif
#ifdef USE_BLEND_MODE_ALPHA
vFinalColor.xyz *= u_lightLevel;
Expand Down
37 changes: 16 additions & 21 deletions HPL2/core/sources/graphics/RendererDeferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,22 @@ namespace hpl {
switch (light.m_light->GetLightType()) {
case eLightType_Point:
return cMath::MatrixScale(light.m_light->GetRadius() * kLightRadiusMul_Medium);
case eLightType_Spot:
{
cLightSpot* pLightSpot = static_cast<cLightSpot*>(light.m_light);
case eLightType_Spot: {
cLightSpot* pLightSpot = static_cast<cLightSpot*>(light.m_light);

float fFarHeight = pLightSpot->GetTanHalfFOV() * pLightSpot->GetRadius() * 2.0f;
// Note: Aspect might be wonky if there is no gobo.
float fFarWidth = fFarHeight * pLightSpot->GetAspect();

return cMath::MatrixScale(
cVector3f(fFarWidth, fFarHeight, light.m_light->GetRadius())); // x and y = "far plane", z = radius
}
case eLightType_Box:
{
cLightBox* pLightBox = static_cast<cLightBox*>(light.m_light);
float fFarHeight = pLightSpot->GetTanHalfFOV() * pLightSpot->GetRadius() * 2.0f;
// Note: Aspect might be wonky if there is no gobo.
float fFarWidth = fFarHeight * pLightSpot->GetAspect();

auto mtx = cMath::MatrixScale(pLightBox->GetSize());
mtx.SetTranslation(pLightBox->GetWorldPosition());
return mtx;
}
return cMath::MatrixScale(
cVector3f(fFarWidth, fFarHeight, light.m_light->GetRadius())); // x and y = "far plane", z = radius
}
case eLightType_Box: {
cLightBox* pLightBox = static_cast<cLightBox*>(light.m_light);
auto mtx = cMath::MatrixScale(pLightBox->GetSize());
mtx.SetTranslation(pLightBox->GetWorldPosition());
return mtx;
}
default:
break;
}
Expand Down Expand Up @@ -1611,8 +1608,7 @@ namespace hpl {
shaderProgram.m_textures.push_back({ m_s_diffuseMap, options.m_gBuffer.m_colorImage->GetHandle(), 0 });
shaderProgram.m_uniforms.push_back({ m_u_lightColor, lightColor });

shaderProgram.m_modelTransform =
cMath::MatrixMul(light->m_light->GetWorldMatrix(), detail::GetLightMtx(*light)).GetTranspose();
shaderProgram.m_modelTransform = detail::GetLightMtx(*light).GetTranspose();

switch (pLightBox->GetBlendFunc()) {
case eLightBoxBlendFunc_Add:
Expand Down Expand Up @@ -1654,8 +1650,7 @@ namespace hpl {
shaderProgram.m_configuration.m_frontStencilTest = CreateStencilTest(
StencilFunction::Always, StencilFail::Keep, StencilDepthFail::Replace, StencilDepthPass::Keep, 0xff, 0xff);

shaderProgram.m_modelTransform =
cMath::MatrixMul(light->m_light->GetWorldMatrix(), detail::GetLightMtx(*light).GetTranspose());
shaderProgram.m_modelTransform = detail::GetLightMtx(*light).GetTranspose();

GraphicsContext::DrawRequest drawRequest{ layoutStream, shaderProgram };
// drawRequest.m_clear = GraphicsContext::ClearRequest{0, 0, 0, ClearOp::Stencil};
Expand Down

0 comments on commit 452903f

Please sign in to comment.