Esempio n. 1
0
        public bool SetBackgroundMaterial(string path)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Material material = null;

            try
            {
                material = new warp_Material(path);
            }
            catch (Exception)
            {
                return(false);
            }

            warp_Texture texture = material.getTexture();

            if (texture == null)
            {
                return(false);
            }

            _scene.environment.setBackground(texture);

            return(true);
        }
Esempio n. 2
0
        public bool SetTexture(string name, string path)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Texture texture = null;

            try
            {
                texture = new warp_Texture(path);
            }
            catch (Exception)
            {
                return(false);
            }

            warp_Material material = (warp_Material)_scene.materialData[name];

            if (material == null)
            {
                return(false);
            }

            material.setTexture(texture);

            return(true);
        }
Esempio n. 3
0
        public warp_Texture getClone()
        {
            warp_Texture t = new warp_Texture(width, height);

            warp_Math.copyBuffer(pixel, t.pixel);
            return(t);
        }
Esempio n. 4
0
 public void setTexture(warp_Texture t)
 {
     texture = t;
     if (texture != null)
     {
         texture.resize();
     }
 }
 public warp_TextureSettings(warp_Texture tex, int w, int h, int t, float p, float d, int s, int[] c)
 {
     texture     = tex;
     width       = w;
     height      = h;
     type        = t;
     persistency = p;
     density     = d;
     samples     = s;
     colors      = c;
 }
        public static warp_Texture CHECKERBOARD(int w, int h, int cellbits, int oddColor, int evenColor)
        {
            warp_Texture t = new warp_Texture(w, h);

            int pos = 0;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    int c = (((x >> cellbits) + (y >> cellbits)) & 1) == 0 ? evenColor : oddColor;
                    t.pixel[pos++] = c;
                }
            }

            return(t);
        }
        public static warp_Texture PERLIN(int w, int h, float persistency,
                                          float density, int samples, int scale)
        {
            initNoiseBuffer();
            warp_Texture t          = new warp_Texture(w, h);
            int          pos        = 0;
            float        wavelength = (float)((w > h) ? w : h) / density;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    t.pixel[pos++] = (int)((float)scale *
                                           perlin2d(x, y, wavelength, persistency,
                                                    samples));
                }
            }
            return(t);
        }
Esempio n. 8
0
        private unsafe void draw(int width, int height, warp_Texture texture, int posx, int posy, int xsize, int ysize)
        {
            if (texture == null)
            {
                return;
            }

            int w = xsize;
            int h = ysize;
            int xBase = posx;
            int yBase = posy;
            int tx = texture.width * 255;
            int ty = texture.height * 255;
            int tw = texture.width;
            int dtx = tx / w;
            int dty = ty / h;
            int txBase = warp_Math.crop(-xBase * dtx, 0, 255 * tx);
            int tyBase = warp_Math.crop(-yBase * dty, 0, 255 * ty);
            int xend = warp_Math.crop(xBase + w, 0, width);
            int yend = warp_Math.crop(yBase + h, 0, height);
            int offset1, offset2;

            xBase = warp_Math.crop(xBase, 0, width);
            yBase = warp_Math.crop(yBase, 0, height);

            fixed(int *px = pixels, txp = texture.pixel)
            {
                ty = tyBase;
                for (int j = yBase; j < yend; j++)
                {
                    tx      = txBase;
                    offset1 = j * width;
                    offset2 = (ty >> 8) * tw;
                    for (int i = xBase; i < xend; i++)
                    {
                        px[i + offset1] = unchecked ((int)0xff000000) | txp[(tx >> 8) + offset2];
                        tx += dtx;
                    }
                    ty += dty;
                }
            }
        }
Esempio n. 9
0
        public void loadFastMaterial(warp_Object obj)
        {
            color        = obj.fastcolor;
            reflectivity = obj.fastreflectivity;
            texture      = obj.fasttexture;
            envmap       = obj.fastenvmappixels;

            if (texture != null)
            {
                tpixels = obj.fasttpixels;
                tw      = obj.fasttw;
                th      = obj.fastth;
                tbitW   = obj.fasttbitw;
                tbitH   = obj.fasttbith;
            }

            mode           = obj.fastmode;
            shademode      = mode & SHADED;
            materialLoaded = true;
            ready          = lightmapLoaded;
        }
Esempio n. 10
0
        private warp_Texture createRadialTexture(int w, int h, int[] colormap, int[] alphamap)
        {
            int          offset;
            float        relX, relY;
            warp_Texture newTexture = new warp_Texture(w, h);

            int[] palette = getPalette(colormap, alphamap);

            for (int y = h - 1; y >= 0; y--)
            {
                offset = y * w;
                for (int x = w - 1; x >= 0; x--)
                {
                    relX = (float)(x - (w >> 1)) / (float)(w >> 1);
                    relY = (float)(y - (h >> 1)) / (float)(h >> 1);
                    newTexture.pixel[offset + x] = palette[warp_Math.crop((int)(255 * Math.Sqrt(relX * relX + relY * relY)), 0, 255)];
                }
            }

            return(newTexture);
        }
