use of org.sunflow.math.Vector3 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.Vector3 in project joons-renderer by joonhyublee.
the class TriangleMeshLight method getPhoton.
public void getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power) {
double rnd = randX1 * totalArea;
int j = areas.length - 1;
for (int i = 0; i < areas.length; i++) {
if (rnd < areas[i]) {
j = i;
break;
}
// try next triangle
rnd -= areas[i];
}
rnd /= areas[j];
randX1 = rnd;
double s = Math.sqrt(1 - randX2);
float u = (float) (randY2 * s);
float v = (float) (1 - s);
float w = 1 - u - v;
int tri3 = j * 3;
int index0 = 3 * triangles[tri3 + 0];
int index1 = 3 * triangles[tri3 + 1];
int index2 = 3 * triangles[tri3 + 2];
p.x = w * points[index0 + 0] + u * points[index1 + 0] + v * points[index2 + 0];
p.y = w * points[index0 + 1] + u * points[index1 + 1] + v * points[index2 + 1];
p.z = w * points[index0 + 2] + u * points[index1 + 2] + v * points[index2 + 2];
p.x += 0.001f * ngs[j].x;
p.y += 0.001f * ngs[j].y;
p.z += 0.001f * ngs[j].z;
OrthoNormalBasis onb = OrthoNormalBasis.makeFromW(ngs[j]);
u = (float) (2 * Math.PI * randX1);
s = Math.sqrt(randY1);
onb.transform(new Vector3((float) (Math.cos(u) * s), (float) (Math.sin(u) * s), (float) (Math.sqrt(1 - randY1))), dir);
Color.mul((float) Math.PI * areas[j], radiance, power);
}
use of org.sunflow.math.Vector3 in project joons-renderer by joonhyublee.
the class FakeGIEngine method init.
@Override
public boolean init(Options options, Scene scene) {
up = options.getVector("gi.fake.up", new Vector3(0, 1, 0)).normalize();
sky = options.getColor("gi.fake.sky", Color.WHITE).copy();
ground = options.getColor("gi.fake.ground", Color.BLACK).copy();
sky.mul((float) Math.PI);
ground.mul((float) Math.PI);
return true;
}
use of org.sunflow.math.Vector3 in project joons-renderer by joonhyublee.
the class IrradianceCacheGIEngine method init.
@Override
public boolean init(Options options, Scene scene) {
// get settings
samples = options.getInt("gi.irr-cache.samples", 256);
tolerance = options.getFloat("gi.irr-cache.tolerance", 0.05f);
invTolerance = 1.0f / tolerance;
minSpacing = options.getFloat("gi.irr-cache.min_spacing", 0.05f);
maxSpacing = options.getFloat("gi.irr-cache.max_spacing", 5.00f);
root = null;
rwl = new ReentrantReadWriteLock();
globalPhotonMap = PluginRegistry.globalPhotonMapPlugins.createObject(options.getString("gi.irr-cache.gmap", null));
// check settings
samples = Math.max(0, samples);
minSpacing = Math.max(0.001f, minSpacing);
maxSpacing = Math.max(0.001f, maxSpacing);
// display settings
UI.printInfo(Module.LIGHT, "Irradiance cache settings:");
UI.printInfo(Module.LIGHT, " * Samples: %d", samples);
if (tolerance <= 0) {
UI.printInfo(Module.LIGHT, " * Tolerance: off");
} else {
UI.printInfo(Module.LIGHT, " * Tolerance: %.3f", tolerance);
}
UI.printInfo(Module.LIGHT, " * Spacing: %.3f to %.3f", minSpacing, maxSpacing);
// prepare root node
Vector3 ext = scene.getBounds().getExtents();
root = new Node(scene.getBounds().getCenter(), 1.0001f * MathUtils.max(ext.x, ext.y, ext.z));
// init global photon map
return (globalPhotonMap != null) ? scene.calculatePhotons(globalPhotonMap, "global", 0, options) : true;
}
use of org.sunflow.math.Vector3 in project joons-renderer by joonhyublee.
the class Hair method prepareShadingState.
@Override
public void prepareShadingState(ShadingState state) {
state.init();
Instance i = state.getInstance();
state.getRay().getPoint(state.getPoint());
Ray r = state.getRay();
Shader s = i.getShader(0);
state.setShader(s != null ? s : this);
int primID = state.getPrimitiveID();
int hair = primID / numSegments;
int line = primID % numSegments;
int vRoot = hair * 3 * (numSegments + 1);
int v0 = vRoot + line * 3;
// tangent vector
Vector3 v = getTangent(line, v0, state.getV());
v = state.transformVectorObjectToWorld(v);
state.setBasis(OrthoNormalBasis.makeFromWV(v, new Vector3(-r.dx, -r.dy, -r.dz)));
state.getBasis().swapVW();
// normal
state.getNormal().set(0, 0, 1);
state.getBasis().transform(state.getNormal());
state.getGeoNormal().set(state.getNormal());
state.getUV().set(0, (line + state.getV()) / numSegments);
}
Aggregations