public Terrain(Program owner) { vegetation = new Vegetation(owner); ground = new GameObject(); heightMap = new Heightmap("data/text_height.png", 1000f, 100, 100); heightMap.MaxHeight = 100f; TerrainMesh sceneryMesh = new TerrainMesh(1.0f, heightMap); //sceneryMesh.Texture = new Bonsai.Objects.Textures.TextureBase("data\\grass.png"); ground.Mesh = sceneryMesh; //ground.RotateXAngle = (float)Math.PI / 2; splatShader = new ShaderBase("splatting", "splatting3.fx"); if (Framework.Instance.DeviceCaps.PixelShaderVersion.Major >= 3) { splatShader.SetTechnique("TextureSplatting_fx30"); } else { splatShader.SetTechnique("TextureSplatting"); } splatShader.SetVariable("matViewProj", ShaderBase.ShaderParameters.CameraProjection); splatShader.SetVariable("sunPosition", new Vector3(1, 1, 1)); splatShader.SetVariable("underwater", 0.0f); splatShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World); splatShader.SetVariable("matInvertTransposeWorld", ShaderBase.ShaderParameters.WorldInvertTranspose); splatShader.SetVariable("cameraPos", ShaderBase.ShaderParameters.CameraPosition); splatShader.SetVariable("nearRepeat", 64.0f); splatShader.SetVariable("farRepeat", 20.0f); splatShader.SetVariable("nearFactor2", 3.0f); splatShader.SetVariable("farFactor2", 2.0f); splatShader.SetVariable("nearFactor3", 3.0f); splatShader.SetVariable("farFactor3", 2.0f); splatShader.SetVariable("nearFactor4", 3.0f); splatShader.SetVariable("farFactor4", 2.0f); splatShader.SetVariable("blendSqDistance", 50f * 50f); splatShader.SetVariable("blendSqWidth", 1.0f / (200f * 200f)); TextureBase normalMap = new TextureBase("data/text_norm.png"); TextureBase alphaMap = new TextureBase("data/text.dds"); TextureBase grassTexture = new TextureBase("data/grass.png"); TextureBase rockTexture = new TextureBase("data/rock.png"); TextureBase rockNormal = new TextureBase("data/splat_rock_normal.jpg"); TextureBase sandTexture = new TextureBase("data/sand.png"); TextureBase concreteTexture = new TextureBase("data/road.png"); splatShader.SetVariable("NormalMapTexture", normalMap); splatShader.SetVariable("AlphaTexture", alphaMap); splatShader.SetVariable("DetailTexture1", grassTexture); splatShader.SetVariable("DetailTexture2", rockTexture); splatShader.SetVariable("DetailTexture2NormalMap", rockNormal); splatShader.SetVariable("DetailTexture3", sandTexture); splatShader.SetVariable("DetailTexture4", concreteTexture); ground.Shader = splatShader; }
public Flag(Vector3 position) { count++; pole = new GameObject(); flag = new GameObject(); if (meshPole == null) { meshPole = new XMesh("data/flagpole.x"); } if (meshFlag == null) { meshFlag = new XMesh("data/flag.x"); flagShader = new ShaderBase("FlagShader", "data/flag.fx"); flagShader.SetVariable("matWorldViewProj", ShaderBase.ShaderParameters.WorldProjection); flagShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World); flagShader.SetVariable("vecLightDir", new Vector3(-0.3529871f, 0.8714578f, -0.3405313f)); flagShader.SetTechnique("TFlag"); } //this.Position = new Microsoft.DirectX.Vector3((count % 2 == 0)?5f:-5f, 0, (count % 2 == 0)?50f:20f); this.Position = position; pole.Mesh = meshPole; pole.Scale = new Vector3(2, 2, 2); flag.Mesh = meshFlag; flag.Position = new Vector3(0, 2.3f, 0); flag.Shader = flagShader; this.AddChild(pole); this.AddChild(flag); this.Scale = new Microsoft.DirectX.Vector3(2f, 2f, 2f); if (!string.IsNullOrEmpty(oldTexture) && !string.IsNullOrEmpty(newTexture)) { meshFlag.ReplaceTexture(oldTexture, newTexture, true); flagShader.SetVariable("Texture", meshFlag.GetTexture(0)); } }
public WindSock() { count++; if (meshWindSock == null) { meshWindSock = new XMesh("flag.x"); flagShader = new ShaderBase("FlagShader", "flag.fx"); flagShader.SetVariable("matWorldViewProj", ShaderBase.ShaderParameters.WorldProjection); flagShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World); flagShader.SetTechnique("TVertexShaderOnly"); //texture = new TextureBase("EuropeFlag.jpg"); //flagShader.SetVariable("Tex0", texture); } this.Mesh = meshWindSock; this.Shader = flagShader; this.Scale = new Microsoft.DirectX.Vector3(1f, 1f, 1f); this.Position = new Microsoft.DirectX.Vector3(1, 1, 0); }
private void Initialize() { if (parameters.SceneryType == SceneryParameters.SceneryTypeEnum.Photofield) { if (parameters.HeightMapFile != null) { heightMap = new Heightmap(parameters.SceneryFolder + parameters.HeightMapFile, (float)parameters.HeightMapSize, parameters.HeightMapResolution, parameters.HeightMapResolution); heightMap.MinHeight = parameters.MinimumHeight; heightMap.MaxHeight = parameters.MaximumHeight; } else { heightMap = new Heightmap(1000); } photoScenery = new PhotoScenery(parameters); // Set lighting conditions if (definition != null) { if (definition.SkyTable.Rows.Count > 0) { DataRow dataRow = definition.SkyTable.Rows[0]; Vector3 ambientVector = (Vector3)dataRow["AmbientLight"]; Vector3 sunVector = (Vector3)dataRow["SunLight"]; SetSky(null, (Vector3)dataRow["SunPosition"], Color.FromArgb((int)(255 * ambientVector.X), (int)(255 * ambientVector.Y), (int)(255 * ambientVector.Z)), Color.FromArgb((int)(255 * sunVector.X), (int)(255 * sunVector.Y), (int)(255 * sunVector.Z)), (float)(dataRow["TerrainAmbient"]), (float)(dataRow["TerrainSun"])); lensFlare = new LensFlare(); } } } else { vegetation = new Vegetation(owner); ground = new GameObject(); heightMap = new Heightmap(parameters.SceneryFolder + parameters.HeightMapFile, 1000f, 100, 100); heightMap.MinHeight = parameters.MinimumHeight; heightMap.MaxHeight = parameters.MaximumHeight; TerrainMesh sceneryMesh = new TerrainMesh(1.0f, heightMap); ground.Mesh = sceneryMesh; // Load the detail settings currentDetail = Bonsai.Utils.Settings.GetValue("SceneryDetail", "2"); dynamicSceneryDetail = Convert.ToInt32(Bonsai.Utils.Settings.GetValue("DynamicScenery", "1")); if (currentDetail.Equals("1")) { sceneryMesh.Texture = new Bonsai.Objects.Textures.TextureBase(parameters.SplatLowFile); } else { //ground.RotateXAngle = (float)Math.PI / 2; //splatShader = new ShaderBase("splatting", "splatting3.fx"); //if (Framework.Instance.DeviceCaps.PixelShaderVersion.Major >= 3) // splatShader.SetTechnique("TextureSplatting_fx30"); //else // splatShader.SetTechnique("TextureSplatting"); splatShader = new ShaderBase("splatting", "splat.fx"); splatShader.SetTechnique("TextureSplatting"); splatShader.SetVariable("matViewProj", ShaderBase.ShaderParameters.CameraProjection); splatShader.SetVariable("sunPosition", new Vector3(1, 1, 1)); splatShader.SetVariable("underwater", 0.0f); splatShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World); splatShader.SetVariable("matInvertTransposeWorld", ShaderBase.ShaderParameters.WorldInvertTranspose); splatShader.SetVariable("cameraPos", ShaderBase.ShaderParameters.CameraPosition); splatShader.SetVariable("nearRepeat", 64.0f); splatShader.SetVariable("farRepeat", 16.0f); splatShader.SetVariable("nearFactor2", 1.0f); splatShader.SetVariable("farFactor2", 1.0f); splatShader.SetVariable("nearFactor3", 1.0f); splatShader.SetVariable("farFactor3", 1.0f); splatShader.SetVariable("nearFactor4", 5.0f); splatShader.SetVariable("farFactor4", 5.0f); splatShader.SetVariable("blendSqDistance", 50f * 50f); splatShader.SetVariable("blendSqWidth", 1.0f / (200f * 200f)); TextureBase normalMap = new TextureBase(parameters.NormalMapFile); TextureBase alphaMap = new TextureBase(parameters.SplatHighFile); //TextureBase grassTexture = new TextureBase("data/grass_zoomout.png"); TextureBase grassTexture = new TextureBase(parameters.Texture1File); TextureBase rockTexture = new TextureBase(parameters.Texture2File); //TextureBase rockNormal = new TextureBase("data/splat_rock_normal.jpg"); TextureBase sandTexture = new TextureBase(parameters.Texture3File); TextureBase concreteTexture = new TextureBase(parameters.Texture4File); splatShader.SetVariable("NormalMapTexture", normalMap); splatShader.SetVariable("AlphaTexture", alphaMap); splatShader.SetVariable("DetailTexture1", grassTexture); splatShader.SetVariable("DetailTexture2", rockTexture); //splatShader.SetVariable("DetailTexture2NormalMap", rockNormal); splatShader.SetVariable("DetailTexture3", sandTexture); splatShader.SetVariable("DetailTexture4", concreteTexture); ground.Shader = splatShader; } CreateSurroundings(); // Load the trees vegetation.LoadTrees(heightMap, definition); // Load the simple trees LoadSimpleTrees(definition); // Load the simple tall trees LoadSimpleTallTrees(definition); // Load the simple small trees LoadSimpleSmallTrees(definition); // Load the scenery objects LoadSceneryObjects(definition); // Load the windmills LoadWindmills(definition); // Load the weather LoadWeather(definition); // Load the dynamic scenery if (dynamicSceneryDetail > 0) { LoadDynamicScenery(definition); } // Load the sky sky = new GameObject(); DomeMesh skyDome = new DomeMesh(4500, 16, 16); sky.Mesh = skyDome; DataRow dataRow = definition.SkyTable.Rows[0]; foreach (DataRow skyRow in definition.SkyTable.Rows) { string skyName = skyRow["Name"].ToString(); if (skyName.Equals(Bonsai.Utils.Settings.GetValue("Sky"))) { dataRow = skyRow; break; } } // Load the water LoadWater(definition); //water = new Water(new Vector3(90, 0, 180), 100f, Bonsai.Objects.Terrain.Water.QualityLevelEnum.Low); if (dataRow != null) { Vector3 ambientVector = (Vector3)dataRow["AmbientLight"]; Vector3 sunVector = (Vector3)dataRow["SunLight"]; SetSky(dataRow["Texture"].ToString(), (Vector3)dataRow["SunPosition"], Color.FromArgb((int)(255 * ambientVector.X), (int)(255 * ambientVector.Y), (int)(255 * ambientVector.Z)), Color.FromArgb((int)(255 * sunVector.X), (int)(255 * sunVector.Y), (int)(255 * sunVector.Z)), (float)(dataRow["TerrainAmbient"]), (float)(dataRow["TerrainSun"])); } // Apply the ads if (Utility.MediaExists("ads/ad1.jpg")) { ApplyAds("ad.jpg", "ads/ad1.jpg"); } if (Utility.MediaExists("ads/ad2.jpg")) { ApplyAds("ad2.jpg", "ads/ad2.jpg"); } lensFlare = new LensFlare(); } #if EDITOR // Load the racing pylons LoadGates(definition); #else if (Program.Instance.Player != null) { Program.Instance.Player.Heightmap = heightMap; Program.Instance.Player.DefaultStartPosition = parameters.DefaultStartPosition; Program.Instance.Player.WaterStartPosition = parameters.WaterStartPosition; } SetWaterCallback(Program.Instance.OnFrameRenderWater); // Rerender the reflection if (Effects.Reflection.Instance != null) { Effects.Reflection.Instance.Invalidate(); } #endif }
public Water(Vector3 position, float size, QualityLevelEnum quality) { this.qualityLevel = quality; squareMesh = new SquareMesh(size, 1, 1, 1.0f); this.Mesh = squareMesh; this.RotateXAngle = (float)Math.PI / 2; this.Position = position; if (quality != QualityLevelEnum.Low) { Vector3 point1 = new Vector3(-1, 0f, 1); Vector3 point2 = new Vector3(1, 0f, 1); Vector3 point3 = new Vector3(-1, 0f, -1); Plane plane = Plane.FromPoints(point1, point2, point3); // reflection //reflectionTexture = new TextureBase(256, 256); reflectionClipPlane = plane; // refraction plane = Plane.FromPoints(point1, point2, point3); plane.C *= -1; refractionClipPlane = plane; waterNormalTexture = new TextureBase("waterbump.dds"); // initialize shader waterShader = new ShaderBase("water", "watereffects.fx"); waterShader.SetVariable("xWorld", ShaderBase.ShaderParameters.World); waterShader.SetVariable("xView", ShaderBase.ShaderParameters.View); waterShader.SetVariable("xReflectionView", ShaderBase.ShaderParameters.Reflection); waterShader.SetVariable("xProjection", ShaderBase.ShaderParameters.Projection); //waterShader.SetVariable("xReflectionMap", reflectionTexture); //waterShader.SetVariable("xRefractionMap", refractionTexture); waterShader.SetVariable("xDrawMode", reflectionRefractionRatio); waterShader.SetVariable("fresnelMode", fresnelMode); waterShader.SetVariable("xdullBlendFactor", 0.2f); waterShader.SetVariable("xEnableTextureBlending", 0); waterShader.SetVariable("xWaterBumpMap", waterNormalTexture); waterShader.SetVariable("xWaterPos", new Vector3(position.X, position.Z, position.Y)); // parameteres for the wave waterShader.SetVariable("WaveLength", 0.1f); waterShader.SetVariable("WaveHeight", 0.4f); waterShader.SetVariable("SunPosition", new Vector3(1.0f, 1.0f, 1.0f)); //waterShader.SetVariable("xCamPos", Framework.Instance.CurrentCamera.LookFrom); //waterShader.SetVariable("xTime", totalTime); waterShader.SetVariable("xWindForce", 20.0f); waterShader.SetVariable("xWindDirection", Matrix.RotationY(1.0f)); //specular reflection parameters waterShader.SetVariable("specPower", 364); waterShader.SetVariable("specPerturb", 4); waterShader.SetTechnique("Water"); CreateShaderResources(Framework.Instance.Device); this.Shader = waterShader; } else // low quality { squareMesh.Texture = new TextureBase("water.jpg"); } Framework.Instance.DeviceReset += new Bonsai.Core.EventArgs.DeviceEventHandler(Instance_DeviceReset); Framework.Instance.DeviceLost += new EventHandler(Instance_DeviceLost); }