From 80ae79b7d598c99f6560f89dc5bdfef1ab14230f Mon Sep 17 00:00:00 2001 From: victorfisac Date: Sat, 15 Jul 2017 16:15:35 +0200 Subject: [PATCH] Applied some changes of raysan5 --- examples/models/resources/shaders/pbr.fs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/models/resources/shaders/pbr.fs b/examples/models/resources/shaders/pbr.fs index ee044f0b3..4d19c01f7 100644 --- a/examples/models/resources/shaders/pbr.fs +++ b/examples/models/resources/shaders/pbr.fs @@ -31,7 +31,7 @@ struct Light { // Input vertex attributes (from vertex shader) in vec2 fragTexCoord; -in vec3 fragPos; +in vec3 fragPosition; in vec3 fragNormal; in vec3 fragTangent; in vec3 fragBinormal; @@ -45,14 +45,14 @@ uniform MaterialProperty occlusion; uniform MaterialProperty emission; uniform MaterialProperty height; -// Input lighting values -uniform Light lights[MAX_LIGHTS]; - // Input uniform values uniform samplerCube irradianceMap; uniform samplerCube prefilterMap; uniform sampler2D brdfLUT; +// Input lighting values +uniform Light lights[MAX_LIGHTS]; + // Other uniform values uniform int renderMode; uniform vec3 viewPos; @@ -173,7 +173,7 @@ void main() // Calculate lighting required attributes vec3 normal = normalize(fragNormal); - vec3 view = normalize(viewPos - fragPos); + vec3 view = normalize(viewPos - fragPosition); vec3 refl = reflect(-view, normal); // Check if parallax mapping is enabled and calculate texture coordinates to use based on height map @@ -217,8 +217,8 @@ void main() if (lights[i].type == LIGHT_DIRECTIONAL) light = -normalize(lights[i].target - lights[i].position); else if (lights[i].type == LIGHT_POINT) { - light = normalize(lights[i].position - fragPos); - float distance = length(lights[i].position - fragPos); + light = normalize(lights[i].position - fragPosition); + float distance = length(lights[i].position - fragPosition); float attenuation = 1.0/(distance*distance); radiance *= attenuation; } @@ -269,6 +269,7 @@ void main() // Calculate fragment color based on render mode vec3 fragmentColor = ambient + Lo + emiss; // Physically Based Rendering + if (renderMode == 1) fragmentColor = color; // Albedo else if (renderMode == 2) fragmentColor = normal; // Normals else if (renderMode == 3) fragmentColor = metal; // Metalness