From a999de7fd3dd3df483544a0ef5126f07eda8419f Mon Sep 17 00:00:00 2001 From: victorfisac Date: Sat, 15 Jul 2017 16:40:43 +0200 Subject: [PATCH] Improved ComputeMaterialProperty() function and added important note --- examples/models/resources/shaders/pbr.fs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/models/resources/shaders/pbr.fs b/examples/models/resources/shaders/pbr.fs index 319259868..347a0d941 100644 --- a/examples/models/resources/shaders/pbr.fs +++ b/examples/models/resources/shaders/pbr.fs @@ -74,8 +74,12 @@ vec2 ParallaxMapping(vec2 texCoords, vec3 viewDir); vec3 ComputeMaterialProperty(MaterialProperty property) { - if (property.useSampler == 1) return texture(property.sampler, texCoord).rgb; - else return property.color; + vec result = vec3(0.0, 0.0, 0.0); + + if (property.useSampler == 1) result = texture(property.sampler, texCoord).rgb; + else result = property.color; + + return result; } float DistributionGGX(vec3 N, vec3 H, float roughness) @@ -177,6 +181,7 @@ void main() vec3 refl = reflect(-view, normal); // Check if parallax mapping is enabled and calculate texture coordinates to use based on height map + // NOTE: remember that 'texCoord' variable must be assigned before calling any ComputeMaterialProperty() function if (height.useSampler == 1) texCoord = ParallaxMapping(fragTexCoord, view); else texCoord = fragTexCoord; // Use default texture coordinates