Skip to content

Commit 0f18110

Browse files
committed
Handle the case when surface normal looks away from the camera
This can happen on very bumpy surfaces that are simulated only by normal maps. In real life these points should be hidden by the relief of the surface, but in render they are often visible. They shouldn't be rendered as shaded as it's done for the light-normal angle, because they can still be lit, but the angle should be clamped from below.
1 parent 47371ad commit 0f18110

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

data/shaders/planet.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ mediump float orenNayar(in mediump vec3 normal, in highp vec3 lightDir, in highp
139139
mediump float cosAngleLightNormal = dot(normal, lightDir); //cos theta_i
140140
mediump float cosAngleEyeNormal = dot(normal, viewDir); //cos theta_r
141141
if(cosAngleLightNormal < 0.) return 0.;
142+
if(cosAngleEyeNormal < 0.)
143+
cosAngleEyeNormal = 0.;
142144
//acos can be quite expensive, can we avoid it?
143145
mediump float angleLightNormal = acos(cosAngleLightNormal); //theta_i
144146
mediump float angleEyeNormal = acos(cosAngleEyeNormal); //theta_r

0 commit comments

Comments
 (0)