本文整理汇总了Java中org.sunflow.math.Vector3.dot方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3.dot方法的具体用法?Java Vector3.dot怎么用?Java Vector3.dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sunflow.math.Vector3
的用法示例。
在下文中一共展示了Vector3.dot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scatterPhoton
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void scatterPhoton(ShadingState state, Color power) {
Color diffuse;
// make sure we are on the right side of the material
if (Vector3.dot(state.getNormal(), state.getRay().getDirection()) > 0.0) {
state.getNormal().negate();
state.getGeoNormal().negate();
}
diffuse = getDiffuse(state);
state.storePhoton(state.getRay().getDirection(), power, diffuse);
float avg = diffuse.getAverage();
double rnd = state.getRandom(0, 0, 1);
if (rnd < avg) {
// photon is scattered
power.mul(diffuse).mul(1.0f / avg);
OrthoNormalBasis onb = state.getBasis();
double u = 2 * Math.PI * rnd / avg;
double v = state.getRandom(0, 1, 1);
float s = (float) Math.sqrt(v);
float s1 = (float) Math.sqrt(1.0 - v);
Vector3 w = new Vector3((float) Math.cos(u) * s, (float) Math.sin(u) * s, s1);
w = onb.transform(w, new Vector3());
state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
}
}
示例2: scatterPhoton
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void scatterPhoton(ShadingState state, Color power) {
Color diffuse;
// make sure we are on the right side of the material
if (Vector3.dot(state.getNormal(), state.getRay().getDirection()) > 0.0) {
state.getNormal().negate();
state.getGeoNormal().negate();
}
diffuse = Color.GRAY;
state.storePhoton(state.getRay().getDirection(), power, diffuse);
float avg = diffuse.getAverage();
double rnd = state.getRandom(0, 0, 1);
if (rnd < avg) {
// photon is scattered
power.mul(diffuse).mul(1.0f / avg);
OrthoNormalBasis onb = state.getBasis();
double u = 2 * Math.PI * rnd / avg;
double v = state.getRandom(0, 1, 1);
float s = (float) Math.sqrt(v);
float s1 = (float) Math.sqrt(1.0 - v);
Vector3 w = new Vector3((float) Math.cos(u) * s, (float) Math.sin(u) * s, s1);
w = onb.transform(w, new Vector3());
state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
}
}
示例3: getGlobalRadiance
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public Color getGlobalRadiance(ShadingState state) {
Point3 p = state.getPoint();
Vector3 n = state.getNormal();
int set = (int) (state.getRandom(0, 1, 1) * numSets);
float maxAvgPow = 0;
float minDist = 1;
Color pow = null;
for (PointLight vpl : virtualLights[set]) {
maxAvgPow = Math.max(maxAvgPow, vpl.power.getAverage());
if (Vector3.dot(n, vpl.n) > 0.9f) {
float d = vpl.p.distanceToSquared(p);
if (d < minDist) {
pow = vpl.power;
minDist = d;
}
}
}
return pow == null ? Color.BLACK : pow.copy().mul(1.0f / maxAvgPow);
}
示例4: getSamples
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void getSamples(ShadingState state) {
if (Vector3.dot(dir, state.getGeoNormal()) < 0 && Vector3.dot(dir, state.getNormal()) < 0) {
// project point onto source plane
float x = state.getPoint().x - src.x;
float y = state.getPoint().y - src.y;
float z = state.getPoint().z - src.z;
float t = ((x * dir.x) + (y * dir.y) + (z * dir.z));
if (t >= 0.0) {
x -= (t * dir.x);
y -= (t * dir.y);
z -= (t * dir.z);
if (((x * x) + (y * y) + (z * z)) <= r2) {
Point3 p = new Point3();
p.x = src.x + x;
p.y = src.y + y;
p.z = src.z + z;
LightSample dest = new LightSample();
dest.setShadowRay(new Ray(state.getPoint(), p));
dest.setRadiance(radiance, radiance);
dest.traceShadow(state);
state.addSample(dest);
}
}
}
}
示例5: correctShadingNormal
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
final void correctShadingNormal() {
// correct shading normals pointing the wrong way
if (Vector3.dot(n, ng) < 0) {
n.negate();
basis.flipW();
}
}
示例6: getRadiance
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public Color getRadiance(ShadingState state) {
// don't use these - gather lights for sphere of directions
// gather lights
state.initLightSamples();
state.initCausticSamples();
Vector3 v = state.getRay().getDirection();
v.negate();
Vector3 h = new Vector3();
Vector3 t = state.getBasis().transform(new Vector3(0, 1, 0));
Color diff = Color.black();
Color spec = Color.black();
for (LightSample ls : state) {
Vector3 l = ls.getShadowRay().getDirection();
float dotTL = Vector3.dot(t, l);
float sinTL = (float) Math.sqrt(1 - dotTL * dotTL);
// float dotVL = Vector3.dot(v, l);
diff.madd(sinTL, ls.getDiffuseRadiance());
Vector3.add(v, l, h);
h.normalize();
float dotTH = Vector3.dot(t, h);
float sinTH = (float) Math.sqrt(1 - dotTH * dotTH);
float s = (float) Math.pow(sinTH, 10.0f);
spec.madd(s, ls.getSpecularRadiance());
}
Color c = Color.add(diff, spec, new Color());
// transparency
return Color.blend(c, state.traceTransparency(), state.getV(), new Color());
}
示例7: getIrradiance
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public Color getIrradiance(ShadingState state, Color diffuseReflectance) {
float cosTheta = Vector3.dot(up, state.getNormal());
float sin2 = (1 - cosTheta * cosTheta);
float sine = sin2 > 0 ? (float) Math.sqrt(sin2) * 0.5f : 0;
if (cosTheta > 0)
return Color.blend(sky, ground, sine);
else
return Color.blend(ground, sky, sine);
}
示例8: getSamples
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void getSamples(ShadingState state) {
Vector3 d = Point3.sub(lightPoint, state.getPoint(), new Vector3());
if (Vector3.dot(d, state.getNormal()) > 0 && Vector3.dot(d, state.getGeoNormal()) > 0) {
LightSample dest = new LightSample();
// prepare shadow ray
dest.setShadowRay(new Ray(state.getPoint(), lightPoint));
float scale = 1.0f / (float) (4 * Math.PI * lightPoint.distanceToSquared(state.getPoint()));
dest.setRadiance(power, power);
dest.getDiffuseRadiance().mul(scale);
dest.getSpecularRadiance().mul(scale);
dest.traceShadow(state);
state.addSample(dest);
}
}
示例9: getSamples
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void getSamples(ShadingState state) {
if (storedPhotons == 0)
return;
NearestPhotons np = new NearestPhotons(state.getPoint(), gatherNum, gatherRadius * gatherRadius);
locatePhotons(np);
if (np.found < 8)
return;
Point3 ppos = new Point3();
Vector3 pdir = new Vector3();
Vector3 pvec = new Vector3();
float invArea = 1.0f / ((float) Math.PI * np.dist2[0]);
float maxNDist = np.dist2[0] * 0.05f;
float f2r2 = 1.0f / (filterValue * filterValue * np.dist2[0]);
float fInv = 1.0f / (1.0f - 2.0f / (3.0f * filterValue));
for (int i = 1; i <= np.found; i++) {
Photon phot = np.index[i];
Vector3.decode(phot.dir, pdir);
float cos = -Vector3.dot(pdir, state.getNormal());
if (cos > 0.001) {
ppos.set(phot.x, phot.y, phot.z);
Point3.sub(ppos, state.getPoint(), pvec);
float pcos = Vector3.dot(pvec, state.getNormal());
if ((pcos < maxNDist) && (pcos > -maxNDist)) {
LightSample sample = new LightSample();
sample.setShadowRay(new Ray(state.getPoint(), pdir.negate()));
sample.setRadiance(new Color().setRGBE(np.index[i].power).mul(invArea / cos), Color.BLACK);
sample.getDiffuseRadiance().mul((1.0f - (float) Math.sqrt(np.dist2[i] * f2r2)) * fInv);
state.addSample(sample);
}
}
}
}
示例10: specularPhong
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
/**
* Computes a phong specular response to the current light samples and
* global illumination.
*
* @param spec specular color
* @param power phong exponent
* @param numRays number of glossy rays to trace
* @return shaded color
*/
public final Color specularPhong(Color spec, float power, int numRays) {
// integrate a phong specular function
Color lr = Color.black();
if (!includeSpecular || spec.isBlack())
return lr;
// reflected direction
float dn = 2 * cosND;
Vector3 refDir = new Vector3();
refDir.x = (dn * n.x) + r.dx;
refDir.y = (dn * n.y) + r.dy;
refDir.z = (dn * n.z) + r.dz;
// direct lighting
for (LightSample sample : this) {
float cosNL = sample.dot(n);
float cosLR = sample.dot(refDir);
if (cosLR > 0)
lr.madd(cosNL * (float) Math.pow(cosLR, power), sample.getSpecularRadiance());
}
// indirect lighting
if (numRays > 0) {
int numSamples = getDepth() == 0 ? numRays : 1;
OrthoNormalBasis onb = OrthoNormalBasis.makeFromW(refDir);
float mul = (2.0f * (float) Math.PI / (power + 1)) / numSamples;
for (int i = 0; i < numSamples; i++) {
// specular indirect lighting
double r1 = getRandom(i, 0, numSamples);
double r2 = getRandom(i, 1, numSamples);
double u = 2 * Math.PI * r1;
double s = (float) Math.pow(r2, 1 / (power + 1));
double s1 = (float) Math.sqrt(1 - s * s);
Vector3 w = new Vector3((float) (Math.cos(u) * s1), (float) (Math.sin(u) * s1), (float) s);
w = onb.transform(w, new Vector3());
float wn = Vector3.dot(w, n);
if (wn > 0)
lr.madd(wn * mul, traceGlossy(new Ray(p, w), i));
}
}
lr.mul(spec).mul((power + 2) / (2.0f * (float) Math.PI));
return lr;
}
示例11: getRadiance
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public Color getRadiance(ShadingState state) {
if (!state.includeSpecular())
return Color.BLACK;
Vector3 reflDir = new Vector3();
Vector3 refrDir = new Vector3();
state.faceforward();
float cos = state.getCosND();
boolean inside = state.isBehind();
float neta = inside ? eta : 1.0f / eta;
float dn = 2 * cos;
reflDir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
reflDir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
reflDir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
// refracted ray
float arg = 1 - (neta * neta * (1 - (cos * cos)));
boolean tir = arg < 0;
if (tir)
refrDir.x = refrDir.y = refrDir.z = 0;
else {
float nK = (neta * cos) - (float) Math.sqrt(arg);
refrDir.x = (neta * state.getRay().dx) + (nK * state.getNormal().x);
refrDir.y = (neta * state.getRay().dy) + (nK * state.getNormal().y);
refrDir.z = (neta * state.getRay().dz) + (nK * state.getNormal().z);
}
// compute Fresnel terms
float cosTheta1 = Vector3.dot(state.getNormal(), reflDir);
float cosTheta2 = -Vector3.dot(state.getNormal(), refrDir);
float pPara = (cosTheta1 - eta * cosTheta2) / (cosTheta1 + eta * cosTheta2);
float pPerp = (eta * cosTheta1 - cosTheta2) / (eta * cosTheta1 + cosTheta2);
float kr = 0.5f * (pPara * pPara + pPerp * pPerp);
float kt = 1 - kr;
Color absorbtion = null;
if (inside && absorptionDistance > 0) {
// this ray is inside the object and leaving it
// compute attenuation that occured along the ray
absorbtion = Color.mul(-state.getRay().getMax() / absorptionDistance, absorptionColor.copy().opposite()).exp();
if (absorbtion.isBlack())
return Color.BLACK; // nothing goes through
}
// refracted ray
Color ret = Color.black();
if (!tir) {
ret.madd(kt, state.traceRefraction(new Ray(state.getPoint(), refrDir), 0)).mul(color);
}
if (!inside || tir)
ret.add(Color.mul(kr, state.traceReflection(new Ray(state.getPoint(), reflDir), 0)).mul(color));
return absorbtion != null ? ret.mul(absorbtion) : ret;
}
示例12: getSamples
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void getSamples(ShadingState state) {
if (getNumSamples() <= 0)
return;
Vector3 wc = Point3.sub(center, state.getPoint(), new Vector3());
float l2 = wc.lengthSquared();
if (l2 <= r2)
return; // inside the sphere?
// top of the sphere as viewed from the current shading point
float topX = wc.x + state.getNormal().x * radius;
float topY = wc.y + state.getNormal().y * radius;
float topZ = wc.z + state.getNormal().z * radius;
if (state.getNormal().dot(topX, topY, topZ) <= 0)
return; // top of the sphere is below the horizon
float cosThetaMax = (float) Math.sqrt(Math.max(0, 1 - r2 / Vector3.dot(wc, wc)));
OrthoNormalBasis basis = OrthoNormalBasis.makeFromW(wc);
int samples = state.getDiffuseDepth() > 0 ? 1 : getNumSamples();
float scale = (float) (2 * Math.PI * (1 - cosThetaMax));
Color c = Color.mul(scale / samples, radiance);
for (int i = 0; i < samples; i++) {
// random offset on unit square
double randX = state.getRandom(i, 0, samples);
double randY = state.getRandom(i, 1, samples);
// cone sampling
double cosTheta = (1 - randX) * cosThetaMax + randX;
double sinTheta = Math.sqrt(1 - cosTheta * cosTheta);
double phi = randY * 2 * Math.PI;
Vector3 dir = new Vector3((float) (Math.cos(phi) * sinTheta), (float) (Math.sin(phi) * sinTheta), (float) cosTheta);
basis.transform(dir);
// check that the direction of the sample is the same as the
// normal
float cosNx = Vector3.dot(dir, state.getNormal());
if (cosNx <= 0)
continue;
float ocx = state.getPoint().x - center.x;
float ocy = state.getPoint().y - center.y;
float ocz = state.getPoint().z - center.z;
float qa = Vector3.dot(dir, dir);
float qb = 2 * ((dir.x * ocx) + (dir.y * ocy) + (dir.z * ocz));
float qc = ((ocx * ocx) + (ocy * ocy) + (ocz * ocz)) - r2;
double[] t = Solvers.solveQuadric(qa, qb, qc);
if (t == null)
continue;
LightSample dest = new LightSample();
// compute shadow ray to the sampled point
dest.setShadowRay(new Ray(state.getPoint(), dir));
// FIXME: arbitrary bias, should handle as in other places
dest.getShadowRay().setMax((float) t[0] - 1e-3f);
// prepare sample
dest.setRadiance(c, c);
dest.traceShadow(state);
state.addSample(dest);
}
}
示例13: store
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void store(ShadingState state, Vector3 dir, Color power, Color diffuse) {
// don't store on the wrong side of a surface
if (Vector3.dot(state.getNormal(), dir) > 0)
return;
Point3 pt = state.getPoint();
// outside grid bounds ?
if (!bounds.contains(pt))
return;
Vector3 ext = bounds.getExtents();
int ix = (int) (((pt.x - bounds.getMinimum().x) * nx) / ext.x);
int iy = (int) (((pt.y - bounds.getMinimum().y) * ny) / ext.y);
int iz = (int) (((pt.z - bounds.getMinimum().z) * nz) / ext.z);
ix = MathUtils.clamp(ix, 0, nx - 1);
iy = MathUtils.clamp(iy, 0, ny - 1);
iz = MathUtils.clamp(iz, 0, nz - 1);
int id = ix + iy * nx + iz * nx * ny;
synchronized (this) {
int hid = id % cellHash.length;
PhotonGroup g = cellHash[hid];
PhotonGroup last = null;
boolean hasID = false;
while (g != null) {
if (g.id == id) {
hasID = true;
if (Vector3.dot(state.getNormal(), g.normal) > NORMAL_THRESHOLD)
break;
}
last = g;
g = g.next;
}
if (g == null) {
g = new PhotonGroup(id, state.getNormal());
if (last == null)
cellHash[hid] = g;
else
last.next = g;
if (!hasID) {
hashSize++; // we have not seen this ID before
// resize hash if we have grown too large
if (hashSize > cellHash.length)
growPhotonHash();
}
}
g.count++;
g.flux.add(power);
g.diffuse.add(diffuse);
numStoredPhotons++;
}
}
示例14: getRadiance
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public synchronized Color getRadiance(Point3 p, Vector3 n) {
if (!bounds.contains(p))
return Color.BLACK;
Vector3 ext = bounds.getExtents();
int ix = (int) (((p.x - bounds.getMinimum().x) * nx) / ext.x);
int iy = (int) (((p.y - bounds.getMinimum().y) * ny) / ext.y);
int iz = (int) (((p.z - bounds.getMinimum().z) * nz) / ext.z);
ix = MathUtils.clamp(ix, 0, nx - 1);
iy = MathUtils.clamp(iy, 0, ny - 1);
iz = MathUtils.clamp(iz, 0, nz - 1);
int id = ix + iy * nx + iz * nx * ny;
rwl.readLock().lock();
PhotonGroup center = null;
for (PhotonGroup g = get(ix, iy, iz); g != null; g = g.next) {
if (g.id == id && Vector3.dot(n, g.normal) > NORMAL_THRESHOLD) {
if (g.radiance == null) {
center = g;
break;
}
Color r = g.radiance.copy();
rwl.readLock().unlock();
return r;
}
}
int vol = 1;
while (true) {
int numPhotons = 0;
int ndiff = 0;
Color irr = Color.black();
Color diff = (center == null) ? Color.black() : null;
for (int z = iz - (vol - 1); z <= iz + (vol - 1); z++) {
for (int y = iy - (vol - 1); y <= iy + (vol - 1); y++) {
for (int x = ix - (vol - 1); x <= ix + (vol - 1); x++) {
int vid = x + y * nx + z * nx * ny;
for (PhotonGroup g = get(x, y, z); g != null; g = g.next) {
if (g.id == vid && Vector3.dot(n, g.normal) > NORMAL_THRESHOLD) {
numPhotons += g.count;
irr.add(g.flux);
if (diff != null) {
diff.add(g.diffuse);
ndiff++;
}
break; // only one valid group can be found,
// skip the others
}
}
}
}
}
if (numPhotons >= numGather || vol >= 3) {
// we have found enough photons
// cache irradiance and return
float area = (2 * vol - 1) / 3.0f * ((ext.x / nx) + (ext.y / ny) + (ext.z / nz));
area *= area;
area *= Math.PI;
irr.mul(1.0f / area);
// upgrade lock manually
rwl.readLock().unlock();
rwl.writeLock().lock();
if (center == null) {
if (ndiff > 0)
diff.mul(1.0f / ndiff);
center = new PhotonGroup(id, n);
center.diffuse.set(diff);
center.next = cellHash[id % cellHash.length];
cellHash[id % cellHash.length] = center;
}
irr.mul(center.diffuse);
center.radiance = irr.copy();
rwl.writeLock().unlock(); // unlock write - done
return irr;
}
vol++;
}
}
示例15: precomputeRadiance
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void precomputeRadiance() {
if (storedPhotons == 0)
return;
// precompute the radiance for all photons that are neither
// leaves nor parents of leaves in the tree.
int quadStoredPhotons = halfStoredPhotons / 2;
Point3 p = new Point3();
Vector3 n = new Vector3();
Point3 ppos = new Point3();
Vector3 pdir = new Vector3();
Vector3 pvec = new Vector3();
Color irr = new Color();
Color pow = new Color();
float maxDist2 = gatherRadius * gatherRadius;
NearestPhotons np = new NearestPhotons(p, numGather, maxDist2);
Photon[] temp = new Photon[quadStoredPhotons + 1];
UI.taskStart("Precomputing radiance", 1, quadStoredPhotons);
for (int i = 1; i <= quadStoredPhotons; i++) {
UI.taskUpdate(i);
Photon curr = photons[i];
p.set(curr.x, curr.y, curr.z);
Vector3.decode(curr.normal, n);
irr.set(Color.BLACK);
np.reset(p, maxDist2);
locatePhotons(np);
if (np.found < 8) {
curr.data = 0;
temp[i] = curr;
continue;
}
float invArea = 1.0f / ((float) Math.PI * np.dist2[0]);
float maxNDist = np.dist2[0] * 0.05f;
for (int j = 1; j <= np.found; j++) {
Photon phot = np.index[j];
Vector3.decode(phot.dir, pdir);
float cos = -Vector3.dot(pdir, n);
if (cos > 0.01f) {
ppos.set(phot.x, phot.y, phot.z);
Point3.sub(ppos, p, pvec);
float pcos = Vector3.dot(pvec, n);
if ((pcos < maxNDist) && (pcos > -maxNDist))
irr.add(pow.setRGBE(phot.power));
}
}
irr.mul(invArea);
// compute radiance
irr.mul(new Color(curr.data)).mul(1.0f / (float) Math.PI);
curr.data = irr.toRGBE();
temp[i] = curr;
}
UI.taskStop();
// resize photon map to only include irradiance photons
numGather /= 4;
maxRadius = 1.4f * (float) Math.sqrt(maxPower * numGather);
if (gatherRadius > maxRadius)
gatherRadius = maxRadius;
storedPhotons = quadStoredPhotons;
halfStoredPhotons = storedPhotons / 2;
log2n = (int) Math.ceil(Math.log(storedPhotons) / Math.log(2.0));
photons = temp;
hasRadiance = true;
}