public bool update(ParameterList pl, SunflowAPI api) { string file = pl.getstring("filename", null); if (file != null) filename = api.resolveIncludeFilename(file); smoothNormals = pl.getbool("smooth_normals", smoothNormals); return filename != null; }
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; }
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; }
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); groundExtendSky = pl.getbool("ground.extendsky", groundExtendSky); groundColor = pl.getColor("ground.color", groundColor); // recompute model initSunSky(); return true; }
public bool update(ParameterList pl, SunflowAPI api) { subdivs = pl.getInt("subdivs", subdivs); smooth = pl.getbool("smooth", smooth); quads = pl.getbool("quads", quads); int nu = pl.getInt("nu", 0); int nv = pl.getInt("nv", 0); pl.setVertexCount(nu * nv); bool uwrap = pl.getbool("uwrap", false); bool vwrap = pl.getbool("vwrap", false); ParameterList.FloatParameter points = pl.getPointArray("points"); if (points != null && points.interp == ParameterList.InterpolationType.VERTEX) { int numUPatches = uwrap ? nu / 3 : (nu - 4) / 3 + 1; int numVPatches = vwrap ? nv / 3 : (nv - 4) / 3 + 1; if (numUPatches < 1 || numVPatches < 1) { UI.printError(UI.Module.GEOM, "Invalid number of patches for bezier mesh - ignoring"); return false; } // generate patches patches = new float[numUPatches * numVPatches][]; for (int v = 0, p = 0; v < numVPatches; v++) { for (int u = 0; u < numUPatches; u++, p++) { float[] patch = patches[p] = new float[16 * 3]; int up = u * 3; int vp = v * 3; for (int pv = 0; pv < 4; pv++) { for (int pu = 0; pu < 4; pu++) { int meshU = (up + pu) % nu; int meshV = (vp + pv) % nv; // copy point patch[3 * (pv * 4 + pu) + 0] = points.data[3 * (meshU + nu * meshV) + 0]; patch[3 * (pv * 4 + pu) + 1] = points.data[3 * (meshU + nu * meshV) + 1]; patch[3 * (pv * 4 + pu) + 2] = points.data[3 * (meshU + nu * meshV) + 2]; } } } } } if (subdivs < 1) { UI.printError(UI.Module.GEOM, "Invalid subdivisions for bezier mesh - ignoring"); return false; } if (patches == null) { UI.printError(UI.Module.GEOM, "No patch data present in bezier mesh - ignoring"); return false; } return true; }