Skip to content

Commit

Permalink
Merge pull request #8 from abwood/spec-fixes-uniform-factors
Browse files Browse the repository at this point in the history
Minor fix to adhere to spec for roughness and metallic factors.
  • Loading branch information
snagy authored Jun 6, 2017
2 parents ec09d0b + cd9fad8 commit 0771537
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
12 changes: 6 additions & 6 deletions scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ class Mesh {
}

// Metallic-Roughness
var metallic = (pbrMat && defined(pbrMat.metallicFactor)) ? pbrMat.metallicFactor : 1.0;
var roughness = (pbrMat && defined(pbrMat.roughnessFactor)) ? pbrMat.roughnessFactor : 1.0;
this.glState.uniforms['u_MetallicRoughnessValues'] = {
funcName: 'uniform2f',
vals: [metallic, roughness]
};
if (pbrMat && pbrMat.metallicRoughnessTexture && gltf.textures.length > pbrMat.metallicRoughnessTexture.index) {
var mrTexInfo = gltf.textures[pbrMat.metallicRoughnessTexture.index];
var mrSrc = this.modelPath + gltf.images[mrTexInfo.source].uri;
Expand All @@ -254,12 +260,6 @@ class Mesh {
if (this.glState.uniforms['u_MetallicRoughnessSampler']) {
delete this.glState.uniforms['u_MetallicRoughnessSampler'];
}
var metallic = (pbrMat && defined(pbrMat.metallicFactor)) ? pbrMat.metallicFactor : 1.0;
var roughness = (pbrMat && defined(pbrMat.roughnessFactor)) ? pbrMat.roughnessFactor : 1.0;
this.glState.uniforms['u_MetallicRoughnessValues'] = {
funcName: 'uniform2f',
vals: [metallic, roughness]
};
}

// Normals
Expand Down
12 changes: 5 additions & 7 deletions shaders/pbr-frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ uniform sampler2D u_EmissiveSampler;
#endif
#ifdef HAS_METALROUGHNESSMAP
uniform sampler2D u_MetallicRoughnessSampler;
#else
uniform vec2 u_MetallicRoughnessValues;
#endif
uniform vec2 u_MetallicRoughnessValues;
#ifdef HAS_OCCLUSIONMAP
uniform sampler2D u_OcclusionSampler;
#endif
Expand Down Expand Up @@ -178,13 +177,12 @@ void main() {
float LdotH = clamp(dot(l,h), 0.0, 1.0);
float VdotH = clamp(dot(v,h), 0.0, 1.0);

#ifdef HAS_METALROUGHNESSMAP
vec4 mrSample = texture2D(u_MetallicRoughnessSampler, v_UV);
float roughness = clamp(mrSample.g, 0.04, 1.0);
float metallic = clamp(mrSample.b, 0.0, 1.0);
#else
float roughness = clamp(u_MetallicRoughnessValues.y, 0.04, 1.0);
float metallic = u_MetallicRoughnessValues.x;
#ifdef HAS_METALROUGHNESSMAP
vec4 mrSample = texture2D(u_MetallicRoughnessSampler, v_UV);
roughness = clamp(mrSample.g * roughness, 0.04, 1.0);
metallic = clamp(mrSample.b * metallic, 0.0, 1.0);
#endif

#ifdef HAS_BASECOLORMAP
Expand Down

0 comments on commit 0771537

Please sign in to comment.