From 5c3267c69d78af8f0f997c32aa3e7a4f379f94d6 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 21 Oct 2020 01:33:33 -0400 Subject: [PATCH] Use frag_position in FOG_SHADER --- Runtime/Graphics/CGraphics.hpp | 89 ++++++++++++---------- Runtime/Graphics/Shaders/CEnvFxShaders.cpp | 2 - 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index 0b0875f57..c5ecba40f 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -518,52 +518,57 @@ using NoColorAttachment = NoColorAttachmentExtposition.z)) - (fog).m_C); \ - switch ((fog).m_mode) { \ - case ERglFogMode::PerspLin: \ - fogZ = fogF; \ - break; \ - case ERglFogMode::PerspExp: \ - fogZ = 1.0 - hsh::exp2(-8.0 * fogF); \ - break; \ - case ERglFogMode::PerspExp2: \ - fogZ = 1.0 - hsh::exp2(-8.0 * fogF * fogF); \ - break; \ - case ERglFogMode::PerspRevExp: \ - fogZ = hsh::exp2(-8.0 * (1.0 - fogF)); \ - break; \ - case ERglFogMode::PerspRevExp2: \ - fogF = 1.0 - fogF; \ - fogZ = hsh::exp2(-8.0 * fogF * fogF); \ - break; \ - default: \ - fogZ = 0.0; \ - break; \ + { \ + float fogF = hsh::saturate(((fog).m_A / ((fog).m_B - this->frag_position.z)) - (fog).m_C); \ + switch ((fog).m_mode) { \ + case ERglFogMode::PerspLin: \ + fogZ = fogF; \ + break; \ + case ERglFogMode::PerspExp: \ + fogZ = 1.0 - hsh::exp2(-8.0 * fogF); \ + break; \ + case ERglFogMode::PerspExp2: \ + fogZ = 1.0 - hsh::exp2(-8.0 * fogF * fogF); \ + break; \ + case ERglFogMode::PerspRevExp: \ + fogZ = hsh::exp2(-8.0 * (1.0 - fogF)); \ + break; \ + case ERglFogMode::PerspRevExp2: \ + fogF = 1.0 - fogF; \ + fogZ = hsh::exp2(-8.0 * fogF * fogF); \ + break; \ + default: \ + fogZ = 0.0; \ + break; \ + } \ } #define FOG_SHADER_UNIFORM(fogUniBuf) \ float fogZ; \ - float fogF = hsh::saturate(((fogUniBuf)->m_A / ((fogUniBuf)->m_B - this->position.z)) - (fogUniBuf)->m_C); \ - switch ((fogUniBuf)->m_mode) { \ - case ERglFogMode::PerspLin: \ - fogZ = fogF; \ - break; \ - case ERglFogMode::PerspExp: \ - fogZ = 1.0 - hsh::exp2(-8.0 * fogF); \ - break; \ - case ERglFogMode::PerspExp2: \ - fogZ = 1.0 - hsh::exp2(-8.0 * fogF * fogF); \ - break; \ - case ERglFogMode::PerspRevExp: \ - fogZ = hsh::exp2(-8.0 * (1.0 - fogF)); \ - break; \ - case ERglFogMode::PerspRevExp2: \ - fogF = 1.0 - fogF; \ - fogZ = hsh::exp2(-8.0 * fogF * fogF); \ - break; \ - default: \ - fogZ = 0.0; \ - break; \ + { \ + float fogF = \ + hsh::saturate(((fogUniBuf)->m_A / ((fogUniBuf)->m_B - this->frag_position.z)) - (fogUniBuf)->m_C); \ + switch ((fogUniBuf)->m_mode) { \ + case ERglFogMode::PerspLin: \ + fogZ = fogF; \ + break; \ + case ERglFogMode::PerspExp: \ + fogZ = 1.0 - hsh::exp2(-8.0 * fogF); \ + break; \ + case ERglFogMode::PerspExp2: \ + fogZ = 1.0 - hsh::exp2(-8.0 * fogF * fogF); \ + break; \ + case ERglFogMode::PerspRevExp: \ + fogZ = hsh::exp2(-8.0 * (1.0 - fogF)); \ + break; \ + case ERglFogMode::PerspRevExp2: \ + fogF = 1.0 - fogF; \ + fogZ = hsh::exp2(-8.0 * fogF * fogF); \ + break; \ + default: \ + fogZ = 0.0; \ + break; \ + } \ } #define FOG_OUT(out, fog, colorIn) \ diff --git a/Runtime/Graphics/Shaders/CEnvFxShaders.cpp b/Runtime/Graphics/Shaders/CEnvFxShaders.cpp index 65b478790..1ad70bf61 100644 --- a/Runtime/Graphics/Shaders/CEnvFxShaders.cpp +++ b/Runtime/Graphics/Shaders/CEnvFxShaders.cpp @@ -25,8 +25,6 @@ struct CEnvFxShadersPipeline hsh::float4 color = vbo->color * envFxUniBuf->moduColor * flakeTexel * envTexel; this->position = envFxUniBuf->proj * (envFxUniBuf->mv * posIn); FOG_SHADER_UNIFORM(fogUniBuf) - // FIXME: hsh binds fog uniform to fragment stage - // only because of m_color reference in here. can/should we avoid that? FOG_OUT_UNIFORM(this->color_out[0], fogUniBuf, color) } };