Skip to content

Commit

Permalink
feat: vanilla ambient specular
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlum committed Feb 13, 2025
1 parent 4606ba9 commit 04906e4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 48 deletions.
4 changes: 2 additions & 2 deletions package/Shaders/DeferredCompositeCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ void SampleSSGISpecular(uint2 pixCoord, sh2 lobe, out float ao, out float3 il)
ssgiIlSpecular = ssgiMixed.rgb;
# endif

finalIrradiance = (finalIrradiance * ssgiAo * smoothstep(0.0, 1.0 - (1.0 / 7.0), glossiness)) + ssgiIlSpecular;
finalIrradiance = (finalIrradiance * ssgiAo) + ssgiIlSpecular;
# else
finalIrradiance *= smoothstep(0.0, 1.0 - (1.0 / 7.0), glossiness);
// finalIrradiance *= sqrt(glossiness);
# endif

color += reflectance * finalIrradiance;
Expand Down
73 changes: 34 additions & 39 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
diffuseColor += directionalAmbientColor;
# endif

float3 F0 = 0.04;
float roughness = 1.0;

# if defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE)
float envMask = EnvmapData.x * MaterialData.x;

Expand All @@ -2316,20 +2319,23 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float3 envColor = 0.0;
bool dynamicCubemap = false;

# if defined(DYNAMIC_CUBEMAPS)
float3 F0 = 0.0;
float envRoughness = 1.0;
# endif

if (envMask > 0.0) {
# if defined(DYNAMIC_CUBEMAPS)
uint2 envSize;
TexEnvSampler.GetDimensions(envSize.x, envSize.y);

# if defined(EMAT)
if (envSize.x == 1 && envSize.y == 1 || complexMaterial) {
# if defined(CREATOR)
# if defined(EMAT)
if (envSize.x == 1 && envSize.y == 1 || complexMaterial || SharedData::cubemapCreatorSettings.Enabled) {
# else
if (envSize.x == 1 && envSize.y == 1 || SharedData::cubemapCreatorSettings.Enabled) {
# endif
# else
# if defined(EMAT)
if (envSize.x == 1 && envSize.y == 1 || complexMaterial) {
# else
if (envSize.x == 1 && envSize.y == 1) {
# endif
# endif

dynamicCubemap = true;
Expand All @@ -2351,6 +2357,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

if (dynamicCubemap) {
float4 envColorBase = TexEnvSampler.SampleLevel(SampEnvSampler, float3(1.0, 0.0, 0.0), 15);
float envRoughness = 1.0;

if (envColorBase.a < 1.0) {
F0 = Color::GammaToLinear(envColorBase.rgb);
Expand All @@ -2373,14 +2380,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
F0 = lerp(F0, Color::GammaToLinear(complexSpecular), complexMaterial);
# endif

if (any(F0 > 0.0))
# if defined(SKYLIGHTING)
envColor = DynamicCubemaps::GetDynamicCubemap(worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, envRoughness, F0, skylightingSH) * envMask;
# else
envColor = DynamicCubemaps::GetDynamicCubemap(worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, envRoughness, F0, ) * envMask;
# endif
else
envColor = 0.0;
envMask = saturate(envMask);
F0 = lerp(0.04, F0, envMask);
roughness = lerp(roughness, envRoughness, pow(envMask, 0.25));
}
}
# endif
Expand All @@ -2393,6 +2395,16 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# endif // defined (ENVMAP) || defined (MULTI_LAYER_PARALLAX) || defined(EYE)

# if defined(DYNAMIC_CUBEMAPS)
# if defined(SKYLIGHTING)
float3 reflectance = DynamicCubemaps::GetDynamicCubemap(worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, roughness, F0, skylightingSH);
# else
float3 reflectance = DynamicCubemaps::GetDynamicCubemap(worldSpaceNormal, worldSpaceVertexNormal, worldSpaceViewDirection, roughness, F0);
# endif
# else
float3 reflectance = 0;
# endif

float2 screenMotionVector = MotionBlur::GetSSMotionVector(input.WorldPosition, input.PreviousWorldPosition, eyeIndex);

# if defined(WETNESS_EFFECTS)
Expand All @@ -2415,7 +2427,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
baseColor.xyz = lerp(baseColor.xyz, pow(baseColor.xyz, 1.0 + wetnessDarkeningAmount), 0.8);
# endif

float3 wetnessReflectance = WetnessEffects::GetWetnessAmbientSpecular(screenUV, wetnessNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 1.0 - wetnessGlossinessSpecular) * wetnessGlossinessSpecular;
float3 wetnessReflectance = WetnessEffects::GetWetnessAmbientSpecular(screenUV, wetnessNormal, worldSpaceVertexNormal, worldSpaceViewDirection, 1.0 - wetnessGlossinessSpecular);

# if !defined(DEFERRED)
wetnessSpecular += wetnessReflectance;
Expand Down Expand Up @@ -2572,9 +2584,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
baseColor.xyz = 0.0;
specularColor = 0.0;
diffuseColor = 0.0;
dynamicCubemap = true;
envColor = 1.0;
envRoughness = 0.0;
reflectance = 1.0;
roughness = 0.0;
color.xyz = 0;
# endif

Expand Down Expand Up @@ -2706,17 +2717,15 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif
psout.Albedo = float4(outputAlbedo, psout.Diffuse.w);

float outGlossiness = saturate(glossiness * SSRParams.w);

# if defined(TRUE_PBR)
psout.Reflectance = float4(indirectSpecularLobeWeight, psout.Diffuse.w);
psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), pbrGlossiness, psout.Diffuse.w);
# elif defined(WETNESS_EFFECTS)
psout.Reflectance = float4(wetnessReflectance, psout.Diffuse.w);
psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), lerp(outGlossiness, 1.0, wetnessGlossinessSpecular), psout.Diffuse.w);
psout.Reflectance = float4(max(reflectance, wetnessReflectance), psout.Diffuse.w);
psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), 1.0 - roughness, psout.Diffuse.w);
# else
psout.Reflectance = float4(0.0.xxx, psout.Diffuse.w);
psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), outGlossiness, psout.Diffuse.w);
psout.Reflectance = float4(reflectance, psout.Diffuse.w);
psout.NormalGlossiness = float4(GBuffer::EncodeNormal(screenSpaceNormal), 1.0 - roughness, psout.Diffuse.w);
# endif

