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
12 changes: 5 additions & 7 deletions package/Shaders/AmbientCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,15 @@ void SampleSSGI(uint2 pixCoord, float3 normalWS, out float ao, out float3 il)
float3 albedo = AlbedoTexture[dispatchID.xy];
float3 masks2 = Masks2Texture[dispatchID.xy];

float pbrWeight = masks2.z;

float3 normalWS = normalize(mul(FrameBuffer::CameraViewInverse[eyeIndex], float4(normalVS, 0)).xyz);

float3 directionalAmbientColor = mul(SharedData::DirectionalAmbient, float4(normalWS, 1.0));

float3 linAlbedo = Color::GammaToLinear(albedo) / Color::AlbedoPreMult;
float3 linDirectionalAmbientColor = Color::GammaToLinear(directionalAmbientColor) / Color::LightPreMult;
float3 linAlbedo = Color::GammaToLinear(albedo);
float3 linDirectionalAmbientColor = Color::GammaToLinear(directionalAmbientColor);
float3 linDiffuseColor = Color::GammaToLinear(diffuseColor);

float3 linAmbient = lerp(Color::GammaToLinear(albedo * directionalAmbientColor), linAlbedo * linDirectionalAmbientColor, pbrWeight);
float3 linAmbient = Color::GammaToLinear(albedo * directionalAmbientColor);

float visibility = 1.0;
#if defined(SKYLIGHTING)
Expand Down Expand Up @@ -120,9 +118,9 @@ void SampleSSGI(uint2 pixCoord, float3 normalWS, out float ao, out float3 il)

linAmbient *= visibility;
diffuseColor = Color::LinearToGamma(linDiffuseColor);
directionalAmbientColor = Color::LinearToGamma(linDirectionalAmbientColor * visibility * Color::LightPreMult);
directionalAmbientColor = Color::LinearToGamma(linDirectionalAmbientColor * visibility);

diffuseColor = lerp(diffuseColor + directionalAmbientColor * albedo, Color::LinearToGamma(linDiffuseColor + linAmbient), pbrWeight);
diffuseColor = diffuseColor + directionalAmbientColor * albedo;

MainRW[dispatchID.xy] = float4(diffuseColor, 1);
};
22 changes: 20 additions & 2 deletions package/Shaders/Common/Color.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ namespace Color
tmp - color.y);
}

const static float AlbedoPreMult = 1 / 1.7; // greater value -> brighter pbr
const static float LightPreMult = 1 / (Math::PI * AlbedoPreMult); // ensure 1/PI as product
// attempt to match vanilla diffuse that's a bit darker than normal srgb textures
const static float AlbedoDiffusePower = 1 / 1.7;

float3 GammaToLinear(float3 color)
{
Expand All @@ -53,6 +53,24 @@ namespace Color
{
return pow(abs(color), 1.0 / 2.2);
}

float3 Diffuse(float3 color)
{
#if defined(TRUE_PBR)
return pow(abs(color), AlbedoDiffusePower);
#else
return color;
#endif
}

float3 Light(float3 color)
{
#if defined(TRUE_PBR)
return color * Math::PI;
#else
return color;
#endif
}
}

#endif //__COLOR_DEPENDENCY_HLSL__
6 changes: 3 additions & 3 deletions package/Shaders/Common/PBR.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ namespace PBR
LightProperties InitLightProperties(float3 lightColor, float3 nonParallaxShadow, float3 parallaxShadow)
{
LightProperties result;
result.LinearLightColor = Color::GammaToLinear(lightColor) * nonParallaxShadow * parallaxShadow / Color::LightPreMult;
result.LinearLightColor = lightColor * nonParallaxShadow * parallaxShadow;
[branch] if ((PBRFlags & Flags::InterlayerParallax) != 0)
{
result.LinearCoatLightColor = Color::GammaToLinear(lightColor) * nonParallaxShadow / Color::LightPreMult;
result.LinearCoatLightColor = lightColor * nonParallaxShadow;
}
else
{
Expand Down Expand Up @@ -587,7 +587,7 @@ namespace PBR
diffuseAO = MultiBounceAO(diffuseColor, diffuseAO.x).y;
specularAO = MultiBounceAO(surfaceProperties.F0, specularAO.x).y;

diffuseLobeWeight *= diffuseAO / Math::PI;
diffuseLobeWeight *= diffuseAO;
specularLobeWeight *= specularAO;
}

Expand Down
4 changes: 1 addition & 3 deletions package/Shaders/DeferredCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il)
MotionVectorsRW[dispatchID.xy] = MotionBlur::GetSSMotionVector(positionWS, positionWS, eyeIndex); // Apply sky motion vectors
}

