private bool updateCameraMatrix(int index, ParameterList pl) { string offset = index < 0 ? "" : string.Format("[{0}]", index); if (index < 0) { index = 0; } Matrix4 transform = pl.getMatrix(string.Format("transform{0}", offset), null); if (transform == null) { // no transform was specified, check eye/target/up Point3 eye = pl.getPoint(string.Format("eye{0}", offset), null); Point3 target = pl.getPoint(string.Format("target{0}", offset), null); Vector3 up = pl.getVector(string.Format("up{0}", offset), null); if (eye != null && target != null && up != null) { c2w[index] = Matrix4.fromBasis(OrthoNormalBasis.makeFromWV(Point3.sub(eye, target, new Vector3()), up)); c2w[index] = Matrix4.translation(eye.x, eye.y, eye.z).multiply(c2w[index]); } else { // the matrix for this index was not specified // return an error, unless this is a regular update return(offset.Length == 0); } } else { c2w[index] = transform; } return(true); }
public bool update(ParameterList pl, SunflowAPI api) { updateBasis(pl.getVector("center", null), pl.getVector("up", null)); numSamples = pl.getInt("samples", numSamples); string filename = pl.getstring("texture", null); if (filename != null) texture = TextureCache.getTexture(api.resolveTextureFilename(filename), true); // 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.Width][]; for(int i = 0;i < imageHistogram.Length;i++) imageHistogram[i] = new float[b.Height]; colHistogram = new float[b.Width]; float du = 1.0f / b.Width; float dv = 1.0f / b.Height; for (int x = 0; x < b.Width; x++) { for (int y = 0; y < b.Height; y++) { float u = (x + 0.5f) * du; float v = (y + 0.5f) * dv; Color c = texture.getPixel(u, v); // box filter the image // c.add(texture.getPixel(u + du, v)); // c.add(texture.getPixel(u + du, v+ dv)); // c.add(texture.getPixel(u, v + dv)); // c.mul(0.25f); 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.Height - 1]; if (x > 0) colHistogram[x] += colHistogram[x - 1]; for (int y = 0; y < b.Height; y++) imageHistogram[x][y] /= imageHistogram[x][b.Height - 1]; } for (int x = 0; x < b.Width; x++) colHistogram[x] /= colHistogram[b.Width - 1]; jacobian = (float) (2 * Math.PI * Math.PI) / (b.Width * b.Height); } // take fixed samples if (pl.getbool("fixed", samples != null)) { // Bitmap loc = new Bitmap(filename); samples = new Vector3[numSamples]; colors = new Color[numSamples]; for (int i = 0; i < numSamples; i++) { double randX = (double) i / (double) numSamples; double randY = QMC.halton(0, i); int x = 0; while (randX >= colHistogram[x] && x < colHistogram.Length - 1) x++; float[] rowHistogram = imageHistogram[x]; int y = 0; while (randY >= rowHistogram[y] && y < rowHistogram.Length - 1) y++; // sample from (x, y) float u = (float) ((x == 0) ? (randX / colHistogram[0]) : ((randX - colHistogram[x - 1]) / (colHistogram[x] - colHistogram[x - 1]))); float v = (float) ((y == 0) ? (randY / rowHistogram[0]) : ((randY - rowHistogram[y - 1]) / (rowHistogram[y] - rowHistogram[y - 1]))); float px = ((x == 0) ? colHistogram[0] : (colHistogram[x] - colHistogram[x - 1])); float py = ((y == 0) ? rowHistogram[0] : (rowHistogram[y] - rowHistogram[y - 1])); float su = (x + u) / colHistogram.Length; float sv = (y + v) / rowHistogram.Length; float invP = (float) Math.Sin(sv * Math.PI) * jacobian / (numSamples * px * py); samples[i] = getDirection(su, sv); basis.transform(samples[i]); colors[i] = texture.getPixel(su, sv).mul(invP); // loc.setPixel(x, y, Color.YELLOW.copy().mul(1e6f)); } // loc.save("samples.hdr"); } else { // turn off samples = null; colors = null; } return true; }
private bool updateCameraMatrix(int index, ParameterList pl) { string offset = index < 0 ? "" : string.Format("[{0}]", index); if (index < 0) index = 0; Matrix4 transform = pl.getMatrix(string.Format("transform{0}", offset), null); if (transform == null) { // no transform was specified, check eye/target/up Point3 eye = pl.getPoint(string.Format("eye{0}", offset), null); Point3 target = pl.getPoint(string.Format("target{0}", offset), null); Vector3 up = pl.getVector(string.Format("up{0}", offset), null); if (eye != null && target != null && up != null) { c2w[index] = Matrix4.fromBasis(OrthoNormalBasis.makeFromWV(Point3.sub(eye, target, new Vector3()), up)); c2w[index] = Matrix4.translation(eye.x, eye.y, eye.z).multiply(c2w[index]); } else { // the matrix for this index was not specified // return an error, unless this is a regular update return offset.Length == 0; } } else c2w[index] = transform; return true; }
public bool update(ParameterList pl, SunflowAPI api) { src = pl.getPoint("source", src); dir = pl.getVector("dir", dir); dir.normalize(); r = pl.getFloat("radius", r); basis = OrthoNormalBasis.makeFromW(dir); r2 = r * r; radiance = pl.getColor("radiance", radiance); return true; }
public bool update(ParameterList pl, SunflowAPI api) { Vector3 up = pl.getVector("up", null); Vector3 east = pl.getVector("east", null); if (up != null && east != null) basis = OrthoNormalBasis.makeFromWV(up, east); else if (up != null) basis = OrthoNormalBasis.makeFromW(up); numSkySamples = pl.getInt("samples", numSkySamples); sunDirWorld = pl.getVector("sundir", sunDirWorld); turbidity = pl.getFloat("turbidity", turbidity); // recompute model initSunSky(); return true; }
public bool 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()][]; for(int i = 0;i < imageHistogram.Length;i++) imageHistogram[i] = new float[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.getbool("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; }