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 GenerateWaterReflectionPoint(Vector3 CameraPosition, Vector3 ViewDirection) { float WaterHeight = (WorldFile.HeightMap[WorldFile.HeightMap.GetLength(0) / 2, WorldFile.HeightMap.GetLength(1) / 2] + WorldFile.WaterHeightMap[WorldFile.WaterHeightMap.GetLength(0) / 2, WorldFile.WaterHeightMap.GetLength(1) / 2]) * WorldFile.HeightScale; float ReflectionHeight = WaterHeight - (CameraPosition.Z - WaterHeight); Vector3 CameraPositionB = new Vector3(CameraPosition.X, CameraPosition.Y, ReflectionHeight); Vector3 ViewDirectionB = new Vector3(ViewDirection.X, ViewDirection.Y, ViewDirection.Z * -1.0f); ReflectionRenderTarget.SetPositionDirection(CameraPositionB, ViewDirectionB, new Vector3(0, 0, 1)); RefractionRenderTarget.SetPositionDirection(CameraPosition, ViewDirection, new Vector3(0, 0, 1)); DepthMapRenderTarget.SetPositionDirection(CameraPosition, ViewDirection, new Vector3(0, 0, 1)); }
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(); }