float pbrWeight = masks2.z;

float glossiness = normalGlossiness.z;

float3 color = lerp(diffuseColor + specularColor, Color::LinearToGamma(Color::GammaToLinear(diffuseColor) + Color::GammaToLinear(specularColor)), pbrWeight);
float3 color = diffuseColor + specularColor;

#if defined(DYNAMIC_CUBEMAPS)

Expand Down
46 changes: 19 additions & 27 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1299,10 +1299,10 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# if defined(TRUE_PBR) && defined(LANDSCAPE)
[branch] if ((PBRFlags & PBR::TerrainFlags::LandTile0PBR) == 0)
{
rawBaseColor.rgb = Color::GammaToLinear(rawBaseColor.rgb) / Color::AlbedoPreMult;
// relevant for linear only
}
# endif
baseColor = rawBaseColor;
baseColor = float4(Color::Diffuse(rawBaseColor.rgb), rawBaseColor.a);

float landSnowMask1 = GetLandSnowMaskValue(baseColor.w);
float4 normalColor = TexNormalSampler.Sample(SampNormalSampler, uv);
Expand Down Expand Up @@ -1390,6 +1390,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

if (input.LandBlendWeights1.y > 0.0) {
float4 landColor2 = TexLandColor2Sampler.Sample(SampLandColor2Sampler, uv);
landColor2.rgb = Color::Diffuse(landColor2.rgb);
float landSnowMask2 = GetLandSnowMaskValue(landColor2.w);
float4 landNormal2 = TexLandNormal2Sampler.Sample(SampLandNormal2Sampler, uv);
landNormal2.xyz = GetLandNormal(landSnowMask2, landNormal2.xyz, uv, SampLandNormal2Sampler, TexLandNormal2Sampler);
Expand All @@ -1409,7 +1410,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
}
else
{
landColor2.rgb = Color::GammaToLinear(landColor2.rgb) / Color::AlbedoPreMult;
rawRMAOS += input.LandBlendWeights1.y * float4(1 - landNormal2.w, 0, 1, 0.04);
}
# endif
Expand All @@ -1418,6 +1418,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

if (input.LandBlendWeights1.z > 0.0) {
float4 landColor3 = TexLandColor3Sampler.Sample(SampLandColor3Sampler, uv);
landColor3.rgb = Color::Diffuse(landColor3.rgb);
float landSnowMask3 = GetLandSnowMaskValue(landColor3.w);
float4 landNormal3 = TexLandNormal3Sampler.Sample(SampLandNormal3Sampler, uv);
landNormal3.xyz = GetLandNormal(landSnowMask3, landNormal3.xyz, uv, SampLandNormal3Sampler, TexLandNormal3Sampler);
Expand All @@ -1437,7 +1438,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
}
else
{
landColor3.rgb = Color::GammaToLinear(landColor3.rgb) / Color::AlbedoPreMult;
rawRMAOS += input.LandBlendWeights1.z * float4(1 - landNormal3.w, 0, 1, 0.04);
}
# endif
Expand All @@ -1446,6 +1446,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

if (input.LandBlendWeights1.w > 0.0) {
float4 landColor4 = TexLandColor4Sampler.Sample(SampLandColor4Sampler, uv);
landColor4.rgb = Color::Diffuse(landColor4.rgb);
float landSnowMask4 = GetLandSnowMaskValue(landColor4.w);
float4 landNormal4 = TexLandNormal4Sampler.Sample(SampLandNormal4Sampler, uv);
landNormal4.xyz = GetLandNormal(landSnowMask4, landNormal4.xyz, uv, SampLandNormal4Sampler, TexLandNormal4Sampler);
Expand All @@ -1465,7 +1466,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
}
else
{
landColor4.rgb = Color::GammaToLinear(landColor4.rgb) / Color::AlbedoPreMult;
rawRMAOS += input.LandBlendWeights1.w * float4(1 - landNormal4.w, 0, 1, 0.04);
}
# endif
Expand All @@ -1474,6 +1474,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

if (input.LandBlendWeights2.x > 0.0) {
float4 landColor5 = TexLandColor5Sampler.Sample(SampLandColor5Sampler, uv);
landColor5.rgb = Color::Diffuse(landColor5.rgb);
float landSnowMask5 = GetLandSnowMaskValue(landColor5.w);
float4 landNormal5 = TexLandNormal5Sampler.Sample(SampLandNormal5Sampler, uv);
landNormal5.xyz = GetLandNormal(landSnowMask5, landNormal5.xyz, uv, SampLandNormal5Sampler, TexLandNormal5Sampler);
Expand All @@ -1493,7 +1494,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
}
else
{
landColor5.rgb = Color::GammaToLinear(landColor5.rgb) / Color::AlbedoPreMult;
rawRMAOS += input.LandBlendWeights2.x * float4(1 - landNormal5.w, 0, 1, 0.04);
}
# endif
Expand All @@ -1502,6 +1502,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

