Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fix to adhere to spec for roughness and metallic factors. #8

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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