Esempio n. 1
0
 public override bool Update(ParameterList pl, SunflowAPI api)
 {
     string filename = pl.getstring("texture", null);
     if (filename != null)
         tex = TextureCache.getTexture(api.resolveTextureFilename(filename), false);
     return tex != null && base.Update(pl, api);
 }
Esempio n. 2
0
 public ImageBasedLight()
 {
     texture = null;
     updateBasis(new Vector3(0, 0, -1), new Vector3(0, 1, 0));
     numSamples = 64;
     numLowSamples = 8;
 }
Esempio n. 3
0
 public UberShader()
 {
     diff = spec = Color.GRAY;
     diffmap = specmap = null;
     diffBlend = specBlend = 1;
     glossyness = 0;
     numSamples = 4;
 }
Esempio n. 4
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     string filename = pl.getstring("texture", null);
     if (filename != null)
         bumpTexture = TextureCache.getTexture(api.resolveTextureFilename(filename), true);
     scale = pl.getFloat("scale", scale);
     return bumpTexture != null;
 }
Esempio n. 5
0
 /**
  * Gets a reference to the texture specified by the given filename. If the
  * texture has already been loaded the previous reference is returned,
  * otherwise, a new texture is created.
  *
  * @param filename image file to load
  * @param isLinear is the texture gamma corrected?
  * @return texture object
  * @see Texture
  */
 public static Texture getTexture(string filename, bool isLinear)
 {
     lock (lockObj)
     {
         if (textures.ContainsKey(filename))
         {
             UI.printInfo(UI.Module.TEX, "Using cached copy for file \"%s\" ...", filename);
             return textures[filename];
         }
         UI.printInfo(UI.Module.TEX, "Using file \"%s\" ...", filename);
         Texture t = new Texture(filename, isLinear);
         textures.Add(filename, t);
         return t;
     }
 }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     diff = pl.getColor("diffuse", diff);
     spec = pl.getColor("specular", spec);
     string filename;
     filename = pl.getstring("diffuse.texture", null);
     if (filename != null)
         diffmap = TextureCache.getTexture(api.resolveTextureFilename(filename), false);
     filename = pl.getstring("specular.texture", null);
     if (filename != null)
         specmap = TextureCache.getTexture(api.resolveTextureFilename(filename), false);
     diffBlend = MathUtils.clamp(pl.getFloat("diffuse.blend", diffBlend), 0, 1);
     specBlend = MathUtils.clamp(pl.getFloat("specular.blend", diffBlend), 0, 1);
     glossyness = MathUtils.clamp(pl.getFloat("glossyness", glossyness), 0, 1);
     numSamples = pl.getInt("samples", numSamples);
     return true;
 }
Esempio n. 8
0
 public TexturedAmbientOcclusionShader()
 {
     tex = null;
 }
Esempio n. 9
0
 public TexturedPhongShader()
 {
     tex = null;
 }
Esempio n. 10
0
 public TexturedShinyDiffuseShader()
 {
     tex = null;
 }
Esempio n. 11
0
 public TexturedWardShader()
 {
     tex = null;
 }
Esempio n. 12
0
 public BumpMappingModifier()
 {
     bumpTexture = null;
     scale = 1;
 }
Esempio n. 13
0
        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;
        }