Skip to content

Conversation

@LiveTrower
Copy link
Contributor

@LiveTrower LiveTrower commented Oct 9, 2025

Currently, the implementation of Godot's clearcoat is broken as it doesn't correctly reflect the sky and doesn't take the reflection probe's reflections into account, resulting in the clearcoat effect being almost nonexistent.

Improvements and Fixes

  • Now, 1.0−F is applied to implement energy conservation.
  • The sky reflections have been fixed.
  • The clearcoat now takes the reflection probes into account.
  • An approximation of iorTof0(f0ToIor(f0),1.5) is now applied.

The following table shows the before and after.

Before After
before after
before-normal after-normal
before-car after-car

⚠️ Important Notes ⚠️

  • I'm not sure if I'm applying the energy conserving (1.0−F) correctly, so this should be taken with a grain of salt.
  • I removed the horizon specular occlusion from the clearcoat since, in my opinion, there isn't a very noticeable difference and also to make it a bit cheaper, but if someone argues that it's necessary, I can bring it back.
  • For compatibility, since the IBL (Image-Based Lighting) isn't applied to the clearcoat, I left it as is because I don't know if this is intentional due to performance concerns.
  • I wonder if it would be a good idea to also apply specular antialiasing to the clearcoat.
  • This PR is important for the integration of sheen shading.

@fire
Copy link
Member

fire commented Oct 10, 2025

diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index a4e61e8..bd98ee1 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -1551,17 +1551,17 @@ void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, bool is_di
 #endif
 
 #if defined(LIGHT_CLEARCOAT_USED)
-		// Clearcoat ignores normal_map, use vertex normal instead
-		float ccNdotH = clamp(A + dot(vertex_normal, H), 0.0, 1.0);
-		float cLdotH5 = SchlickFresnel(cLdotH);
+	// Clearcoat ignores normal_map, use vertex normal instead
+	float ccNdotH = clamp(A + dot(vertex_normal, H), 0.0, 1.0);
+	float cLdotH5 = SchlickFresnel(cLdotH);
 
-		float Dr = D_GGX(ccNdotH, mix(0.001, 0.1, clearcoat_roughness));
-		float Gr = V_Kelemen(cLdotH);
-		float Fr = mix(0.04, 1.0, cLdotH5) * clearcoat;
-		cc_attenuation = 1.0 - Fr;
-		float clearcoat_specular_brdf_NL = clearcoat * Gr * Fr * Dr * cNdotL;
+	float Dr = D_GGX(ccNdotH, mix(0.001, 0.1, clearcoat_roughness));
+	float Gr = V_Kelemen(cLdotH);
+	float Fr = mix(0.04, 1.0, cLdotH5) * clearcoat;
+	cc_attenuation = 1.0 - Fr;
+	float clearcoat_specular_brdf_NL = clearcoat * Gr * Fr * Dr * cNdotL;
 
-		specular_light += clearcoat_specular_brdf_NL * light_color * attenuation * specular_amount;
+	specular_light += clearcoat_specular_brdf_NL * light_color * attenuation * specular_amount;
 #endif // LIGHT_CLEARCOAT_USED
 
 	if (metallic < 1.0) {

The github actions is complaining about formatting.

@LiveTrower
Copy link
Contributor Author

@fire I'm having trouble with the CHANGELOG.md. The pre-commit hook is giving me this message: "CHANGELOG.md:1297: hidding ==> hiding, hidden." I assume it's because of a typo or spelling error.

@LiveTrower LiveTrower force-pushed the clearcoat-improvements branch from fbe3e95 to e58b2ee Compare October 10, 2025 19:22
@LiveTrower
Copy link
Contributor Author

I already solved it.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected in Forward+ and Compatibility.

In Mobile, I get a shader compilation error (and subsequent error spam) though: test_clearcoat_mobile.zip

Visual comparison in Forward+:

Type Before After
None Screenshot_20251014_174412_none_before Screenshot_20251014_174320_none_after
ReflectionProbe Screenshot_20251014_174400_rp_before Screenshot_20251014_174302_rp_after
SSR Screenshot_20251014_174407_ssr_before Screenshot_20251014_174314_ssr_after
ReflectionProbe + SSR Screenshot_20251014_174355_ssr_rp_before Screenshot_20251014_174255_ssr_rp_after

@LiveTrower
Copy link
Contributor Author

In Mobile, I get a shader compilation error (and subsequent error spam) though: test_clearcoat_mobile.zip

On my end, it's not giving me any error. Could you please show me the error you're getting?

@LiveTrower LiveTrower force-pushed the clearcoat-improvements branch from e58b2ee to 99cc0ae Compare October 22, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants