Search in sources :

Example 1 with Bitmap

use of org.sunflow.image.Bitmap in project joons-renderer by joonhyublee.

the class Texture method getBump.

public Vector3 getBump(float x, float y, OrthoNormalBasis basis, float scale) {
    Bitmap bitmapv = getBitmap();
    float dx = 1.0f / bitmapv.getWidth();
    float dy = 1.0f / bitmapv.getHeight();
    float b0 = getPixel(x, y).getLuminance();
    float bx = getPixel(x + dx, y).getLuminance();
    float by = getPixel(x, y + dy).getLuminance();
    return basis.transform(new Vector3(scale * (b0 - bx), scale * (b0 - by), 1)).normalize();
}
Also used : Bitmap(org.sunflow.image.Bitmap) Vector3(org.sunflow.math.Vector3)

Example 2 with Bitmap

use of org.sunflow.image.Bitmap in project joons-renderer by joonhyublee.

the class ImageBasedLight method update.

public boolean update(ParameterList pl, SunflowAPI api) {
    updateBasis(pl.getVector("center", null), pl.getVector("up", null));
    numSamples = pl.getInt("samples", numSamples);
    numLowSamples = pl.getInt("lowsamples", numLowSamples);
    String filename = pl.getString("texture", null);
    if (filename != null) {
        texture = TextureCache.getTexture(api.resolveTextureFilename(filename), false);
    }
    // no texture provided
    if (texture == null) {
        return false;
    }
    Bitmap b = texture.getBitmap();
    if (b == null) {
        return false;
    }
    // rebuild histograms if this is a new texture
    if (filename != null) {
        imageHistogram = new float[b.getWidth()][b.getHeight()];
        colHistogram = new float[b.getWidth()];
        float du = 1.0f / b.getWidth();
        float dv = 1.0f / b.getHeight();
        for (int x = 0; x < b.getWidth(); x++) {
            for (int y = 0; y < b.getHeight(); y++) {
                float u = (x + 0.5f) * du;
                float v = (y + 0.5f) * dv;
                Color c = texture.getPixel(u, v);
                imageHistogram[x][y] = c.getLuminance() * (float) Math.sin(Math.PI * v);
                if (y > 0) {
                    imageHistogram[x][y] += imageHistogram[x][y - 1];
                }
            }
            colHistogram[x] = imageHistogram[x][b.getHeight() - 1];
            if (x > 0) {
                colHistogram[x] += colHistogram[x - 1];
            }
            for (int y = 0; y < b.getHeight(); y++) {
                imageHistogram[x][y] /= imageHistogram[x][b.getHeight() - 1];
            }
        }
        for (int x = 0; x < b.getWidth(); x++) {
            colHistogram[x] /= colHistogram[b.getWidth() - 1];
        }
        jacobian = (float) (2 * Math.PI * Math.PI) / (b.getWidth() * b.getHeight());
    }
    // take fixed samples
    if (pl.getBoolean("fixed", samples != null)) {
        // high density samples
        samples = new Vector3[numSamples];
        colors = new Color[numSamples];
        generateFixedSamples(samples, colors);
        // low density samples
        lowSamples = new Vector3[numLowSamples];
        lowColors = new Color[numLowSamples];
        generateFixedSamples(lowSamples, lowColors);
    } else {
        // turn off
        samples = lowSamples = null;
        colors = lowColors = null;
    }
    return true;
}
Also used : Bitmap(org.sunflow.image.Bitmap) Color(org.sunflow.image.Color)

Example 3 with Bitmap

use of org.sunflow.image.Bitmap in project joons-renderer by joonhyublee.

the class Texture method getPixel.

/**
 * Gets the color at location (x,y) in the texture. The lookup is performed
 * using the fractional component of the coordinates, treating the texture
 * as a unit square tiled in both directions. Bicubic filtering is performed
 * on the four nearest pixels to the lookup point.
 *
 * @param x x coordinate into the texture
 * @param y y coordinate into the texture
 * @return filtered color at location (x,y)
 */
public Color getPixel(float x, float y) {
    Bitmap bitmapc = getBitmap();
    x = MathUtils.frac(x);
    y = MathUtils.frac(y);
    float dx = x * (bitmapc.getWidth() - 1);
    float dy = y * (bitmapc.getHeight() - 1);
    int ix0 = (int) dx;
    int iy0 = (int) dy;
    int ix1 = (ix0 + 1) % bitmapc.getWidth();
    int iy1 = (iy0 + 1) % bitmapc.getHeight();
    float u = dx - ix0;
    float v = dy - iy0;
    u = u * u * (3.0f - (2.0f * u));
    v = v * v * (3.0f - (2.0f * v));
    float k00 = (1.0f - u) * (1.0f - v);
    Color c00 = bitmapc.readColor(ix0, iy0);
    float k01 = (1.0f - u) * v;
    Color c01 = bitmapc.readColor(ix0, iy1);
    float k10 = u * (1.0f - v);
    Color c10 = bitmapc.readColor(ix1, iy0);
    float k11 = u * v;
    Color c11 = bitmapc.readColor(ix1, iy1);
    Color c = Color.mul(k00, c00);
    c.madd(k01, c01);
    c.madd(k10, c10);
    c.madd(k11, c11);
    return c;
}
Also used : Bitmap(org.sunflow.image.Bitmap) Color(org.sunflow.image.Color)

Aggregations

Bitmap (org.sunflow.image.Bitmap)3 Color (org.sunflow.image.Color)2 Vector3 (org.sunflow.math.Vector3)1