glsl-face-normal
approximate face normal in the fragment shader
Last updated 6 years ago by mattdesl .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install glsl-face-normal 
SYNC missed versions from official npm registry.

glsl-face-normal

stable

demo-image

(click for demo)

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 : enable
varying vec3 vViewPos;

#pragma glslify: faceNormal = require('glsl-face-normal')

void main() {
  vec3 normal = faceNormal(vViewPos);
  //... lighting
}

Vertex:

varying vec3 vViewPos;

void main() {
  vec4 pos = vec4(position, 1.0);
  vec4 mpos = modelViewMatrix * pos;
  gl_Position = projectionMatrix * mpos;
  vViewPos = -mpos.xyz;
}

Usage

NPM

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.

Current Tags

  • 1.0.2                                ...           latest (6 years ago)

3 Versions

  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 8
Dependencies (0)
None
Dev Dependencies (7)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |