Changes the name of the array shadow renderer to InPassShadowRenderer. Also addressed some comments on the PR
This commit is contained in:
parent
54ef6ec280
commit
d444c28183
@ -105,17 +105,6 @@ public class TechniqueDef implements Savable, Cloneable {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
FixedPipeline,
|
FixedPipeline,
|
||||||
/**
|
|
||||||
* Similar to {@link #SinglePass} except the type of each light is known
|
|
||||||
* at shader compile time.
|
|
||||||
* <p>
|
|
||||||
* The advantage is that the shader can be much more efficient, i.e. not
|
|
||||||
* do operations required for spot and point lights if it knows the
|
|
||||||
* light is a directional light. The disadvantage is that the number of
|
|
||||||
* shaders used balloons because of the variations in the number of
|
|
||||||
* lights used by objects.
|
|
||||||
*/
|
|
||||||
StaticPass
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ShadowMode {
|
public enum ShadowMode {
|
||||||
|
@ -1,200 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009-2016 jMonkeyEngine
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are
|
|
||||||
* met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package com.jme3.material.logic;
|
|
||||||
|
|
||||||
import com.jme3.asset.AssetManager;
|
|
||||||
import com.jme3.light.DirectionalLight;
|
|
||||||
import com.jme3.light.Light;
|
|
||||||
import com.jme3.light.LightList;
|
|
||||||
import com.jme3.light.PointLight;
|
|
||||||
import com.jme3.light.SpotLight;
|
|
||||||
import com.jme3.material.TechniqueDef;
|
|
||||||
import com.jme3.math.Matrix4f;
|
|
||||||
import com.jme3.math.Vector3f;
|
|
||||||
import com.jme3.renderer.Caps;
|
|
||||||
import com.jme3.renderer.RenderManager;
|
|
||||||
import com.jme3.renderer.Renderer;
|
|
||||||
import com.jme3.shader.DefineList;
|
|
||||||
import com.jme3.shader.Shader;
|
|
||||||
import com.jme3.shader.Uniform;
|
|
||||||
import com.jme3.shader.VarType;
|
|
||||||
import com.jme3.shadow.next.array.ArrayShadowMap;
|
|
||||||
import com.jme3.shadow.next.array.ArrayShadowMapSlice;
|
|
||||||
import com.jme3.shadow.next.array.DirectionalArrayShadowMap;
|
|
||||||
import com.jme3.shadow.next.array.PointArrayShadowMap;
|
|
||||||
import com.jme3.shadow.next.array.SpotArrayShadowMap;
|
|
||||||
import com.jme3.shadow.next.array.SpotArrayShadowMapSlice;
|
|
||||||
import com.jme3.texture.TextureArray;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
public class ShadowStaticPassLightingLogic extends StaticPassLightingLogic {
|
|
||||||
|
|
||||||
private static final String DEFINE_NUM_PSSM_SPLITS = "NUM_PSSM_SPLITS";
|
|
||||||
private static final String DEFINE_NUM_SHADOW_DIR_LIGHTS = "NUM_SHADOW_DIR_LIGHTS";
|
|
||||||
private static final String DEFINE_NUM_SHADOW_POINT_LIGHTS = "NUM_SHADOW_POINT_LIGHTS";
|
|
||||||
private static final String DEFINE_NUM_SHADOW_SPOT_LIGHTS = "NUM_SHADOW_SPOT_LIGHTS";
|
|
||||||
|
|
||||||
private final int numPssmSplitsDefineId;
|
|
||||||
private final int numShadowDirLightsDefineId;
|
|
||||||
private final int numShadowPointLightsDefineId;
|
|
||||||
private final int numShadowSpotLightsDefineId;
|
|
||||||
private int numShadowDirLights = 0;
|
|
||||||
private int numShadowPointLights = 0;
|
|
||||||
private int numShadowSpotLights = 0;
|
|
||||||
|
|
||||||
public ShadowStaticPassLightingLogic(TechniqueDef techniqueDef) {
|
|
||||||
super(techniqueDef);
|
|
||||||
numPssmSplitsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_PSSM_SPLITS, VarType.Int);
|
|
||||||
numShadowDirLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_SHADOW_DIR_LIGHTS, VarType.Int);
|
|
||||||
numShadowPointLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_SHADOW_POINT_LIGHTS, VarType.Int);
|
|
||||||
numShadowSpotLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_SHADOW_SPOT_LIGHTS, VarType.Int);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void makeCurrentBase(AssetManager assetManager, RenderManager renderManager,
|
|
||||||
EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {
|
|
||||||
|
|
||||||
tempDirLights.clear();
|
|
||||||
tempPointLights.clear();
|
|
||||||
tempSpotLights.clear();
|
|
||||||
ambientLightColor.set(0, 0, 0, 1);
|
|
||||||
numShadowDirLights = 0;
|
|
||||||
numShadowPointLights = 0;
|
|
||||||
numShadowSpotLights = 0;
|
|
||||||
|
|
||||||
int pssmSplits = 0;
|
|
||||||
|
|
||||||
for (Light light : lights) {
|
|
||||||
switch (light.getType()) {
|
|
||||||
case Directional:
|
|
||||||
if (light.getShadowMap() != null) {
|
|
||||||
pssmSplits = light.getShadowMap().getNumSlices();
|
|
||||||
tempDirLights.add(numShadowDirLights, (DirectionalLight) light);
|
|
||||||
numShadowDirLights++;
|
|
||||||
} else {
|
|
||||||
tempDirLights.add((DirectionalLight) light);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Point:
|
|
||||||
if (light.getShadowMap() != null) {
|
|
||||||
tempPointLights.add(numShadowPointLights, (PointLight) light);
|
|
||||||
numShadowPointLights++;
|
|
||||||
} else {
|
|
||||||
tempPointLights.add((PointLight) light);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Spot:
|
|
||||||
if (light.getShadowMap() != null) {
|
|
||||||
tempSpotLights.add(numShadowSpotLights, (SpotLight) light);
|
|
||||||
numShadowSpotLights++;
|
|
||||||
} else {
|
|
||||||
tempSpotLights.add((SpotLight) light);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Ambient:
|
|
||||||
ambientLightColor.addLocal(light.getColor());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ambientLightColor.a = 1.0f;
|
|
||||||
|
|
||||||
defines.set(numDirLightsDefineId, tempDirLights.size() - numShadowDirLights);
|
|
||||||
defines.set(numPointLightsDefineId, tempPointLights.size() - numShadowPointLights);
|
|
||||||
defines.set(numSpotLightsDefineId, tempSpotLights.size() - numShadowSpotLights);
|
|
||||||
|
|
||||||
defines.set(numShadowDirLightsDefineId, numShadowDirLights);
|
|
||||||
defines.set(numShadowPointLightsDefineId, numShadowPointLights);
|
|
||||||
defines.set(numShadowSpotLightsDefineId, numShadowSpotLights);
|
|
||||||
|
|
||||||
defines.set(numPssmSplitsDefineId, pssmSplits);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateShadowUniforms(Renderer renderer, Shader shader, int nextTextureUnit) {
|
|
||||||
TextureArray array = null;
|
|
||||||
Vector3f pssmSplits = null;
|
|
||||||
|
|
||||||
Uniform shadowMatricesUniform = shader.getUniform("g_ShadowMatrices");
|
|
||||||
|
|
||||||
shadowMatricesUniform.setMatrix4Length(
|
|
||||||
numShadowDirLights * 4 +
|
|
||||||
numShadowPointLights * 6 +
|
|
||||||
numShadowSpotLights);
|
|
||||||
|
|
||||||
int shadowMatrixIndex = 0;
|
|
||||||
for (int i = 0; i < numShadowDirLights; i++) {
|
|
||||||
DirectionalArrayShadowMap map = (DirectionalArrayShadowMap) tempDirLights.get(i).getShadowMap();
|
|
||||||
array = map.getArray();
|
|
||||||
pssmSplits = map.getProjectionSplitPositions();
|
|
||||||
for (int j = 0; j < map.getNumSlices(); j++) {
|
|
||||||
ArrayShadowMapSlice slice = (ArrayShadowMapSlice) map.getSlice(j);
|
|
||||||
shadowMatricesUniform.setMatrix4InArray(
|
|
||||||
slice.getBiasedViewProjectionMatrix(),
|
|
||||||
shadowMatrixIndex);
|
|
||||||
shadowMatrixIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < numShadowPointLights; i++) {
|
|
||||||
PointArrayShadowMap map = (PointArrayShadowMap) tempPointLights.get(i).getShadowMap();
|
|
||||||
array = map.getArray();
|
|
||||||
for (int j = 0; j < map.getNumSlices(); j++) {
|
|
||||||
ArrayShadowMapSlice slice = (ArrayShadowMapSlice) map.getSlice(j);
|
|
||||||
shadowMatricesUniform.setMatrix4InArray(
|
|
||||||
slice.getBiasedViewProjectionMatrix(),
|
|
||||||
shadowMatrixIndex);
|
|
||||||
shadowMatrixIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < numShadowSpotLights; i++) {
|
|
||||||
SpotArrayShadowMap map = (SpotArrayShadowMap) tempSpotLights.get(i).getShadowMap();
|
|
||||||
array = map.getArray();
|
|
||||||
SpotArrayShadowMapSlice slice = map.getSlice(0);
|
|
||||||
shadowMatricesUniform.setMatrix4InArray(
|
|
||||||
slice.getBiasedViewProjectionMatrix(),
|
|
||||||
shadowMatrixIndex);
|
|
||||||
shadowMatrixIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (array != null) {
|
|
||||||
renderer.setTexture(nextTextureUnit, array);
|
|
||||||
Uniform shadowMapArrayUniform = shader.getUniform("g_ShadowMapArray");
|
|
||||||
shadowMapArrayUniform.setValue(VarType.Int, nextTextureUnit);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pssmSplits != null) {
|
|
||||||
Uniform pssmSplitsUniform = shader.getUniform("g_PssmSplits");
|
|
||||||
pssmSplitsUniform.setValue(VarType.Vector3, pssmSplits);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,191 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009-2015 jMonkeyEngine
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are
|
|
||||||
* met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package com.jme3.material.logic;
|
|
||||||
|
|
||||||
import com.jme3.asset.AssetManager;
|
|
||||||
import com.jme3.light.DirectionalLight;
|
|
||||||
import com.jme3.light.Light;
|
|
||||||
import com.jme3.light.LightList;
|
|
||||||
import com.jme3.light.PointLight;
|
|
||||||
import com.jme3.light.SpotLight;
|
|
||||||
import com.jme3.material.TechniqueDef;
|
|
||||||
import com.jme3.math.ColorRGBA;
|
|
||||||
import com.jme3.math.Matrix4f;
|
|
||||||
import com.jme3.math.Vector3f;
|
|
||||||
import com.jme3.renderer.Caps;
|
|
||||||
import com.jme3.renderer.RenderManager;
|
|
||||||
import com.jme3.renderer.Renderer;
|
|
||||||
import com.jme3.scene.Geometry;
|
|
||||||
import com.jme3.shader.DefineList;
|
|
||||||
import com.jme3.shader.Shader;
|
|
||||||
import com.jme3.shader.Uniform;
|
|
||||||
import com.jme3.shader.VarType;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rendering logic for static pass.
|
|
||||||
*
|
|
||||||
* @author Kirill Vainer
|
|
||||||
*/
|
|
||||||
public class StaticPassLightingLogic extends DefaultTechniqueDefLogic {
|
|
||||||
|
|
||||||
protected static final String DEFINE_NUM_DIR_LIGHTS = "NUM_DIR_LIGHTS";
|
|
||||||
protected static final String DEFINE_NUM_POINT_LIGHTS = "NUM_POINT_LIGHTS";
|
|
||||||
protected static final String DEFINE_NUM_SPOT_LIGHTS = "NUM_SPOT_LIGHTS";
|
|
||||||
|
|
||||||
protected final int numDirLightsDefineId;
|
|
||||||
protected final int numPointLightsDefineId;
|
|
||||||
protected final int numSpotLightsDefineId;
|
|
||||||
|
|
||||||
protected final ColorRGBA ambientLightColor = new ColorRGBA(0, 0, 0, 1);
|
|
||||||
protected final Vector3f tempPosition = new Vector3f();
|
|
||||||
protected final Vector3f tempDirection = new Vector3f();
|
|
||||||
|
|
||||||
protected final ArrayList<DirectionalLight> tempDirLights = new ArrayList<>();
|
|
||||||
protected final ArrayList<PointLight> tempPointLights = new ArrayList<>();
|
|
||||||
protected final ArrayList<SpotLight> tempSpotLights = new ArrayList<>();
|
|
||||||
|
|
||||||
public StaticPassLightingLogic(TechniqueDef techniqueDef) {
|
|
||||||
super(techniqueDef);
|
|
||||||
|
|
||||||
numDirLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_DIR_LIGHTS, VarType.Int);
|
|
||||||
numPointLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_POINT_LIGHTS, VarType.Int);
|
|
||||||
numSpotLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_SPOT_LIGHTS, VarType.Int);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void makeCurrentBase(AssetManager assetManager, RenderManager renderManager,
|
|
||||||
EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {
|
|
||||||
|
|
||||||
// TODO: if it ever changes that render isn't called
|
|
||||||
// right away with the same geometry after makeCurrent, it would be
|
|
||||||
// a problem.
|
|
||||||
// Do a radix sort.
|
|
||||||
tempDirLights.clear();
|
|
||||||
tempPointLights.clear();
|
|
||||||
tempSpotLights.clear();
|
|
||||||
ambientLightColor.set(0, 0, 0, 1);
|
|
||||||
|
|
||||||
for (Light light : lights) {
|
|
||||||
switch (light.getType()) {
|
|
||||||
case Directional:
|
|
||||||
tempDirLights.add((DirectionalLight) light);
|
|
||||||
break;
|
|
||||||
case Point:
|
|
||||||
tempPointLights.add((PointLight) light);
|
|
||||||
break;
|
|
||||||
case Spot:
|
|
||||||
tempSpotLights.add((SpotLight) light);
|
|
||||||
break;
|
|
||||||
case Ambient:
|
|
||||||
ambientLightColor.addLocal(light.getColor());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ambientLightColor.a = 1.0f;
|
|
||||||
|
|
||||||
defines.set(numDirLightsDefineId, tempDirLights.size());
|
|
||||||
defines.set(numPointLightsDefineId, tempPointLights.size());
|
|
||||||
defines.set(numSpotLightsDefineId, tempSpotLights.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
|
|
||||||
EnumSet<Caps> rendererCaps, Geometry geometry, DefineList defines) {
|
|
||||||
LightList lights = getFilteredLightList(renderManager, geometry);
|
|
||||||
makeCurrentBase(assetManager, renderManager, rendererCaps, lights, defines);
|
|
||||||
return techniqueDef.getShader(assetManager, rendererCaps, defines);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateLightListUniforms(Matrix4f viewMatrix, Shader shader) {
|
|
||||||
Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
|
|
||||||
ambientColor.setValue(VarType.Vector4, ambientLightColor);
|
|
||||||
|
|
||||||
Uniform lightData = shader.getUniform("g_LightData");
|
|
||||||
|
|
||||||
int totalSize = tempDirLights.size() * 2
|
|
||||||
+ tempPointLights.size() * 2
|
|
||||||
+ tempSpotLights.size() * 3;
|
|
||||||
lightData.setVector4Length(totalSize);
|
|
||||||
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
for (SpotLight light : tempSpotLights) {
|
|
||||||
ColorRGBA color = light.getColor();
|
|
||||||
float lightTypeAndShadowMap = encodeLightTypeAndShadowMapIndex(light);
|
|
||||||
lightData.setVector4InArray(color.r, color.g, color.b, lightTypeAndShadowMap, index++);
|
|
||||||
|
|
||||||
tempPosition.set(light.getPosition());
|
|
||||||
float invRange = light.getInvSpotRange();
|
|
||||||
lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRange, index++);
|
|
||||||
|
|
||||||
tempDirection.set(light.getDirection());
|
|
||||||
float spotAngleCos = light.getPackedAngleCos();
|
|
||||||
lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, spotAngleCos, index++);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (DirectionalLight light : tempDirLights) {
|
|
||||||
ColorRGBA color = light.getColor();
|
|
||||||
float lightTypeAndShadowMap = encodeLightTypeAndShadowMapIndex(light);
|
|
||||||
lightData.setVector4InArray(color.r, color.g, color.b, lightTypeAndShadowMap, index++);
|
|
||||||
|
|
||||||
tempDirection.set(light.getDirection());
|
|
||||||
lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, 1f, index++);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PointLight light : tempPointLights) {
|
|
||||||
ColorRGBA color = light.getColor();
|
|
||||||
float lightTypeAndShadowMap = encodeLightTypeAndShadowMapIndex(light);
|
|
||||||
lightData.setVector4InArray(color.r, color.g, color.b, lightTypeAndShadowMap, index++);
|
|
||||||
|
|
||||||
tempPosition.set(light.getPosition());
|
|
||||||
float invRadius = light.getInvRadius();
|
|
||||||
lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRadius, index++);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateShadowUniforms(Renderer renderer, Shader shader, int nextTextureUnit) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(RenderManager renderManager, Shader shader, Geometry geometry, int nextTextureUnit) {
|
|
||||||
Renderer renderer = renderManager.getRenderer();
|
|
||||||
Matrix4f viewMatrix = renderManager.getCurrentCamera().getViewMatrix();
|
|
||||||
updateLightListUniforms(viewMatrix, shader);
|
|
||||||
updateShadowUniforms(renderer, shader, nextTextureUnit);
|
|
||||||
renderer.setShader(shader);
|
|
||||||
renderMeshFromGeometry(renderer, geometry);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -75,7 +75,7 @@ import java.util.ArrayList;
|
|||||||
*
|
*
|
||||||
* @author Kirill Vainer
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
public class PreShadowArrayRenderer implements SceneProcessor {
|
public class InPassShadowRenderer implements SceneProcessor {
|
||||||
|
|
||||||
private static final String PRE_SHADOW_TECHNIQUE_NAME = "PreShadow";
|
private static final String PRE_SHADOW_TECHNIQUE_NAME = "PreShadow";
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public class PreShadowArrayRenderer implements SceneProcessor {
|
|||||||
// parameters for directional lights
|
// parameters for directional lights
|
||||||
private final DirectionalShadowParameters directionalParams = new DirectionalShadowParameters();
|
private final DirectionalShadowParameters directionalParams = new DirectionalShadowParameters();
|
||||||
|
|
||||||
public PreShadowArrayRenderer() {
|
public InPassShadowRenderer() {
|
||||||
for (int i = 0; i < points.length; i++) {
|
for (int i = 0; i < points.length; i++) {
|
||||||
points[i] = new Vector3f();
|
points[i] = new Vector3f();
|
||||||
}
|
}
|
@ -38,7 +38,6 @@ import com.jme3.renderer.ViewPort;
|
|||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.control.AbstractControl;
|
import com.jme3.scene.control.AbstractControl;
|
||||||
import com.jme3.shader.VarType;
|
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.TextureArray;
|
import com.jme3.texture.TextureArray;
|
||||||
import com.jme3.ui.Picture;
|
import com.jme3.ui.Picture;
|
||||||
@ -54,7 +53,7 @@ final class ShadowDebugControl extends AbstractControl {
|
|||||||
|
|
||||||
private final List<Picture> pictures = new ArrayList<>();
|
private final List<Picture> pictures = new ArrayList<>();
|
||||||
|
|
||||||
public ShadowDebugControl(AssetManager assetManager, PreShadowArrayRenderer shadowRenderer) {
|
public ShadowDebugControl(AssetManager assetManager, InPassShadowRenderer shadowRenderer) {
|
||||||
TextureArray shadowMapArray = shadowRenderer.getShadowMapTexture();
|
TextureArray shadowMapArray = shadowRenderer.getShadowMapTexture();
|
||||||
Image shadowMap = shadowMapArray.getImage();
|
Image shadowMap = shadowMapArray.getImage();
|
||||||
for (int i = 0; i < shadowMap.getDepth(); i++) {
|
for (int i = 0; i < shadowMap.getDepth(); i++) {
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009-2016 jMonkeyEngine
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are
|
|
||||||
* met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package com.jme3.shadow.next;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Kirill Vainer
|
|
||||||
*/
|
|
||||||
public interface ShadowParameters {
|
|
||||||
}
|
|
@ -48,6 +48,11 @@ public class DirectionalArrayShadowMapSlice extends BaseArrayShadowMapSlice<Dire
|
|||||||
this.shadowCamera.setParallelProjection(true);
|
this.shadowCamera.setParallelProjection(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isParallelToYUp(Vector3f direction) {
|
||||||
|
return direction.x == 0 && direction.z == 0
|
||||||
|
&& (direction.y == -1 || direction.y == 1);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateShadowCamera(
|
public void updateShadowCamera(
|
||||||
ViewPort viewPort,
|
ViewPort viewPort,
|
||||||
DirectionalLight light,
|
DirectionalLight light,
|
||||||
@ -55,7 +60,12 @@ public class DirectionalArrayShadowMapSlice extends BaseArrayShadowMapSlice<Dire
|
|||||||
float near,
|
float near,
|
||||||
float far,
|
float far,
|
||||||
Vector3f[] points) {
|
Vector3f[] points) {
|
||||||
shadowCamera.lookAtDirection(light.getDirection(), shadowCamera.getUp());
|
if (isParallelToYUp(light.getDirection())) {
|
||||||
|
// direction and up cannot be parallel
|
||||||
|
shadowCamera.lookAtDirection(light.getDirection(), Vector3f.UNIT_Z);
|
||||||
|
} else {
|
||||||
|
shadowCamera.lookAtDirection(light.getDirection(), Vector3f.UNIT_Y);
|
||||||
|
}
|
||||||
|
|
||||||
int textureSize = frameBuffer.getWidth();
|
int textureSize = frameBuffer.getWidth();
|
||||||
ShadowUtil.updateFrustumPoints(viewPort.getCamera(), near, far, points);
|
ShadowUtil.updateFrustumPoints(viewPort.getCamera(), near, far, points);
|
||||||
|
@ -53,6 +53,7 @@ public abstract class BaseShadowMapSlice<T extends Light> implements ShadowMapSl
|
|||||||
protected final Texture2D depthTexture;
|
protected final Texture2D depthTexture;
|
||||||
protected final Camera shadowCamera;
|
protected final Camera shadowCamera;
|
||||||
protected final Vector3f[] points;
|
protected final Vector3f[] points;
|
||||||
|
protected final Matrix4f biasedViewProjectionMatrix = new Matrix4f();
|
||||||
|
|
||||||
public BaseShadowMapSlice(int size, Vector3f[] points) {
|
public BaseShadowMapSlice(int size, Vector3f[] points) {
|
||||||
this.depthTexture = new Texture2D(size, size, Image.Format.Depth16);
|
this.depthTexture = new Texture2D(size, size, Image.Format.Depth16);
|
||||||
@ -81,7 +82,6 @@ public abstract class BaseShadowMapSlice<T extends Light> implements ShadowMapSl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Matrix4f getBiasedViewProjectionMatrix() {
|
public Matrix4f getBiasedViewProjectionMatrix() {
|
||||||
// return shadowCamera.getViewProjectionMatrix();
|
return BIAS_MATRIX.mult(shadowCamera.getViewProjectionMatrix(), biasedViewProjectionMatrix);
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,13 @@
|
|||||||
package com.jme3.shadow.next.pssm;
|
package com.jme3.shadow.next.pssm;
|
||||||
|
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
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;
|
||||||
import com.jme3.shadow.next.ShadowParameters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Kirill Vainer
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
public final class DirectionalShadowParameters implements ShadowParameters {
|
public final class DirectionalShadowParameters {
|
||||||
|
|
||||||
private float lambda = 0.65f;
|
private float lambda = 0.65f;
|
||||||
private int numSplits = 4;
|
private int numSplits = 4;
|
||||||
@ -61,7 +59,9 @@ public final class DirectionalShadowParameters implements ShadowParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setNumSplits(int numSplits) {
|
public void setNumSplits(int numSplits) {
|
||||||
// TODO: ensure it is 1 to 4
|
if (numSplits < 1 || numSplits > 4) {
|
||||||
|
throw new IllegalArgumentException("Number of splits must be between 1 and 4");
|
||||||
|
}
|
||||||
this.numSplits = numSplits;
|
this.numSplits = numSplits;
|
||||||
this.splitPositions = new float[numSplits + 1];
|
this.splitPositions = new float[numSplits + 1];
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ void lightComputeDir(in vec3 worldPos, in float lightType, in vec4 position, out
|
|||||||
lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
|
lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
|
||||||
lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0);
|
lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0);
|
||||||
#else
|
#else
|
||||||
lightDir.w = 1.0; // clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
|
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
|
||||||
#endif
|
#endif
|
||||||
lightDir.xyz = tempVec / vec3(dist);
|
lightDir.xyz = tempVec / vec3(dist);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ import com.jme3.material.RenderState.BlendMode;
|
|||||||
import com.jme3.material.RenderState.FaceCullMode;
|
import com.jme3.material.RenderState.FaceCullMode;
|
||||||
import com.jme3.material.TechniqueDef.LightMode;
|
import com.jme3.material.TechniqueDef.LightMode;
|
||||||
import com.jme3.material.TechniqueDef.ShadowMode;
|
import com.jme3.material.TechniqueDef.ShadowMode;
|
||||||
import com.jme3.material.logic.StaticPassLightingLogic;
|
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector2f;
|
import com.jme3.math.Vector2f;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
@ -645,9 +644,6 @@ public class J3MLoader implements AssetLoader {
|
|||||||
case SinglePass:
|
case SinglePass:
|
||||||
technique.setLogic(new SinglePassLightingLogic(technique));
|
technique.setLogic(new SinglePassLightingLogic(technique));
|
||||||
break;
|
break;
|
||||||
case StaticPass:
|
|
||||||
technique.setLogic(new ShadowStaticPassLightingLogic(technique));
|
|
||||||
break;
|
|
||||||
case SinglePassAndImageBased:
|
case SinglePassAndImageBased:
|
||||||
technique.setLogic(new SinglePassAndImageBasedLightingLogic(technique));
|
technique.setLogic(new SinglePassAndImageBasedLightingLogic(technique));
|
||||||
break;
|
break;
|
||||||
|
@ -52,7 +52,7 @@ import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
|||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.shape.Box;
|
import com.jme3.scene.shape.Box;
|
||||||
import com.jme3.scene.shape.Quad;
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.jme3.shadow.next.PreShadowArrayRenderer;
|
import com.jme3.shadow.next.InPassShadowRenderer;
|
||||||
import com.jme3.system.AppSettings;
|
import com.jme3.system.AppSettings;
|
||||||
|
|
||||||
public class TestInPassShadows extends SimpleApplication {
|
public class TestInPassShadows extends SimpleApplication {
|
||||||
@ -60,7 +60,7 @@ public class TestInPassShadows extends SimpleApplication {
|
|||||||
private DirectionalLight dl;
|
private DirectionalLight dl;
|
||||||
private SpotLight sl;
|
private SpotLight sl;
|
||||||
private PointLight pl;
|
private PointLight pl;
|
||||||
private PreShadowArrayRenderer psr;
|
private InPassShadowRenderer ipsr;
|
||||||
private ToneMapFilter tmf;
|
private ToneMapFilter tmf;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -114,14 +114,14 @@ public class TestInPassShadows extends SimpleApplication {
|
|||||||
30);
|
30);
|
||||||
rootNode.addLight(pl);
|
rootNode.addLight(pl);
|
||||||
|
|
||||||
psr = new PreShadowArrayRenderer();
|
ipsr = new InPassShadowRenderer();
|
||||||
psr.setTextureSize(512);
|
ipsr.setTextureSize(512);
|
||||||
psr.setPolyOffset(5, 0);
|
ipsr.setPolyOffset(5, 0);
|
||||||
psr.directional().setNumSplits(1);
|
ipsr.directional().setNumSplits(1);
|
||||||
psr.addLight(dl);
|
ipsr.addLight(dl);
|
||||||
psr.addLight(sl);
|
ipsr.addLight(sl);
|
||||||
psr.addLight(pl);
|
ipsr.addLight(pl);
|
||||||
viewPort.addProcessor(psr);
|
viewPort.addProcessor(ipsr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadScene() {
|
private void loadScene() {
|
||||||
@ -186,7 +186,7 @@ public class TestInPassShadows extends SimpleApplication {
|
|||||||
units -= tpf * 50f;
|
units -= tpf * 50f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
psr.setPolyOffset(factor, units);
|
ipsr.setPolyOffset(factor, units);
|
||||||
System.out.println("PolyOffset(" + factor + ", " + units + ")");
|
System.out.println("PolyOffset(" + factor + ", " + units + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user