private warp_Texture GetTexture(UUID id) { warp_Texture ret = null; byte[] asset = m_scene.AssetService.GetData(id.ToString()); if (asset != null) { IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface <IJ2KDecoder>(); try { using (Bitmap img = (Bitmap)imgDecoder.DecodeToImage(asset)) { ret = new warp_Texture(img); img.Dispose(); } } catch (Exception e) { m_log.Warn(string.Format("[WARP 3D IMAGE MODULE]: Failed to decode asset {0}, exception ", id), e); } } return(ret); }
public string GetOrCreateMaterial(WarpRenderer renderer, Color4 faceColor, UUID textureID, bool useAverageTextureColor, SceneObjectPart sop) { int color = ConvertColor(faceColor); string idstr = textureID.ToString() + color.ToString(); string materialName = "MAPMAT" + idstr; if (renderer.Scene.material(materialName) != null) { return(materialName); } warp_Material mat = new warp_Material(); warp_Texture texture = GetTexture(textureID, sop); if (texture != null) { if (useAverageTextureColor) { color = warp_Color.multiply(color, texture.averageColor); } else { mat.setTexture(texture); } } else { color = warp_Color.multiply(color, warp_Color.Grey); } mat.setColor(color); renderer.Scene.addMaterial(materialName, mat); return(materialName); }
private warp_Texture GetTexture(UUID id) { warp_Texture ret = null; if (id == UUID.Zero) { return(ret); } if (m_warpTextures.TryGetValue(id.ToString(), out ret)) { return(ret); } byte[] asset = m_scene.AssetService.GetData(id.ToString()); if (asset != null) { try { using (Bitmap img = (Bitmap)m_imgDecoder.DecodeToImage(asset)) ret = new warp_Texture(img, 8); // reduce textures size to 256x256 } catch (Exception e) { m_log.Warn(string.Format("[WARP 3D IMAGE MODULE]: Failed to decode asset {0}, exception ", id), e); } } m_warpTextures[id.ToString()] = ret; return(ret); }
warp_Texture GetTexture(UUID id) { warp_Texture ret = null; if (id == UUID.Zero) { id = (UUID)Constants.MISSING_TEXTURE_ID; } byte [] assetData = m_scene.AssetService.GetData(id.ToString(), false); // suppress warnings here if (assetData == null || assetData.Length == 0) { assetData = m_scene.AssetService.GetData(Constants.MISSING_TEXTURE_ID); // not found, replace with something identifable } if (assetData != null && assetData.Length > 0) { IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface <IJ2KDecoder> (); Bitmap img = (Bitmap)imgDecoder.DecodeToImage(assetData); if (img != null) { ret = new warp_Texture(img); img.Dispose(); return(ret); } } MainConsole.Instance.Debug("[WarpTile generator]: Gettexture returning null, asset id: " + id); return(ret); }
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 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; }
private warp_Texture GetTexture(UUID id) { warp_Texture ret = null; byte[] asset = m_scene.AssetService.GetData(id.ToString()); if (asset != null) { IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface <IJ2KDecoder>(); Bitmap img = (Bitmap)imgDecoder.DecodeToImage(asset); if (img != null) { return(new warp_Texture(img)); } } return(ret); }
private warp_Texture GetTexture(UUID id) { warp_Texture ret = null; AssetBase asset = m_scene.AssetService.Get(id.ToString()); if (asset != null) { IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface <IJ2KDecoder>(); Bitmap img = (Bitmap)imgDecoder.DecodeToImage(asset.Data); if (img != null) { ret = new warp_Texture(img); img.Dispose(); } asset.Dispose(); } return(ret); }
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; }
public string GetOrCreateMaterial(WarpRenderer renderer, Color4 faceColor, UUID textureID) { string materialName = "Color-" + faceColor.ToString() + "-Texture-" + textureID.ToString(); if (renderer.Scene.material(materialName) == null) { renderer.AddMaterial(materialName, ConvertColor(faceColor)); if (faceColor.A < 1f) { renderer.Scene.material(materialName).setTransparency((byte)((1f - faceColor.A) * 255f)); } warp_Texture texture = GetTexture(textureID); if (texture != null) { renderer.Scene.material(materialName).setTexture(texture); } } return(materialName); }
public string GetOrCreateMaterial(WarpRenderer renderer, Color4 faceColor, UUID textureID) { string materialName = "Color-" + faceColor + "-Texture-" + textureID; if (renderer.Scene.material(materialName) == null) { MainConsole.Instance.DebugFormat("[WarpTile generator]: Creating material {0}", materialName); renderer.AddMaterial(materialName, ConvertColor(faceColor)); if (faceColor.A < 1f) { renderer.Scene.material(materialName).setTransparency((byte)((1f - faceColor.A) * 255f)); } warp_Texture texture = GetTexture(textureID); if (texture != null) { renderer.Scene.material(materialName).setTexture(texture); } } return(materialName); }
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); 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++) { pixels [i + offset1] = unchecked((int)0xff000000) | texture.pixel [(tx >> 8) + offset2]; tx += dtx; } ty += dty; } }
private warp_Texture GetTexture(UUID id, SceneObjectPart sop) { warp_Texture ret = null; if (id == UUID.Zero) { return(ret); } if (m_warpTextures.TryGetValue(id.ToString(), out ret)) { return(ret); } byte[] asset = m_scene.AssetService.GetData(id.ToString()); if (asset != null) { try { using (Bitmap img = (Bitmap)m_imgDecoder.DecodeToImage(asset)) ret = new warp_Texture(img, 8); // reduce textures size to 256x256 } catch (Exception e) { m_log.WarnFormat("[Warp3D]: Failed to decode texture {0} for prim {1} at {2}, exception {3}", id.ToString(), sop.Name, sop.GetWorldPosition().ToString(), e.Message); } } else { m_log.WarnFormat("[Warp3D]: missing texture {0} data for prim {1} at {2}", id.ToString(), sop.Name, sop.GetWorldPosition().ToString()); } m_warpTextures[id.ToString()] = ret; return(ret); }
private void CreateTerrain(IScene scene, WarpRenderer renderer, ITerrain terrain, RegionInfo regionInfo) { float[] heightmap = (terrain != null) ? terrain.GetHeightmap() : new float[256 * 256]; warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { int v = y * 256 + x; float height = heightmap[v]; warp_Vector pos = ConvertVector(new Vector3(x, y, height)); obj.addVertex(new warp_Vertex(pos, (float)x / 255f, (float)(255 - y) / 255f)); } } for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { if (x < 255 && y < 255) { int v = y * 256 + x; // Normal Vector3 v1 = new Vector3(x, y, heightmap[y * 256 + x]); Vector3 v2 = new Vector3(x + 1, y, heightmap[y * 256 + x + 1]); Vector3 v3 = new Vector3(x, y + 1, heightmap[(y + 1) * 256 + x]); warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); norm = norm.reverse(); obj.vertex(v).n = norm; // Triangle 1 obj.addTriangle( v, v + 1, v + 256); // Triangle 2 obj.addTriangle( v + 256 + 1, v + 256, v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; if (regionInfo != null) { textureIDs[0] = regionInfo.TerrainDetail0; textureIDs[1] = regionInfo.TerrainDetail1; textureIDs[2] = regionInfo.TerrainDetail2; textureIDs[3] = regionInfo.TerrainDetail3; startHeights[0] = regionInfo.TerrainStartHeight00; startHeights[1] = regionInfo.TerrainStartHeight01; startHeights[2] = regionInfo.TerrainStartHeight10; startHeights[3] = regionInfo.TerrainStartHeight11; heightRanges[0] = regionInfo.TerrainHeightRange00; heightRanges[1] = regionInfo.TerrainHeightRange01; heightRanges[2] = regionInfo.TerrainHeightRange10; heightRanges[3] = regionInfo.TerrainHeightRange11; } Bitmap image = TerrainSplat.Splat(heightmap, textureIDs, startHeights, heightRanges, scene.MinPosition, m_assetClient); warp_Texture texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); material.setReflectivity(50); renderer.Scene.addMaterial("TerrainColor", material); renderer.SetObjectMaterial("Terrain", "TerrainColor"); }
public warp_Material (warp_Texture t) { setTexture (t); reflectivity = 255; }
public void setTexture (warp_Texture t) { texture = t; if (texture != null) texture.resize (); }
public void setBackground(warp_Texture t) { background=t; }
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; }
public void setBackground(warp_Texture t) { background = t; }
warp_Texture GetTexture (UUID id) { warp_Texture ret = null; if (id == UUID.Zero) id = (UUID)Constants.MISSING_TEXTURE_ID; byte [] assetData = m_scene.AssetService.GetData (id.ToString ()); if (assetData == null || assetData.Length == 0) assetData = m_scene.AssetService.GetData (Constants.MISSING_TEXTURE_ID); // not found, replace with something identifable if (assetData != null && assetData.Length > 0) { IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder> (); Bitmap img = (Bitmap)imgDecoder.DecodeToImage (assetData); if (img != null) { ret = new warp_Texture (img); img.Dispose (); return ret; } } MainConsole.Instance.Debug ("Gettexture returning null, asset id: " + id); return ret; }
warp_Object CreateTerrain(WarpRenderer renderer, bool textureTerrain) { ITerrainChannel terrain = m_scene.RequestModuleInterface <ITerrainChannel> (); float diffX = 1.0f; //(float) m_scene.RegionInfo.RegionSizeX/(float) Constants.RegionSize; float diffY = 1.0f; //(float) m_scene.RegionInfo.RegionSizeY/(float) Constants.RegionSize; int newRsX = m_scene.RegionInfo.RegionSizeX / (int)diffX; int newRsY = m_scene.RegionInfo.RegionSizeY / (int)diffY; warp_Object obj = new warp_Object(newRsX * newRsY, ((newRsX - 1) * (newRsY - 1) * 2)); for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diffY) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diffX) { float t_height = terrain [(int)x, (int)y]; float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; //clamp to eliminate artifacts t_height = Utils.Clamp(t_height, waterHeight - 0.5f, waterHeight + 0.5f); if (t_height < 0.0f) { t_height = 0.0f; } warp_Vector pos = ConvertVector(x / diffX, y / diffY, t_height); obj.addVertex( new warp_Vertex(pos, x / m_scene.RegionInfo.RegionSizeX, (m_scene.RegionInfo.RegionSizeY - y) / (m_scene.RegionInfo.RegionSizeY))); } } const float normal_map_reduction = 2.0f; //2.0f-2.5f is the sweet spot for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diffY) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diffX) { float newX = x / diffX; float newY = y / diffY; if (newX < newRsX - 1 && newY < newRsY - 1) { int v = (int)(newY * newRsX + newX); // Normal Vector3 v1 = new Vector3(newX, newY, (terrain [(int)x, (int)y]) / normal_map_reduction); Vector3 v2 = new Vector3(newX + 1, newY, (terrain [(int)x + 1, (int)y]) / normal_map_reduction); Vector3 v3 = new Vector3(newX, newY + 1, (terrain [(int)x, (int)(y + 1)]) / normal_map_reduction); warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); norm = norm.reverse(); obj.vertex(v).n = norm; // Triangle 1 obj.addTriangle( v, v + 1, v + newRsX); // Triangle 2 obj.addTriangle( v + newRsX + 1, v + newRsX, v + 1); } } } renderer.Scene.addObject("Terrain", obj); renderer.Scene.sceneobject("Terrain").setPos(0.0f, 0.0f, 0.0f); UUID [] textureIDs = new UUID [4]; float [] startHeights = new float [4]; float [] heightRanges = new float [4]; RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs [0] = regionInfo.TerrainTexture1; textureIDs [1] = regionInfo.TerrainTexture2; textureIDs [2] = regionInfo.TerrainTexture3; textureIDs [3] = regionInfo.TerrainTexture4; startHeights [0] = (float)regionInfo.Elevation1SW; startHeights [1] = (float)regionInfo.Elevation1NW; startHeights [2] = (float)regionInfo.Elevation1SE; startHeights [3] = (float)regionInfo.Elevation1NE; heightRanges [0] = (float)regionInfo.Elevation2SW; heightRanges [1] = (float)regionInfo.Elevation2NW; heightRanges [2] = (float)regionInfo.Elevation2SE; heightRanges [3] = (float)regionInfo.Elevation2NE; uint globalX, globalY; Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); Bitmap image = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain); warp_Texture texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); material.setReflectivity(0); // reduces tile seams a bit thanks lkalif renderer.Scene.addMaterial("TerrainColor", material); renderer.SetObjectMaterial("Terrain", "TerrainColor"); image.Dispose(); return(obj); }
public void add (warp_Texture texture, int posx, int posy, int xsize, int ysize) { add (width, height, texture, posx, posy, xsize, ysize); }
private warp_Object CreateTerrain(WarpRenderer renderer, bool textureTerrain) { ITerrainChannel terrain = m_scene.RequestModuleInterface <ITerrainChannel>(); float diff = (float)m_scene.RegionInfo.RegionSizeY / (float)Constants.RegionSize; warp_Object obj = new warp_Object(Constants.RegionSize * Constants.RegionSize, ((Constants.RegionSize - 1) * (Constants.RegionSize - 1) * 2)); for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) { warp_Vector pos = ConvertVector(x, y, terrain[(int)x, (int)y]); obj.addVertex(new warp_Vertex(pos, x / (float)(m_scene.RegionInfo.RegionSizeX), (((float)m_scene.RegionInfo.RegionSizeX) - y) / (m_scene.RegionInfo.RegionSizeX))); } } for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) { float newX = x / diff; float newY = y / diff; if (newX < Constants.RegionSize - 1 && newY < Constants.RegionSize - 1) { int v = (int)(newY * Constants.RegionSize + newX); // Normal Vector3 v1 = new Vector3(newX, newY, (terrain[(int)x, (int)y]) / Constants.TerrainCompression); Vector3 v2 = new Vector3(newX + 1, newY, (terrain[(int)x + 1, (int)y]) / Constants.TerrainCompression); Vector3 v3 = new Vector3(newX, newY + 1, (terrain[(int)x, (int)(y + 1)]) / Constants.TerrainCompression); warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); norm = norm.reverse(); obj.vertex(v).n = norm; // Triangle 1 obj.addTriangle( v, v + 1, v + Constants.RegionSize); // Triangle 2 obj.addTriangle( v + Constants.RegionSize + 1, v + Constants.RegionSize, v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs[0] = regionInfo.TerrainTexture1; textureIDs[1] = regionInfo.TerrainTexture2; textureIDs[2] = regionInfo.TerrainTexture3; textureIDs[3] = regionInfo.TerrainTexture4; startHeights[0] = (float)regionInfo.Elevation1SW; startHeights[1] = (float)regionInfo.Elevation1NW; startHeights[2] = (float)regionInfo.Elevation1SE; startHeights[3] = (float)regionInfo.Elevation1NE; heightRanges[0] = (float)regionInfo.Elevation2SW; heightRanges[1] = (float)regionInfo.Elevation2NW; heightRanges[2] = (float)regionInfo.Elevation2SE; heightRanges[3] = (float)regionInfo.Elevation2NE; uint globalX, globalY; Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); Bitmap image = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain); warp_Texture texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); material.setReflectivity(0); // reduces tile seams a bit thanks lkalif renderer.Scene.addMaterial("TerrainColor", material); renderer.SetObjectMaterial("Terrain", "TerrainColor"); return(obj); }
public void drawBackground (warp_Texture texture, int posx, int posy, int xsize, int ysize) { draw (width, height, texture, posx, posy, xsize, ysize); }
private void CreateTerrain(WarpRenderer renderer, bool textureTerrain) { ITerrainChannel terrain = m_scene.RequestModuleInterface <ITerrainChannel>(); warp_Object obj = new warp_Object(m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY, (m_scene.RegionInfo.RegionSizeX - 1) * (m_scene.RegionInfo.RegionSizeY - 1) * 2); for (int y = 0; y < m_scene.RegionInfo.RegionSizeY; y++) { for (int x = 0; x < m_scene.RegionInfo.RegionSizeX; x++) { float height = terrain[x, y]; warp_Vector pos = ConvertVector(new Vector3(x, y, height)); obj.addVertex(new warp_Vertex(pos, (float)x / (m_scene.RegionInfo.RegionSizeX - 1), (float)((m_scene.RegionInfo.RegionSizeX - 1) - y) / (m_scene.RegionInfo.RegionSizeX - 1))); } } for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += 1) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += 1) { if (x < m_scene.RegionInfo.RegionSizeX - 1 && y < m_scene.RegionInfo.RegionSizeY - 1) { float v = y * m_scene.RegionInfo.RegionSizeX + x; // Normal warp_Vector norm = new warp_Vector(x, y, terrain.GetNormalizedGroundHeight((int)x, (int)y)); norm = norm.reverse(); obj.vertex((int)v).n = norm; // Triangle 1 obj.addTriangle( (int)v, (int)v + 1, (int)v + m_scene.RegionInfo.RegionSizeX); // Triangle 2 obj.addTriangle( (int)v + m_scene.RegionInfo.RegionSizeX + 1, (int)v + m_scene.RegionInfo.RegionSizeX, (int)v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs[0] = regionInfo.TerrainTexture1; textureIDs[1] = regionInfo.TerrainTexture2; textureIDs[2] = regionInfo.TerrainTexture3; textureIDs[3] = regionInfo.TerrainTexture4; startHeights[0] = (float)regionInfo.Elevation1SW; startHeights[1] = (float)regionInfo.Elevation1NW; startHeights[2] = (float)regionInfo.Elevation1SE; startHeights[3] = (float)regionInfo.Elevation1NE; heightRanges[0] = (float)regionInfo.Elevation2SW; heightRanges[1] = (float)regionInfo.Elevation2NW; heightRanges[2] = (float)regionInfo.Elevation2SE; heightRanges[3] = (float)regionInfo.Elevation2NE; uint globalX, globalY; Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); Bitmap image = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain); warp_Texture texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); material.setReflectivity(50); renderer.Scene.addMaterial("TerrainColor", material); renderer.SetObjectMaterial("Terrain", "TerrainColor"); }
private warp_Object CreateTerrain(WarpRenderer renderer, bool textureTerrain) { ITerrainChannel terrain = m_scene.RequestModuleInterface<ITerrainChannel>(); float diff = (float) m_scene.RegionInfo.RegionSizeY/(float) Constants.RegionSize; warp_Object obj = new warp_Object(Constants.RegionSize*Constants.RegionSize, ((Constants.RegionSize - 1)*(Constants.RegionSize - 1)*2)); for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) { warp_Vector pos = ConvertVector(x, y, terrain[(int) x, (int) y]); obj.addVertex(new warp_Vertex(pos, x/(float) (m_scene.RegionInfo.RegionSizeX), (((float) m_scene.RegionInfo.RegionSizeX) - y)/ (m_scene.RegionInfo.RegionSizeX))); } } for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) { float newX = x/diff; float newY = y/diff; if (newX < Constants.RegionSize - 1 && newY < Constants.RegionSize - 1) { int v = (int) (newY*Constants.RegionSize + newX); // Normal Vector3 v1 = new Vector3(newX, newY, (terrain[(int) x, (int) y])/Constants.TerrainCompression); Vector3 v2 = new Vector3(newX + 1, newY, (terrain[(int) x + 1, (int) y])/Constants.TerrainCompression); Vector3 v3 = new Vector3(newX, newY + 1, (terrain[(int) x, (int) (y + 1)])/Constants.TerrainCompression); warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); norm = norm.reverse(); obj.vertex(v).n = norm; // Triangle 1 obj.addTriangle( v, v + 1, v + Constants.RegionSize); // Triangle 2 obj.addTriangle( v + Constants.RegionSize + 1, v + Constants.RegionSize, v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs[0] = regionInfo.TerrainTexture1; textureIDs[1] = regionInfo.TerrainTexture2; textureIDs[2] = regionInfo.TerrainTexture3; textureIDs[3] = regionInfo.TerrainTexture4; startHeights[0] = (float) regionInfo.Elevation1SW; startHeights[1] = (float) regionInfo.Elevation1NW; startHeights[2] = (float) regionInfo.Elevation1SE; startHeights[3] = (float) regionInfo.Elevation1NE; heightRanges[0] = (float) regionInfo.Elevation2SW; heightRanges[1] = (float) regionInfo.Elevation2NW; heightRanges[2] = (float) regionInfo.Elevation2SE; heightRanges[3] = (float) regionInfo.Elevation2NE; uint globalX, globalY; Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); Bitmap image = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain); warp_Texture texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); material.setReflectivity(0); // reduces tile seams a bit thanks lkalif renderer.Scene.addMaterial("TerrainColor", material); renderer.SetObjectMaterial("Terrain", "TerrainColor"); return obj; }
warp_Object CreateTerrain (WarpRenderer renderer, bool textureTerrain) { ITerrainChannel terrain = m_scene.RequestModuleInterface<ITerrainChannel> (); float diffX = 1.0f; //(float) m_scene.RegionInfo.RegionSizeX/(float) Constants.RegionSize; float diffY = 1.0f; //(float) m_scene.RegionInfo.RegionSizeY/(float) Constants.RegionSize; int newRsX = m_scene.RegionInfo.RegionSizeX / (int)diffX; int newRsY = m_scene.RegionInfo.RegionSizeY / (int)diffY; warp_Object obj = new warp_Object (newRsX * newRsY, ((newRsX - 1) * (newRsY - 1) * 2)); for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diffY) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diffX) { float t_height = terrain [(int)x, (int)y]; float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; //clamp to eliminate artifacts t_height = Utils.Clamp (t_height, waterHeight - 0.5f, waterHeight + 0.5f); if (t_height < 0.0f) t_height = 0.0f; warp_Vector pos = ConvertVector (x / diffX, y / diffY, t_height); obj.addVertex ( new warp_Vertex (pos, x / m_scene.RegionInfo.RegionSizeX, (m_scene.RegionInfo.RegionSizeY - y) / (m_scene.RegionInfo.RegionSizeY))); } } const float normal_map_reduction = 2.0f; //2.0f-2.5f is the sweet spot for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diffY) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diffX) { float newX = x / diffX; float newY = y / diffY; if (newX < newRsX - 1 && newY < newRsY - 1) { int v = (int)(newY * newRsX + newX); // Normal Vector3 v1 = new Vector3 (newX, newY, (terrain [(int)x, (int)y]) / normal_map_reduction); Vector3 v2 = new Vector3 (newX + 1, newY, (terrain [(int)x + 1, (int)y]) / normal_map_reduction); Vector3 v3 = new Vector3 (newX, newY + 1, (terrain [(int)x, (int)(y + 1)]) / normal_map_reduction); warp_Vector norm = ConvertVector (SurfaceNormal (v1, v2, v3)); norm = norm.reverse (); obj.vertex (v).n = norm; // Triangle 1 obj.addTriangle ( v, v + 1, v + newRsX); // Triangle 2 obj.addTriangle ( v + newRsX + 1, v + newRsX, v + 1); } } } renderer.Scene.addObject ("Terrain", obj); renderer.Scene.sceneobject ("Terrain").setPos (0.0f, 0.0f, 0.0f); UUID [] textureIDs = new UUID [4]; float [] startHeights = new float [4]; float [] heightRanges = new float [4]; RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs [0] = regionInfo.TerrainTexture1; textureIDs [1] = regionInfo.TerrainTexture2; textureIDs [2] = regionInfo.TerrainTexture3; textureIDs [3] = regionInfo.TerrainTexture4; startHeights [0] = (float)regionInfo.Elevation1SW; startHeights [1] = (float)regionInfo.Elevation1NW; startHeights [2] = (float)regionInfo.Elevation1SE; startHeights [3] = (float)regionInfo.Elevation1NE; heightRanges [0] = (float)regionInfo.Elevation2SW; heightRanges [1] = (float)regionInfo.Elevation2NW; heightRanges [2] = (float)regionInfo.Elevation2SE; heightRanges [3] = (float)regionInfo.Elevation2NE; uint globalX, globalY; Utils.LongToUInts (m_scene.RegionInfo.RegionHandle, out globalX, out globalY); Bitmap image = TerrainSplat.Splat (terrain, textureIDs, startHeights, heightRanges, new Vector3d (globalX, globalY, 0.0), m_scene.AssetService, textureTerrain); warp_Texture texture = new warp_Texture (image); warp_Material material = new warp_Material (texture); material.setReflectivity (0); // reduces tile seams a bit thanks lkalif renderer.Scene.addMaterial ("TerrainColor", material); renderer.SetObjectMaterial ("Terrain", "TerrainColor"); image.Dispose (); return obj; }
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; }
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; }
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; }
// Add a terrain to the renderer. // Note that we create a 'low resolution' 256x256 vertex terrain rather than trying for // full resolution. This saves a lot of memory especially for very large regions. private void CreateTerrain(WarpRenderer renderer, bool textureTerrain) { ITerrainChannel terrain = m_scene.Heightmap; // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding float diff = (float)m_scene.RegionInfo.RegionSizeX / 256f; warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); // Create all the vertices for the terrain for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) { warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); obj.addVertex(new warp_Vertex(pos, x / (float)m_scene.RegionInfo.RegionSizeX, (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY)); } } // Now that we have all the vertices, make another pass and create // the normals for each of the surface triangles and // create the list of triangle indices. for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) { for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) { float newX = x / diff; float newY = y / diff; if (newX < 255 && newY < 255) { int v = (int)newY * 256 + (int)newX; // Normal for a triangle made up of three adjacent vertices Vector3 v1 = new Vector3(newX, newY, (float)terrain[(int)x, (int)y]); Vector3 v2 = new Vector3(newX + 1, newY, (float)terrain[(int)(x + 1), (int)y]); Vector3 v3 = new Vector3(newX, newY + 1, (float)terrain[(int)x, ((int)(y + 1))]); warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); norm = norm.reverse(); obj.vertex(v).n = norm; // Make two triangles for each of the squares in the grid of vertices obj.addTriangle( v, v + 1, v + 256); obj.addTriangle( v + 256 + 1, v + 256, v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; OpenSim.Framework.RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs[0] = regionInfo.TerrainTexture1; textureIDs[1] = regionInfo.TerrainTexture2; textureIDs[2] = regionInfo.TerrainTexture3; textureIDs[3] = regionInfo.TerrainTexture4; startHeights[0] = (float)regionInfo.Elevation1SW; startHeights[1] = (float)regionInfo.Elevation1NW; startHeights[2] = (float)regionInfo.Elevation1SE; startHeights[3] = (float)regionInfo.Elevation1NE; heightRanges[0] = (float)regionInfo.Elevation2SW; heightRanges[1] = (float)regionInfo.Elevation2NW; heightRanges[2] = (float)regionInfo.Elevation2SE; heightRanges[3] = (float)regionInfo.Elevation2NE; uint globalX, globalY; Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); warp_Texture texture; using ( Bitmap image = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) { texture = new warp_Texture(image); } warp_Material material = new warp_Material(texture); material.setReflectivity(50); renderer.Scene.addMaterial("TerrainColor", material); renderer.Scene.material("TerrainColor").setReflectivity(0); // reduces tile seams a bit thanks lkalif renderer.SetObjectMaterial("Terrain", "TerrainColor"); }
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; }
// Add a terrain to the renderer. // Note that we create a 'low resolution' 256x256 vertex terrain rather than trying for // full resolution. This saves a lot of memory especially for very large regions. private void CreateTerrain(WarpRenderer renderer, bool textureTerrain) { ITerrainChannel terrain = m_scene.Heightmap; float regionsx = m_scene.RegionInfo.RegionSizeX; float regionsy = m_scene.RegionInfo.RegionSizeY; // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding float diff = regionsx / 256f; int npointsx = (int)(regionsx / diff); int npointsy = (int)(regionsy / diff); float invsx = 1.0f / regionsx; float invsy = 1.0f / (float)m_scene.RegionInfo.RegionSizeY; // Create all the vertices for the terrain warp_Object obj = new warp_Object(); for (float y = 0; y < regionsy; y += diff) { for (float x = 0; x < regionsx; x += diff) { warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); obj.addVertex(new warp_Vertex(pos, x * invsx, 1.0f - y * invsy)); } } // Now that we have all the vertices, make another pass and // create the list of triangle indices. float invdiff = 1.0f / diff; int limx = npointsx - 1; int limy = npointsy - 1; for (float y = 0; y < regionsy; y += diff) { for (float x = 0; x < regionsx; x += diff) { float newX = x * invdiff; float newY = y * invdiff; if (newX < limx && newY < limy) { int v = (int)newY * npointsx + (int)newX; // Make two triangles for each of the squares in the grid of vertices obj.addTriangle( v, v + 1, v + npointsx); obj.addTriangle( v + npointsx + 1, v + npointsx, v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; OpenSim.Framework.RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs[0] = regionInfo.TerrainTexture1; textureIDs[1] = regionInfo.TerrainTexture2; textureIDs[2] = regionInfo.TerrainTexture3; textureIDs[3] = regionInfo.TerrainTexture4; startHeights[0] = (float)regionInfo.Elevation1SW; startHeights[1] = (float)regionInfo.Elevation1NW; startHeights[2] = (float)regionInfo.Elevation1SE; startHeights[3] = (float)regionInfo.Elevation1NE; heightRanges[0] = (float)regionInfo.Elevation2SW; heightRanges[1] = (float)regionInfo.Elevation2NW; heightRanges[2] = (float)regionInfo.Elevation2SE; heightRanges[3] = (float)regionInfo.Elevation2NE; uint globalX, globalY; Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); warp_Texture texture; using (Bitmap image = TerrainSplat.Splat( terrain, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); material.setReflectivity(50); renderer.Scene.addMaterial("TerrainColor", material); renderer.Scene.material("TerrainColor").setReflectivity(0); // reduces tile seams a bit thanks lkalif renderer.SetObjectMaterial("Terrain", "TerrainColor"); }
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 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 setEnvmap (warp_Texture env) { envmap = env; env.resize (256, 256); }
// 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; }
// Add a terrain to the renderer. // Note that we create a 'low resolution' 257x257 vertex terrain rather than trying for // full resolution. This saves a lot of memory especially for very large regions. private void CreateTerrain(WarpRenderer renderer) { ITerrainChannel terrain = m_scene.Heightmap; float regionsx = m_scene.RegionInfo.RegionSizeX; float regionsy = m_scene.RegionInfo.RegionSizeY; // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding int bitWidth; int bitHeight; const double log2inv = 1.4426950408889634073599246810019; bitWidth = (int)Math.Ceiling((Math.Log(terrain.Width) * log2inv)); bitHeight = (int)Math.Ceiling((Math.Log(terrain.Height) * log2inv)); if (bitWidth > 8) // more than 256 is very heavy :( { bitWidth = 8; } if (bitHeight > 8) { bitHeight = 8; } int twidth = (int)Math.Pow(2, bitWidth); int theight = (int)Math.Pow(2, bitHeight); float diff = regionsx / twidth; int npointsx = (int)(regionsx / diff); int npointsy = (int)(regionsy / diff); float invsx = 1.0f / (npointsx * diff); float invsy = 1.0f / (npointsy * diff); npointsx++; npointsy++; // Create all the vertices for the terrain warp_Object obj = new warp_Object(); warp_Vector pos; float x, y; float tv; for (y = 0; y < regionsy; y += diff) { tv = y * invsy; for (x = 0; x < regionsx; x += diff) { pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); obj.addVertex(new warp_Vertex(pos, x * invsx, tv)); } pos = ConvertVector(x, y, (float)terrain[(int)(x - diff), (int)y]); obj.addVertex(new warp_Vertex(pos, 1.0f, tv)); } int lastY = (int)(y - diff); for (x = 0; x < regionsx; x += diff) { pos = ConvertVector(x, y, (float)terrain[(int)x, lastY]); obj.addVertex(new warp_Vertex(pos, x * invsx, 1.0f)); } pos = ConvertVector(x, y, (float)terrain[(int)(x - diff), lastY]); obj.addVertex(new warp_Vertex(pos, 1.0f, 1.0f)); // create triangles. int limx = npointsx - 1; int limy = npointsy - 1; for (int j = 0; j < limy; j++) { for (int i = 0; i < limx; i++) { int v = j * npointsx + i; // Make two triangles for each of the squares in the grid of vertices obj.addTriangle( v, v + 1, v + npointsx); obj.addTriangle( v + npointsx + 1, v + npointsx, v + 1); } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; OpenSim.Framework.RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs[0] = regionInfo.TerrainTexture1; textureIDs[1] = regionInfo.TerrainTexture2; textureIDs[2] = regionInfo.TerrainTexture3; textureIDs[3] = regionInfo.TerrainTexture4; startHeights[0] = (float)regionInfo.Elevation1SW; startHeights[1] = (float)regionInfo.Elevation1NW; startHeights[2] = (float)regionInfo.Elevation1SE; startHeights[3] = (float)regionInfo.Elevation1NE; heightRanges[0] = (float)regionInfo.Elevation2SW; heightRanges[1] = (float)regionInfo.Elevation2NW; heightRanges[2] = (float)regionInfo.Elevation2SE; heightRanges[3] = (float)regionInfo.Elevation2NE; warp_Texture texture; using (Bitmap image = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, m_scene.RegionInfo.WorldLocX, m_scene.RegionInfo.WorldLocY, m_scene.AssetService, m_imgDecoder, m_textureTerrain, m_textureAverageTerrain, twidth, twidth)) texture = new warp_Texture(image); warp_Material material = new warp_Material(texture); renderer.Scene.addMaterial("TerrainMat", material); renderer.SetObjectMaterial("Terrain", "TerrainMat"); }
public void setBackground (warp_Texture t) { environment.setBackground (t); }
private void CreateTerrain(WarpRenderer renderer, bool textureTerrain) { ITerrainChannel terrain = m_scene.Heightmap; float[] heightmap = terrain.GetFloatsSerialised(); warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { int v = y * 256 + x; float height = heightmap[v]; warp_Vector pos = ConvertVector(new Vector3(x, y, height)); obj.addVertex(new warp_Vertex(pos, (float)x / 255f, (float)(255 - y) / 255f)); } } for (int y = 0; y < 256; y++) { for (int x = 0; x < 256; x++) { if (x < 255 && y < 255) { int v = y * 256 + x; // Normal Vector3 v1 = new Vector3(x, y, heightmap[y * 256 + x]); Vector3 v2 = new Vector3(x + 1, y, heightmap[y * 256 + x + 1]); Vector3 v3 = new Vector3(x, y + 1, heightmap[(y + 1) * 256 + x]); warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); norm = norm.reverse(); obj.vertex(v).n = norm; // Triangle 1 obj.addTriangle( v, v + 1, v + 256); // Triangle 2 obj.addTriangle( v + 256 + 1, v + 256, v + 1); } } } renderer.Scene.addObject("Terrain", obj); UUID[] textureIDs = new UUID[4]; float[] startHeights = new float[4]; float[] heightRanges = new float[4]; RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; textureIDs[0] = regionInfo.TerrainTexture1; textureIDs[1] = regionInfo.TerrainTexture2; textureIDs[2] = regionInfo.TerrainTexture3; textureIDs[3] = regionInfo.TerrainTexture4; startHeights[0] = (float)regionInfo.Elevation1SW; startHeights[1] = (float)regionInfo.Elevation1NW; startHeights[2] = (float)regionInfo.Elevation1SE; startHeights[3] = (float)regionInfo.Elevation1NE; heightRanges[0] = (float)regionInfo.Elevation2SW; heightRanges[1] = (float)regionInfo.Elevation2NW; heightRanges[2] = (float)regionInfo.Elevation2SE; heightRanges[3] = (float)regionInfo.Elevation2NE; uint globalX, globalY; Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); warp_Texture texture; using ( Bitmap image = TerrainSplat.Splat( heightmap, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) { texture = new warp_Texture(image); } warp_Material material = new warp_Material(texture); material.setReflectivity(50); renderer.Scene.addMaterial("TerrainColor", material); renderer.Scene.material("TerrainColor").setReflectivity(0); // reduces tile seams a bit thanks lkalif renderer.SetObjectMaterial("Terrain", "TerrainColor"); }
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; }