diff --git a/jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java b/jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java index cb1618f37..68cdafeff 100644 --- a/jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java +++ b/jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java @@ -427,13 +427,13 @@ public class EnvMapUtils { }*/ - public static int getSampleFromMip(int mipLevel, int miptot) { - return Math.min(1 << (miptot + mipLevel * 2), 8192); + public static int getSampleFromMip(int mipLevel, int miptot) { + return mipLevel==0?1:Math.min(1 << (miptot - 1 + (mipLevel) * 2 ), 8192); } public static float getRoughnessFromMip(int miplevel, int miptot) { - float mipScale = 1.2f; - float mipOffset = 0.0f; + float mipScale = 1.0f; + float mipOffset = -0.3f; return pow(2, (float) (miplevel - (miptot - 1) + mipOffset) / mipScale); } 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 25c4ff535..8dc79ecd0 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 "ShaderLib/PBR.glsllib" +#import "Common/ShaderLib/PBR.glsllib" #import "Common/ShaderLib/Lighting.glsllib" varying vec2 texCoord; diff --git a/jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib index 6a2faad40..74f3768af 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib @@ -106,6 +106,7 @@ void PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir, outSpecular = vec3(specular) * lightColor; } +//https://knarkowicz.wordpress.com/2014/12/27/analytical-dfg-term-for-ibl/ vec3 EnvDFGPolynomial( vec3 specularColor, float roughness, float ndotv ){ float x = 1.0 - roughness; float y = ndotv; @@ -128,7 +129,7 @@ vec3 EnvDFGPolynomial( vec3 specularColor, float roughness, float ndotv ){ float delta = clamp(( d0 + d1 * x + d2 * y + d3 * x * x + d4 * x * y + d5 * y * y + d6 * x * x * x ), 0.0, 1.0); float scale = delta - bias; - bias *= clamp( 50.0 * specularColor.y, 0.0, 1.0 ); + bias *= clamp( 2.5 / (roughness) * specularColor.y, 0.0, 1.0 ); return specularColor * scale + bias; } @@ -142,8 +143,8 @@ 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.5 + 6.0 - 1.0; - vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb; + float Lod = log2(Roughness) * 1.1 + 6.0 - 1.0; + vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz, Lod).rgb; return PrefilteredColor * EnvDFGPolynomial(SpecularColor, Roughness, ndotv); }