Changed the way IBL is switched on and off in the PBR shader and in the technique def logic because the old way was causing some issues on mac... for some unknown reason.

Now it's toggled on and off with a define, but there might still be some issues on mac when there are several lighting passes.
define_list_fix
Rémy Bouquet 9 years ago
parent 8f701460aa
commit 85c119c132
  1. 2
      jme3-core/src/main/java/com/jme3/material/Material.java
  2. 19
      jme3-core/src/main/java/com/jme3/material/logic/SinglePassAndImageBasedLightingLogic.java
  3. 38
      jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag
  4. 2
      jme3-examples/src/main/java/jme3test/material/TestParallaxPBR.java

@ -961,8 +961,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
renderManager.updateUniformBindings(shader);
// Set material parameters
//TODO RRemove the unit when texture units are handled in the Uniform
int unit = updateShaderMaterialParameters(renderer, shader, overrides, renderManager.getForcedMatParams());
// Clear any uniforms not changed by material.

@ -48,9 +48,11 @@ public final class SinglePassAndImageBasedLightingLogic extends DefaultTechnique
private static final String DEFINE_SINGLE_PASS_LIGHTING = "SINGLE_PASS_LIGHTING";
private static final String DEFINE_NB_LIGHTS = "NB_LIGHTS";
private static final String DEFINE_INDIRECT_LIGHTING = "INDIRECT_LIGHTING";
private static final RenderState ADDITIVE_LIGHT = new RenderState();
private final ColorRGBA ambientLightColor = new ColorRGBA(0, 0, 0, 1);
private LightProbe lightProbe = null;
static {
ADDITIVE_LIGHT.setBlendMode(BlendMode.AlphaAdditive);
@ -59,11 +61,13 @@ public final class SinglePassAndImageBasedLightingLogic extends DefaultTechnique
private final int singlePassLightingDefineId;
private final int nbLightsDefineId;
private final int indirectLightingDefineId;
public SinglePassAndImageBasedLightingLogic(TechniqueDef techniqueDef) {
super(techniqueDef);
singlePassLightingDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_SINGLE_PASS_LIGHTING, VarType.Boolean);
nbLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NB_LIGHTS, VarType.Int);
indirectLightingDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_INDIRECT_LIGHTING, VarType.Boolean);
}
@Override
@ -71,6 +75,18 @@ public final class SinglePassAndImageBasedLightingLogic extends DefaultTechnique
EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {
defines.set(nbLightsDefineId, renderManager.getSinglePassLightBatchSize() * 3);
defines.set(singlePassLightingDefineId, true);
//TODO here we have a problem, this is called once before render, so the define will be set for all passes (in case we have more than NB_LIGHTS lights)
//Though the second pass should not render IBL as it is taken care of on first pass like ambient light in phong lighting.
//We cannot change the define between passes and the old technique, and for some reason the code fails on mac (renders nothing).
lightProbe = extractIndirectLights(lights,false);
if(lightProbe == null){
defines.set(indirectLightingDefineId, false);
} else {
defines.set(indirectLightingDefineId, true);
}
return super.makeCurrent(assetManager, renderManager, rendererCaps, lights, defines);
}
@ -100,7 +116,7 @@ public final class SinglePassAndImageBasedLightingLogic extends DefaultTechnique
Uniform lightProbeIrrMap = shader.getUniform("g_IrradianceMap");
Uniform lightProbePemMap = shader.getUniform("g_PrefEnvMap");
LightProbe lightProbe = null;
lightProbe = null;
if (startIndex != 0) {
// apply additive blending for 2nd and future passes
rm.getRenderer().applyRenderState(ADDITIVE_LIGHT);
@ -132,7 +148,6 @@ public final class SinglePassAndImageBasedLightingLogic extends DefaultTechnique
Vector4f tmpVec = vars.vect4f1;
int curIndex;
int endIndex = numLights + startIndex;
boolean useIBL = false;
for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) {

@ -19,12 +19,12 @@ uniform float m_Metallic;
varying vec3 wPosition;
//#ifdef INDIRECT_LIGHTING
#ifdef INDIRECT_LIGHTING
// uniform sampler2D m_IntegrateBRDF;
uniform samplerCube g_PrefEnvMap;
uniform samplerCube g_IrradianceMap;
uniform vec4 g_LightProbeData;
//#endif
#endif
#ifdef BASECOLORMAP
uniform sampler2D m_BaseColorMap;
@ -201,27 +201,29 @@ void main(){
gl_FragColor.rgb += directLighting * fallOff;
}
vec3 rv = reflect(-viewDir.xyz, normal.xyz);
//prallax fix for spherical bounds from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
// g_LightProbeData.w is 1/probe radius, g_LightProbeData.xyz is the position of the lightProbe.
rv = g_LightProbeData.w * (wPosition - g_LightProbeData.xyz) +rv;
#ifdef INDIRECT_LIGHTING
vec3 rv = reflect(-viewDir.xyz, normal.xyz);
//prallax fix for spherical bounds from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
// g_LightProbeData.w is 1/probe radius, g_LightProbeData.xyz is the position of the lightProbe.
rv = g_LightProbeData.w * (wPosition - g_LightProbeData.xyz) +rv;
//horizon fade from http://marmosetco.tumblr.com/post/81245981087
float horiz = dot(rv, wNormal.xyz);
float horizFadePower= 1.0 - Roughness;
horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
horiz *= horiz;
//horizon fade from http://marmosetco.tumblr.com/post/81245981087
float horiz = dot(rv, wNormal.xyz);
float horizFadePower= 1.0 - Roughness;
horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
horiz *= horiz;
vec3 indirectDiffuse = vec3(0.0);
vec3 indirectSpecular = vec3(0.0);
indirectDiffuse = textureCube(g_IrradianceMap, normal.xyz).rgb * diffuseColor.rgb;
vec3 indirectDiffuse = vec3(0.0);
vec3 indirectSpecular = vec3(0.0);
indirectDiffuse = textureCube(g_IrradianceMap, normal.xyz).rgb * diffuseColor.rgb;
indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz);
indirectSpecular *= vec3(horiz);
indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz);
indirectSpecular *= vec3(horiz);
vec3 indirectLighting = indirectDiffuse + indirectSpecular;
vec3 indirectLighting = indirectDiffuse + indirectSpecular;
gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting * step( 0.0, g_LightProbeData.w);
gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting * step( 0.0, g_LightProbeData.w);
#endif
#if defined(EMISSIVE) || defined (EMISSIVEMAP)
#ifdef EMISSIVEMAP

@ -57,7 +57,7 @@ public class TestParallaxPBR extends SimpleApplication {
}
public void setupSkyBox() {
rootNode.attachChild(SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false));
rootNode.attachChild(SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", SkyFactory.EnvMapType.CubeMap));
}
DirectionalLight dl;

Loading…
Cancel
Save