Esempio n. 11
0
        public bool SetBackgroundTexture(string path)
        {
            if (_scene == null)
            {
                return(false);
            }

            warp_Texture texture = null;

            try
            {
                texture = new warp_Texture(path);
            }
            catch (Exception)
            {
                return(false);
            }

            _scene.environment.setBackground(texture);

            return(true);
        }
Esempio n. 12
0
        private void addFlare(warp_Texture texture, float relPos)
        {
            flares++;

            if (flares == 1)
            {
                flare     = new warp_Texture[1];
                flareDist = new float[1];
            }
            else
            {
                warp_Texture[] temp1 = new warp_Texture[flares];
                System.Array.Copy(flare, 0, temp1, 0, flares - 1);           // check this
                flare = temp1;

                float[] temp2 = new float[flares];
                System.Array.Copy(flareDist, 0, temp2, 0, flares - 1);
                flareDist = temp2;
            }

            flare[flares - 1]     = texture;
            flareDist[flares - 1] = relPos;
        }
Esempio n. 13
0
        public static warp_Texture GRAIN(int w, int h, float persistency,
                                         float density, int samples, int levels,
                                         int scale)
        // TIP: For wooden textures
        {
            initNoiseBuffer();
            warp_Texture t          = new warp_Texture(w, h);
            int          pos        = 0;
            float        wavelength = (float)((w > h) ? w : h) / density;
            float        perlin;

            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    perlin = (float)levels *
                             perlin2d(x, y, wavelength, persistency, samples);
                    t.pixel[pos++] = (int)((float)scale *
                                           (perlin - (float)(int)perlin));
                }
            }
            return(t);
        }
Esempio n. 14
0
        private warp_Texture createRays(int size, int rays, int rad, int color)
        {
            int          pos;
            float        relPos;
            warp_Texture texture = new warp_Texture(size, size);

            int[] radialMap = new int [1024];
            warp_Math.clearBuffer(radialMap, 0);

            for (int i = 0; i < rays; i++)
            {
                pos = (int)warp_Math.random(rad, 1023 - rad);
                for (int k = pos - rad; k <= pos + rad; k++)
                {
                    relPos        = (float)(k - pos + rad) / (float)(rad * 2);
                    radialMap[k] += (int)(255 * (1 + Math.Sin((relPos - 0.25) * 3.14159 * 2)) / 2);
                }
            }

            int   angle, offset, reldist;
            float xrel, yrel;

            for (int y = size - 1; y >= 0; y--)
            {
                offset = y * size;
                for (int x = size - 1; x >= 0; x--)
                {
                    xrel    = (float)(2 * x - size) / (float)size;
                    yrel    = (float)(2 * y - size) / (float)size;
                    angle   = (int)(1023 * Math.Atan2(xrel, yrel) / 3.14159 / 2) & 1023;
                    reldist = Math.Max((int)(255 - 255 * warp_Math.pythagoras(xrel, yrel)), 0);
                    texture.pixel[x + offset] = warp_Color.scale(color, radialMap[angle] * reldist / 255);
                }
            }

            return(texture);
        }
Esempio n. 15
0
 public void setEnvmap(warp_Texture env)
 {
     envmap = env;
     env.resize(256, 256);
 }
Esempio n. 16
0
 public warp_Material(warp_Texture t)
 {
     setTexture(t);
     reflectivity = 255;
 }
Esempio n. 17
0
        private void readTexture(BinaryReader inStream, bool textureId)
        {
            warp_Texture t  = null;
            int          id = inStream.ReadSByte();

            if (id == 1)
            {
                t = new warp_Texture("c:/source/Warp3D/materials/skymap.jpg");

                if (t != null && textureId)
                {
                    texturePath     = t.path;
                    textureSettings = null;
                    setTexture(t);
                }
                if (t != null && !textureId)
                {
                    envmapPath     = t.path;
                    envmapSettings = null;
                    setEnvmap(t);
                }
            }

            if (id == 2)
            {
                int w    = readInt(inStream);
                int h    = readInt(inStream);
                int type = inStream.ReadSByte();

                float persistency = readInt(inStream);
                float density     = readInt(inStream);

                persistency = .5f;
                density     = .5f;

                int   samples   = inStream.ReadByte();
                int   numColors = inStream.ReadByte();
                int[] colors    = new int[numColors];
                for (int i = 0; i < numColors; i++)
                {
                    colors[i] = readInt(inStream);
                }
                if (type == 1)
                {
                    t = warp_TextureFactory.PERLIN(w, h, persistency, density, samples, 1024).colorize(warp_Color.makeGradient(colors, 1024));
                }
                if (type == 2)
                {
                    t = warp_TextureFactory.WAVE(w, h, persistency, density, samples, 1024).colorize(warp_Color.makeGradient(colors, 1024));
                }
                if (type == 3)
                {
                    t = warp_TextureFactory.GRAIN(w, h, persistency, density, samples, 20, 1024).colorize(warp_Color.makeGradient(colors, 1024));
                }

                if (textureId)
                {
                    texturePath     = null;
                    textureSettings = new warp_TextureSettings(t, w, h, type, persistency, density, samples, colors);
                    setTexture(t);
                }
                else
                {
                    envmapPath     = null;
                    envmapSettings = new warp_TextureSettings(t, w, h, type, persistency, density, samples, colors);
                    setEnvmap(t);
                }
            }
        }
