remove hacks from ShadowUtil
This commit is contained in:
parent
6487def9d3
commit
42432ed4ea
@ -271,7 +271,6 @@ public class ShadowUtil {
|
|||||||
{
|
{
|
||||||
// global variables set in order not to have recursive process method with too many parameters
|
// global variables set in order not to have recursive process method with too many parameters
|
||||||
Matrix4f viewProjMatrix;
|
Matrix4f viewProjMatrix;
|
||||||
public Integer casterCount;
|
|
||||||
BoundingBox splitBB, casterBB;
|
BoundingBox splitBB, casterBB;
|
||||||
GeometryList splitOccluders;
|
GeometryList splitOccluders;
|
||||||
TempVars vars;
|
TempVars vars;
|
||||||
@ -279,9 +278,8 @@ public class ShadowUtil {
|
|||||||
public OccludersExtractor() {}
|
public OccludersExtractor() {}
|
||||||
|
|
||||||
// initialize the global OccludersExtractor variables
|
// initialize the global OccludersExtractor variables
|
||||||
public OccludersExtractor(Matrix4f vpm, int cc, BoundingBox sBB, BoundingBox cBB, GeometryList sOCC, TempVars v) {
|
public OccludersExtractor(Matrix4f vpm, BoundingBox sBB, BoundingBox cBB, GeometryList sOCC, TempVars v) {
|
||||||
viewProjMatrix = vpm;
|
viewProjMatrix = vpm;
|
||||||
casterCount = cc;
|
|
||||||
splitBB = sBB;
|
splitBB = sBB;
|
||||||
casterBB = cBB;
|
casterBB = cBB;
|
||||||
splitOccluders = sOCC;
|
splitOccluders = sOCC;
|
||||||
@ -293,9 +291,8 @@ public class ShadowUtil {
|
|||||||
* The global OccludersExtractor variables need to be initialized first.
|
* The global OccludersExtractor variables need to be initialized first.
|
||||||
* Variables are updated and used in {@link ShadowUtil#updateShadowCamera} at last.
|
* Variables are updated and used in {@link ShadowUtil#updateShadowCamera} at last.
|
||||||
*/
|
*/
|
||||||
public int addOccluders(Spatial scene) {
|
public void addOccluders(Spatial scene) {
|
||||||
if ( scene != null ) process(scene);
|
if ( scene != null ) process(scene);
|
||||||
return casterCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean intersectsIgnoreNearZ(BoundingBox splitBB, BoundingSphere occSphere) {
|
private boolean intersectsIgnoreNearZ(BoundingBox splitBB, BoundingSphere occSphere) {
|
||||||
@ -357,7 +354,6 @@ public class ShadowUtil {
|
|||||||
BoundingVolume occBox = bv.transform(viewProjMatrix, vars.bbox);
|
BoundingVolume occBox = bv.transform(viewProjMatrix, vars.bbox);
|
||||||
if (intersectsIgnoreNearZ(splitBB, occBox)) {
|
if (intersectsIgnoreNearZ(splitBB, occBox)) {
|
||||||
casterBB.mergeLocal(occBox);
|
casterBB.mergeLocal(occBox);
|
||||||
casterCount++;
|
|
||||||
if (splitOccluders != null) {
|
if (splitOccluders != null) {
|
||||||
splitOccluders.add(occluder);
|
splitOccluders.add(occluder);
|
||||||
}
|
}
|
||||||
@ -384,7 +380,7 @@ public class ShadowUtil {
|
|||||||
GeometryList receivers,
|
GeometryList receivers,
|
||||||
Camera shadowCam,
|
Camera shadowCam,
|
||||||
Vector3f[] points,
|
Vector3f[] points,
|
||||||
GeometryList splitOccluders,
|
GeometryList shadowCasters,
|
||||||
float shadowMapSize) {
|
float shadowMapSize) {
|
||||||
|
|
||||||
boolean ortho = shadowCam.isParallelProjection();
|
boolean ortho = shadowCam.isParallelProjection();
|
||||||
@ -392,7 +388,7 @@ public class ShadowUtil {
|
|||||||
shadowCam.setProjectionMatrix(null);
|
shadowCam.setProjectionMatrix(null);
|
||||||
|
|
||||||
if (ortho) {
|
if (ortho) {
|
||||||
shadowCam.setFrustum(-shadowCam.getFrustumFar(), shadowCam.getFrustumFar(), -1, 1, 1, -1);
|
shadowCam.setFrustum(-1, 1, -1, 1, 1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create transform to rotate points to viewspace
|
// create transform to rotate points to viewspace
|
||||||
@ -405,8 +401,7 @@ public class ShadowUtil {
|
|||||||
BoundingBox casterBB = new BoundingBox();
|
BoundingBox casterBB = new BoundingBox();
|
||||||
BoundingBox receiverBB = new BoundingBox();
|
BoundingBox receiverBB = new BoundingBox();
|
||||||
|
|
||||||
int casterCount = 0, receiverCount = 0;
|
if (receivers != null && receivers.size() != 0) {
|
||||||
|
|
||||||
for (int i = 0; i < receivers.size(); i++) {
|
for (int i = 0; i < receivers.size(); i++) {
|
||||||
// convert bounding box to light's viewproj space
|
// convert bounding box to light's viewproj space
|
||||||
Geometry receiver = receivers.get(i);
|
Geometry receiver = receivers.get(i);
|
||||||
@ -417,24 +412,20 @@ public class ShadowUtil {
|
|||||||
//Nehon : prevent NaN and infinity values to screw the final bounding box
|
//Nehon : prevent NaN and infinity values to screw the final bounding box
|
||||||
if (!Float.isNaN(recvBox.getCenter().x) && !Float.isInfinite(recvBox.getCenter().x)) {
|
if (!Float.isNaN(recvBox.getCenter().x) && !Float.isInfinite(recvBox.getCenter().x)) {
|
||||||
receiverBB.mergeLocal(recvBox);
|
receiverBB.mergeLocal(recvBox);
|
||||||
receiverCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
receiverBB.setXExtent(Float.POSITIVE_INFINITY);
|
||||||
|
receiverBB.setYExtent(Float.POSITIVE_INFINITY);
|
||||||
|
receiverBB.setZExtent(Float.POSITIVE_INFINITY);
|
||||||
|
}
|
||||||
|
|
||||||
// collect splitOccluders through scene recursive traverse
|
// collect splitOccluders through scene recursive traverse
|
||||||
OccludersExtractor occExt = new OccludersExtractor(viewProjMatrix, casterCount, splitBB, casterBB, splitOccluders, vars);
|
OccludersExtractor occExt = new OccludersExtractor(viewProjMatrix, splitBB, casterBB, shadowCasters, vars);
|
||||||
for (Spatial scene : viewPort.getScenes()) {
|
for (Spatial scene : viewPort.getScenes()) {
|
||||||
occExt.addOccluders(scene);
|
occExt.addOccluders(scene);
|
||||||
}
|
}
|
||||||
casterCount = occExt.casterCount;
|
|
||||||
|
|
||||||
//Nehon 08/18/2010 this is to avoid shadow bleeding when the ground is set to only receive shadows
|
|
||||||
if (casterCount != receiverCount) {
|
|
||||||
casterBB.setXExtent(casterBB.getXExtent() + 2.0f);
|
|
||||||
casterBB.setYExtent(casterBB.getYExtent() + 2.0f);
|
|
||||||
casterBB.setZExtent(casterBB.getZExtent() + 2.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3f casterMin = casterBB.getMin(vars.vect1);
|
Vector3f casterMin = casterBB.getMin(vars.vect1);
|
||||||
Vector3f casterMax = casterBB.getMax(vars.vect2);
|
Vector3f casterMax = casterBB.getMax(vars.vect2);
|
||||||
@ -445,27 +436,26 @@ public class ShadowUtil {
|
|||||||
Vector3f splitMin = splitBB.getMin(vars.vect5);
|
Vector3f splitMin = splitBB.getMin(vars.vect5);
|
||||||
Vector3f splitMax = splitBB.getMax(vars.vect6);
|
Vector3f splitMax = splitBB.getMax(vars.vect6);
|
||||||
|
|
||||||
splitMin.z = 0;
|
|
||||||
|
|
||||||
// if (!ortho) {
|
|
||||||
// shadowCam.setFrustumPerspective(45, 1, 1, splitMax.z);
|
|
||||||
// }
|
|
||||||
|
|
||||||
Matrix4f projMatrix = shadowCam.getProjectionMatrix();
|
Matrix4f projMatrix = shadowCam.getProjectionMatrix();
|
||||||
|
|
||||||
Vector3f cropMin = vars.vect7;
|
Vector3f cropMin = vars.vect7;
|
||||||
Vector3f cropMax = vars.vect8;
|
Vector3f cropMax = vars.vect8;
|
||||||
|
|
||||||
|
if (shadowCasters.size() > 0) {
|
||||||
// IMPORTANT: Special handling for Z values
|
// IMPORTANT: Special handling for Z values
|
||||||
cropMin.x = max(max(casterMin.x, receiverMin.x), splitMin.x);
|
cropMin.x = max(max(casterMin.x, receiverMin.x), splitMin.x);
|
||||||
cropMax.x = min(min(casterMax.x, receiverMax.x), splitMax.x);
|
cropMax.x = min(min(casterMax.x, receiverMax.x), splitMax.x);
|
||||||
|
|
||||||
cropMin.y = max(max(casterMin.y, receiverMin.y), splitMin.y);
|
cropMin.y = max(max(casterMin.y, receiverMin.y), splitMin.y);
|
||||||
cropMax.y = min(min(casterMax.y, receiverMax.y), splitMax.y);
|
cropMax.y = min(min(casterMax.y, receiverMax.y), splitMax.y);
|
||||||
|
|
||||||
cropMin.z = min(casterMin.z, splitMin.z);
|
cropMin.z = min(casterMin.z, splitMin.z);
|
||||||
cropMax.z = min(receiverMax.z, splitMax.z);
|
cropMax.z = min(receiverMax.z, splitMax.z);
|
||||||
|
} else {
|
||||||
|
// Set crop = split so that everything in the scene has a depth < 1.0 in light space.
|
||||||
|
// This avoids shadowing everything when there are no casters.
|
||||||
|
cropMin.set(splitMin);
|
||||||
|
cropMax.set(splitMax);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the crop matrix.
|
// Create the crop matrix.
|
||||||
float scaleX, scaleY, scaleZ;
|
float scaleX, scaleY, scaleZ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user