if (input.LandBlendWeights2.y > 0.0) {
float4 landColor6 = TexLandColor6Sampler.Sample(SampLandColor6Sampler, uv);
landColor6.rgb = Color::Diffuse(landColor6.rgb);
float landSnowMask6 = GetLandSnowMaskValue(landColor6.w);
float4 landNormal6 = TexLandNormal6Sampler.Sample(SampLandNormal6Sampler, uv);
landNormal6.xyz = GetLandNormal(landSnowMask6, landNormal6.xyz, uv, SampLandNormal6Sampler, TexLandNormal6Sampler);
Expand All @@ -1521,7 +1522,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
}
else
{
landColor6.rgb = Color::GammaToLinear(landColor6.rgb) / Color::AlbedoPreMult;
rawRMAOS += input.LandBlendWeights2.y * float4(1 - landNormal6.w, 0, 1, 0.04);
}
# endif
Expand Down Expand Up @@ -1889,7 +1889,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
waterRoughnessSpecular = 1.0 - wetnessGlossinessSpecular;
# endif

float3 dirLightColor = DirLightColor.xyz;
float3 dirLightColor = Color::Light(DirLightColor.xyz);
float3 dirLightColorMultiplier = 1;

# if defined(WATER_EFFECTS)
Expand Down Expand Up @@ -2039,7 +2039,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if defined(WETNESS_EFFECTS)
if (waterRoughnessSpecular < 1.0)
wetnessSpecular += WetnessEffects::GetWetnessSpecular(wetnessNormal, normalizedDirLightDirectionWS, worldSpaceViewDirection, Color::GammaToLinear(dirLightColor * dirDetailShadow) / Color::LightPreMult, waterRoughnessSpecular);
wetnessSpecular += WetnessEffects::GetWetnessSpecular(wetnessNormal, normalizedDirLightDirectionWS, worldSpaceViewDirection, Color::GammaToLinear(dirLightColor * dirDetailShadow), waterRoughnessSpecular);
# endif
# endif

Expand All @@ -2054,7 +2054,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
continue;

