Skip to content

Commit

Permalink
refactor: rename sRGB2Lin to SkyrimGamma2Lin, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pentalimbed committed Aug 17, 2024
1 parent 0b7d849 commit a557986
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ float3 GetDynamicCubemapSpecularIrradiance(float2 uv, float3 N, float3 VN, float

float3 specularIrradiance = specularTexture.SampleLevel(SampColorSampler, R, level).xyz;
specularIrradiance *= horizon;
specularIrradiance = sRGB2Lin(specularIrradiance);
specularIrradiance = SkyrimGamma2Lin(specularIrradiance);

return specularIrradiance;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughne
return horizon * ((F0 + S) * specularBRDF.x + specularBRDF.y);
# else
float3 specularIrradiance = specularTexture.SampleLevel(SampColorSampler, R, level).xyz;
specularIrradiance = sRGB2Lin(specularIrradiance);
specularIrradiance = SkyrimGamma2Lin(specularIrradiance);

return specularIrradiance * ((F0 + S) * specularBRDF.x + specularBRDF.y);
# endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ float3 GetSamplingVector(uint3 ThreadID, in RWTexture2DArray<float4> OutputTextu
}

#if defined(REFLECTIONS)
color.rgb = lerp(color.rgb, sRGB2Lin(ReflectionsTexture.SampleLevel(LinearSampler, uv, 0)), saturate(mipLevel / 8.0));
color.rgb = lerp(color.rgb, SkyrimGamma2Lin(ReflectionsTexture.SampleLevel(LinearSampler, uv, 0)), saturate(mipLevel / 8.0));
#else
color.rgb = lerp(color.rgb, color.rgb * sRGB2Lin(DefaultCubemap.SampleLevel(LinearSampler, uv, 0).x) * 2, saturate(mipLevel / 8.0));
color.rgb = lerp(color.rgb, color.rgb * SkyrimGamma2Lin(DefaultCubemap.SampleLevel(LinearSampler, uv, 0).x) * 2, saturate(mipLevel / 8.0));
#endif

color.rgb = Lin2sRGB(color.rgb);
color.rgb = Lin2SkyrimGamma(color.rgb);
EnvInferredTexture[ThreadID] = max(0, color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ float3 tangentToWorld(const float3 v, const float3 N, const float3 S, const floa
return S * v.x + T * v.y + N * v.z;
}

float3 sRGB2Lin(float3 color)
float3 SkyrimGamma2Lin(float3 color)
{
return color > 0.04045 ? pow(color / 1.055 + 0.055 / 1.055, 2.4) : color / 12.92;
}

float3 Lin2sRGB(float3 color)
float3 Lin2SkyrimGamma(float3 color)
{
return color > 0.0031308 ? 1.055 * pow(color, 1.0 / 2.4) - 0.055 : 12.92 * color;
}
Expand Down Expand Up @@ -181,11 +181,11 @@ float3 Lin2sRGB(float3 color)
// Mip level to sample from.
float mipLevel = max(0.5 * log2(ws / wt) + 1.0, 0.0);

color += sRGB2Lin(inputTexture.SampleLevel(linear_wrap_sampler, Li, mipLevel).rgb) * cosLi;
color += SkyrimGamma2Lin(inputTexture.SampleLevel(linear_wrap_sampler, Li, mipLevel).rgb) * cosLi;
weight += cosLi;
}
}
color /= weight;

