Skip to content

Commit

Permalink
Merge bb5902c into 9f0e708
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Aug 17, 2020
2 parents 9f0e708 + bb5902c commit bef3dd5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
2 changes: 2 additions & 0 deletions modules/experimental/src/gltf/gltf-material-parser.js
Expand Up @@ -103,6 +103,8 @@ export default class GLTFMaterialParser {
}

parseMaterial(material) {
this.uniforms.u_Unlit = Boolean(material.unlit);

if (material.pbrMetallicRoughness) {
this.parsePbrMetallicRoughness(material.pbrMetallicRoughness);
}
Expand Down
43 changes: 26 additions & 17 deletions modules/shadertools/src/modules/pbr/pbr-fragment.glsl.js
Expand Up @@ -21,6 +21,11 @@ export default `\
precision highp float;
// Uniforms
// TODO - rename to 'pbr_u...'
uniform bool u_Unlit;
#ifdef USE_IBL
uniform samplerCube u_DiffuseEnvSampler;
uniform samplerCube u_SpecularEnvSampler;
Expand Down Expand Up @@ -336,31 +341,35 @@ vec4 pbr_filterColor(vec4 colorUnused)
vec3 color = vec3(0, 0, 0);
#ifdef USE_LIGHTS
// Apply ambient light
PBRInfo_setAmbientLight(pbrInputs);
color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
// Apply directional light
SMART_FOR(int i = 0, i < MAX_LIGHTS, i < lighting_uDirectionalLightCount, i++) {
if (i < lighting_uDirectionalLightCount) {
PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
if (u_Unlit) {
// Apply ambient light
PBRInfo_setAmbientLight(pbrInputs);
color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
// Apply directional light
SMART_FOR(int i = 0, i < MAX_LIGHTS, i < lighting_uDirectionalLightCount, i++) {
if (i < lighting_uDirectionalLightCount) {
PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
}
}
}
// Apply point light
SMART_FOR(int i = 0, i < MAX_LIGHTS, i < lighting_uPointLightCount, i++) {
if (i < lighting_uPointLightCount) {
PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
// Apply point light
SMART_FOR(int i = 0, i < MAX_LIGHTS, i < lighting_uPointLightCount, i++) {
if (i < lighting_uPointLightCount) {
PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
}
}
}
#endif
// Calculate lighting contribution from image based lighting source (IBL)
#ifdef USE_IBL
color += getIBLContribution(pbrInputs, n, reflection);
if (!u_Unlit) {
color += getIBLContribution(pbrInputs, n, reflection);
}
#endif
// Apply optional PBR terms for additional (optional) shading
Expand Down

0 comments on commit bef3dd5

Please sign in to comment.