optimize pssm split calculation

in-pass-shadows
Kirill Vainer 7 years ago
parent a3145885d9
commit 0a4a439745
  1. 2
      jme3-core/src/main/java/com/jme3/material/logic/ShadowStaticPassLightingLogic.java
  2. 5
      jme3-core/src/main/java/com/jme3/shadow/next/array/DirectionalArrayShadowMap.java
  3. 7
      jme3-core/src/main/java/com/jme3/shadow/next/pssm/DirectionalShadowParameters.java
  4. 15
      jme3-core/src/main/resources/Common/ShaderLib/InPassShadows.glsl

@ -187,7 +187,7 @@ public class ShadowStaticPassLightingLogic extends StaticPassLightingLogic {
if (pssmSplits != null) { if (pssmSplits != null) {
Uniform pssmSplitsUniform = shader.getUniform("g_PssmSplits"); Uniform pssmSplitsUniform = shader.getUniform("g_PssmSplits");
pssmSplitsUniform.setValue(VarType.Vector4, pssmSplits); pssmSplitsUniform.setValue(VarType.Vector3, pssmSplits);
} }
} }
} }

@ -34,7 +34,6 @@ package com.jme3.shadow.next.array;
import com.jme3.light.DirectionalLight; import com.jme3.light.DirectionalLight;
import com.jme3.light.Light; import com.jme3.light.Light;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.math.Vector4f;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.GeometryList; import com.jme3.renderer.queue.GeometryList;
@ -47,7 +46,7 @@ import com.jme3.texture.TextureArray;
public class DirectionalArrayShadowMap extends BaseArrayShadowMap<DirectionalArrayShadowMapSlice> { public class DirectionalArrayShadowMap extends BaseArrayShadowMap<DirectionalArrayShadowMapSlice> {
private final DirectionalLight light; private final DirectionalLight light;
private final Vector4f projectionSplitPositions = new Vector4f(); private final Vector3f projectionSplitPositions = new Vector3f();
public DirectionalArrayShadowMap(DirectionalLight light, TextureArray array, int firstArraySlice, int textureSize, int numSplits, Vector3f[] points) { public DirectionalArrayShadowMap(DirectionalLight light, TextureArray array, int firstArraySlice, int textureSize, int numSplits, Vector3f[] points) {
super(array, firstArraySlice); super(array, firstArraySlice);
@ -70,7 +69,7 @@ public class DirectionalArrayShadowMap extends BaseArrayShadowMap<DirectionalArr
} }
} }
public Vector4f getProjectionSplitPositions() { public Vector3f getProjectionSplitPositions() {
return projectionSplitPositions; return projectionSplitPositions;
} }

@ -31,6 +31,7 @@
*/ */
package com.jme3.shadow.next.pssm; package com.jme3.shadow.next.pssm;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector4f; import com.jme3.math.Vector4f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.shadow.PssmShadowUtil; import com.jme3.shadow.PssmShadowUtil;
@ -45,7 +46,7 @@ public final class DirectionalShadowParameters implements ShadowParameters {
private int numSplits = 4; private int numSplits = 4;
protected float zFarOverride = 0; protected float zFarOverride = 0;
private float[] splitPositions = new float[numSplits + 1]; private float[] splitPositions = new float[numSplits + 1];
private final Vector4f projectionSplitPositions = new Vector4f(); private final Vector3f projectionSplitPositions = new Vector3f();
public float getLambda() { public float getLambda() {
return lambda; return lambda;
@ -69,7 +70,7 @@ public final class DirectionalShadowParameters implements ShadowParameters {
return splitPositions; return splitPositions;
} }
public Vector4f getProjectionSplitPositions() { public Vector3f getProjectionSplitPositions() {
return projectionSplitPositions; return projectionSplitPositions;
} }
@ -124,7 +125,7 @@ public final class DirectionalShadowParameters implements ShadowParameters {
switch (splitPositions.length) { switch (splitPositions.length) {
case 5: case 5:
projectionSplitPositions.w = 1.0f; // = viewCamera.getViewToProjectionZ(splitPositions[4]); // projectionSplitPositions.w = 1.0f;
case 4: case 4:
projectionSplitPositions.z = viewCamera.getViewToProjectionZ(splitPositions[3]); projectionSplitPositions.z = viewCamera.getViewToProjectionZ(splitPositions[3]);
case 3: case 3:

@ -27,22 +27,13 @@
} }
#else #else
uniform sampler2DArrayShadow g_ShadowMapArray; uniform sampler2DArrayShadow g_ShadowMapArray;
uniform vec4 g_PssmSplits; uniform vec3 g_PssmSplits;
int pssmSliceOffset; int pssmSliceOffset;
void Shadow_ProcessPssmSlice() { void Shadow_ProcessPssmSlice() {
#ifdef NUM_PSSM_SPLITS #if defined(NUM_PSSM_SPLITS) && NUM_PSSM_SPLITS > 1
float z = gl_FragCoord.z; pssmSliceOffset = int(dot(step(g_PssmSplits.xyz, gl_FragCoord.zzz), vec3(1.0)));
if (z < g_PssmSplits[0]) {
pssmSliceOffset = 0;
} else if (z < g_PssmSplits[1]) {
pssmSliceOffset = 1;
} else if (z < g_PssmSplits[2]) {
pssmSliceOffset = 2;
} else {
pssmSliceOffset = 3;
}
#else #else
pssmSliceOffset = 0; pssmSliceOffset = 0;
#endif #endif

Loading…
Cancel
Save