Esempio n. 18
0
 public void drawBackground(warp_Texture texture, int posx, int posy, int xsize, int ysize)
 {
     draw(width, height, texture, posx, posy, xsize, ysize);
 }
Esempio n. 19
0
 public void setBackground(warp_Texture t)
 {
     background = t;
 }
Esempio n. 20
0
        private const int T = 8;  // TEXTURED

        public void cacheMaterialData()
        {
            fastcolor        = material.color;
            fastreflectivity = material.reflectivity;
            fasttexture      = material.texture;
            if (material.envmap != null)
            {
                fastenvmappixels = material.envmap.pixel;
            }
            else
            {
                fastenvmappixels = null;
            }

            if (fasttexture != null)
            {
                if (projectedmaxMips < 2)
                {
                    fastcolor   = warp_Color.multiply(fastcolor, fasttexture.averageColor);
                    fasttexture = null;
                }
                else
                {
                    int mip = projectedmaxMips - 2;
//                    int mip = fasttexture.maxmips;
                    if (mip < fasttexture.maxmips)
                    {
                        if (!fasttexture.hasmips)
                        {
                            fasttexture.GenMips();
                        }

                        fasttpixels = fasttexture.mips[mip];
                        fasttbitw   = fasttexture.mipsBitWidth[mip];
                        fasttbith   = fasttexture.mipsBitHeight[mip];
                        fasttw      = fasttexture.mipstw[mip] - 1;
                        fastth      = fasttexture.mipsth[mip] - 1;
                    }
                    else
                    {
                        fasttpixels = fasttexture.pixel;
                        fasttw      = fasttexture.width - 1;
                        fastth      = fasttexture.height - 1;
                        fasttbitw   = fasttexture.bitWidth;
                        fasttbith   = fasttexture.bitHeight;
                    }
                }
            }

            int m = 0;

            if (!material.flat)
            {
                m |= P;
            }
            if (fastenvmappixels != null)
            {
                m |= E;
            }
            if (fasttexture != null)
            {
                m |= T;
            }
            if (material.wireframe)
            {
                m |= W;
            }
            fastmode = m;
        }
Esempio n. 21
0
        // Material loader
        public void loadMaterial(warp_Object obj)
        {
            warp_Material material = obj.material;

            color        = material.color;
            reflectivity = material.reflectivity;
            texture      = material.texture;
            if (material.envmap != null)
            {
                envmap = material.envmap.pixel;
            }
            else
            {
                envmap = null;
            }

            if (texture != null)
            {
                if (obj.projectedmaxMips < 2)
                {
                    color   = warp_Color.multiply(color, texture.averageColor);
                    texture = null;
                }
                else
                {
                    int mip = obj.projectedmaxMips - 1;
                    if (mip > texture.maxmips)
                    {
                        mip = texture.maxmips;
                    }

                    if (texture.mips[mip] != null)
                    {
                        tpixels = texture.mips[mip];
                        tbitW   = texture.mipsBitWidth[mip];
                        tbitH   = texture.mipsBitHeight[mip];
                        tw      = texture.mipstw[mip] - 1;
                        th      = texture.mipsth[mip] - 1;
                    }
                    else
                    {
                        tpixels = texture.pixel;
                        tw      = texture.width - 1;
                        th      = texture.height - 1;
                        tbitW   = texture.bitWidth;
                        tbitH   = texture.bitHeight;
                    }
                }
            }

            mode = 0;
            if (!material.flat)
            {
                mode |= P;
            }
            if (envmap != null)
            {
                mode |= E;
            }
            if (texture != null)
            {
                mode |= T;
            }
            if (material.wireframe)
            {
                mode |= W;
            }

            shademode      = mode & SHADED;
            materialLoaded = true;
            ready          = lightmapLoaded;
        }
Esempio n. 22
0
 public void setBackground(warp_Texture t)
 {
     environment.setBackground(t);
 }
Esempio n. 23
0
 public void add(warp_Texture texture, int posx, int posy, int xsize, int ysize)
 {
     add(width, height, texture, posx, posy, xsize, ysize);
 }