float intensityMultiplier = 1 - intensityFactor * intensityFactor;
float3 lightColor = PointLightColor[lightIndex].xyz * intensityMultiplier;
float3 lightColor = Color::Light(PointLightColor[lightIndex].xyz) * intensityMultiplier;
float lightShadow = 1.f;
if (Permutation::PixelShaderDescriptor & Permutation::LightingFlags::DefShadow) {
if (lightIndex < numShadowLights) {
Expand Down Expand Up @@ -2151,7 +2151,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
continue;

float intensityMultiplier = 1 - intensityFactor * intensityFactor;
float3 lightColor = light.color.xyz * intensityMultiplier;
float3 lightColor = Color::Light(light.color.xyz) * intensityMultiplier;
float lightShadow = 1.0;

float shadowComponent = 1.0;
Expand Down Expand Up @@ -2254,7 +2254,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if defined(WETNESS_EFFECTS)
if (waterRoughnessSpecular < 1.0)
wetnessSpecular += WetnessEffects::GetWetnessSpecular(wetnessNormal, normalizedLightDirection, worldSpaceViewDirection, Color::GammaToLinear(lightColor) / Color::LightPreMult, waterRoughnessSpecular);
wetnessSpecular += WetnessEffects::GetWetnessSpecular(wetnessNormal, normalizedLightDirection, worldSpaceViewDirection, Color::GammaToLinear(lightColor), waterRoughnessSpecular);
# endif
}
# endif
Expand All @@ -2267,9 +2267,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
if (Permutation::PixelShaderDescriptor & Permutation::LightingFlags::CharacterLight) {
float charLightMul = saturate(dot(worldSpaceViewDirection, worldSpaceNormal.xyz)) * CharacterLightParams.x + CharacterLightParams.y * saturate(dot(float2(0.164398998, -0.986393988), worldSpaceNormal.yz));
float charLightColor = min(CharacterLightParams.w, max(0, CharacterLightParams.z * TexCharacterLightProjNoiseSampler.Sample(SampCharacterLightProjNoiseSampler, baseShadowUV).x));
# if defined(TRUE_PBR)
charLightColor = Color::GammaToLinear(charLightColor).x / Color::LightPreMult;
# endif
diffuseColor += (charLightMul * charLightColor).xxx;
}
# endif
Expand All @@ -2296,9 +2293,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif

float3 directionalAmbientColor = mul(DirectionalAmbient, modelNormal);
# if defined(TRUE_PBR)
directionalAmbientColor = Color::GammaToLinear(directionalAmbientColor) / Color::LightPreMult;
# endif

float3 reflectionDiffuseColor = diffuseColor + directionalAmbientColor;

Expand All @@ -2307,11 +2301,11 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
skylightingDiffuse = lerp(1.0, skylightingDiffuse, Skylighting::getFadeOutFactor(input.WorldPosition.xyz));
skylightingDiffuse = Skylighting::mixDiffuse(SharedData::skylightingSettings, skylightingDiffuse);
# if !defined(TRUE_PBR)
directionalAmbientColor = Color::GammaToLinear(directionalAmbientColor) / Color::LightPreMult;
directionalAmbientColor = Color::GammaToLinear(directionalAmbientColor);
# endif
directionalAmbientColor *= skylightingDiffuse;
# if !defined(TRUE_PBR)
directionalAmbientColor = Color::LinearToGamma(directionalAmbientColor * Color::LightPreMult);
directionalAmbientColor = Color::LinearToGamma(directionalAmbientColor);
# endif
# endif

Expand Down Expand Up @@ -2563,12 +2557,10 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
specularColor *= complexSpecular;
# endif // defined (EMAT) && defined(ENVMAP)

# if !defined(TRUE_PBR)
# if !defined(DEFERRED)
# if !defined(DEFERRED)
color.xyz += specularColor;
# endif
color.xyz = Color::GammaToLinear(color.xyz);
# endif
color.xyz = Color::GammaToLinear(color.xyz);

# if defined(WETNESS_EFFECTS) && !defined(TRUE_PBR)
color.xyz += wetnessSpecular * wetnessGlossinessSpecular;
Expand All @@ -2589,7 +2581,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

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

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

float3 outputAlbedo = baseColor.xyz * vertexColor;
# if defined(TRUE_PBR)
outputAlbedo = Color::LinearToGamma(indirectDiffuseLobeWeight * Color::AlbedoPreMult);
outputAlbedo = 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 @@ -680,9 +680,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
skylighting = lerp(1.0, skylighting, Skylighting::getFadeOutFactor(input.WorldPosition));
skylighting = Skylighting::mixDiffuse(SharedData::skylightingSettings, skylighting);

directionalAmbientColor = Color::GammaToLinear(directionalAmbientColor) / Color::LightPreMult;
directionalAmbientColor = Color::GammaToLinear(directionalAmbientColor);
directionalAmbientColor *= skylighting;
directionalAmbientColor = Color::LinearToGamma(directionalAmbientColor * Color::LightPreMult);
directionalAmbientColor = Color::LinearToGamma(directionalAmbientColor);
# endif // SKYLIGHTING

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

float3 normalVS = normalize(FrameBuffer::WorldToView(normal, false, eyeIndex));
# if defined(TRUE_PBR)
psout.Albedo = float4(Color::LinearToGamma(indirectDiffuseLobeWeight * Color::AlbedoPreMult), 1);
psout.Albedo = float4(Color::LinearToGamma(indirectDiffuseLobeWeight), 1);
psout.NormalGlossiness = float4(GBuffer::EncodeNormal(normalVS), 1 - pbrSurfaceProperties.Roughness, 1);
psout.Reflectance = float4(indirectSpecularLobeWeight, 1);
psout.Parameters = float4(0, 0, 1, 1);
Expand Down Expand Up @@ -837,9 +837,9 @@ PS_OUTPUT main(PS_INPUT input)
skylighting = lerp(1.0, skylighting, Skylighting::getFadeOutFactor(input.WorldPosition));
skylighting = Skylighting::mixDiffuse(SharedData::skylightingSettings, skylighting);

directionalAmbientColor = Color::GammaToLinear(directionalAmbientColor) / Color::LightPreMult;
directionalAmbientColor = Color::GammaToLinear(directionalAmbientColor);
directionalAmbientColor *= skylighting;
directionalAmbientColor = Color::LinearToGamma(directionalAmbientColor * Color::LightPreMult);
directionalAmbientColor = Color::LinearToGamma(directionalAmbientColor);
# endif // SKYLIGHTING

diffuseColor += directionalAmbientColor;
Expand Down