Beispiel #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);
 }
 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;
 }
        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));
        }
Beispiel #4
0
        public bool update(ParameterList pl, SunflowAPI api)
        {
            string filename = pl.getstring("texture", null);

            if (filename != null)
            {
                normalMap = TextureCache.getTexture(api.resolveTextureFilename(filename), true);
            }
            return(normalMap != null);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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;
        }
Beispiel #8
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;
 }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
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;
        }