Search in sources :

Example 1 with RasterPoint

use of org.jwildfire.create.tina.base.raster.RasterPoint in project JWildfire by thargor6.

the class LogDensityFilter method addSolidColors.

private boolean addSolidColors(LogDensityPoint dest, RasterPoint rp, double colorScale) {
    if (solidRendering && rp.hasNormals) {
        LightViewCalculator lightViewCalculator = raster.getLightViewCalculator();
        double avgVisibility;
        if (rp.hasShadows) {
            avgVisibility = 0.0;
            int shadowCount = 0;
            for (int i = 0; i < rp.visibility.length; i++) {
                avgVisibility += rp.visibility[i];
                shadowCount++;
            }
            if (shadowCount > 0) {
                avgVisibility /= (double) shadowCount;
            } else {
                avgVisibility = 1.0;
            }
        } else {
            avgVisibility = 1.0;
        }
        RGBColorD rawColor;
        MaterialSettings material = flame.getSolidRenderSettings().getInterpolatedMaterial(rp.material);
        if (material == null) {
            RGBColorD bgColor = new RGBColorD(dest.bgRed, dest.bgGreen, dest.bgBlue, 1.0 / VecMathLib.COLORSCL);
            double visibility = 0.0;
            for (int i = 0; i < flame.getSolidRenderSettings().getLights().size(); i++) {
                DistantLight light = flame.getSolidRenderSettings().getLights().get(i);
                visibility += light.isCastShadows() && rp.hasShadows ? rp.visibility[i] : avgVisibility;
            }
            visibility = GfxMathLib.clamp(visibility);
            rawColor = new RGBColorD(bgColor, visibility);
        } else {
            double aoInt = Tools.limitValue(flame.getSolidRenderSettings().getAoIntensity(), 0.0, 4.0);
            boolean withSSAO = flame.getSolidRenderSettings().isAoEnabled();
            double ambientIntensity = Math.max(0.0, withSSAO ? (material.getAmbient() - rp.ao * aoInt) : material.getAmbient());
            double aoDiffuseInfluence = flame.getSolidRenderSettings().getAoAffectDiffuse();
            double diffuseIntensity = Math.max(0.0, withSSAO ? (material.getDiffuse() - rp.ao * aoInt * aoDiffuseInfluence) : material.getDiffuse());
            double specularIntensity = material.getPhong();
            SimpleImage reflectionMap = null;
            if (material.getReflMapIntensity() > MathLib.EPSILON && material.getReflMapFilename() != null && material.getReflMapFilename().length() > 0) {
                try {
                    reflectionMap = (SimpleImage) RessourceManager.getImage(material.getReflMapFilename());
                } catch (Exception e) {
                    material.setReflMapFilename(null);
                    e.printStackTrace();
                }
            }
            RGBColorD objColor = new RGBColorD(rp.solidRed * logScaleCalculator.getBalanceRed(), rp.solidGreen * logScaleCalculator.getBalanceGreen(), rp.solidBlue * logScaleCalculator.getBalanceBlue(), 1.0 / VecMathLib.COLORSCL);
            rawColor = new RGBColorD(objColor, ambientIntensity * avgVisibility);
            VectorD normal = new VectorD(rp.nx, rp.ny, rp.nz);
            VectorD viewDir = new VectorD(0.0, 0.0, 1.0);
            for (int i = 0; i < flame.getSolidRenderSettings().getLights().size(); i++) {
                DistantLight light = flame.getSolidRenderSettings().getLights().get(i);
                VectorD lightDir = lightViewCalculator.getLightDir()[i];
                double visibility = light.isCastShadows() && rp.hasShadows ? rp.visibility[i] : avgVisibility;
                double cosa = VectorD.dot(lightDir, normal);
                if (cosa > MathLib.EPSILON) {
                    double diffResponse = material.getLightDiffFunc().evaluate(cosa);
                    rawColor.addFrom(light.getRed() + objColor.r * ambientIntensity / 3.0, light.getGreen() + objColor.g * ambientIntensity / 3.0, light.getBlue() + objColor.b * ambientIntensity / 3.0, visibility * diffResponse * diffuseIntensity * light.getIntensity());
                }
                if (specularIntensity > MathLib.EPSILON) {
                    VectorD r = VectorD.reflect(lightDir, normal);
                    double vr = VectorD.dot(viewDir, r);
                    if (vr < MathLib.EPSILON) {
                        double specularResponse = MathLib.pow(material.getLightDiffFunc().evaluate(-vr), material.getPhongSize());
                        rawColor.addFrom(material.getPhongRed(), material.getPhongGreen(), material.getPhongBlue(), visibility * specularResponse * specularIntensity * light.getIntensity());
                    }
                }
                // http://www.reindelsoftware.com/Documents/Mapping/Mapping.html
                if (reflectionMap != null) {
                    double reflectionMapIntensity = Math.max(0.0, withSSAO ? (material.getReflMapIntensity() - rp.ao * aoInt * aoDiffuseInfluence) : material.getReflMapIntensity());
                    VectorD r = VectorD.reflect(viewDir, normal);
                    UVPairD uv;
                    switch(material.getReflectionMapping()) {
                        case SPHERICAL:
                            uv = UVPairD.sphericalOpenGlMapping(r);
                            break;
                        case BLINN_NEWELL:
                        default:
                            uv = UVPairD.sphericalBlinnNewellLatitudeMapping(r);
                            break;
                    }
                    RGBColorD reflMapColor = uv.getColorFromMap(reflectionMap);
                    rawColor.addFrom(reflMapColor.r * logScaleCalculator.getBalanceRed(), reflMapColor.g * logScaleCalculator.getBalanceGreen(), reflMapColor.b * logScaleCalculator.getBalanceBlue(), visibility * reflectionMapIntensity);
                }
            }
        }
        dest.solidRed += rawColor.r * colorScale * VecMathLib.COLORSCL;
        dest.solidGreen += rawColor.g * colorScale * VecMathLib.COLORSCL;
        dest.solidBlue += rawColor.b * colorScale * VecMathLib.COLORSCL;
        dest.hasSolidColors = true;
        return true;
    }
    return false;
}
Also used : RGBColorD(org.jwildfire.base.mathlib.VecMathLib.RGBColorD) MaterialSettings(org.jwildfire.create.tina.base.solidrender.MaterialSettings) SimpleImage(org.jwildfire.image.SimpleImage) DistantLight(org.jwildfire.create.tina.base.solidrender.DistantLight) VectorD(org.jwildfire.base.mathlib.VecMathLib.VectorD) RasterPoint(org.jwildfire.create.tina.base.raster.RasterPoint) UVPairD(org.jwildfire.base.mathlib.VecMathLib.UVPairD)

