Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including glsl-diffuse-lambert with all npm packages installed. Try it out:

glsl-diffuse-lambert lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("glsl-diffuse-lambert/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

glsl-diffuse-lambert v1.0.0

Lambertian diffuse lighting for GLSL

glsl-diffuse-lambert

A simple Lambertian diffuse lighting model (somewhat trivial, but included for completeness).

Example

#pragma glslify: lambert = require(glsl-diffuse-lambert)

uniform vec3 lightPosition;

varying vec3 surfacePosition, surfaceNormal;

void main() {
  //Light geometry
  vec3 lightDirection = normalize(lightPosition - surfacePosition);

  //Surface properties
  vec3 normal = normalize(surfaceNormal);
  
  //Compute diffuse light intensity
  float power = lambert(
    lightDirection, 
    normal);

  gl_FragColor = vec4(power,power,power,1.0);
}

Usage

Install with npm:

npm install glsl-diffuse-lambert

Then use with glslify.

API

#pragma glslify: lambert = require(glsl-diffuse-lambert)
float lambert(vec3 lightDir, vec3 normal)

Computes the diffuse intensity in the Lambertian model

  • lightDir is a unit length vec3 pointing from the surface point toward the light
  • normal is the unit length surface normal at the sample point

Returns A float representing the diffuse light intensity

License

(c) 2014 Mikola Lysenko. MIT License

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free