diff --git a/package/Shaders/AmbientCompositeCS.hlsl b/package/Shaders/AmbientCompositeCS.hlsl index 30614f181..946785500 100644 --- a/package/Shaders/AmbientCompositeCS.hlsl +++ b/package/Shaders/AmbientCompositeCS.hlsl @@ -55,6 +55,8 @@ RWTexture2D DiffuseAmbientRW : register(u1); half3 linDirectionalAmbientColor = sRGB2Lin(directionalAmbientColor); half3 linDiffuseColor = sRGB2Lin(diffuseColor); + half3 linAmbient = lerp(sRGB2Lin(albedo * directionalAmbientColor), linAlbedo * linDirectionalAmbientColor, pbrWeight); + half visibility = 1.0; #if defined(SKYLIGHTING) float rawDepth = DepthTexture[dispatchID.xy]; @@ -87,10 +89,11 @@ RWTexture2D DiffuseAmbientRW : register(u1); linDiffuseColor += ssgiDiffuse.rgb; #endif + linAmbient *= visibility; diffuseColor = Lin2sRGB(linDiffuseColor); directionalAmbientColor = Lin2sRGB(linDirectionalAmbientColor * visibility); - diffuseColor = diffuseColor + directionalAmbientColor * albedo; + diffuseColor = lerp(diffuseColor + directionalAmbientColor * albedo, Lin2sRGB(linDiffuseColor + linAmbient), pbrWeight); MainRW[dispatchID.xy] = diffuseColor; }; \ No newline at end of file diff --git a/package/Shaders/Common/PBR.hlsli b/package/Shaders/Common/PBR.hlsli index 07e54be98..9c8d6c15c 100644 --- a/package/Shaders/Common/PBR.hlsli +++ b/package/Shaders/Common/PBR.hlsli @@ -87,8 +87,6 @@ namespace PBR struct LightProperties { - float3 LightColor; - float3 CoatLightColor; float3 LinearLightColor; float3 LinearCoatLightColor; }; @@ -96,16 +94,13 @@ namespace PBR LightProperties InitLightProperties(float3 lightColor, float3 nonParallaxShadow, float3 parallaxShadow) { LightProperties result; - result.LightColor = lightColor * nonParallaxShadow * parallaxShadow; result.LinearLightColor = sRGB2Lin(lightColor) * nonParallaxShadow * parallaxShadow; [branch] if ((PBRFlags & TruePBR_InterlayerParallax) != 0) { - result.CoatLightColor = lightColor * nonParallaxShadow; result.LinearCoatLightColor = sRGB2Lin(lightColor) * nonParallaxShadow; } else { - result.CoatLightColor = result.LightColor; result.LinearCoatLightColor = result.LinearLightColor; } return result; @@ -423,12 +418,12 @@ namespace PBR #if !defined(LANDSCAPE) && !defined(LODLANDSCAPE) [branch] if ((PBRFlags & TruePBR_HairMarschner) != 0) { - transmission += PI * lightProperties.LightColor * GetHairColorMarschner(N, V, L, NdotL, NdotV, VdotL, 0, 1, 0, surfaceProperties); + transmission += lightProperties.LinearLightColor * GetHairColorMarschner(N, V, L, NdotL, NdotV, VdotL, 0, 1, 0, surfaceProperties); } else #endif { - diffuse += lightProperties.LightColor * satNdotL; + diffuse += lightProperties.LinearLightColor * satNdotL * GetDiffuseDirectLightMultiplierLambert(); #if defined(GLINT) GlintInput glintInput; @@ -444,9 +439,9 @@ namespace PBR float3 F; #if defined(GLINT) - specular += PI * GetSpecularDirectLightMultiplierMicrofacetWithGlint(surfaceProperties.Roughness, surfaceProperties.F0, satNdotL, satNdotV, satNdotH, satVdotH, glintInput, F) * lightProperties.LinearLightColor * satNdotL; + specular += GetSpecularDirectLightMultiplierMicrofacetWithGlint(surfaceProperties.Roughness, surfaceProperties.F0, satNdotL, satNdotV, satNdotH, satVdotH, glintInput, F) * lightProperties.LinearLightColor * satNdotL; #else - specular += PI * GetSpecularDirectLightMultiplierMicrofacet(surfaceProperties.Roughness, surfaceProperties.F0, satNdotL, satNdotV, satNdotH, satVdotH, F) * lightProperties.LinearLightColor * satNdotL; + specular += GetSpecularDirectLightMultiplierMicrofacet(surfaceProperties.Roughness, surfaceProperties.F0, satNdotL, satNdotV, satNdotH, satVdotH, F) * lightProperties.LinearLightColor * satNdotL; #endif float2 specularBRDF = 0; @@ -459,7 +454,7 @@ namespace PBR #if !defined(LANDSCAPE) && !defined(LODLANDSCAPE) [branch] if ((PBRFlags & TruePBR_Fuzz) != 0) { - float3 fuzzSpecular = PI * GetSpecularDirectLightMultiplierMicroflakes(surfaceProperties.Roughness, surfaceProperties.FuzzColor, satNdotL, satNdotV, satNdotH, satVdotH) * lightProperties.LinearLightColor * satNdotL; + float3 fuzzSpecular = GetSpecularDirectLightMultiplierMicroflakes(surfaceProperties.Roughness, surfaceProperties.FuzzColor, satNdotL, satNdotV, satNdotH, satVdotH) * lightProperties.LinearLightColor * satNdotL; [branch] if (pbrSettings.UseMultipleScattering) { fuzzSpecular *= 1 + surfaceProperties.FuzzColor * (1 / (specularBRDF.x + specularBRDF.y) - 1); @@ -474,7 +469,7 @@ namespace PBR float forwardScatter = exp2(saturate(-VdotL) * subsurfacePower - subsurfacePower); float backScatter = saturate(satNdotL * surfaceProperties.Thickness + (1.0 - surfaceProperties.Thickness)) * 0.5; float subsurface = lerp(backScatter, 1, forwardScatter) * (1.0 - surfaceProperties.Thickness); - transmission += surfaceProperties.SubsurfaceColor * subsurface * lightProperties.LightColor; + transmission += surfaceProperties.SubsurfaceColor * subsurface * lightProperties.LinearLightColor; } else if ((PBRFlags & TruePBR_TwoLayer) != 0) { @@ -493,13 +488,13 @@ namespace PBR } float3 coatF; - float3 coatSpecular = PI * GetSpecularDirectLightMultiplierMicrofacet(surfaceProperties.CoatRoughness, surfaceProperties.CoatF0, coatNdotL, coatNdotV, coatNdotH, coatVdotH, coatF) * lightProperties.LinearCoatLightColor * coatNdotL; + float3 coatSpecular = GetSpecularDirectLightMultiplierMicrofacet(surfaceProperties.CoatRoughness, surfaceProperties.CoatF0, coatNdotL, coatNdotV, coatNdotH, coatVdotH, coatF) * lightProperties.LinearCoatLightColor * coatNdotL; float3 layerAttenuation = 1 - coatF * surfaceProperties.CoatStrength; diffuse *= layerAttenuation; specular *= layerAttenuation; - coatDiffuse += lightProperties.CoatLightColor * coatNdotL; + coatDiffuse += lightProperties.LinearCoatLightColor * coatNdotL; specular += coatSpecular * surfaceProperties.CoatStrength; } #endif @@ -518,7 +513,7 @@ namespace PBR float VdotH = saturate(dot(V, H)); float3 wetnessF; - float3 wetnessSpecular = PI * GetSpecularDirectLightMultiplierMicrofacet(roughness, wetnessF0, NdotL, NdotV, NdotH, VdotH, wetnessF) * lightColor * NdotL; + float3 wetnessSpecular = GetSpecularDirectLightMultiplierMicrofacet(roughness, wetnessF0, NdotL, NdotV, NdotH, VdotH, wetnessF) * lightColor * NdotL; return wetnessSpecular * wetnessStrength; } @@ -593,7 +588,7 @@ namespace PBR // https://marmosetco.tumblr.com/post/81245981087 float3 R = reflect(-V, N); float horizon = min(1.0 + dot(R, VN), 1.0); - horizon *= horizon * horizon; + horizon = horizon * horizon; specularLobeWeight *= horizon; float3 diffuseAO = surfaceProperties.AO; @@ -604,7 +599,7 @@ namespace PBR specularAO = MultiBounceAO(surfaceProperties.F0, specularAO.x).y; } - diffuseLobeWeight *= diffuseAO; + diffuseLobeWeight *= diffuseAO / PI; specularLobeWeight *= specularAO; } @@ -621,7 +616,7 @@ namespace PBR // https://marmosetco.tumblr.com/post/81245981087 float3 R = reflect(-V, N); float horizon = min(1.0 + dot(R, VN), 1.0); - horizon *= horizon * horizon; + horizon = horizon * horizon; specularLobeWeight *= horizon; return specularLobeWeight * wetnessStrength; diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index 2a2dcebea..91acde44e 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -1272,7 +1272,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # if defined(TRUE_PBR) && defined(LANDSCAPE) [branch] if ((PBRFlags & TruePBR_LandTile0PBR) == 0) { - rawBaseColor.rgb = pow(rawBaseColor.rgb, pbrSettings.BaseColorGamma); + rawBaseColor.rgb = sRGB2Lin(rawBaseColor.rgb) * PI; } # endif baseColor = rawBaseColor; @@ -1382,7 +1382,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { - landColor2.rgb = pow(landColor2.rgb, pbrSettings.BaseColorGamma); + landColor2.rgb = sRGB2Lin(landColor2.rgb) * PI; rawRMAOS += input.LandBlendWeights1.y * float4(1 - landNormal2.w, 0, 1, 0.04); } # endif @@ -1410,7 +1410,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { - landColor3.rgb = pow(landColor3.rgb, pbrSettings.BaseColorGamma); + landColor3.rgb = sRGB2Lin(landColor3.rgb) * PI; rawRMAOS += input.LandBlendWeights1.z * float4(1 - landNormal3.w, 0, 1, 0.04); } # endif @@ -1438,7 +1438,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { - landColor4.rgb = pow(landColor4.rgb, pbrSettings.BaseColorGamma); + landColor4.rgb = sRGB2Lin(landColor4.rgb) * PI; rawRMAOS += input.LandBlendWeights1.w * float4(1 - landNormal4.w, 0, 1, 0.04); } # endif @@ -1466,7 +1466,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { - landColor5.rgb = pow(landColor5.rgb, pbrSettings.BaseColorGamma); + landColor5.rgb = sRGB2Lin(landColor5.rgb) * PI; rawRMAOS += input.LandBlendWeights2.x * float4(1 - landNormal5.w, 0, 1, 0.04); } # endif @@ -1494,7 +1494,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { - landColor6.rgb = pow(landColor6.rgb, pbrSettings.BaseColorGamma); + landColor6.rgb = sRGB2Lin(landColor6.rgb) * PI; rawRMAOS += input.LandBlendWeights2.y * float4(1 - landNormal6.w, 0, 1, 0.04); } # endif @@ -1655,8 +1655,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace baseColor.xyz *= 1 - pbrSurfaceProperties.Metallic; - baseColor.xyz = pow(baseColor.xyz, 1 / pbrSettings.BaseColorGamma); - pbrSurfaceProperties.BaseColor = baseColor.xyz; float3 coatModelNormal = modelNormal.xyz; @@ -1673,8 +1671,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace pbrSurfaceProperties.SubsurfaceColor *= sampledSubsurfaceProperties.xyz; pbrSurfaceProperties.Thickness *= sampledSubsurfaceProperties.w; } - - pbrSurfaceProperties.SubsurfaceColor = pow(pbrSurfaceProperties.SubsurfaceColor, 1 / pbrSettings.BaseColorGamma); } else if ((PBRFlags & TruePBR_TwoLayer) != 0) { @@ -1710,8 +1706,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } # endif } - - pbrSurfaceProperties.CoatColor = pow(pbrSurfaceProperties.CoatColor, 1 / pbrSettings.BaseColorGamma); } [branch] if ((PBRFlags & TruePBR_Fuzz) != 0) @@ -2260,7 +2254,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 directionalAmbientColor = mul(DirectionalAmbient, modelNormal); # if defined(TRUE_PBR) - directionalAmbientColor = directionalAmbientColor; + directionalAmbientColor = sRGB2Lin(directionalAmbientColor); # endif float3 reflectionDiffuseColor = diffuseColor + directionalAmbientColor; @@ -2268,9 +2262,13 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # if defined(SKYLIGHTING) 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); +# endif directionalAmbientColor *= skylightingDiffuse; +# if !defined(TRUE_PBR) directionalAmbientColor = Lin2sRGB(directionalAmbientColor); +# endif # endif # if defined(TRUE_PBR) && defined(LOD_LAND_BLEND) && !defined(DEFERRED) @@ -2387,7 +2385,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif # if !defined(DYNAMIC_CUBEMAPS) - specularColorPBR += indirectSpecularLobeWeight * sRGB2Lin(directionalAmbientColor); + specularColorPBR += indirectSpecularLobeWeight * directionalAmbientColor; # endif # if !defined(DEFERRED) @@ -2398,7 +2396,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace indirectDiffuseLobeWeight *= vertexColor; # endif - color.xyz += pow(emitColor.xyz, 1 / pbrSettings.BaseColorGamma); + color.xyz += emitColor.xyz; color.xyz += transmissionColor; # else color.xyz += diffuseColor * baseColor.xyz; @@ -2478,9 +2476,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # if !defined(DEFERRED) color.xyz += specularColor; # endif -# endif - color.xyz = sRGB2Lin(color.xyz); +# endif # if defined(WETNESS_EFFECTS) && !defined(TRUE_PBR) color.xyz += wetnessSpecular * wetnessGlossinessSpecular; @@ -2501,7 +2498,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # if defined(DEFERRED) specularColorPBR = lerp(specularColorPBR, 0, lodLandBlendFactor); - indirectDiffuseLobeWeight = lerp(indirectDiffuseLobeWeight, input.Color.xyz * lodLandColor * lodLandFadeFactor, lodLandBlendFactor); + indirectDiffuseLobeWeight = lerp(indirectDiffuseLobeWeight, sRGB2Lin(input.Color.xyz * lodLandColor * lodLandFadeFactor), lodLandBlendFactor); indirectSpecularLobeWeight = lerp(indirectSpecularLobeWeight, 0, lodLandBlendFactor); pbrGlossiness = lerp(pbrGlossiness, 0, lodLandBlendFactor); # endif @@ -2648,7 +2645,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 outputAlbedo = baseColor.xyz * vertexColor; # if defined(TRUE_PBR) - outputAlbedo = indirectDiffuseLobeWeight; + outputAlbedo = Lin2sRGB(indirectDiffuseLobeWeight); # endif psout.Albedo = float4(outputAlbedo, psout.Diffuse.w);