Changes the name of the array shadow renderer to InPassShadowRenderer. Also addressed some comments on the PR
parent
54ef6ec280
commit
d444c28183
@ -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); |
||||
} |
||||
|
||||
} |
@ -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 { |
||||
} |
Loading…
Reference in new issue