optimize pssm split calculation

in-pass-shadows
Kirill Vainer 7 years ago
parent a3145885d9
commit 2c385914c6
  1. 6
      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

@ -39,7 +39,7 @@ import com.jme3.light.PointLight;
import com.jme3.light.SpotLight;
import com.jme3.material.TechniqueDef;
import com.jme3.math.Matrix4f;
import com.jme3.math.Vector4f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Caps;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.Renderer;
@ -149,7 +149,7 @@ public class ShadowStaticPassLightingLogic extends StaticPassLightingLogic {
@Override
protected void updateShadowUniforms(Renderer renderer, Shader shader, int nextTextureUnit) {
TextureArray array = null;
Vector4f pssmSplits = null;
Vector3f pssmSplits = null;
Uniform shadowMatricesUniform = shader.getUniform("g_ShadowMatrices");
@ -187,7 +187,7 @@ public class ShadowStaticPassLightingLogic extends StaticPassLightingLogic {
if (pssmSplits != null) {
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.Light;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector4f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.GeometryList;
@ -47,7 +46,7 @@ import com.jme3.texture.TextureArray;
public class DirectionalArrayShadowMap extends BaseArrayShadowMap<DirectionalArrayShadowMapSlice> {
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) {
super(array, firstArraySlice);
@ -70,7 +69,7 @@ public class DirectionalArrayShadowMap extends BaseArrayShadowMap<DirectionalArr
}
}
public Vector4f getProjectionSplitPositions() {
public Vector3f getProjectionSplitPositions() {
return projectionSplitPositions;
}

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

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

Loading…
Cancel
Save