Coder Social home page Coder Social logo

glsl-ggx's Introduction

glsl-ggx

glsl ggx lighting model

example

view this example

var regl = require('regl')()
var camera = require('regl-camera')(regl, {
  distance: 100,
  center: [0,58,0],
  theta: Math.PI/2
})
var glx = require('glslify')
var anormals = require('angle-normals')
var dragon = require('stanford-dragon')

var draw = regl({
  frag: glx`
    precision mediump float;
    #pragma glslify: ggx = require('glsl-ggx')
    uniform vec3 eye, lightpos;
    varying vec3 vpos, vnorm;
    void main () {
      vec3 N = vnorm, V = normalize(eye-vpos), L = normalize(lightpos-vpos);
      float spec = max(0.0,ggx(N,V,L,0.2,0.7));
      vec3 c = vec3(0.955,0.637,0.538); // copper
      gl_FragColor = vec4(pow(c*spec,vec3(2.2)),1);
    }
  `,
  vert: `
    precision mediump float;
    uniform mat4 projection, view;
    attribute vec3 position, normal;
    varying vec3 vpos, vnorm;
    void main () {
      vpos = position;
      vnorm = normal;
      gl_Position = projection * view * vec4(position,1);
    }
  `,
  attributes: {
    position: dragon.positions,
    normal: anormals(dragon.cells, dragon.positions)
  },
  elements: dragon.cells,
  uniforms: {
    lightpos: function (context) {
      var t = context.time*4, r = 30
      return [Math.cos(t)*r,Math.sin(t)*r+60,200]
    }
  }
})
regl.frame(function () {
  regl.clear({ color: [0.4,0.2,0.4,1], depth: true })
  camera(function () { draw() })
})

api

#pragma glslify: ggx = require('glsl-ggx')

float l = ggx(vec3 N, vec3 V, vec3 L, float roughness, float F0)

Compute the ggx specular lighting from:

  • vec3 N - surface normal
  • vec3 V - normalized view direction
  • vec3 L - normalized light direction
  • float roughness - smooth (0.0) to rough (1.0)
  • float F0 - fresnel term, 0.0 to 1.0

license

BSD

glsl-ggx's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

glsl-ggx's Issues

Halfvec computation

Hi,
First of all, thanks for sharing your ggx implementation !

There seems to be an error in your halfvec computation.
You've written it as the substraction of the view by the lightdir (vec3 H = normalize(L - V);) but it should the addition of the two.

Regards

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.