Example 2 with RasterPoint

use of org.jwildfire.create.tina.base.raster.RasterPoint in project JWildfire by thargor6.

the class ShadowCalculator method calcSmoothShadowIntensity.

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;
    }
}
Also used : RasterPoint(org.jwildfire.create.tina.base.raster.RasterPoint)

Example 3 with RasterPoint

use of org.jwildfire.create.tina.base.raster.RasterPoint in project JWildfire by thargor6.

the class ShadowCalculator method calcFastShadowIntensity.

private void calcFastShadowIntensity(int pX, int pY, RasterPoint pDestRasterPoint, int i) {
    if (accLightProjectionZBuf != null && accLightProjectionZBuf[i] != null) {
        if (accLightProjectionZBuf[i][pX][pY] > NormalsCalculator.ZBUF_ZMIN) {
            pDestRasterPoint.visibility[i] = accLightProjectionZBuf[i][pX][pY];
        }
    } else {
        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);
                        if (lightZ < shadowZBuf[i][x][y] - shadowDistBias) {
                            pDestRasterPoint.visibility[i] = 0.0;
                        }
                    // pDestRasterPoint.visibility[i] = GfxMathLib.step(shadowZBuf[i][x][y] - bias, lightZ);
                    }
                }
            }
        }
    }
}
Also used : RasterPoint(org.jwildfire.create.tina.base.raster.RasterPoint)

Aggregations

RasterPoint (org.jwildfire.create.tina.base.raster.RasterPoint)3 RGBColorD (org.jwildfire.base.mathlib.VecMathLib.RGBColorD)1 UVPairD (org.jwildfire.base.mathlib.VecMathLib.UVPairD)1 VectorD (org.jwildfire.base.mathlib.VecMathLib.VectorD)1 DistantLight (org.jwildfire.create.tina.base.solidrender.DistantLight)1 MaterialSettings (org.jwildfire.create.tina.base.solidrender.MaterialSettings)1 SimpleImage (org.jwildfire.image.SimpleImage)1