diff --git a/examples/shaders/resources/shaders/glsl330/pbr.fs b/examples/shaders/resources/shaders/glsl330/pbr.fs index 5375d4498..d7544d310 100644 --- a/examples/shaders/resources/shaders/glsl330/pbr.fs +++ b/examples/shaders/resources/shaders/glsl330/pbr.fs @@ -24,8 +24,8 @@ in mat3 TBN; // Output fragment color out vec4 finalColor; -// Input uniform values +// Input uniform values uniform int numOfLights; uniform sampler2D albedoMap; uniform sampler2D mraMap; @@ -55,105 +55,108 @@ uniform vec3 viewPos; uniform vec3 ambientColor; uniform float ambient; -// refl in range 0 to 1 -// returns base reflectivity to 1 -// incrase reflectivity when surface view at larger angle -vec3 schlickFresnel(float hDotV,vec3 refl) +// Reflectivity in range 0.0 to 1.0 +// NOTE: Reflectivity is increased when surface view at larger angle +vec3 SchlickFresnel(float hDotV,vec3 refl) { - return refl + (1.0 - refl) * pow(1.0 - hDotV,5.0); + return refl + (1.0 - refl)*pow(1.0 - hDotV, 5.0); } -float ggxDistribution(float nDotH,float roughness) +float GgxDistribution(float nDotH,float roughness) { - float a = roughness * roughness * roughness * roughness; - float d = nDotH * nDotH * (a - 1.0) + 1.0; - d = PI * d * d; - return a / max(d,0.0000001); + float a = roughness * roughness * roughness * roughness; + float d = nDotH * nDotH * (a - 1.0) + 1.0; + d = PI * d * d; + return a / max(d,0.0000001); } -float geomSmith(float nDotV,float nDotL,float roughness) +float GeomSmith(float nDotV,float nDotL,float roughness) { - float r = roughness + 1.0; - float k = r * r / 8.0; - float ik = 1.0 - k; - float ggx1 = nDotV / (nDotV * ik + k); - float ggx2 = nDotL / (nDotL * ik + k); - return ggx1 * ggx2; + float r = roughness + 1.0; + float k = r*r / 8.0; + float ik = 1.0 - k; + float ggx1 = nDotV/(nDotV*ik + k); + float ggx2 = nDotL/(nDotL*ik + k); + return ggx1*ggx2; } -vec3 pbr(){ - vec3 albedo = texture(albedoMap,vec2(fragTexCoord.x*tiling.x+offset.x,fragTexCoord.y*tiling.y+offset.y)).rgb; - albedo = vec3(albedoColor.x*albedo.x,albedoColor.y*albedo.y,albedoColor.z*albedo.z); - float metallic = clamp(metallicValue,0.0,1.0); - float roughness = clamp(roughnessValue,0.0,1.0); - float ao = clamp(aoValue,0.0,1.0); - if(useTexMRA == 1) { - vec4 mra = texture(mraMap, vec2(fragTexCoord.x * tiling.x + offset.x, fragTexCoord.y * tiling.y + offset.y)) * useTexMRA; - metallic = clamp(mra.r+metallicValue,0.04,1.0); - roughness = clamp(mra.g+roughnessValue,0.04,1.0); - ao = (mra.b+aoValue)*0.5; - } - - - - vec3 N = normalize(fragNormal); - if(useTexNormal == 1) { - N = texture(normalMap, vec2(fragTexCoord.x * tiling.x + offset.y, fragTexCoord.y * tiling.y + offset.y)).rgb; - N = normalize(N * 2.0 - 1.0); - N = normalize(N * TBN); - } - - vec3 V = normalize(viewPos - fragPosition); - - vec3 e = vec3(0); - e = (texture(emissiveMap, vec2(fragTexCoord.x*tiling.x+offset.x, fragTexCoord.y*tiling.y+offset.y)).rgb).g * emissiveColor.rgb*emissivePower * useTexEmissive; - - - - - - //return N;//vec3(metallic,metallic,metallic); - //if dia-electric use base reflectivity of 0.04 otherwise ut is a metal use albedo as base reflectivity - vec3 baseRefl = mix(vec3(0.04),albedo.rgb,metallic); - vec3 Lo = vec3(0.0); // acumulate lighting lum - - for(int i=0;iuri + i + 1, &data); if (result == cgltf_result_success) diff --git a/src/rtextures.c b/src/rtextures.c index c53d30aa6..a16fb386a 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -1967,7 +1967,7 @@ void ImageBlurGaussian(Image *image, int blurSize) { avgG += pixelsCopy1[row*image->width + i].y; avgB += pixelsCopy1[row*image->width + i].z; avgAlpha += pixelsCopy1[row*image->width + i].w; - } + } for (int x = 0; x < image->width; x++) {