PBR, fixed the way metallic material base color was handled for indirect lighting.

Also calibrated roughness so that it matches Substance painter renderer.
define_list_fix
Nehon 9 years ago
parent 1276dc583e
commit 9e1a1f6131
  1. 11
      jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag
  2. 4
      jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib

@ -1,5 +1,5 @@
#import "Common/ShaderLib/Parallax.glsllib" #import "Common/ShaderLib/Parallax.glsllib"
#import "Common/ShaderLib/PBR.glsllib" #import "ShaderLib/PBR.glsllib"
#import "Common/ShaderLib/Lighting.glsllib" #import "Common/ShaderLib/Lighting.glsllib"
varying vec2 texCoord; varying vec2 texCoord;
@ -111,14 +111,14 @@ void main(){
vec4 albedo = Color; vec4 albedo = Color;
#endif #endif
#ifdef ROUGHNESSMAP #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 #else
float Roughness = max(m_Roughness,1e-8); float Roughness = max(m_Roughness, 1e-8);
#endif #endif
#ifdef METALLICMAP #ifdef METALLICMAP
float Metallic = texture2D(m_MetallicMap, newTexCoord).r; float Metallic = texture2D(m_MetallicMap, newTexCoord).r;
#else #else
float Metallic = max(m_Metallic,0.00); float Metallic = max(m_Metallic, 0.0);
#endif #endif
float alpha = Color.a * albedo.a; float alpha = Color.a * albedo.a;
@ -214,7 +214,7 @@ void main(){
vec3 indirectDiffuse = vec3(0.0); vec3 indirectDiffuse = vec3(0.0);
vec3 indirectSpecular = 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 = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz);
indirectSpecular *= vec3(horiz); indirectSpecular *= vec3(horiz);
@ -234,4 +234,5 @@ void main(){
gl_FragColor.a = alpha; gl_FragColor.a = alpha;
} }

@ -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){ vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec){
//TODO magic values should be replaced by defines. //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; vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb;
vec2 EnvBRDF = texture2D(integrateBRDF,vec2(Roughness, ndotv)).rg; vec2 EnvBRDF = texture2D(integrateBRDF,vec2(Roughness, ndotv)).rg;
return PrefilteredColor * ( SpecularColor * EnvBRDF.x+ EnvBRDF.y ); 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){ vec3 ApproximateSpecularIBLPolynomial(samplerCube envMap, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec){
//TODO magic values should be replaced by defines. //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; vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb;
return PrefilteredColor * EnvDFGPolynomial(SpecularColor, Roughness, ndotv); return PrefilteredColor * EnvDFGPolynomial(SpecularColor, Roughness, ndotv);
} }

Loading…
Cancel
Save