diff --git a/Resources/Engine/Shaders/Common/Utils.ovfxh b/Resources/Engine/Shaders/Common/Utils.ovfxh index 82ffc679..6e662631 100644 --- a/Resources/Engine/Shaders/Common/Utils.ovfxh +++ b/Resources/Engine/Shaders/Common/Utils.ovfxh @@ -1,10 +1,15 @@ -vec3 UnPack(float target) +vec3 UnPack(float packedFloat) { - return vec3 ( - float((uint(target) >> 24) & 0xff) * 0.003921568627451, - float((uint(target) >> 16) & 0xff) * 0.003921568627451, - float((uint(target) >> 8) & 0xff) * 0.003921568627451 - ); + // Reinterpret the float bits as a uint + uint value = floatBitsToUint(packedFloat); + + // Extract bytes + uint c0 = (value >> 24) & 0xFFu; + uint c1 = (value >> 16) & 0xFFu; + uint c2 = (value >> 8) & 0xFFu; + + // Convert back to float in [0,1] + return vec3(c0, c1, c2) / 255.0; } vec2 TileAndOffsetTexCoords(vec2 texCoords, vec2 tiling, vec2 offset) diff --git a/Resources/Engine/Shaders/Standard.ovfx b/Resources/Engine/Shaders/Standard.ovfx index 7de07a3a..5092a077 100644 --- a/Resources/Engine/Shaders/Standard.ovfx +++ b/Resources/Engine/Shaders/Standard.ovfx @@ -211,8 +211,15 @@ void main() // Simple built-in tonemapping (Reinhard) and gamma correction for elements // not affected by post-processing (e.g. debug, UI, etc.), but still aiming // to approximate the final PBR look. - pbr = mix(pbr, pbr / (pbr + vec3(1.0)), u_BuiltInToneMapping); - pbr = mix(pbr, pow(pbr, vec3(1.0 / 2.2)), u_BuiltInGammaCorrection); + if (u_BuiltInToneMapping) + { + pbr = pbr / (pbr + vec3(1.0)); + } + + if (u_BuiltInGammaCorrection) + { + pbr = pow(pbr, vec3(1.0 / 2.2)); + } const vec3 emissive = texture(u_EmissiveMap, texCoords).rgb * u_EmissiveColor * u_EmissiveIntensity; pbr += emissive; diff --git a/Sources/OvRendering/src/OvRendering/Entities/Light.cpp b/Sources/OvRendering/src/OvRendering/Entities/Light.cpp index 1e22121c..5a13eeb9 100644 --- a/Sources/OvRendering/src/OvRendering/Entities/Light.cpp +++ b/Sources/OvRendering/src/OvRendering/Entities/Light.cpp @@ -4,6 +4,7 @@ * @licence: MIT */ +#include #include #include @@ -58,6 +59,13 @@ namespace uint32_t Pack(const OvMaths::FVector3& p_toPack) { + OVASSERT( + p_toPack.x >= 0.f && p_toPack.x <= 1.f && + p_toPack.y >= 0.f && p_toPack.y <= 1.f && + p_toPack.z >= 0.f && p_toPack.z <= 1.f, + "Cannot pack color vector, one of its component is out of range [0;1]!" + ); + return Pack(static_cast(p_toPack.x * 255.f), static_cast(p_toPack.y * 255.f), static_cast(p_toPack.z * 255.f), 0); } @@ -134,7 +142,7 @@ OvMaths::FMatrix4 OvRendering::Entities::Light::GenerateMatrix() const result.data[5] = forward.y; result.data[6] = forward.z; - result.data[8] = static_cast(Pack(color)); + result.data[8] = std::bit_cast(Pack(color)); result.data[12] = static_cast(type); result.data[13] = cutoff;