use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class PerlinModifier method modify.
@Override
public void modify(ShadingState state) {
Point3 p = state.transformWorldToObject(state.getPoint());
p.x *= size;
p.y *= size;
p.z *= size;
Vector3 normal = state.transformNormalWorldToObject(state.getNormal());
double f0 = f(p.x, p.y, p.z);
double fx = f(p.x + .0001, p.y, p.z);
double fy = f(p.x, p.y + .0001, p.z);
double fz = f(p.x, p.y, p.z + .0001);
normal.x -= scale * (fx - f0) / .0001;
normal.y -= scale * (fy - f0) / .0001;
normal.z -= scale * (fz - f0) / .0001;
normal.normalize();
state.getNormal().set(state.transformNormalObjectToWorld(normal));
state.getNormal().normalize();
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
}
use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class RA2Parser method parse.
@Override
public boolean parse(String filename, SunflowAPIInterface api) {
try {
UI.printInfo(Module.USER, "RA2 - Reading geometry: \"%s\" ...", filename);
File file = new File(filename);
FileInputStream stream = new FileInputStream(filename);
MappedByteBuffer map = stream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
map.order(ByteOrder.LITTLE_ENDIAN);
FloatBuffer buffer = map.asFloatBuffer();
float[] data = new float[buffer.capacity()];
for (int i = 0; i < data.length; i++) {
data[i] = buffer.get(i);
}
stream.close();
api.parameter("points", "point", "vertex", data);
int[] triangles = new int[3 * (data.length / 9)];
for (int i = 0; i < triangles.length; i++) {
triangles[i] = i;
}
// create geo
api.parameter("triangles", triangles);
api.geometry(filename, "triangle_mesh");
// create shader
api.shader(filename + ".shader", "simple");
// create instance
api.parameter("shaders", filename + ".shader");
api.instance(filename + ".instance", filename);
} catch (FileNotFoundException e) {
Logger.getLogger(RA2Parser.class.getName()).log(Level.SEVERE, null, e);
return false;
} catch (IOException e) {
Logger.getLogger(RA2Parser.class.getName()).log(Level.SEVERE, null, e);
return false;
}
try {
filename = filename.replace(".ra2", ".txt");
UI.printInfo(Module.USER, "RA2 - Reading camera : \"%s\" ...", filename);
Parser p = new Parser(filename);
Point3 eye = new Point3();
eye.x = p.getNextFloat();
eye.y = p.getNextFloat();
eye.z = p.getNextFloat();
Point3 to = new Point3();
to.x = p.getNextFloat();
to.y = p.getNextFloat();
to.z = p.getNextFloat();
Vector3 up = new Vector3();
switch(p.getNextInt()) {
case 0:
up.set(1, 0, 0);
break;
case 1:
up.set(0, 1, 0);
break;
case 2:
up.set(0, 0, 1);
break;
default:
UI.printWarning(Module.USER, "RA2 - Invalid up vector specification - using Z axis");
up.set(0, 0, 1);
break;
}
api.parameter("eye", eye);
api.parameter("target", to);
api.parameter("up", up);
String cameraName = filename + ".camera";
api.parameter(FOV, 80f);
api.camera(cameraName, "pinhole");
api.parameter("camera", cameraName);
api.parameter("resolutionX", 1024);
api.parameter("resolutionY", 1024);
api.options(SunflowAPI.DEFAULT_OPTIONS);
p.close();
} catch (FileNotFoundException e) {
UI.printWarning(Module.USER, "RA2 - Camera file not found");
} catch (IOException e) {
Logger.getLogger(RA2Parser.class.getName()).log(Level.SEVERE, null, e);
return false;
}
return true;
}
use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class TriangleMeshLight method update.
@Override
public boolean update(ParameterList pl, SunflowAPI api) {
radiance = pl.getColor("radiance", radiance);
numSamples = pl.getInt("samples", numSamples);
if (super.update(pl, api)) {
// precompute triangle areas and normals
areas = new float[getNumPrimitives()];
ngs = new Vector3[getNumPrimitives()];
totalArea = 0;
for (int tri3 = 0, i = 0; tri3 < triangles.length; tri3 += 3, i++) {
int a = triangles[tri3 + 0];
int b = triangles[tri3 + 1];
int c = triangles[tri3 + 2];
Point3 v0p = getPoint(a);
Point3 v1p = getPoint(b);
Point3 v2p = getPoint(c);
ngs[i] = Point3.normal(v0p, v1p, v2p);
areas[i] = 0.5f * ngs[i].length();
ngs[i].normalize();
totalArea += areas[i];
}
} else {
return false;
}
return true;
}
use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class IrradianceCacheGIEngine method insert.
private void insert(Point3 p, Vector3 n, float r0, Color irr) {
if (tolerance <= 0) {
return;
}
Node node = root;
r0 = MathUtils.clamp(r0 * tolerance, minSpacing, maxSpacing) * invTolerance;
if (root.isInside(p)) {
while (node.sideLength >= (4.0 * r0 * tolerance)) {
int k = 0;
k |= (p.x > node.center.x) ? 1 : 0;
k |= (p.y > node.center.y) ? 2 : 0;
k |= (p.z > node.center.z) ? 4 : 0;
if (node.children[k] == null) {
Point3 c = new Point3(node.center);
c.x += ((k & 1) == 0) ? -node.quadSideLength : node.quadSideLength;
c.y += ((k & 2) == 0) ? -node.quadSideLength : node.quadSideLength;
c.z += ((k & 4) == 0) ? -node.quadSideLength : node.quadSideLength;
node.children[k] = new Node(c, node.halfSideLength);
}
node = node.children[k];
}
}
Sample s = new Sample(p, n, r0, irr);
s.next = node.first;
node.first = s;
}
use of org.sunflow.math.Point3 in project joons-renderer by joonhyublee.
the class ParticleSurface method prepareShadingState.
@Override
public void prepareShadingState(ShadingState state) {
state.init();
state.getRay().getPoint(state.getPoint());
Point3 localPoint = state.transformWorldToObject(state.getPoint());
localPoint.x -= particles[3 * state.getPrimitiveID() + 0];
localPoint.y -= particles[3 * state.getPrimitiveID() + 1];
localPoint.z -= particles[3 * state.getPrimitiveID() + 2];
state.getNormal().set(localPoint.x, localPoint.y, localPoint.z);
state.getNormal().normalize();
state.setShader(state.getInstance().getShader(0));
state.setModifier(state.getInstance().getModifier(0));
// into object space
Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
state.getNormal().set(worldNormal);
state.getNormal().normalize();
state.getGeoNormal().set(state.getNormal());
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
}
Aggregations