Skip to content

Commit ca57d69

Browse files
committed
feat: make gloss work with double sided materials
1 parent b5f11a9 commit ca57d69

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/front/src/core/PostproductionRenderer/src/projected-normal-material.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,21 @@ export function getProjectedNormalMaterial() {
5757
#include <clipping_planes_fragment>
5858
vec3 cameraPixelVec = normalize(vCameraPosition - vPosition);
5959
float dotProduct = dot(vNormal, cameraPixelVec);
60-
float gloss = abs(dotProduct);
6160
62-
float fresnel = pow(1.0 - dotProduct, fresnelExponent) * fresnelFactor;
61+
// Use abs() for both gloss and fresnel to handle DoubleSide materials
62+
// On back faces, dotProduct is negative, which breaks the fresnel calculation
63+
64+
float absDotProduct = abs(dotProduct);
65+
float gloss = absDotProduct;
66+
67+
// Use absDotProduct instead of dotProduct to prevent values > 1.0
6368
64-
// Apply a power function to create smoother transitions
65-
// Lower gamma values (e.g., 0.3-0.5) create smoother, more gradual transitions
66-
// Higher values (0.6-1.0) keep it closer to linear
69+
float fresnel = pow(1.0 - absDotProduct, fresnelExponent) * fresnelFactor;
70+
6771
gloss = pow(gloss, glossExponent) * glossFactor;
6872
6973
float result = gloss + fresnel;
70-
74+
7175
gl_FragColor = vec4(result, result, result, 1.);
7276
}
7377
`,

0 commit comments

Comments
 (0)