public warp_Texture getClone() { warp_Texture t = new warp_Texture(width, height); warp_Math.copyBuffer(pixel, t.pixel); return(t); }
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); }
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); }
public void setTexture(warp_Texture t) { texture = t; if (texture != null) { texture.resize(); } }
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 = ((w > h) ? w : h) / density; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { t.pixel [pos++] = (int)(scale * perlin2d(x, y, wavelength, persistency, samples)); } } return(t); }
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); }
// Material loader public void loadMaterial(warp_Material material) { color = material.color; transparency = material.transparency; reflectivity = material.reflectivity; texture = material.texture; if (material.envmap != null) { envmap = material.envmap.pixel; } else { envmap = null; } if (texture != null) { 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; } materialLoaded = true; ready = lightmapLoaded && materialLoaded; }
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 = ((w > h) ? w : h) / density; float perlin; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { perlin = levels * perlin2d(x, y, wavelength, persistency, samples); t.pixel [pos++] = (int)(scale * (perlin - (int)perlin)); } } return(t); }
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); }
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); }
void draw(int drawwidth, int drawheight, 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, drawwidth); int yend = warp_Math.crop(yBase + h, 0, drawheight); int offset1, offset2; xBase = warp_Math.crop(xBase, 0, drawwidth); yBase = warp_Math.crop(yBase, 0, drawheight); ty = tyBase; for (int j = yBase; j < yend; j++) { tx = txBase; offset1 = j * drawwidth; offset2 = (ty >> 8) * tw; for (int i = xBase; i < xend; i++) { pixels [i + offset1] = unchecked ((int)0xff000000) | texture.pixel [(tx >> 8) + offset2]; tx += dtx; } ty += dty; } }
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]; Array.Copy(flare, 0, temp1, 0, flares - 1); // check this flare = temp1; float[] temp2 = new float[flares]; Array.Copy(flareDist, 0, temp2, 0, flares - 1); flareDist = temp2; } flare [flares - 1] = texture; flareDist [flares - 1] = relPos; }
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); }
public void drawBackground(warp_Texture texture, int posx, int posy, int xsize, int ysize) { draw(width, height, texture, posx, posy, xsize, ysize); }
public void add(warp_Texture texture, int posx, int posy, int xsize, int ysize) { add(width, height, texture, posx, posy, xsize, ysize); }
public void setBackground(warp_Texture t) { environment.setBackground(t); }
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); } } }
public warp_Material(warp_Texture t) { setTexture(t); reflectivity = 255; }
public void setEnvmap(warp_Texture env) { envmap = env; env.resize(256, 256); }