From 9e1a1f61314cc5371e679a9038cf27769731b3e8 Mon Sep 17 00:00:00 2001 From: Nehon Date: Tue, 8 Dec 2015 23:57:08 +0100 Subject: [PATCH] PBR, fixed the way metallic material base color was handled for indirect lighting. Also calibrated roughness so that it matches Substance painter renderer. --- .../resources/Common/MatDefs/Light/PBRLighting.frag | 11 ++++++----- .../src/main/resources/Common/ShaderLib/PBR.glsllib | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag index c89397814..25c4ff535 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag @@ -1,5 +1,5 @@ #import "Common/ShaderLib/Parallax.glsllib" -#import "Common/ShaderLib/PBR.glsllib" +#import "ShaderLib/PBR.glsllib" #import "Common/ShaderLib/Lighting.glsllib" varying vec2 texCoord; @@ -111,14 +111,14 @@ void main(){ vec4 albedo = Color; #endif #ifdef ROUGHNESSMAP - float Roughness = texture2D(m_RoughnessMap, newTexCoord).r * max(m_Roughness,1e-8); + float Roughness = texture2D(m_RoughnessMap, newTexCoord).r * max(m_Roughness, 1e-8); #else - float Roughness = max(m_Roughness,1e-8); + float Roughness = max(m_Roughness, 1e-8); #endif #ifdef METALLICMAP float Metallic = texture2D(m_MetallicMap, newTexCoord).r; #else - float Metallic = max(m_Metallic,0.00); + float Metallic = max(m_Metallic, 0.0); #endif float alpha = Color.a * albedo.a; @@ -214,7 +214,7 @@ void main(){ vec3 indirectDiffuse = vec3(0.0); vec3 indirectSpecular = vec3(0.0); - indirectDiffuse = textureCube(g_IrradianceMap, rv.xyz).rgb * albedo.rgb; + indirectDiffuse = textureCube(g_IrradianceMap, rv.xyz).rgb * diffuseColor.rgb; indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz); indirectSpecular *= vec3(horiz); @@ -233,5 +233,6 @@ void main(){ #endif gl_FragColor.a = alpha; + } diff --git a/jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib index 5979af533..6a2faad40 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib @@ -134,7 +134,7 @@ vec3 EnvDFGPolynomial( vec3 specularColor, float roughness, float ndotv ){ vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec){ //TODO magic values should be replaced by defines. - float Lod = log2(Roughness) * 1.2 + 6.0 - 1.0; + float Lod = log2(Roughness) * 1.5 + 6.0 - 1.0; vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb; vec2 EnvBRDF = texture2D(integrateBRDF,vec2(Roughness, ndotv)).rg; return PrefilteredColor * ( SpecularColor * EnvBRDF.x+ EnvBRDF.y ); @@ -142,7 +142,7 @@ vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 Spe vec3 ApproximateSpecularIBLPolynomial(samplerCube envMap, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec){ //TODO magic values should be replaced by defines. - float Lod = log2(Roughness) * 1.2 + 6.0 - 1.0; + float Lod = log2(Roughness) * 1.5 + 6.0 - 1.0; vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb; return PrefilteredColor * EnvDFGPolynomial(SpecularColor, Roughness, ndotv); }