Giter VIP home page Giter VIP logo

glsl-specular-cook-torrance's Introduction

glsl-specular-cook-torrance

Computes the specular power in the Cook-Torrance model.

Example

#pragma glslify: cookTorranceSpec = require(glsl-specular-cook-torrance)

uniform vec3 eyePosition;
uniform vec3 lightPosition;

uniform float roughness, fresnel;

varying vec3 surfacePosition, surfaceNormal;

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

  //Surface properties
  vec3 normal = normalize(surfaceNormal);
  
  //Compute specular power
  float power = cookTorranceSpec(
    lightDirection, 
    viewDirection, 
    normal, 
    roughness,
    fresnel);

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

Usage

Install with npm:

npm install glsl-specular-cook-torrance

Then use with glslify.

API

#pragma glslify: cookTorrance = require(glsl-specular-cook-torrance)
float cookTorrance(vec3 lightDir, vec3 eyeDir, vec3 normal, float roughness, float fresnel)

Computes the specular power in the Cook-Torrance

  • lightDir is a unit length vec3 pointing from the surface point toward the light
  • eyeDir is a unit length vec3 pointing from the surface point toward the camera
  • normal is the unit length surface normal at the sample point
  • roughness is the surface roughness parameter, between 0 and 1. 0 means surface is perfectly smooth, 1 means surface is matte
  • fresnel the Fresnel exponent. 0 = no Fresnel, higher values create a rim effect around objects

Returns A float representing the specular power

Note Unlike the usual Cook-Torrance model, the light power is not scaled by 1/(normal . lightDirection). This avoids an unnecessary numerically unstable division, but requires modifying how diffuse light is calculated.

License

(c) 2014 Mikola Lysenko. MIT License

glsl-specular-cook-torrance's People

Contributors

mattdesl avatar mikolalysenko avatar wemyju avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.