From 84e3a1d118fdb23c7f60e9dec941d8ed47c8df37 Mon Sep 17 00:00:00 2001 From: piespy <63455655+piespy@users.noreply.github.com> Date: Sun, 21 Sep 2025 12:15:51 +0200 Subject: [PATCH 1/3] Fix incorrect normals of two-sided materials; optional define to disable this Use VFACE pixel shader semantic to determine which side of a two-sided material is drawn, and adjust normal vector. This allows e.g. lighting to apply to both sides. Define MATERIAL_SINGLESIDE in a material file to disable this. --- Materials/material_common_2.0.fxsub | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Materials/material_common_2.0.fxsub b/Materials/material_common_2.0.fxsub index ae77ad2c..b7a5bdd5 100644 --- a/Materials/material_common_2.0.fxsub +++ b/Materials/material_common_2.0.fxsub @@ -1542,11 +1542,17 @@ GbufferParam MaterialPS( in float2 coord0 : TEXCOORD1, #if OCCLUSION_MAP_TYPE == 2 || OCCLUSION_MAP_TYPE == 3 in float2 coord1 : TEXCOORD2, +#endif +#ifndef MATERIAL_SINGLESIDE + in float faceside : VFACE, #endif in float4 worldPos : TEXCOORD3) { normal = normalize(normal); +#ifdef MATERIAL_SINGLESIDE + float faceside = 1; +#endif #if PARALLAX_MAP_FROM #if PARALLAX_MAP_UV_FLIP coord0.y = 1 - coord0.y; @@ -1566,7 +1572,7 @@ GbufferParam MaterialPS( MaterialParam material; material.albedo = GetSubAlbedo(GetAlbedo(coord0), coord0); - material.normal = GetNormal(normal, worldPos.xyz, coord0); + material.normal = GetNormal(normal, worldPos.xyz, coord0) * faceside; #if SPECULAR_ANTIALIASING_ENABLE material.smoothness = GeometricNormalFiltering(GetSmoothness(coord0), material.normal, specularAntiAliasingVariance, specularAntiAliasingThreshold); #else @@ -1594,11 +1600,17 @@ GbufferParam Material2PS( in float2 coord0 : TEXCOORD1, #if OCCLUSION_MAP_TYPE == 2 || OCCLUSION_MAP_TYPE == 3 in float2 coord1 : TEXCOORD2, +#endif +#ifndef MATERIAL_SINGLESIDE + in float faceside : VFACE, #endif in float4 worldPos : TEXCOORD3) { normal = normalize(normal); +#ifdef MATERIAL_SINGLESIDE + float faceside = 1; +#endif #if PARALLAX_MAP_FROM #if PARALLAX_MAP_UV_FLIP coord0.y = 1 - coord0.y; @@ -1623,7 +1635,7 @@ GbufferParam Material2PS( MaterialParam material; material.albedo = GetSubAlbedo(GetAlbedo(coord0), coord0); - material.normal = GetNormal(normal, worldPos.xyz, coord0); + material.normal = GetNormal(normal, worldPos.xyz, coord0) * faceside; material.smoothness = min(geometricSmoothness, GetSmoothness(coord0)); material.metalness = GetMetalness(coord0); material.specular = GetSpecular(coord0); @@ -1677,4 +1689,5 @@ OBJECT_TEC(MainTecBS0, "object_ss") technique EdgeTec{} technique ShadowTech{} -technique ZplotTec{} \ No newline at end of file + +technique ZplotTec{} From a0901ae653ddd917f9b521f161a6c64e3935abd2 Mon Sep 17 00:00:00 2001 From: piespy <63455655+piespy@users.noreply.github.com> Date: Sun, 21 Sep 2025 12:25:30 +0200 Subject: [PATCH 2/3] Fix incorrect normals of two-sided materials; optional define to disable Use VFACE pixel shader semantic to determine which side of a two-sided material is drawn, and adjust normal vector. This allows e.g. lighting to apply to both sides. Define MATERIAL_SINGLESIDE in a material file to disable this. --- Materials/material_common_2.0.fxsub | 1 - 1 file changed, 1 deletion(-) diff --git a/Materials/material_common_2.0.fxsub b/Materials/material_common_2.0.fxsub index b7a5bdd5..956a362d 100644 --- a/Materials/material_common_2.0.fxsub +++ b/Materials/material_common_2.0.fxsub @@ -1689,5 +1689,4 @@ OBJECT_TEC(MainTecBS0, "object_ss") technique EdgeTec{} technique ShadowTech{} - technique ZplotTec{} From 53f8aee64aa665491bca1f66cc70d2cd12741aeb Mon Sep 17 00:00:00 2001 From: piespy <63455655+piespy@users.noreply.github.com> Date: Sun, 21 Sep 2025 12:29:15 +0200 Subject: [PATCH 3/3] Fix incorrect normals of two-sided materials; optional define to disable this Use VFACE pixel shader semantic to determine which side of a two-sided material is drawn, and adjust normal vector. This allows e.g. lighting to apply to both sides. Define MATERIAL_SINGLESIDE in a material file to disable this.