Skip to content

Commit

Permalink
use light.direction in pbr
Browse files Browse the repository at this point in the history
  • Loading branch information
d̶m̶m̶n̶ authored and d̶m̶m̶n̶ committed May 12, 2016
1 parent 96f076a commit 1bbf262
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions webgl/shaders/pbr-glsl.js
Expand Up @@ -4,8 +4,8 @@ export default function() {
return `
struct Light
{
vec3 position;
vec3 color;
vec3 direction;
};
float G1V ( float dotNV, float k ) {
Expand Down Expand Up @@ -43,38 +43,36 @@ float GGX(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 computePBRLighting (
Light light,
vec3 position,
Ray ray,
vec3 normal,
vec3 albedo,
float metalness,
float roughness,
sampler2D texture,
sampler2D textureBlured
samplerCube texture,
samplerCube textureBlured
) {
// material
float fresnel_pow = 1.5;
vec3 color_mod = vec3(1.0);
light.color *= textureCube(texture,vec3(1.0,0.0,0.0)).xyz * 1.2;
light.color *= textureCube(texture, vec3(1.0,0.0,0.0)).xyz * 1.2;
// IBL
vec3 ibl_diffuse = textureCube(textureBlured, normal);
vec3 ibl_reflection = textureCube(textureBlured, reflect(ray.direction,normal));
vec3 ibl_diffuse = textureCube(textureBlured, normal).xyz;
vec3 ibl_reflection = textureCube(textureBlured, reflect(ray.direction, normal)).xyz;
// fresnel
float fresnel = max(1.0 - dot(normal, -ray.direction), 0.0);
fresnel = pow(fresnel, fresnel_pow);
// reflection
vec3 refl = textureCube(texture,reflect(ray.direction,normal)).xyz;
vec3 refl = textureCube(texture, reflect(ray.direction,normal)).xyz;
refl = mix(refl,ibl_reflection,(1.0-fresnel)*roughness);
refl = mix(refl,ibl_reflection,roughness);
// specular
vec3 lightDirection = normalize(light.position - position);
float power = 1.0 / max(roughness * 0.4,0.01);
vec3 spec = light.color * GGX(normal, -ray.direction, lightDirection, roughness * 0.7, 0.2);
vec3 spec = light.color * GGX(normal, -ray.direction, light.direction, roughness * 0.7, 0.2);
refl -= spec;
// diffuse
Expand Down

0 comments on commit 1bbf262

Please sign in to comment.