Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Resources/Engine/Shaders/Common/Utils.ovfxh
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
11 changes: 9 additions & 2 deletions Resources/Engine/Shaders/Standard.ovfx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion Sources/OvRendering/src/OvRendering/Entities/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @licence: MIT
*/

#include <bit>
#include <format>

#include <OvDebug/Assertion.h>
Expand Down Expand Up @@ -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<uint8_t>(p_toPack.x * 255.f), static_cast<uint8_t>(p_toPack.y * 255.f), static_cast<uint8_t>(p_toPack.z * 255.f), 0);
}

Expand Down Expand Up @@ -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<float>(Pack(color));
result.data[8] = std::bit_cast<float>(Pack(color));

result.data[12] = static_cast<float>(type);
result.data[13] = cutoff;
Expand Down