public void InitializeGeometry(RenderManager RenderManager) { Geom = new Geometry3D(Name); Geom.Shader = RenderManager.Shaders["Water"].Clone(); Geom.Shader.Parameters["TerrainScale"].SetValue(WorldFile.TerrainScale); Geom.Shader.Parameters["HeightScale"].SetValue(WorldFile.HeightScale); Geom.Shader.Parameters["TerrainWidth"].SetValue(WorldFile.SX); Geom.Shader.Parameters["TerrainLength"].SetValue(WorldFile.SY); Geom.Shader.Parameters["WaveMap"].SetValue(RenderManager.Textures["WaveMap1"]); Geom.Shader.Parameters["WaveMap2"].SetValue(RenderManager.Textures["WaveMap2"]); Geom.Shader.Parameters["FoamMap"].SetValue(RenderManager.Textures["Foam"]); Geom.Shader.Parameters["NoiseMap"].SetValue(RenderManager.Textures["Noise"]); Geom.Shader.Parameters["NearPlane"].SetValue(RenderManager.Camera.NearPlaneClip); Geom.Shader.Parameters["FarPlane"].SetValue(RenderManager.Camera.FarPlaneClip); ReflectionRenderTarget.AddClipMap(Name, new Texture2D(RenderManager.Graphics, WorldFile.SX + 1, WorldFile.SY + 1), new Vector3(Position.X, Position.Y, Position.Z), new Vector4(WorldFile.SX * WorldFile.TerrainScale, WorldFile.SY * WorldFile.TerrainScale, WorldFile.HeightScale, 0)); RefractionRenderTarget.AddClipMap(Name, new Texture2D(RenderManager.Graphics, WorldFile.SX + 1, WorldFile.SY + 1), new Vector3(Position.X, Position.Y, Position.Z), new Vector4(WorldFile.SX * WorldFile.TerrainScale, WorldFile.SY * WorldFile.TerrainScale, WorldFile.HeightScale, 0)); DepthMapRenderTarget.AddClipMap(Name, new Texture2D(RenderManager.Graphics, WorldFile.SX + 1, WorldFile.SY + 1), new Vector3(Position.X, Position.Y, Position.Z), new Vector4(WorldFile.SX * WorldFile.TerrainScale, WorldFile.SY * WorldFile.TerrainScale, WorldFile.HeightScale, 0)); ReflectionRenderTarget.SetClipMapPosition(Name, Position); RefractionRenderTarget.SetClipMapPosition(Name, Position); DepthMapRenderTarget.SetClipMapPosition(Name, Position); Geom.HasCull = false; Geom.Position = WorldFile.GetPosition(); Geom.RenderBucket = Geometry3D.RenderQueue.Transparent; Geom.CurrentRenderMode = Geometry3D.RenderMode.NonIndexBufferless; Geom.VertexCount = (WorldFile.WaterHeightMap.GetLength(0) - 1) * (WorldFile.WaterHeightMap.GetLength(1) - 1) * 6; }
public void Update(RenderManager Render, SettingsContainer WorldSettings, Vector3 Position) { int[] LOD = WorldSettings.LOD; Vector3 FilePosition = WorldFile.GetPosition(); float Distance = Math.Min(Math.Abs(Position.X - FilePosition.X), Math.Abs(Position.Y - FilePosition.Y)); if (MaterialData0.Width != WorldFile.MaterialMap.GetLength(0) || MaterialData0.Height != WorldFile.MaterialMap.GetLength(1)) { MaterialData0.Dispose(); MaterialData1.Dispose(); MaterialData0 = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, WorldFile.MaterialMap, WorldFile.SecondaryMaterialMap, WorldFile.DecalMaterialMap, WorldFile.DecalMaterialMap); MaterialData1 = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, WorldFile.BlendAlphaMap, WorldFile.DecalAlphaMap, WorldFile.DecalAlphaMap, WorldFile.DecalAlphaMap); } if (WorldFile.HasTerrainUpdate) { TerrainGeometry.DepthShader.Parameters["TerrainScale"].SetValue(WorldFile.TerrainScale); TerrainGeometry.Shader.Parameters["TerrainScale"].SetValue(WorldFile.TerrainScale); TerrainGeometry.DepthShader.Parameters["TerrainWidth"].SetValue(WorldFile.SX); TerrainGeometry.DepthShader.Parameters["TerrainHeight"].SetValue(WorldFile.SY); TerrainGeometry.DepthShader.Parameters["HeightScale"].SetValue(WorldFile.HeightScale); TerrainGeometry.Shader.Parameters["HeightScale"].SetValue(WorldFile.HeightScale); GraphicsUtil.FillTexture(HeightMap, WorldFile.HeightMap); GraphicsUtil.FillTexture(MaterialData0, WorldFile.MaterialMap, WorldFile.SecondaryMaterialMap, WorldFile.DecalMaterialMap, WorldFile.DecalMaterialMap); GraphicsUtil.FillTexture(MaterialData1, WorldFile.BlendAlphaMap, WorldFile.DecalAlphaMap, WorldFile.DecalAlphaMap, WorldFile.DecalAlphaMap); TerrainGeometry.Shader.Parameters["TerrainWidth"].SetValue(WorldFile.SX); TerrainGeometry.Shader.Parameters["TerrainHeight"].SetValue(WorldFile.SY); TerrainGeometry.Shader.Parameters["MaterialWidth"].SetValue(WorldFile.MaterialMap.GetLength(0)); TerrainGeometry.Shader.Parameters["MaterialHeight"].SetValue(WorldFile.MaterialMap.GetLength(1)); TerrainGeometry.Shader.Parameters["MaterialData0"].SetValue(MaterialData0); TerrainGeometry.Shader.Parameters["MaterialData1"].SetValue(MaterialData1); TerrainGeometry.Shader.Parameters["HeightMap"].SetValue(HeightMap); TerrainGeometry.DepthShader.Parameters["HeightMap"].SetValue(HeightMap); } Vector3 LightPosition = new Vector3(0, 0, 20); TerrainGeometry.Shader.Parameters["CameraPosition"].SetValue(Position); TerrainGeometry.Shader.Parameters["LightPosition"].SetValue(WorldSettings.DebugLightPosition); TerrainGeometry.Shader.Parameters["LightColor"].SetValue(WorldSettings.DebugDirectLightColor); TerrainGeometry.Shader.Parameters["AmbientLightColor"].SetValue(WorldSettings.DebugAmbientLightColor); TerrainGeometry.Position = WorldFile.GetPosition(); }
public void InitializeGeometry(RenderManager RenderManager, SettingsContainer WorldSettings) { TerrainGeometry = new Geometry3D(Name); TerrainGeometry.Shader = RenderManager.Shaders["Terrain"].Clone(); TerrainGeometry.DepthShader = RenderManager.Shaders["Depth-Terrain"].Clone(); TerrainGeometry.Shader.Parameters["TextureSize"].SetValue(1.0f / WorldSettings.TextureSize); TerrainGeometry.DepthShader.Parameters["TerrainScale"].SetValue(WorldFile.TerrainScale); TerrainGeometry.Shader.Parameters["TerrainScale"].SetValue(WorldFile.TerrainScale); TerrainGeometry.Shader.Parameters["TerrainWidth"].SetValue(WorldFile.SX); TerrainGeometry.Shader.Parameters["TerrainHeight"].SetValue(WorldFile.SY); TerrainGeometry.DepthShader.Parameters["TerrainWidth"].SetValue(WorldFile.SX); TerrainGeometry.DepthShader.Parameters["TerrainHeight"].SetValue(WorldFile.SY); TerrainGeometry.Shader.Parameters["MaterialWidth"].SetValue(WorldFile.MaterialMap.GetLength(0)); TerrainGeometry.Shader.Parameters["MaterialHeight"].SetValue(WorldFile.MaterialMap.GetLength(1)); TerrainGeometry.Shader.Parameters["DiffuseMap"].SetValue(RenderManager.Textures["Terrain-Diffuse"]); TerrainGeometry.Shader.Parameters["RoughnessMap"].SetValue(RenderManager.Textures["Terrain-Roughness"]); TerrainGeometry.Shader.Parameters["MaterialNormalMap"].SetValue(RenderManager.Textures["Terrain-Normal"]); TerrainGeometry.Shader.Parameters["MetalnessMap"].SetValue(RenderManager.Textures["Terrain-Metalness"]); TerrainGeometry.Shader.Parameters["DecalDiffuseMap"].SetValue(RenderManager.Textures["TerrainDecal-Diffuse"]); TerrainGeometry.Shader.Parameters["DecalMetalnessMap"].SetValue(RenderManager.Textures["TerrainDecal-Roughness"]); TerrainGeometry.Shader.Parameters["DecalNormalMap"].SetValue(RenderManager.Textures["TerrainDecal-Normal"]); TerrainGeometry.Shader.Parameters["DecalRoughnessMap"].SetValue(RenderManager.Textures["TerrainDecal-Roughness"]); TerrainGeometry.Shader.Parameters["DecalToleranceMap"].SetValue(RenderManager.Textures["TerrainDecal-Tolerance"]); Vector3 ChunkPosition = new Vector3(WorldFile.IDX * WorldFile.SX * WorldFile.TerrainScale, WorldFile.IDY * WorldFile.SY * WorldFile.TerrainScale, 0); TerrainGeometry.Shader.Parameters["Position"].SetValue(ChunkPosition); TerrainGeometry.DepthShader.Parameters["Position"].SetValue(ChunkPosition); TerrainGeometry.HasCull = false; TerrainGeometry.Position = WorldFile.GetPosition(); TerrainGeometry.RenderBucket = Geometry3D.RenderQueue.Solid; TerrainGeometry.CurrentRenderMode = Geometry3D.RenderMode.NonIndexBufferless; TerrainGeometry.VertexCount = (WorldFile.HeightMap.GetLength(0) - 1) * (WorldFile.HeightMap.GetLength(1) - 1) * 6; }
public void InitializeGeometry(RenderManager RenderManager) { Geom = new Geometry3D(Name); Geom.Shader = RenderManager.Shaders["TerrainCover"].Clone(); Geom.Shader.Parameters["TerrainScale"].SetValue(WorldFile.TerrainScale); Geom.Shader.Parameters["TerrainWidth"].SetValue(WorldFile.SX); Geom.Shader.Parameters["TerrainHeight"].SetValue(WorldFile.SY); Geom.Shader.Parameters["HeightScale"].SetValue(WorldFile.HeightScale); Vector3 ChunkPosition = new Vector3(WorldFile.IDX * WorldFile.SX * WorldFile.TerrainScale, WorldFile.IDY * WorldFile.SY * WorldFile.TerrainScale, 0); Geom.Shader.Parameters["Position"].SetValue(ChunkPosition); Geom.HasCull = false; Geom.Position = WorldFile.GetPosition(); Geom.RenderBucket = Geometry3D.RenderQueue.Transparent; Geom.CurrentRenderMode = Geometry3D.RenderMode.NonIndexBufferless; Geom.VertexCount = (WorldFile.HeightMap.GetLength(0) - 1) * (WorldFile.HeightMap.GetLength(1) - 1) * 6; }
public CollisionResults RayCastWater(Vector3 Origin, Vector3 Direction, float Range, WorldFile File) { if (FileManager.MasteryFile == null) { return(new CollisionResults()); } SettingsContainer Settings = FileManager.MasteryFile.Settings; List <WorldFile> ActiveWorldFiles = FileManager.MasteryFile.ActiveWorldFiles; List <Vector2> QuadCheck = new List <Vector2>(); CollisionResults Results = new CollisionResults(); int LOD = FileManager.CurrentWorldFile.LODID; if (FileManager.CurrentWorldFile != null) { float TerrainScale = File.TerrainScale; float HeightScale = File.HeightScale; int[,] HeightMap = File.HeightMap; int[,] WaterHeightMap = File.WaterHeightMap; float Precision = TerrainScale * 0.5f; for (float j = 0; j < Range; j += Precision) { Vector3 CurrentPosition = Origin + (Direction * j); Vector3 CurrentVertexPosition = (CurrentPosition - File.GetPosition()) / TerrainScale; int VX = (int)Math.Floor(CurrentVertexPosition.X); int VY = (int)Math.Floor(CurrentVertexPosition.Y); if (VX < 0 || VY < 0 || VX >= HeightMap.GetLength(0) - 1 || VY >= HeightMap.GetLength(1) - 1) { continue; } float MidPoint = (HeightMap[VX, VY] + HeightMap[VX + 1, VY] + HeightMap[VX, VY + 1] + HeightMap[VX + 1, VY + 1] + WaterHeightMap[VX, VY] + WaterHeightMap[VX + 1, VY] + WaterHeightMap[VX, VY + 1] + WaterHeightMap[VX + 1, VY + 1]) / 4; Vector3[] QuadVertices = { new Vector3(0, 0, (WaterHeightMap[VX, VY] + HeightMap[VX, VY]) * HeightScale), new Vector3(TerrainScale, 0, (WaterHeightMap[VX + 1, VY] + HeightMap[VX + 1, VY]) * HeightScale), new Vector3(0, TerrainScale, (WaterHeightMap[VX, VY + 1] + HeightMap[VX, VY + 1]) * HeightScale), new Vector3(TerrainScale, TerrainScale, (WaterHeightMap[VX + 1, VY + 1] + HeightMap[VX + 1, VY + 1]) * HeightScale) }; if (!QuadCheck.Contains(new Vector2(VX, VY))) { QuadCheck.Add(new Vector2(VX, VY)); Vector3 VertexWorldPosition = File.GetPosition() + new Vector3(VX * TerrainScale, VY * TerrainScale, 0); for (int k = 0; k < Indices.Length; k += 3) { Vector3 V0 = VertexWorldPosition + QuadVertices[Indices[k]]; Vector3 V1 = VertexWorldPosition + QuadVertices[Indices[k + 1]]; Vector3 V2 = VertexWorldPosition + QuadVertices[Indices[k + 2]]; if (CollisionUtil.Intersect(V0, V1, V2, Origin, Direction)) { TerrainWaterContainer WaterGeom = WaterGeometries.Where(x => x.WorldFile.FileName == FileManager.CurrentWorldFile.FileName).First(); Vector3 CollisionPoint = CollisionUtil.GetCollisionPoint(V0, V1, V2, Origin, Direction); CollisionResult Result = new CollisionResult( V0, V1, V2, Origin, CollisionPoint, WaterGeom.Geom); Results.Add(Result); } } } } } return(Results); }
public void Update(RenderManager Render, Vector3 Position, Vector3 ViewDirection, float Time) { int[] LOD = WorldSettings.LOD; Vector3 FilePosition = WorldFile.GetPosition(); float Distance = Math.Min(Math.Abs(Position.X - FilePosition.X), Math.Abs(Position.Y - FilePosition.Y)); //TODO if (WaterData0.Width != WorldFile.WaterMap.GetLength(0) || WaterData0.Height != WorldFile.WaterMap.GetLength(1)) { WaterData0.Dispose(); WaterData1.Dispose(); WaterColorData0.Dispose(); WaterColorData1.Dispose(); WaterData0 = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, WorldFile.FlowXMap, WorldFile.FlowYMap, WorldFile.FlowPulseSpeedMap, WorldFile.FlowBackTimeMap); WaterData1 = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, WorldFile.WaterMap); WaterColorData0 = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, WorldFile.WaterColorR, WorldFile.WaterColorG, WorldFile.WaterColorB, WorldFile.WaterColorA); WaterColorData1 = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, WorldFile.WaterNormalMap, WorldFile.WaterFresnelMap, WorldFile.FoamRampMap0, WorldFile.WaterColorFalloffMap); WaveData0 = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, WorldFile.WaveLengthMap, WorldFile.WaveHeightMap, WorldFile.WaveHeightMap, WorldFile.WaveLengthMap); } if (WorldFile.HasTerrainUpdate) { Geom.Shader.Parameters["TerrainScale"].SetValue(WorldFile.TerrainScale); Geom.Shader.Parameters["HeightScale"].SetValue(WorldFile.HeightScale); Geom.Shader.Parameters["TerrainWidth"].SetValue(WorldFile.SX); Geom.Shader.Parameters["TerrainLength"].SetValue(WorldFile.SY); Geom.Shader.Parameters["DataWidth"].SetValue(WorldFile.FlowXMap.GetLength(0)); Geom.Shader.Parameters["DataHeight"].SetValue(WorldFile.FlowXMap.GetLength(1)); GraphicsUtil.FillTexture(WaterData0, WorldFile.FlowXMap, WorldFile.FlowYMap, WorldFile.FlowPulseSpeedMap, WorldFile.FlowBackTimeMap); GraphicsUtil.FillTexture(WaterData1, WorldFile.WaterMap); GraphicsUtil.FillTexture(WaterColorData0, WorldFile.WaterColorR, WorldFile.WaterColorG, WorldFile.WaterColorB, WorldFile.WaterColorA); GraphicsUtil.FillTexture(WaterColorData1, WorldFile.WaterNormalMap, WorldFile.WaterFresnelMap, WorldFile.FoamRampMap0, WorldFile.WaterColorFalloffMap); GraphicsUtil.FillTexture(WaveData0, WorldFile.WaveLengthMap, WorldFile.WaveHeightMap, WorldFile.FoamRampMap0, WorldFile.WaterColorFalloffMap); Geom.Shader.Parameters["WaterDataMap0"].SetValue(WaterData0); Geom.Shader.Parameters["WaterDataMap1"].SetValue(WaterData1); Geom.Shader.Parameters["ColorDataMap0"].SetValue(WaterColorData0); Geom.Shader.Parameters["ColorDataMap1"].SetValue(WaterColorData1); Geom.Shader.Parameters["WaveDataMap0"].SetValue(WaveData0); Geom.Shader.Parameters["HeightMap"].SetValue(Terrain.HeightMap); WaterHeightMap.Dispose(); WaterHeightMap = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, WorldFile.WaterHeightMap); //GraphicsUtil.FillTexture(WaterHeightMap, WorldFile.WaterHeightMap); Geom.Shader.Parameters["WaterHeightMap"].SetValue(WaterHeightMap); WaterClipMap.Dispose(); WaterClipMap = GraphicsUtil.MaterialMapsToTexture(Render.Graphics, VoxelUtil.AddValues(WorldFile.HeightMap, WorldFile.WaterHeightMap)); ReflectionRenderTarget.SetClipPlaneMap(Name, WaterClipMap); RefractionRenderTarget.SetClipPlaneMap(Name, WaterClipMap); DepthMapRenderTarget.SetClipPlaneMap(Name, WaterClipMap); } Geom.Shader.Parameters["ShineDamper"].SetValue(WorldSettings.WaterShineDamper); Geom.Shader.Parameters["Reflectivity"].SetValue(WorldSettings.WaterReflectivity); Geom.Shader.Parameters["MinSpecular"].SetValue(WorldSettings.MinimumSpecular); Geom.Shader.Parameters["WaterRepeatTime"].SetValue(WorldSettings.WaterRepeatTime); Geom.Shader.Parameters["WaterSpeed"].SetValue(WorldSettings.WaterSpeed); Geom.PassSetting = WorldSettings.WaterPassSetting; Geom.PassMipSetting = WorldSettings.WaterPassMipSetting; Geom.Shader.Parameters["TexSize"].SetValue(WorldSettings.TextureSize); Vector3 ChunkPosition = new Vector3(WorldFile.IDX * WorldFile.SX * WorldFile.TerrainScale, WorldFile.IDY * WorldFile.SX * WorldFile.TerrainScale, 0); Geom.Shader.Parameters["Position"].SetValue(ChunkPosition); Geom.Position = WorldFile.GetPosition(); }