# if defined(TERRAIN_BLENDING)
Expand All @@ -2727,20 +2736,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
psout.Parameters.w = psout.Diffuse.w;
# endif

# if (defined(ENVMAP) || defined(MULTI_LAYER_PARALLAX) || defined(EYE))
# if defined(DYNAMIC_CUBEMAPS)
if (dynamicCubemap) {
# if defined(WETNESS_EFFECTS)
psout.Reflectance.xyz = max(envColor, wetnessReflectance);
psout.NormalGlossiness.z = lerp(1.0 - envRoughness, 1.0, wetnessGlossinessSpecular);
# else
psout.Reflectance.xyz = envColor;
psout.NormalGlossiness.z = 1.0 - envRoughness;
# endif
}
# endif
# endif

# if defined(SSS) && defined(SKIN)
psout.Masks = float4(saturate(baseColor.a), !(Permutation::ExtraShaderDescriptor & Permutation::ExtraFlags::IsBeastRace), 0, psout.Diffuse.w);
# elif defined(WETNESS_EFFECTS)
Expand Down
23 changes: 16 additions & 7 deletions package/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,8 @@ struct PS_OUTPUT
float4 NormalGlossiness : SV_Target2;
float4 Albedo : SV_Target3;
float4 Specular : SV_Target4;
# if defined(TRUE_PBR)
float4 Reflectance : SV_Target5;
# endif // TRUE_PBR
float4 Masks : SV_Target6;
# if defined(TRUE_PBR)
float4 Parameters : SV_Target7;
# endif // TRUE_PBR
# endif // RENDER_DEPTH
};
#else
Expand Down Expand Up @@ -717,10 +712,24 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
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);
# else

float3 F0 = 0.04;
float roughness = 1.0;

# if defined(DYNAMIC_CUBEMAPS)
# if defined(SKYLIGHTING)
float3 reflectance = DynamicCubemaps::GetDynamicCubemap(normal, normal, viewDirection, roughness, F0, 0);
# else
float3 reflectance = DynamicCubemaps::GetDynamicCubemap(normal, normal, viewDirection, roughness, F0);
# endif
# else
float3 reflectance = 0;
# endif

psout.Reflectance = float4(reflectance, 1);
psout.Albedo = float4(albedo, 1);
psout.NormalGlossiness = float4(GBuffer::EncodeNormal(normalVS), specColor.w, 1);
psout.NormalGlossiness = float4(GBuffer::EncodeNormal(normalVS), 1.0 - roughness, 1);
# endif

psout.Specular = float4(specularColor, 1);
Expand Down

0 comments on commit 04906e4

Please sign in to comment.