outputTexture[ThreadID] = float4(Lin2sRGB(color), 1.0);
outputTexture[ThreadID] = float4(Lin2SkyrimGamma(color), 1.0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cbuffer UpdateData : register(b1)
bool IsSaturated(float value) { return value == saturate(value); }
bool IsSaturated(float2 value) { return IsSaturated(value.x) && IsSaturated(value.y); }

float3 sRGB2Lin(float3 color)
float3 SkyrimGamma2Lin(float3 color)
{
return color > 0.04045 ? pow(color / 1.055 + 0.055 / 1.055, 2.4) : color / 12.92;
}
Expand Down Expand Up @@ -172,7 +172,7 @@ float smoothbumpstep(float edge0, float edge1, float x)

if (linearDepth > 16.5) { // Ignore objects which are too close
float3 color = ColorTexture.SampleLevel(LinearSampler, uv, 0);
float4 output = float4(sRGB2Lin(color), 1.0);
float4 output = float4(SkyrimGamma2Lin(color), 1.0);
float lerpFactor = 1.0 / 64.0;

half4 positionCS = half4(2 * half2(uv.x, -uv.y + 1) - 1, depth, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void readHistory(

half3 radiance = 0;
#ifdef GI
radiance = sRGB2Lin(FULLRES_LOAD(srcDiffuse, pixCoord, uv * frameScale, samplerLinearClamp).rgb * GIStrength);
radiance = SkyrimGamma2Lin(FULLRES_LOAD(srcDiffuse, pixCoord, uv * frameScale, samplerLinearClamp).rgb * GIStrength);
# ifdef GI_BOUNCE
radiance += prev_ambient.rgb * GIBounceFade;
# endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ float4 SSSSBlurCS(
float4 colorM = ColorTexture[DTid.xy];

#if defined(HORIZONTAL)
colorM.rgb = sRGB2Lin(colorM.rgb);
colorM.rgb = SkyrimGamma2Lin(colorM.rgb);
#endif

if (sssAmount == 0)
Expand Down Expand Up @@ -157,7 +157,7 @@ float4 SSSSBlurCS(
float3 color = ColorTexture[coords].rgb;

#if defined(HORIZONTAL)
color.rgb = sRGB2Lin(color.rgb);
color.rgb = SkyrimGamma2Lin(color.rgb);
#endif

float depth = DepthTexture[coords].r;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cbuffer PerFrameSSS : register(b1)
bool humanProfile = MaskTexture[DTid.xy].y == sssAmount;

float4 color = SSSSBlurCS(DTid.xy, texCoord, float2(0.0, 1.0), sssAmount, humanProfile);
color.rgb = Lin2sRGB(color.rgb);
color.rgb = Lin2SkyrimGamma(color.rgb);
SSSRW[DTid.xy] = float4(color.rgb, 1.0);

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ float3 GetWetnessAmbientSpecular(float2 uv, float3 N, float3 VN, float3 V, float
float3 specularIrradiance = 1.0;
# else
float level = roughness * 7.0;
float3 specularIrradiance = sRGB2Lin(specularTexture.SampleLevel(SampColorSampler, R, level));
float3 specularIrradiance = SkyrimGamma2Lin(specularTexture.SampleLevel(SampColorSampler, R, level));
# endif
#else
float3 specularIrradiance = 1.0;
Expand Down
14 changes: 7 additions & 7 deletions package/Shaders/AmbientCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ RWTexture2D<half3> DiffuseAmbientRW : register(u1);

half3 directionalAmbientColor = mul(DirectionalAmbient, half4(normalWS, 1.0));

half3 linAlbedo = sRGB2Lin(albedo);
half3 linDirectionalAmbientColor = sRGB2Lin(directionalAmbientColor);
half3 linDiffuseColor = sRGB2Lin(diffuseColor);
half3 linAlbedo = SkyrimGamma2Lin(albedo);
half3 linDirectionalAmbientColor = SkyrimGamma2Lin(directionalAmbientColor);
half3 linDiffuseColor = SkyrimGamma2Lin(diffuseColor);

half3 linAmbient = lerp(sRGB2Lin(albedo * directionalAmbientColor), linAlbedo * linDirectionalAmbientColor, pbrWeight);
half3 linAmbient = lerp(SkyrimGamma2Lin(albedo * directionalAmbientColor), linAlbedo * linDirectionalAmbientColor, pbrWeight);

half visibility = 1.0;
#if defined(SKYLIGHTING)
Expand Down Expand Up @@ -90,10 +90,10 @@ RWTexture2D<half3> DiffuseAmbientRW : register(u1);
#endif

linAmbient *= visibility;
diffuseColor = Lin2sRGB(linDiffuseColor);
directionalAmbientColor = Lin2sRGB(linDirectionalAmbientColor * visibility);
diffuseColor = Lin2SkyrimGamma(linDiffuseColor);
directionalAmbientColor = Lin2SkyrimGamma(linDirectionalAmbientColor * visibility);

diffuseColor = lerp(diffuseColor + directionalAmbientColor * albedo, Lin2sRGB(linDiffuseColor + linAmbient), pbrWeight);
diffuseColor = lerp(diffuseColor + directionalAmbientColor * albedo, Lin2SkyrimGamma(linDiffuseColor + linAmbient), pbrWeight);

MainRW[dispatchID.xy] = diffuseColor;
};
4 changes: 2 additions & 2 deletions package/Shaders/Common/Color.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ float RGBToLuminance2(float3 color)
return dot(color, float3(0.299, 0.587, 0.114));
}

float3 sRGB2Lin(float3 color)
float3 SkyrimGamma2Lin(float3 color)
{
return pow(abs(color), 1.5);
}

float3 Lin2sRGB(float3 color)
float3 Lin2SkyrimGamma(float3 color)
{
return pow(abs(color), 1.0 / 1.5);
}
16 changes: 8 additions & 8 deletions package/Shaders/DeferredCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Texture2D<half4> SpecularSSGITexture : register(t10);

half glossiness = normalGlossiness.z;

half3 color = lerp(diffuseColor + specularColor, Lin2sRGB(sRGB2Lin(diffuseColor) + sRGB2Lin(specularColor)), pbrWeight);
half3 color = lerp(diffuseColor + specularColor, Lin2SkyrimGamma(SkyrimGamma2Lin(diffuseColor) + SkyrimGamma2Lin(specularColor)), pbrWeight);

#if defined(DYNAMIC_CUBEMAPS)

Expand All @@ -73,7 +73,7 @@ Texture2D<half4> SpecularSSGITexture : register(t10);

normalWS = lerp(normalWS, float3(0, 0, 1), wetnessMask);

color = sRGB2Lin(color);
color = SkyrimGamma2Lin(color);

half depth = DepthTexture[dispatchID.xy];

Expand All @@ -89,12 +89,12 @@ Texture2D<half4> SpecularSSGITexture : register(t10);
half roughness = 1.0 - glossiness;
half level = roughness * 7.0;

half3 directionalAmbientColor = sRGB2Lin(mul(DirectionalAmbient, half4(R, 1.0)));
half3 directionalAmbientColor = SkyrimGamma2Lin(mul(DirectionalAmbient, half4(R, 1.0)));
half3 finalIrradiance = 0;

# if defined(INTERIOR)
half3 specularIrradiance = EnvTexture.SampleLevel(LinearSampler, R, level).xyz;
specularIrradiance = sRGB2Lin(specularIrradiance);
specularIrradiance = SkyrimGamma2Lin(specularIrradiance);

finalIrradiance += specularIrradiance;
# elif defined(SKYLIGHTING)
Expand All @@ -114,19 +114,19 @@ Texture2D<half4> SpecularSSGITexture : register(t10);

if (skylightingSpecular < 1.0) {
specularIrradiance = EnvTexture.SampleLevel(LinearSampler, R, level).xyz;
specularIrradiance = sRGB2Lin(specularIrradiance);
specularIrradiance = SkyrimGamma2Lin(specularIrradiance);
}

half3 specularIrradianceReflections = 1.0;

if (skylightingSpecular > 0.0) {
specularIrradianceReflections = EnvReflectionsTexture.SampleLevel(LinearSampler, R, level).xyz;
specularIrradianceReflections = sRGB2Lin(specularIrradianceReflections);
specularIrradianceReflections = SkyrimGamma2Lin(specularIrradianceReflections);
}
finalIrradiance = finalIrradiance * skylightingSpecular + lerp(specularIrradiance, specularIrradianceReflections, skylightingSpecular);
# else
half3 specularIrradianceReflections = EnvReflectionsTexture.SampleLevel(LinearSampler, R, level).xyz;
specularIrradianceReflections = sRGB2Lin(specularIrradianceReflections);
specularIrradianceReflections = SkyrimGamma2Lin(specularIrradianceReflections);

finalIrradiance += specularIrradianceReflections;
# endif
Expand All @@ -138,7 +138,7 @@ Texture2D<half4> SpecularSSGITexture : register(t10);

color += reflectance * finalIrradiance;

color = Lin2sRGB(color);
color = Lin2SkyrimGamma(color);
}

#endif
Expand Down
30 changes: 15 additions & 15 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float3 screenSpaceNormal = normalize(WorldToView(worldSpaceNormal, false, eyeIndex));

# if defined(TRUE_PBR)
baseColor.xyz = pow(baseColor.xyz, 1 / 1.5);
baseColor.xyz = Lin2SkyrimGamma(baseColor.xyz);

PBR::SurfaceProperties pbrSurfaceProperties = PBR::InitSurfaceProperties();

Expand Down Expand Up @@ -1998,7 +1998,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if defined(WETNESS_EFFECTS)
if (waterRoughnessSpecular < 1.0)
wetnessSpecular += GetWetnessSpecular(wetnessNormal, normalizedDirLightDirectionWS, worldSpaceViewDirection, sRGB2Lin(dirLightColor * dirDetailShadow), waterRoughnessSpecular);
wetnessSpecular += GetWetnessSpecular(wetnessNormal, normalizedDirLightDirectionWS, worldSpaceViewDirection, SkyrimGamma2Lin(dirLightColor * dirDetailShadow), waterRoughnessSpecular);
# endif
# endif

Expand Down Expand Up @@ -2207,7 +2207,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if defined(WETNESS_EFFECTS)
if (waterRoughnessSpecular < 1.0)
wetnessSpecular += GetWetnessSpecular(wetnessNormal, normalizedLightDirection, worldSpaceViewDirection, sRGB2Lin(lightColor), waterRoughnessSpecular);
wetnessSpecular += GetWetnessSpecular(wetnessNormal, normalizedLightDirection, worldSpaceViewDirection, SkyrimGamma2Lin(lightColor), waterRoughnessSpecular);
# endif
}
# endif
Expand Down Expand Up @@ -2261,11 +2261,11 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float skylightingDiffuse = shFuncProductIntegral(skylightingSH, shEvaluateCosineLobe(skylightingSettings.DirectionalDiffuse ? worldSpaceNormal : float3(0, 0, 1))) / shPI;
skylightingDiffuse = Skylighting::mixDiffuse(skylightingSettings, skylightingDiffuse);
# if !defined(TRUE_PBR)
directionalAmbientColor = sRGB2Lin(directionalAmbientColor);
directionalAmbientColor = SkyrimGamma2Lin(directionalAmbientColor);
# endif
directionalAmbientColor *= skylightingDiffuse;
# if !defined(TRUE_PBR)
directionalAmbientColor = Lin2sRGB(directionalAmbientColor);
directionalAmbientColor = Lin2SkyrimGamma(directionalAmbientColor);
# endif
# endif

Expand Down Expand Up @@ -2296,7 +2296,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
dynamicCubemap = true;
envColorBase = TexEnvSampler.SampleLevel(SampEnvSampler, float3(1.0, 0.0, 0.0), 0);
if (envColorBase.a < 1.0) {
F0 = sRGB2Lin(envColorBase.rgb) + sRGB2Lin(baseColor.rgb);
F0 = SkyrimGamma2Lin(envColorBase.rgb) + SkyrimGamma2Lin(baseColor.rgb);
envRoughness = envColorBase.a;
} else {
F0 = 1.0;
Expand All @@ -2307,7 +2307,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# if defined(CREATOR)
if (cubemapCreatorSettings.Enabled) {
dynamicCubemap = true;
F0 = sRGB2Lin(cubemapCreatorSettings.CubemapColor.rgb) + sRGB2Lin(baseColor.xyz);
F0 = SkyrimGamma2Lin(cubemapCreatorSettings.CubemapColor.rgb) + SkyrimGamma2Lin(baseColor.xyz);
envRoughness = cubemapCreatorSettings.CubemapColor.a;
}
# endif
Expand All @@ -2316,7 +2316,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# if defined(EMAT)
envRoughness = lerp(envRoughness, 1.0 - complexMaterialColor.y, (float)complexMaterial);
envRoughness *= envRoughness;
F0 = lerp(F0, sRGB2Lin(complexSpecular), (float)complexMaterial);
F0 = lerp(F0, SkyrimGamma2Lin(complexSpecular), (float)complexMaterial);
# endif

envColor = GetDynamicCubemap(screenUV, worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, envRoughness, F0, diffuseColor, viewPosition.z) * envMask;
Expand Down Expand Up @@ -2445,7 +2445,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# else
diffuseColor = 1.0;
# endif
specularColor = sRGB2Lin(specularColor);
specularColor = SkyrimGamma2Lin(specularColor);
}
# endif

Expand All @@ -2462,7 +2462,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif
# if defined(DYNAMIC_CUBEMAPS)
if (dynamicCubemap)
specularColor = Lin2sRGB(specularColor);
specularColor = Lin2SkyrimGamma(specularColor);
# endif
# endif

Expand All @@ -2475,7 +2475,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
color.xyz += specularColor;
# endif

color.xyz = sRGB2Lin(color.xyz);
color.xyz = SkyrimGamma2Lin(color.xyz);
# endif

# if defined(WETNESS_EFFECTS) && !defined(TRUE_PBR)
Expand All @@ -2486,7 +2486,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
color.xyz += specularColorPBR;
# endif

color.xyz = Lin2sRGB(color.xyz);
color.xyz = Lin2SkyrimGamma(color.xyz);

# if defined(LOD_LAND_BLEND) && defined(TRUE_PBR)
{
Expand All @@ -2497,7 +2497,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if defined(DEFERRED)
specularColorPBR = lerp(specularColorPBR, 0, lodLandBlendFactor);
indirectDiffuseLobeWeight = lerp(indirectDiffuseLobeWeight, sRGB2Lin(input.Color.xyz * lodLandColor * lodLandFadeFactor), lodLandBlendFactor);
indirectDiffuseLobeWeight = lerp(indirectDiffuseLobeWeight, SkyrimGamma2Lin(input.Color.xyz * lodLandColor * lodLandFadeFactor), lodLandBlendFactor);
indirectSpecularLobeWeight = lerp(indirectSpecularLobeWeight, 0, lodLandBlendFactor);
pbrGlossiness = lerp(pbrGlossiness, 0, lodLandBlendFactor);
# endif
Expand Down Expand Up @@ -2638,13 +2638,13 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

float3 outputSpecular = specularColor.xyz;
# if defined(TRUE_PBR)
outputSpecular = Lin2sRGB(specularColorPBR.xyz);
outputSpecular = Lin2SkyrimGamma(specularColorPBR.xyz);
# endif
psout.Specular = float4(outputSpecular, psout.Diffuse.w);

float3 outputAlbedo = baseColor.xyz * vertexColor;
# if defined(TRUE_PBR)
outputAlbedo = Lin2sRGB(indirectDiffuseLobeWeight);
outputAlbedo = Lin2SkyrimGamma(indirectDiffuseLobeWeight);
# endif
psout.Albedo = float4(outputAlbedo, psout.Diffuse.w);

Expand Down
10 changes: 5 additions & 5 deletions package/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

diffuseColor.xyz += transmissionColor;
specularColor.xyz += specularColorPBR;
specularColor.xyz = Lin2sRGB(specularColor.xyz);
diffuseColor.xyz = Lin2sRGB(diffuseColor.xyz);
specularColor.xyz = Lin2SkyrimGamma(specularColor.xyz);
diffuseColor.xyz = Lin2SkyrimGamma(diffuseColor.xyz);
# else

# if !defined(SSGI)
Expand All @@ -648,9 +648,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float skylighting = shFuncProductIntegral(skylightingSH, shEvaluateCosineLobe(skylightingSettings.DirectionalDiffuse ? normal : float3(0, 0, 1))) / shPI;
skylighting = Skylighting::mixDiffuse(skylightingSettings, skylighting);

directionalAmbientColor = sRGB2Lin(directionalAmbientColor);
directionalAmbientColor = SkyrimGamma2Lin(directionalAmbientColor);
directionalAmbientColor *= skylighting;
directionalAmbientColor = Lin2sRGB(directionalAmbientColor);
directionalAmbientColor = Lin2SkyrimGamma(directionalAmbientColor);
# endif // SKYLIGHTING

diffuseColor += directionalAmbientColor;
Expand Down Expand Up @@ -681,7 +681,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

float3 normalVS = normalize(WorldToView(normal, false, eyeIndex));
# if defined(TRUE_PBR)
psout.Albedo = float4(Lin2sRGB(indirectDiffuseLobeWeight), 1);
psout.Albedo = float4(Lin2SkyrimGamma(indirectDiffuseLobeWeight), 1);
psout.NormalGlossiness = float4(EncodeNormal(normalVS), 1 - pbrSurfaceProperties.Roughness, 1);
psout.Reflectance = float4(indirectSpecularLobeWeight, 1);
psout.Parameters = float4(0, 0, 1, 1);
Expand Down

0 comments on commit a557986

Please sign in to comment.