Exemplo n.º 1
0
 public void accelerateShadows() {
   if (withAcceleration) {
     accLightProjectionZBuf = new float[lightCount][][];
     for (int i = 0; i < lightCount; i++) {
       if (shadowZBuf[i] != null) {
         accLightProjectionZBuf[i] = new float[rasterWidth][rasterHeight];
         for (int pX = 0; pX < rasterWidth; pX++) {
           for (int pY = 0; pY < rasterHeight; pY++) {
             accLightProjectionZBuf[i][pX][pY] = NormalsCalculator.ZBUF_ZMIN;
             float originX = originXBuf[pX][pY];
             if (originX != NormalsCalculator.ZBUF_ZMIN) {
               float originY = originYBuf[pX][pY];
               if (originY != NormalsCalculator.ZBUF_ZMIN) {
                 float originZ = originZBuf[pX][pY];
                 if (originZ != NormalsCalculator.ZBUF_ZMIN) {
                   int x =
                       projectPointToLightMapX(
                           i,
                           lightViewCalculator.applyLightProjectionX(
                               i, originX, originY, originZ));
                   int y =
                       projectPointToLightMapY(
                           i,
                           lightViewCalculator.applyLightProjectionY(
                               i, originX, originY, originZ));
                   if (x >= 0
                       && x < shadowZBuf[i].length
                       && y >= 0
                       && y < shadowZBuf[i][0].length) {
                     double lightZ =
                         lightViewCalculator.applyLightProjectionZ(i, originX, originY, originZ);
                     accLightProjectionZBuf[i][pX][pY] =
                         (float) GfxMathLib.step(shadowZBuf[i][x][y] - shadowDistBias, lightZ);
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
 }
Exemplo n.º 2
0
  private void calcSmoothShadowIntensity(
      int pX,
      int pY,
      RasterPoint pDestRasterPoint,
      int i,
      int shadowSmoothRadius,
      double[][] shadowSmoothKernel) {
    pDestRasterPoint.visibility[i] = 1.0;
    double totalIntensity = 0.0;

    if (accLightProjectionZBuf != null && accLightProjectionZBuf[i] != null) {
      int dl = shadowSmoothRadius / 8 + 1;
      for (int k = -shadowSmoothRadius; k <= shadowSmoothRadius; k += dl) {
        int dstX = pX + k;
        if (dstX >= 0 && dstX < originXBuf.length) {
          for (int l = -shadowSmoothRadius; l <= shadowSmoothRadius; l += dl) {
            int dstY = pY + l;
            if (dstY >= 0 && dstY < originXBuf[0].length) {
              if (accLightProjectionZBuf[i][dstX][dstY] > NormalsCalculator.ZBUF_ZMIN) {
                double intensity =
                    shadowSmoothKernel[k + shadowSmoothRadius][l + shadowSmoothRadius];
                totalIntensity += intensity;
                pDestRasterPoint.visibility[i] += accLightProjectionZBuf[i][dstX][dstY] * intensity;
              }
            }
          }
        }
      }
    } else {

      for (int k = -shadowSmoothRadius; k <= shadowSmoothRadius; k++) {
        int dstX = pX + k;
        if (dstX >= 0 && dstX < originXBuf.length) {
          for (int l = -shadowSmoothRadius; l <= shadowSmoothRadius; l++) {
            int dstY = pY + l;
            if (dstY >= 0 && dstY < originXBuf[0].length) {
              float originX = originXBuf[dstX][dstY];
              if (originX != NormalsCalculator.ZBUF_ZMIN) {
                float originY = originYBuf[dstX][dstY];
                if (originY != NormalsCalculator.ZBUF_ZMIN) {
                  float originZ = originZBuf[dstX][dstY];
                  if (originZ != NormalsCalculator.ZBUF_ZMIN) {
                    int x =
                        projectPointToLightMapX(
                            i,
                            lightViewCalculator.applyLightProjectionX(
                                i, originX, originY, originZ));
                    int y =
                        projectPointToLightMapY(
                            i,
                            lightViewCalculator.applyLightProjectionY(
                                i, originX, originY, originZ));
                    if (x >= 0
                        && x < shadowZBuf[i].length
                        && y >= 0
                        && y < shadowZBuf[i][0].length) {
                      double intensity =
                          shadowSmoothKernel[k + shadowSmoothRadius][l + shadowSmoothRadius];
                      totalIntensity += intensity;
                      double lightZ =
                          lightViewCalculator.applyLightProjectionZ(i, originX, originY, originZ);
                      pDestRasterPoint.visibility[i] +=
                          GfxMathLib.step(shadowZBuf[i][x][y] - shadowDistBias, lightZ) * intensity;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    if (totalIntensity > MathLib.EPSILON) {
      pDestRasterPoint.visibility[i] /= totalIntensity;
    }
  }