use of org.sunflow.image.Color in project joons-renderer by joonhyublee.
the class IrradianceCacheGIEngine method getIrradiance.
@Override
public Color getIrradiance(ShadingState state, Color diffuseReflectance) {
if (samples <= 0) {
return Color.BLACK;
}
if (state.getDiffuseDepth() > 0) {
// do simple path tracing for additional bounces (single ray)
float xi = (float) state.getRandom(0, 0, 1);
float xj = (float) state.getRandom(0, 1, 1);
float phi = (float) (xi * 2 * Math.PI);
float cosPhi = (float) Math.cos(phi);
float sinPhi = (float) Math.sin(phi);
float sinTheta = (float) Math.sqrt(xj);
float cosTheta = (float) Math.sqrt(1.0f - xj);
Vector3 w = new Vector3();
w.x = cosPhi * sinTheta;
w.y = sinPhi * sinTheta;
w.z = cosTheta;
OrthoNormalBasis onb = state.getBasis();
onb.transform(w);
Ray r = new Ray(state.getPoint(), w);
ShadingState temp = state.traceFinalGather(r, 0);
return temp != null ? getGlobalRadiance(temp).copy().mul((float) Math.PI) : Color.BLACK;
}
rwl.readLock().lock();
Color irr;
try {
irr = getIrradiance(state.getPoint(), state.getNormal());
} finally {
rwl.readLock().unlock();
}
if (irr == null) {
// compute new sample
irr = Color.black();
OrthoNormalBasis onb = state.getBasis();
float invR = 0;
float minR = Float.POSITIVE_INFINITY;
Vector3 w = new Vector3();
for (int i = 0; i < samples; i++) {
float xi = (float) state.getRandom(i, 0, samples);
float xj = (float) state.getRandom(i, 1, samples);
float phi = (float) (xi * 2 * Math.PI);
float cosPhi = (float) Math.cos(phi);
float sinPhi = (float) Math.sin(phi);
float sinTheta = (float) Math.sqrt(xj);
float cosTheta = (float) Math.sqrt(1.0f - xj);
w.x = cosPhi * sinTheta;
w.y = sinPhi * sinTheta;
w.z = cosTheta;
onb.transform(w);
Ray r = new Ray(state.getPoint(), w);
ShadingState temp = state.traceFinalGather(r, i);
if (temp != null) {
minR = Math.min(r.getMax(), minR);
invR += 1.0f / r.getMax();
temp.getInstance().prepareShadingState(temp);
irr.add(getGlobalRadiance(temp));
}
}
irr.mul((float) Math.PI / samples);
invR = samples / invR;
rwl.writeLock().lock();
try {
insert(state.getPoint(), state.getNormal(), invR, irr);
} finally {
rwl.writeLock().unlock();
}
}
return irr;
}
use of org.sunflow.image.Color in project joons-renderer by joonhyublee.
the class LightSample method traceShadow.
/**
* Trace the shadow ray, attenuating the sample's color by the opacity of
* intersected objects.
*
* @param state shading state representing the point to be shaded
*/
public final void traceShadow(ShadingState state) {
Color opacity = state.traceShadow(shadowRay);
Color.blend(ldiff, Color.BLACK, opacity, ldiff);
Color.blend(lspec, Color.BLACK, opacity, lspec);
}
use of org.sunflow.image.Color 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;
}
Aggregations