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

shadertools: Support glTF unlit flag in PBR materials #1394

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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