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
40 changes: 20 additions & 20 deletions package/Shaders/Common/Color.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,6 @@ namespace Color
return pow(abs(color), 1.0 / 2.2);
}

#if defined(PSHADER) || defined(CSHADER) || defined(COMPUTESHADER)
// Attempt to match vanilla materials that are darker than PBR
const static float PBRLightingScale = ENABLE_LL ? 1.0 : 0.65;

// Attempt to normalise reflection brightness against DALC
const static float ReflectionNormalisationScale = ENABLE_LL ? 1.0 : 0.65;

const static float PBRLightingCompensation = ENABLE_LL ? 1.0 : Math::PI;

// Linear Lighting Functions
float3 LLGammaToLinear(float3 color)
{
return ENABLE_LL ? SkyrimGammaToLinear(color) : color;
}

float3 LLLinearToGamma(float3 color)
{
return ENABLE_LL ? LinearToSkyrimGamma(color) : color;
}

float3 GammaToLinearSafe(float3 color)
{
return sign(color) * pow(abs(color), 2.2);
Expand Down Expand Up @@ -195,6 +175,26 @@ namespace Color

} // namespace pq

#if defined(PSHADER) || defined(CSHADER) || defined(COMPUTESHADER)
// Attempt to match vanilla materials that are darker than PBR
const static float PBRLightingScale = ENABLE_LL ? 1.0 : 0.65;

// Attempt to normalise reflection brightness against DALC
const static float ReflectionNormalisationScale = ENABLE_LL ? 1.0 : 0.65;

const static float PBRLightingCompensation = ENABLE_LL ? 1.0 : Math::PI;

// Linear Lighting Functions
float3 LLGammaToLinear(float3 color)
{
return ENABLE_LL ? SkyrimGammaToLinear(color) : color;
}

float3 LLLinearToGamma(float3 color)
{
return ENABLE_LL ? LinearToSkyrimGamma(color) : color;
}

float3 Diffuse(float3 color)
{
# if defined(TRUE_PBR)
Expand Down
16 changes: 15 additions & 1 deletion package/Shaders/Common/DisplayMapping.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace DisplayMapping
{
linearCol /= maxPqValue;

float3 colToPow = pow(linearCol, PQ_constant_N);
float3 colToPow = pow(abs(linearCol), PQ_constant_N);
float3 numerator = PQ_constant_C1 + PQ_constant_C2 * colToPow;
float3 denominator = 1.0 + PQ_constant_C3 * colToPow;
float3 pq = pow(numerator / denominator, PQ_constant_M);
Expand All @@ -101,6 +101,20 @@ namespace DisplayMapping
return linearColor;
}

float3 ConvertGameToPQ(float3 gammaColor)
{
float3 linearColor = Color::GammaToLinearSafe(gammaColor);
linearColor = Color::BT709ToBT2020(linearColor);
return LinearToPQ(linearColor, 10000.0);
}

float3 ConvertPQToGame(float3 pqColor)
{
float3 linearColor = PQtoLinear(pqColor, 10000.0);
linearColor = Color::BT2020ToBT709(linearColor);
return Color::LinearToGammaSafe(linearColor);
}

// RGB with sRGB/Rec.709 primaries to CIE XYZ
float3 RGBToXYZ(float3 c)
{
Expand Down
51 changes: 38 additions & 13 deletions package/Shaders/Common/VR.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,44 @@ namespace Stereo
return uv;
}

/**
Gets the eyeIndex for Compute Shaders
@param texCoord Texcoord on the screen [0,1]
@returns eyeIndex (0 left, 1 right)
*/
uint GetEyeIndexFromTexCoord(float2 texCoord)
{
#ifdef VR
return (texCoord.x >= 0.5) ? 1 : 0;
#endif // VR
return 0;
}

/**
* @brief Applies motion velocity to UV coordinates and determines if the resulting mono UV is out of screen bounds.
* @param uv Screen UV coordinates (stereo in VR, mono in SE)
* @param velocity Delta motion mapping
* @param isOutOfBounds Output flag indicating if the motion went out of bounds
* @return Newly displaced UV coordinate mapped back to correct space (stereo in VR, mono in SE). Clamped if necessary.
*/
float2 ApplyVelocityToUV(float2 uv, float2 velocity, out bool isOutOfBounds)
{
uint eyeIndex = Stereo::GetEyeIndexFromTexCoord(uv);
float2 prevUVmono = Stereo::ConvertFromStereoUV(uv, eyeIndex) + velocity;
float2 clampedMono = prevUVmono;

#ifdef VR
// VR logic: mono.x < 0 is clamped to 0, not rejected. OOB fires for mono.x >= 1 or mono.y outside [0, 1] inclusive.
isOutOfBounds = (prevUVmono.x >= 1.0) || (prevUVmono.y <= 0.0) || (prevUVmono.y >= 1.0);
clampedMono.x = saturate(prevUVmono.x);
#else
// SE logic: inclusive boundaries on both sides.
isOutOfBounds = any(prevUVmono >= 1.0) || any(prevUVmono <= 0.0);
#endif

return Stereo::ConvertToStereoUV(clampedMono, eyeIndex);
Comment thread
alandtse marked this conversation as resolved.
}

/**
Converts to the eye specific screenposition [0,Resolution].
In VR, texture buffers include the left and right eye in the same buffer. Flat only has a single camera for the entire width.
Expand Down Expand Up @@ -124,19 +162,6 @@ namespace Stereo
return float4(xy * a_resolution, screenPosition.zw);
}

/**
Gets the eyeIndex for Compute Shaders
@param texCoord Texcoord on the screen [0,1]
@returns eyeIndex (0 left, 1 right)
*/
uint GetEyeIndexFromTexCoord(float2 texCoord)
{
#ifdef VR
return (texCoord.x >= 0.5) ? 1 : 0;
#endif // VR
return 0;
}

/**
* @brief Converts UV coordinates from the range [0, 1] to normalized screen space [-1, 1].
*
Expand Down
Loading
Loading