diff --git a/package/Shaders/AmbientCompositeCS.hlsl b/package/Shaders/AmbientCompositeCS.hlsl index 946785500..30614f181 100644 --- a/package/Shaders/AmbientCompositeCS.hlsl +++ b/package/Shaders/AmbientCompositeCS.hlsl @@ -55,8 +55,6 @@ 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]; @@ -89,11 +87,10 @@ RWTexture2D DiffuseAmbientRW : register(u1); linDiffuseColor += ssgiDiffuse.rgb; #endif - linAmbient *= visibility; diffuseColor = Lin2sRGB(linDiffuseColor); directionalAmbientColor = Lin2sRGB(linDirectionalAmbientColor * visibility); - diffuseColor = lerp(diffuseColor + directionalAmbientColor * albedo, Lin2sRGB(linDiffuseColor + linAmbient), pbrWeight); + diffuseColor = diffuseColor + directionalAmbientColor * albedo; 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 f52e8295e..07e54be98 100644 --- a/package/Shaders/Common/PBR.hlsli +++ b/package/Shaders/Common/PBR.hlsli @@ -85,6 +85,32 @@ namespace PBR return surfaceProperties; } + struct LightProperties + { + float3 LightColor; + float3 CoatLightColor; + float3 LinearLightColor; + float3 LinearCoatLightColor; + }; + + 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; + } + float3 AdjustDirectionalLightColor(float3 lightColor) { return pbrSettings.DirectionalLightColorMultiplier * sRGB2Lin(lightColor); @@ -372,7 +398,7 @@ namespace PBR return color; } - void GetDirectLightInput(out float3 diffuse, out float3 coatDiffuse, out float3 transmission, out float3 specular, float3 N, float3 coatN, float3 V, float3 coatV, float3 L, float3 coatL, float3 lightColor, float3 coatLightColor, SurfaceProperties surfaceProperties, + void GetDirectLightInput(out float3 diffuse, out float3 coatDiffuse, out float3 transmission, out float3 specular, float3 N, float3 coatN, float3 V, float3 coatV, float3 L, float3 coatL, LightProperties lightProperties, SurfaceProperties surfaceProperties, float3x3 tbnTr, float2 uv) { diffuse = 0; @@ -397,12 +423,12 @@ namespace PBR #if !defined(LANDSCAPE) && !defined(LODLANDSCAPE) [branch] if ((PBRFlags & TruePBR_HairMarschner) != 0) { - transmission += PI * lightColor * GetHairColorMarschner(N, V, L, NdotL, NdotV, VdotL, 0, 1, 0, surfaceProperties); + transmission += PI * lightProperties.LightColor * GetHairColorMarschner(N, V, L, NdotL, NdotV, VdotL, 0, 1, 0, surfaceProperties); } else #endif { - diffuse += lightColor * satNdotL; + diffuse += lightProperties.LightColor * satNdotL; #if defined(GLINT) GlintInput glintInput; @@ -418,9 +444,9 @@ namespace PBR float3 F; #if defined(GLINT) - specular += PI * GetSpecularDirectLightMultiplierMicrofacetWithGlint(surfaceProperties.Roughness, surfaceProperties.F0, satNdotL, satNdotV, satNdotH, satVdotH, glintInput, F) * lightColor * satNdotL; + specular += PI * 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) * lightColor * satNdotL; + specular += PI * GetSpecularDirectLightMultiplierMicrofacet(surfaceProperties.Roughness, surfaceProperties.F0, satNdotL, satNdotV, satNdotH, satVdotH, F) * lightProperties.LinearLightColor * satNdotL; #endif float2 specularBRDF = 0; @@ -433,7 +459,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) * lightColor * satNdotL; + float3 fuzzSpecular = PI * 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); @@ -448,7 +474,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 * lightColor; + transmission += surfaceProperties.SubsurfaceColor * subsurface * lightProperties.LightColor; } else if ((PBRFlags & TruePBR_TwoLayer) != 0) { @@ -467,13 +493,13 @@ namespace PBR } float3 coatF; - float3 coatSpecular = PI * GetSpecularDirectLightMultiplierMicrofacet(surfaceProperties.CoatRoughness, surfaceProperties.CoatF0, coatNdotL, coatNdotV, coatNdotH, coatVdotH, coatF) * coatLightColor * coatNdotL; + float3 coatSpecular = PI * GetSpecularDirectLightMultiplierMicrofacet(surfaceProperties.CoatRoughness, surfaceProperties.CoatF0, coatNdotL, coatNdotV, coatNdotH, coatVdotH, coatF) * lightProperties.LinearCoatLightColor * coatNdotL; float3 layerAttenuation = 1 - coatF * surfaceProperties.CoatStrength; diffuse *= layerAttenuation; specular *= layerAttenuation; - coatDiffuse += coatLightColor * coatNdotL; + coatDiffuse += lightProperties.CoatLightColor * coatNdotL; specular += coatSpecular * surfaceProperties.CoatStrength; } #endif diff --git a/package/Shaders/Common/SharedData.hlsli b/package/Shaders/Common/SharedData.hlsli index faf6c777a..bb7f4985f 100644 --- a/package/Shaders/Common/SharedData.hlsli +++ b/package/Shaders/Common/SharedData.hlsli @@ -137,6 +137,7 @@ struct PBRSettings float DirectionalLightColorMultiplier; float PointLightColorMultiplier; float AmbientLightColorMultiplier; + float BaseColorGamma; uint UseMultipleScattering; uint UseMultiBounceAO; uint3 pad0; diff --git a/package/Shaders/Lighting.hlsl b/package/Shaders/Lighting.hlsl index ff0a27aeb..98090571a 100644 --- a/package/Shaders/Lighting.hlsl +++ b/package/Shaders/Lighting.hlsl @@ -1270,6 +1270,12 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif // LANDSCAPE float4 rawBaseColor = TexColorSampler.Sample(SampColorSampler, diffuseUv); +# if defined(TRUE_PBR) && defined(LANDSCAPE) + [branch] if ((PBRFlags & TruePBR_LandTile0PBR) == 0) + { + rawBaseColor.rgb = pow(rawBaseColor.rgb, pbrSettings.BaseColorGamma); + } +# endif baseColor = rawBaseColor; float landSnowMask1 = GetLandSnowMaskValue(baseColor.w); @@ -1359,7 +1365,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace if (input.LandBlendWeights1.y > 0.0) { float4 landColor2 = TexLandColor2Sampler.Sample(SampLandColor2Sampler, uv); float landSnowMask2 = GetLandSnowMaskValue(landColor2.w); - baseColor += input.LandBlendWeights1.yyyy * landColor2; float4 landNormal2 = TexLandNormal2Sampler.Sample(SampLandNormal2Sampler, uv); landNormal2.xyz = GetLandNormal(landSnowMask2, landNormal2.xyz, uv, SampLandNormal2Sampler, TexLandNormal2Sampler); normal.xyz += input.LandBlendWeights1.yyy * landNormal2.xyz; @@ -1378,15 +1383,16 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { + landColor2.rgb = pow(landColor2.rgb, pbrSettings.BaseColorGamma); rawRMAOS += input.LandBlendWeights1.y * float4(1 - landNormal2.w, 0, 1, 0.04); } + baseColor += input.LandBlendWeights1.yyyy * landColor2; # endif } if (input.LandBlendWeights1.z > 0.0) { float4 landColor3 = TexLandColor3Sampler.Sample(SampLandColor3Sampler, uv); float landSnowMask3 = GetLandSnowMaskValue(landColor3.w); - baseColor += input.LandBlendWeights1.zzzz * landColor3; float4 landNormal3 = TexLandNormal3Sampler.Sample(SampLandNormal3Sampler, uv); landNormal3.xyz = GetLandNormal(landSnowMask3, landNormal3.xyz, uv, SampLandNormal3Sampler, TexLandNormal3Sampler); normal.xyz += input.LandBlendWeights1.zzz * landNormal3.xyz; @@ -1405,15 +1411,16 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { + landColor3.rgb = pow(landColor3.rgb, pbrSettings.BaseColorGamma); rawRMAOS += input.LandBlendWeights1.z * float4(1 - landNormal3.w, 0, 1, 0.04); } + baseColor += input.LandBlendWeights1.zzzz * landColor3; # endif } if (input.LandBlendWeights1.w > 0.0) { float4 landColor4 = TexLandColor4Sampler.Sample(SampLandColor4Sampler, uv); float landSnowMask4 = GetLandSnowMaskValue(landColor4.w); - baseColor += input.LandBlendWeights1.wwww * landColor4; float4 landNormal4 = TexLandNormal4Sampler.Sample(SampLandNormal4Sampler, uv); landNormal4.xyz = GetLandNormal(landSnowMask4, landNormal4.xyz, uv, SampLandNormal4Sampler, TexLandNormal4Sampler); normal.xyz += input.LandBlendWeights1.www * landNormal4.xyz; @@ -1432,15 +1439,16 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { + landColor4.rgb = pow(landColor4.rgb, pbrSettings.BaseColorGamma); rawRMAOS += input.LandBlendWeights1.w * float4(1 - landNormal4.w, 0, 1, 0.04); } + baseColor += input.LandBlendWeights1.wwww * landColor4; # endif } if (input.LandBlendWeights2.x > 0.0) { float4 landColor5 = TexLandColor5Sampler.Sample(SampLandColor5Sampler, uv); float landSnowMask5 = GetLandSnowMaskValue(landColor5.w); - baseColor += input.LandBlendWeights2.xxxx * landColor5; float4 landNormal5 = TexLandNormal5Sampler.Sample(SampLandNormal5Sampler, uv); landNormal5.xyz = GetLandNormal(landSnowMask5, landNormal5.xyz, uv, SampLandNormal5Sampler, TexLandNormal5Sampler); normal.xyz += input.LandBlendWeights2.xxx * landNormal5.xyz; @@ -1459,15 +1467,16 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { + landColor5.rgb = pow(landColor5.rgb, pbrSettings.BaseColorGamma); rawRMAOS += input.LandBlendWeights2.x * float4(1 - landNormal5.w, 0, 1, 0.04); } + baseColor += input.LandBlendWeights2.xxxx * landColor5; # endif } if (input.LandBlendWeights2.y > 0.0) { float4 landColor6 = TexLandColor6Sampler.Sample(SampLandColor6Sampler, uv); float landSnowMask6 = GetLandSnowMaskValue(landColor6.w); - baseColor += input.LandBlendWeights2.yyyy * landColor6; float4 landNormal6 = TexLandNormal6Sampler.Sample(SampLandNormal6Sampler, uv); landNormal6.xyz = GetLandNormal(landSnowMask6, landNormal6.xyz, uv, SampLandNormal6Sampler, TexLandNormal6Sampler); normal.xyz += input.LandBlendWeights2.yyy * landNormal6.xyz; @@ -1486,8 +1495,10 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } else { + landColor6.rgb = pow(landColor6.rgb, pbrSettings.BaseColorGamma); rawRMAOS += input.LandBlendWeights2.y * float4(1 - landNormal6.w, 0, 1, 0.04); } + baseColor += input.LandBlendWeights2.yyyy * landColor6; # endif } @@ -1645,6 +1656,8 @@ 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; @@ -1661,6 +1674,8 @@ 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) { @@ -1696,6 +1711,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } # endif } + + pbrSurfaceProperties.CoatColor = pow(pbrSurfaceProperties.CoatColor, 1 / pbrSettings.BaseColorGamma); } [branch] if ((PBRFlags & TruePBR_Fuzz) != 0) @@ -1945,10 +1962,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace dirLightColorMultiplier *= dirShadow; - float3 noParallaxShadowDirLightColorMultiplier = dirLightColorMultiplier * dirDetailShadow; - dirDetailShadow *= parallaxShadow; - float3 fullShadowDirLightColorMultiplier = dirLightColorMultiplier * dirDetailShadow; - float3 diffuseColor = 0.0.xxx; float3 specularColor = 0.0.xxx; @@ -1958,34 +1971,26 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 lodLandDiffuseColor = 0; - dirLightColor *= dirLightColorMultiplier; - # if defined(TRUE_PBR) { - float3 pbrDirLightColor = PBR::AdjustDirectionalLightColor(DirLightColor.xyz); - float3 mainLayerFinalLightColor = fullShadowDirLightColorMultiplier * pbrDirLightColor; - float coatShadowDirLightColorMultiplier = fullShadowDirLightColorMultiplier; - [branch] if ((PBRFlags & TruePBR_InterlayerParallax) != 0) - { - coatShadowDirLightColorMultiplier = noParallaxShadowDirLightColorMultiplier; - } - float3 coatFinalLightColor = coatShadowDirLightColorMultiplier * pbrDirLightColor; - + PBR::LightProperties lightProperties = PBR::InitLightProperties(dirLightColor, dirLightColorMultiplier * dirDetailShadow, parallaxShadow); float3 dirDiffuseColor, coatDirDiffuseColor, dirTransmissionColor, dirSpecularColor; - PBR::GetDirectLightInput(dirDiffuseColor, coatDirDiffuseColor, dirTransmissionColor, dirSpecularColor, modelNormal.xyz, coatModelNormal, refractedViewDirection, viewDirection, refractedDirLightDirection, DirLightDirection, mainLayerFinalLightColor, coatFinalLightColor, pbrSurfaceProperties, tbnTr, uvOriginal); + PBR::GetDirectLightInput(dirDiffuseColor, coatDirDiffuseColor, dirTransmissionColor, dirSpecularColor, modelNormal.xyz, coatModelNormal, refractedViewDirection, viewDirection, refractedDirLightDirection, DirLightDirection, lightProperties, pbrSurfaceProperties, tbnTr, uvOriginal); lightsDiffuseColor += dirDiffuseColor; coatLightsDiffuseColor += coatDirDiffuseColor; transmissionColor += dirTransmissionColor; specularColorPBR += dirSpecularColor * !Interior; # if defined(LOD_LAND_BLEND) - lodLandDiffuseColor += dirLightColor * saturate(dirLightAngle) * dirDetailShadow; + lodLandDiffuseColor += dirLightColor * saturate(dirLightAngle) * dirLightColorMultiplier * dirDetailShadow * parallaxShadow; # endif # if defined(WETNESS_EFFECTS) if (waterRoughnessSpecular < 1.0) - specularColorPBR += PBR::GetWetnessDirectLightSpecularInput(wetnessNormal, worldSpaceViewDirection, normalizedDirLightDirectionWS, coatFinalLightColor, waterRoughnessSpecular); + specularColorPBR += PBR::GetWetnessDirectLightSpecularInput(wetnessNormal, worldSpaceViewDirection, normalizedDirLightDirectionWS, lightProperties.LinearCoatLightColor, waterRoughnessSpecular); # endif } # else + dirDetailShadow *= parallaxShadow; + dirLightColor *= dirLightColorMultiplier; float3 dirDiffuseColor = dirLightColor * saturate(dirLightAngle) * dirDetailShadow; # if defined(SOFT_LIGHTING) || defined(RIM_LIGHTING) || defined(BACK_LIGHTING) @@ -2043,8 +2048,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 normalizedLightDirection = normalize(lightDirection); - lightColor *= lightShadow; - # if defined(TRUE_PBR) { float3 pointDiffuseColor, coatPointDiffuseColor, pointTransmissionColor, pointSpecularColor; @@ -2053,14 +2056,15 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace { refractedLightDirection = -refract(-normalizedLightDirection, coatModelNormal, eta); } - float3 pbrLightColor = PBR::AdjustPointLightColor(lightColor); - PBR::GetDirectLightInput(pointDiffuseColor, coatPointDiffuseColor, pointTransmissionColor, pointSpecularColor, modelNormal.xyz, coatModelNormal, refractedViewDirection, viewDirection, refractedLightDirection, normalizedLightDirection, pbrLightColor, pbrLightColor, pbrSurfaceProperties, tbnTr, uvOriginal); + PBR::LightProperties lightProperties = PBR::InitLightProperties(lightColor, lightShadow, 1); + PBR::GetDirectLightInput(pointDiffuseColor, coatPointDiffuseColor, pointTransmissionColor, pointSpecularColor, modelNormal.xyz, coatModelNormal, refractedViewDirection, viewDirection, refractedLightDirection, normalizedLightDirection, lightProperties, pbrSurfaceProperties, tbnTr, uvOriginal); lightsDiffuseColor += pointDiffuseColor; coatLightsDiffuseColor += coatPointDiffuseColor; transmissionColor += pointTransmissionColor; specularColorPBR += pointSpecularColor; } # else + lightColor *= lightShadow; float lightAngle = dot(modelNormal.xyz, normalizedLightDirection.xyz); float3 lightDiffuseColor = lightColor * saturate(lightAngle.xxx); @@ -2172,31 +2176,23 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace } # endif - float3 noParallaxShadowLightColor = lightColor * lightShadow; - lightColor = parallaxShadow * noParallaxShadowLightColor; - float3 fullShadowLightColor = lightColor * contactShadow; - # if defined(TRUE_PBR) { - float3 mainLayerFinalLightColor = PBR::AdjustPointLightColor(fullShadowLightColor); - float3 coatFinalLightColor = mainLayerFinalLightColor; - [branch] if ((PBRFlags & TruePBR_InterlayerParallax) != 0) - { - coatFinalLightColor = PBR::AdjustPointLightColor(noParallaxShadowLightColor); - } - + PBR::LightProperties lightProperties = PBR::InitLightProperties(lightColor, lightShadow * contactShadow, parallaxShadow); float3 pointDiffuseColor, coatPointDiffuseColor, pointTransmissionColor, pointSpecularColor; - PBR::GetDirectLightInput(pointDiffuseColor, coatPointDiffuseColor, pointTransmissionColor, pointSpecularColor, worldSpaceNormal.xyz, coatWorldNormal, refractedViewDirectionWS, worldSpaceViewDirection, refractedLightDirection, normalizedLightDirection, mainLayerFinalLightColor, coatFinalLightColor, pbrSurfaceProperties, tbnTr, uvOriginal); + PBR::GetDirectLightInput(pointDiffuseColor, coatPointDiffuseColor, pointTransmissionColor, pointSpecularColor, worldSpaceNormal.xyz, coatWorldNormal, refractedViewDirectionWS, worldSpaceViewDirection, refractedLightDirection, normalizedLightDirection, lightProperties, pbrSurfaceProperties, tbnTr, uvOriginal); lightsDiffuseColor += pointDiffuseColor; coatLightsDiffuseColor += coatPointDiffuseColor; transmissionColor += pointTransmissionColor; specularColorPBR += pointSpecularColor; # if defined(WETNESS_EFFECTS) if (waterRoughnessSpecular < 1.0) - specularColorPBR += PBR::GetWetnessDirectLightSpecularInput(wetnessNormal, worldSpaceViewDirection, normalizedLightDirection, coatFinalLightColor, waterRoughnessSpecular); + specularColorPBR += PBR::GetWetnessDirectLightSpecularInput(wetnessNormal, worldSpaceViewDirection, normalizedLightDirection, lightProperties.LinearCoatLightColor, waterRoughnessSpecular); # endif } # else + lightColor *= parallaxShadow * lightShadow; + float3 lightDiffuseColor = lightColor * contactShadow * saturate(lightAngle.xxx); # if defined(SOFT_LIGHTING) @@ -2265,7 +2261,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 directionalAmbientColor = mul(DirectionalAmbient, modelNormal); # if defined(TRUE_PBR) - directionalAmbientColor = PBR::AdjustAmbientLightColor(directionalAmbientColor); + directionalAmbientColor = directionalAmbientColor; # endif float3 reflectionDiffuseColor = diffuseColor + directionalAmbientColor; @@ -2273,13 +2269,9 @@ 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) @@ -2396,7 +2388,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # endif # if !defined(DYNAMIC_CUBEMAPS) - specularColorPBR += indirectSpecularLobeWeight * directionalAmbientColor; + specularColorPBR += indirectSpecularLobeWeight * sRGB2Lin(directionalAmbientColor); # endif # if !defined(DEFERRED) @@ -2407,7 +2399,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace indirectDiffuseLobeWeight *= vertexColor; # endif - color.xyz += emitColor.xyz; + color.xyz += pow(emitColor.xyz, 1 / pbrSettings.BaseColorGamma); color.xyz += transmissionColor; # else color.xyz += diffuseColor * baseColor.xyz; @@ -2487,9 +2479,9 @@ 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; @@ -2510,7 +2502,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, input.Color.xyz * lodLandColor * lodLandFadeFactor, lodLandBlendFactor); indirectSpecularLobeWeight = lerp(indirectSpecularLobeWeight, 0, lodLandBlendFactor); pbrGlossiness = lerp(pbrGlossiness, 0, lodLandBlendFactor); # endif @@ -2657,7 +2649,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 outputAlbedo = baseColor.xyz * vertexColor; # if defined(TRUE_PBR) - outputAlbedo = Lin2sRGB(indirectDiffuseLobeWeight); + outputAlbedo = indirectDiffuseLobeWeight; # endif psout.Albedo = float4(outputAlbedo, psout.Diffuse.w); diff --git a/package/Shaders/RunGrass.hlsl b/package/Shaders/RunGrass.hlsl index d3380e3a0..1cf822b7e 100644 --- a/package/Shaders/RunGrass.hlsl +++ b/package/Shaders/RunGrass.hlsl @@ -539,19 +539,18 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace float3 lightsDiffuseColor = 0; float3 lightsSpecularColor = 0; - dirLightColor *= dirLightColorMultiplier; - # if defined(TRUE_PBR) { - float3 pbrDirLightColor = PBR::AdjustDirectionalLightColor(DirLightColorShared.xyz) * dirLightColorMultiplier * dirShadow; - + PBR::LightProperties lightProperties = PBR::InitLightProperties(DirLightColorShared.xyz, dirLightColorMultiplier * dirShadow, 1); float3 dirDiffuseColor, coatDirDiffuseColor, dirTransmissionColor, dirSpecularColor; - PBR::GetDirectLightInput(dirDiffuseColor, coatDirDiffuseColor, dirTransmissionColor, dirSpecularColor, normal, normal, viewDirection, viewDirection, DirLightDirection, DirLightDirection, pbrDirLightColor, pbrDirLightColor, pbrSurfaceProperties, tbn, input.TexCoord.xy); + PBR::GetDirectLightInput(dirDiffuseColor, coatDirDiffuseColor, dirTransmissionColor, dirSpecularColor, normal, normal, viewDirection, viewDirection, DirLightDirection, DirLightDirection, lightProperties, pbrSurfaceProperties, tbn, input.TexCoord.xy); lightsDiffuseColor += dirDiffuseColor; transmissionColor += dirTransmissionColor; specularColorPBR += dirSpecularColor; } # else + dirLightColor *= dirLightColorMultiplier; + lightsDiffuseColor += dirLightColor * saturate(dirLightAngle) * dirShadow; float3 albedo = max(0, baseColor.xyz * input.VertexColor.xyz); @@ -592,9 +591,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace # if defined(TRUE_PBR) { + PBR::LightProperties lightProperties = PBR::InitLightProperties(lightColor * intensityMultiplier, 1, 1); float3 pointDiffuseColor, coatDirDiffuseColor, pointTransmissionColor, pointSpecularColor; - float3 pbrLightColor = PBR::AdjustPointLightColor(lightColor * intensityMultiplier); - PBR::GetDirectLightInput(pointDiffuseColor, coatDirDiffuseColor, pointTransmissionColor, pointSpecularColor, normal, normal, viewDirection, viewDirection, normalizedLightDirection, normalizedLightDirection, pbrLightColor, pbrLightColor, pbrSurfaceProperties, tbn, input.TexCoord.xy); + PBR::GetDirectLightInput(pointDiffuseColor, coatDirDiffuseColor, pointTransmissionColor, pointSpecularColor, normal, normal, viewDirection, viewDirection, normalizedLightDirection, normalizedLightDirection, lightProperties, pbrSurfaceProperties, tbn, input.TexCoord.xy); lightsDiffuseColor += pointDiffuseColor; transmissionColor += pointTransmissionColor; specularColorPBR += pointSpecularColor; diff --git a/src/TruePBR.cpp b/src/TruePBR.cpp index 9f0f07e74..58ea69f38 100644 --- a/src/TruePBR.cpp +++ b/src/TruePBR.cpp @@ -141,6 +141,8 @@ void TruePBR::DrawSettings() settings.useMultiBounceAO = useMultiBounceAO; } + ImGui::SliderFloat("Base Color Gamma", &settings.baseColorGamma, 1.f, 3.f, "%.3f"); + ImGui::SliderFloat("Direct Light Color Multiplier", &globalPBRDirectLightColorMultiplier, 1e-3f, 1e2f, "%.3f", ImGuiSliderFlags_Logarithmic); ImGui::SliderFloat("Ambient Light Color Multiplier", &globalPBRAmbientLightColorMultiplier, 1e-3f, 1e2f, "%.3f", ImGuiSliderFlags_Logarithmic); ImGui::TreePop(); @@ -164,6 +166,9 @@ void TruePBR::LoadSettings(json& o_json) settings.useMultiBounceAO = o_json["Use Multi-bounce AO"]; } + if (o_json["Base Color Gamma"].is_number_float()) { + settings.baseColorGamma = o_json["Base Color Gamma"]; + } if (o_json["Direct Light Color Multiplier"].is_number_float()) { globalPBRDirectLightColorMultiplier = o_json["Direct Light Color Multiplier"]; } @@ -177,6 +182,7 @@ void TruePBR::SaveSettings(json& o_json) o_json["Use Multiple Scattering"] = (bool)settings.useMultipleScattering; o_json["Use Multi-bounce AO"] = (bool)settings.useMultiBounceAO; + o_json["Base Color Gamma"] = settings.baseColorGamma; o_json["Direct Light Color Multiplier"] = globalPBRDirectLightColorMultiplier; o_json["Ambient Light Color Multiplier"] = globalPBRAmbientLightColorMultiplier; } diff --git a/src/TruePBR.h b/src/TruePBR.h index 94cd419ba..ef7f9ceff 100644 --- a/src/TruePBR.h +++ b/src/TruePBR.h @@ -57,9 +57,10 @@ struct TruePBR float directionalLightColorMultiplier = 1.f; float pointLightColorMultiplier = 1.f; float ambientLightColorMultiplier = 1.f; + float baseColorGamma = 1.9f; uint32_t useMultipleScattering = true; uint32_t useMultiBounceAO = true; - uint32_t pad[3]; + uint32_t pad[2]; } settings{}; static_assert(sizeof(Settings) % 16 == 0);