glsl-face-normal
Approximates face normals in the fragment shader for flat shading from the position in camera space.
Note: You need to enable GL_OES_standard_derivatives
.
Fragment:
#extension GL_OES_standard_derivatives : enablevarying vec3 vViewPos; # faceNormal = require('glsl-face-normal') void
Vertex:
varying vec3 vViewPos; void
Usage
vec3 normal = faceNormal(vec3 pos)
Approximates the face normal
from the given pos
, which is typically the position in camera-space.
For better precision, you can use the eye relative position instead.
License
MIT. See LICENSE.md for details.