More fine tuning calibration of roughness, and various visual fixes for PBR

define_list_fix
Nehon 9 years ago
parent 9e1a1f6131
commit ab76585ff2
  1. 6
      jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java
  2. 2
      jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag
  3. 7
      jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib

@ -428,12 +428,12 @@ public class EnvMapUtils {
}*/
public static int getSampleFromMip(int mipLevel, int miptot) {
return Math.min(1 << (miptot + mipLevel * 2), 8192);
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);
}

@ -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;

@ -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);
}

Loading…
Cancel
Save