public TerrainRenderer(TerrainShader shader, Matrix4 projectionMatrix) { this.shader = shader; shader.Start(); shader.LoadProjectionMatrix(projectionMatrix); shader.Stop(); }
private bool Render() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, ortho, and base view matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoMatrix = D3D.OrthoMatrix; // Render the terrain using the terrain shader. TerrainModel.Render(D3D.DeviceContext); if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, Light.Direction, ColourTexture1.TextureResource, ColourTexture2.TextureResource, ColourTexture3.TextureResource, ColourTexture4.TextureResource, AlphaTexture1.TextureResource, NormalTexture1.TextureResource, NormalTexture2.TextureResource)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public Terrain(Device device, String texture, int pitch, Renderer renderer) { HeightMap = new System.Drawing.Bitmap(@"Data/Textures/" + texture); WaterShader = new WaterShader(device); TerrainShader = new TerrainShader(device); _width = HeightMap.Width - 1; _height = HeightMap.Height - 1; _pitch = pitch; _terrainTextures = new ShaderResourceView[4]; _terrainTextures[0] = new Texture(device, "Sand.png").TextureResource; _terrainTextures[1] = new Texture(device, "Grass.png").TextureResource; _terrainTextures[2] = new Texture(device, "Ground.png").TextureResource; _terrainTextures[3] = new Texture(device, "Rock.png").TextureResource; _reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f); _refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f); _noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000); _reflectionTexture = new RenderTexture(device, renderer.ScreenSize); _refractionTexture = new RenderTexture(device, renderer.ScreenSize); _renderer = renderer; _bitmap = new Bitmap(device, _refractionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0); _bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0); _bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0); _bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120); _bumpMap = _renderer.TextureManager.Create("OceanWater.png"); _skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png")); BuildBuffers(device); WaveTranslation = new Vector2(0, 0); }
public void Shutdown() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the font shader object. FontShader?.Shuddown(); FontShader = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public TerrainRenderer(TerrainShader _shader) { shader = _shader; shader.Start(); shader.LoadTextureUnits(); shader.Stop(); }
private bool RenderGraphics() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, and ortho matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix cameraViewMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoD3DMatrix = D3D.OrthoMatrix; // Construct the frustum. Frustum.ConstructFrustum(DSystemConfiguration.ScreenDepth, projectionMatrix, cameraViewMatrix); // Set the terrain shader parameters only once now that it will use for rendering. if (!TerrainShader.SetShaderParameters(D3D.DeviceContext, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource)) { return(false); } // Render the terrain using the quad tree and terrain shader. QuadTree.Render(D3D.DeviceContext, Frustum, TerrainShader); // Set the number of rendered terrain triangles since some were culled. if (!Text.SetRenderCount(QuadTree.DrawCount, D3D.DeviceContext)) { return(false); } if (!Text.SetSentenceByIndex(11, "TEST", D3D.DeviceContext)) { return(false); } // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. if (!Text.Render(D3D.DeviceContext, FontShader, worldMatrix, orthoD3DMatrix)) { return(false); } // Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public void Render(DeviceContext deviceContext, Frustrum frustrum, TerrainShader terrainShader) { // Reset the number of the triangles that are drawn for this frame. DrawCount = 0; // Render each node that is visible at the parent node and moving down the tree. RenderNode(deviceContext, ParentNode, frustrum, terrainShader); }
public bool RenderTerrainShader(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, ShaderResourceView normal, Vector3 lightDirection, Vector4 diffuse) { if (!TerrainShader.Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, normal, lightDirection, diffuse)) { return(false); } return(true); }
public void Render(TerrainShader shader) { if (VertexBuffer == null || !VertexBuffer.DataSet) { return; } GL.DrawElements(BeginMode.LineStrip, indices.Length / 3, DrawElementsType.UnsignedShort, 0); }
public void Shutdown() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the water shader object. WaterShader?.ShutDown(); WaterShader = null; // Release the water object. WaterModel?.ShutDown(); WaterModel = null; // Release the reflection shader object. ReflectionShader?.ShutDown(); ReflectionShader = null; // Release the reflection render to texture object. ReflectionTexture?.Shutdown(); ReflectionTexture = null; // Release the refraction render to texture object. RefractionTexture?.Shutdown(); RefractionTexture = null; // Release the sky plane shader object. SkyPlaneShader?.ShutDown(); SkyPlaneShader = null; // Release the sky plane object. SkyPlane?.ShurDown(); SkyPlane = null; // Release the sky dome shader object. SkyDomeShader?.ShutDown(); SkyDomeShader = null; // Release the sky dome object. SkyDome?.ShutDown(); SkyDome = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public MainRenderer() { GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); createProjectionMatrix(); entityShader = new EntityShader("Flat"); renderer = new EntityRenderer(entityShader, ProjectionMatrix); terrainRenderer = new TerrainRenderer(terrainShader, ProjectionMatrix); terrainShader = new TerrainShader("Flat"); }
public static void CameraChanged(Video.ICamera cam) { TerrainShader.SetValue("matrixViewProj", cam.ViewProj); TerrainShader.SetValue("CameraPosition", cam.Position); SkyShader.SetValue("matrixViewProj", cam.ViewProj); MDXShader.SetValue("matrixViewProj", cam.ViewProj); MDXShader.SetValue("CameraPosition", cam.Position); WMOShader.SetValue("matrixViewProj", cam.ViewProj); WMOShader.SetValue("CameraPosition", cam.Position); BoxShader.SetValue("matrixViewProj", cam.ViewProj); }
public void ShutDown() { // Release the sky dome shader object. SkyDomeShader.ShutDown(); SkyDomeShader = null; // Release the Terrain Shader ibject. TerrainShader?.ShutDown(); TerrainShader = null; // Release the font shader object. FontShader?.Shuddown(); FontShader = null; }
private bool RenderGraphics() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, and ortho matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix cameraViewMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoD3DMatrix = D3D.OrthoMatrix; // Render the terrain buffers. TerrainModel.Render(D3D.DeviceContext); // Render the model using the color shader. if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource)) { return(false); } // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Render the mini map. if (!MiniMap.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix, TextureShader)) { return(false); } // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix)) { return(false); } // Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private void SaveData(TerrainShader s) { paths = s.baseMaps.ToArray(); CleanPaths(paths); tiles = s.baseTiles.ToArray(); detPaths = s.detMaps.ToArray(); CleanPaths(detPaths); detTiles = s.detTiles.ToArray(); bumpmaps = s.bumpMaps.ToArray(); CleanPaths(bumpmaps); bumpTiles = s.bumpTiles.ToArray(); blendPath = s.blendPath.Replace('\\', '/') + ".tif"; blendTile = s.blendTile; }
public void Initiliaze(Camera camera) { entityShader = new EntityShader(); terrainShader = new TerrainShader(); shaderUI = new SpriteShader(); textShader = new TextShader(); skyboxShader = new SkyboxShader(); entityRenderer = new EntityRenderer(entityShader); terrainRenderer = new TerrainRenderer(terrainShader); spriteRenderer = new SpriteRenderer(shaderUI); textRenderer = new TextRenderer(textShader); skyboxRenderer = new SkyboxRenderer(skyboxShader, camera.GetProjectionMatrix()); }
public Terrain(IContext context, IList <LandProvince> provinces) { _borderTexture = context.TextureManager.Create("Border.png").TextureResource; _paperTexture = context.TextureManager.Create("paper.png", "Data/UI/").TextureResource; _hatchTexture = context.TextureManager.Create("hatch2.png", "Data/UI/").TextureResource; _shader = context.Shaders.Get <TerrainShader>(); _minimapShader = context.Shaders.Get <TerrainMinimapShader>(); BuildBuffers(context, provinces); _provinceColorTexture = GenerateProvinceTexture(context, provinces, p => p.Color); _realmColorTexture = GenerateProvinceTexture(context, provinces, p => p.Owner.Color); int maxFood = provinces.Max(p => p.FoodPotential()); _foodAvailabilityTexture = GenerateProvinceTexture(context, provinces, p => LevelColor(p.FoodPotential(), 0, maxFood)); CurrentRenderingMode = RenderingMode.Realm; }
public void Shutdown() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the depth shader object. DepthShader?.ShutDown(); DepthShader = null; // Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the debug window bitmap object. DebugWindow?.Shutdown(); DebugWindow = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
protected override void OnLoad(EventArgs e) { CursorVisible = false; Mouse.Move += OnMouseMove; Mouse.ButtonUp += OnMouseButtonUp; Mouse.ButtonDown += OnMouseButtonDown; Mouse.WheelChanged += OnMouseWheelChanged; myCamera = new Camera(MathHelper.Pi / 3.0f, (float)Width / (float)Height, 32768.0f); myShader = new TerrainShader(); myShader.Camera = myCamera; var stream = ResourceManager.ReadFile("5000000000.hght"); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); myTerrain = new Terrain(new ZeldaHeightmap(buffer)); }
public override void OnInspectorGUI() { //base.OnInspectorGUI(); TerrainShader shader = (TerrainShader)target; if (DrawDefaultInspector()) { if (shader.autoUpdateLighting) { shader.ApplyLighting(); } if (shader.autoUpdateTerrain) { shader.ApplyTerrain(); } if (shader.autoUpdateTextures) { shader.ApplyTextures(); } } }
static ShaderCollection() { TerrainShader = ShaderManager.Shaders.GetShader("TerrainShader"); TerrainShader.SetTechnique(0); SkyShader = ShaderManager.Shaders.GetShader("SkySphere"); SkyShader.SetTechnique(0); MDXShader = ShaderManager.Shaders.GetShader("MDXShader"); MDXShader.SetTechnique(0); WMOShader = ShaderManager.Shaders.GetShader("WMOShader"); WMOShader.SetTechnique(0); BoxShader = ShaderManager.Shaders.GetShader("BoxShader"); BoxShader.SetTechnique(0); Game.GameManager.PropertyChanged += (property) => { switch (property) { case Game.GameProperties.FogStart: { TerrainShader.SetValue("fogStart", Game.GameManager.WorldManager.FogStart); MDXShader.SetValue("fogStart", Game.GameManager.WorldManager.FogStart); WMOShader.SetValue("fogStart", Game.GameManager.WorldManager.FogStart); } break; case Game.GameProperties.FogDistance: { float fogEnd = Game.GameManager.WorldManager.FogStart + Game.GameManager.WorldManager.FogDistance; TerrainShader.SetValue("fogEnd", fogEnd); MDXShader.SetValue("fogEnd", fogEnd); WMOShader.SetValue("fogEnd", fogEnd); } break; } }; //if (Game.GameManager.IsPandaria) TerrainShader.SetValue("minimapMode", true); }
/// <summary> /// Generates a shader for a specific set of enabled textures. Results are cached internally. /// </summary> /// <param name="lighting">Get a shader with lighting enabled?</param> /// <param name="textureMask">A bitmask that indicates which textures are enabled.</param> internal TerrainShader GetTerrainShader(bool lighting, int textureMask) { var terrainShaders = lighting ? _terrainShadersLighting : _terrainShadersNoLighting; if (terrainShaders[textureMask] == null) { var texturesList = new LinkedList <int>(); for (int i = 0; i < 16; i++) { if (textureMask.HasFlag(1 << i)) { texturesList.AddLast(i + 1); } } var controllers = new Dictionary <string, IEnumerable <int> >(1) { { "textures", texturesList } }; RegisterChild(terrainShaders[textureMask] = new TerrainShader(lighting, controllers)); } return(terrainShaders[textureMask]); }
public void Shutdown() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the camera object. Camera = null; // Release the texture objects. ColourTexture1?.ShutDown(); ColourTexture1 = null; ColourTexture2?.ShutDown(); ColourTexture2 = null; ColourTexture3?.ShutDown(); ColourTexture3 = null; ColourTexture4?.ShutDown(); ColourTexture4 = null; AlphaTexture1?.ShutDown(); AlphaTexture1 = null; NormalTexture1?.ShutDown(); NormalTexture1 = null; NormalTexture2?.ShutDown(); NormalTexture2 = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
Material SetupTerrainMaterial(TerrainShader shader, string basePath) { Material material = new Material(Shader.Find("Adjutant/MultiBlend")); Texture2D tex; /* Debug.Log("Dumping Terrain Shader parameters: "+shader.sName); * * for(int i=0;i<shader.baseMaps.Count;i++){ * Debug.LogFormat("Base[{0}]:{1}",i,shader.baseMaps[i]); * } */ string overlayPath = null; for (int i = 0; i < shader.detMaps.Count; i++) { //Debug.LogFormat("Det[{0}]:{1}",i,shader.detMaps[i]); if (shader.detMaps[i].Contains("overlay")) { overlayPath = shader.detMaps[i]; } } if (overlayPath != null) { tex = (Texture2D)AssetDatabase.LoadAssetAtPath(basePath + overlayPath.Replace('\\', '/') + ".tif", typeof(Texture2D)); if (tex != null) { material.SetTexture("_MainTex", tex); TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(basePath + shader.detMaps[0].Replace('\\', '/') + ".tif"); if (ti != null) { material.SetFloat("_OverlayAlpha", (ti.DoesSourceTextureHaveAlpha()?1f:0f)); } } } tex = (Texture2D)AssetDatabase.LoadAssetAtPath(basePath + shader.blendPath.Replace('\\', '/') + ".tif", typeof(Texture2D)); if (tex != null) { material.SetTexture("_BlendTex", tex); } // tex = (Texture2D)AssetDatabase.LoadAssetAtPath(basePath+shader.baseMaps[0].Replace('\\','/')+".tif",typeof(Texture2D)); string texName = ""; Vector2 offset = Vector2.zero; //Texture2DArray baseMaps = new Texture2DArray(tex.width,tex.height,shader.baseMaps.Count,TextureFormat.DXT5,false); float hasAlpha; for (int i = 0; i < shader.baseMaps.Count; i++) { TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(basePath + shader.baseMaps[i].Replace('\\', '/') + ".tif"); if (ti == null) { continue; } hasAlpha = (ti.DoesSourceTextureHaveAlpha()?1f:0f); tex = (Texture2D)AssetDatabase.LoadAssetAtPath(basePath + shader.baseMaps[i].Replace('\\', '/') + ".tif", typeof(Texture2D)); if (tex != null) { switch (i) { case 0: texName = "_RTex"; offset = shader.baseTiles[i]; break; case 1: texName = "_GTex"; offset = shader.baseTiles[i]; break; case 2: texName = "_BTex"; offset = shader.baseTiles[i]; break; case 3: texName = "_ATex"; offset = shader.baseTiles[i]; break; } material.SetTexture(texName, tex); material.SetTextureScale(texName, offset); material.SetFloat(texName + "Alpha", hasAlpha); } // } //material.SetFloatArray("_HasAlpha",hasAlpha); //baseMaps.Apply(); //AssetDatabase.CreateAsset(baseMaps,basePath+shader.sName+"BaseMaps.asset"); //set blend //material.SetTexture("_BaseMaps",baseMaps); //set base //set tiling return(material); }
static void Main(string[] args) { Window w = new Window(1920, 1080); EngineCore.AddImage("default.png", "default"); DefaultShader ds = new DefaultShader("default.vert", "default.frag"); String defaultShader = EngineCore.AddShader(ds, "Default"); GUIShader gui = new GUIShader("gui.vert", "gui.frag"); String guiShader = EngineCore.AddShader(gui, "GUI"); WaterShader water = new WaterShader("water.vert", "water.frag"); String waterShader = EngineCore.AddShader(water, "Water"); SkyboxShader skybox = new SkyboxShader("skybox.vert", "skybox.frag"); String skyboxShader = EngineCore.AddShader(skybox, "Skybox"); ShadowShader shadow = new ShadowShader("shadow.vert", "shadow.frag"); String shadowShader = EngineCore.AddShader(shadow, "Shadow"); TerrainShader terrain = new TerrainShader("terrain.vert", "terrain.frag"); String terrainShader = EngineCore.AddShader(terrain, "Terrain"); String cubeModel = EngineCore.AddModel("cubeything.obj", "cube"); String terrainModel = EngineCore.AddModel("terrain.obj", "terrain"); String quad = EngineCore.AddModel("quad.obj", "Quad"); String cubeObj = EngineCore.AddModel("cube.obj", "Cube"); EngineCore.AddModel("tree.obj", "tree"); EngineCore.AddModel("rock.obj", "rock"); Light l = new Light(new Vector3(0, 3, 0), System.Drawing.Color.White); ds.lights.Add(l); terrain.lights.Add(l); Light l2 = new Light(new Vector3(0, 10, 0), System.Drawing.Color.White); water.lights.Add(l2); EngineCore.AddImage("tree.png", "treeImg"); EngineCore.AddImage("rock.png", "rockImg"); String boatObj = EngineCore.AddModel("boat.obj", "Boat"); EngineCore.AddImage("boards.jpg", "Boards"); Boat boat = new Boat(new Vector3(2, 0.2f, 2), new Vector3(0, 34, 0), new Vector3(0.25f, 0.25f, 0.25f), "Boards"); EngineCore.AddObject("Boat", boat); String ground = EngineCore.AddImage("grass.jpg", "Ground"); Terrain terrainObj = new Terrain("New Terrain", "Ground", "heightMap.png"); EngineCore.AddObject("Terrain", terrainObj); EngineCore.AddImage("dudv.png", "DuDvMap"); EngineCore.AddImage("normal.png", "NormalMap"); Water waterObj = new Water(new Vector3(0, 0.25f, 0), System.Drawing.Color.Blue, new Vector2(1920, 1080), "DuDvMap", new Vector3(10, 10, 10)); waterObj.AttachNormalMap("NormalMap"); EngineCore.AddObject("water", waterObj); EngineCore.AddSkybox(new string[] { "Skybox/xpos.png", "Skybox/xneg.png", "Skybox/ypos.png", "Skybox/yneg.png", "Skybox/zpos.png", "Skybox/zneg.png" }, "Skybox", 500); w.Run(); }
static void readShaders(BinaryReader reader, AMF amf, bool skip = false, bool dumpNames = false) { //ShaderInfo amf.shaderInfos = new List <AdjutantSharp.ShaderInfo>(); //ShaderTypes List <int> shaderTypes = new List <int>(); long sCount = reader.ReadInt32(); Debug.Log("Shader Count:" + sCount); long sAddress = reader.ReadInt32(); long fPos = reader.BaseStream.Position; int debugCount = 0; if (sCount > 0) { reader.BaseStream.Seek(sAddress, SeekOrigin.Begin); for (int i = 0; i < sCount; i++) { string sName = reader.ReadCString(); int sType = 0; if (sName.Substring(0, 1).Equals("*")) { sType = 1; sName = sName.Substring(1); } if (dumpNames) { if (sType == 0) { Console.Write("Regular"); } else { Console.Write("Terrain"); } Debug.Log("Shader:" + sName + " tints:" + (amf.version > 1.1f)); } shaderTypes.Add(sType); if (sType == 0) { amf.shaderInfos.Add(new RegularShader(sName, reader, amf.version > 1.1f, (dumpNames && debugCount < 1))); debugCount++; } else { amf.shaderInfos.Add(new TerrainShader(sName, reader)); if (dumpNames && amf.shaderInfos[i].sName.Equals("cust_wall")) { TerrainShader ts = (TerrainShader)amf.shaderInfos[i]; Debug.Log("cust_wall"); for (int maps = 0; maps < ts.baseMaps.Count; maps++) { Debug.Log("[" + maps + "]:" + ts.baseMaps[maps] + " [" + ts.baseTiles[maps].x + "," + ts.baseTiles[maps].y + "] " + ts.detMaps[maps] + " " + ts.detTiles[maps].ToString()); } Debug.Log("Blend tile:" + ts.blendPath + " " + ts.blendTile.ToString()); } } } } reader.BaseStream.Seek(fPos, SeekOrigin.Begin); }
private bool RenderGraphics() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, and ortho matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix cameraViewMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoD3DMatrix = D3D.OrthoMatrix; // Get the position of the camera. Vector3 cameraPostion = Camera.GetPosition(); // Translate the sky dome to be centered around the camera position. Matrix.Translation(cameraPostion.X, cameraPostion.Y, cameraPostion.Z, out worldMatrix); // Turn off back face culling. D3D.TurnOffCulling(); // Turn off the Z buffer. D3D.TurnZBufferOff(); // Render the sky dome using the sky dome shader. SkyDome.Render(D3D.DeviceContext); if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, SkyDome.ApexColour, SkyDome.CenterColour)) { return(false); } // Turn back face culling back on. D3D.TurnOnCulling(); // Enable additive blending so the clouds blend with the sky dome color. D3D.EnableSecondBlendState(); // Render the sky plane using the sky plane shader. SkyPlane.Render(D3D.DeviceContext); if (!SkyPlaneShader.Render(D3D.DeviceContext, SkyPlane.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, SkyPlane.CloudTexture.TextureResource, SkyPlane.PerturbTexture.TextureResource, SkyPlane.m_Translation, SkyPlane.m_Scale, SkyPlane.m_Brightness)) { return(false); } // Turn off blending D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on. D3D.TurnZBufferOn(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Render the terrain buffers. TerrainModel.Render(D3D.DeviceContext); // Render the model using the color shader. if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource)) { return(false); } //// Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); //// Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix)) { return(false); } //// Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); //// Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private bool Render() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, ortho, base view and reflection matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoMatrix = D3D.OrthoMatrix; Matrix baseViewMatrix = Camera.BaseViewMatrix; Matrix reflectionMatrix = Camera.ReflectionViewMatrix; // Get the position of the camera. Vector3 cameraPosition = Camera.GetPosition(); // Translate the sky dome to be centered around the camera position. Matrix.Translation(cameraPosition.X, cameraPosition.Y, cameraPosition.Z, out worldMatrix); // Turn off back face culling and the Z buffer. D3D.TurnOffCulling(); D3D.TurnZBufferOff(); // Render the sky dome using the sky dome shader. SkyDome.Render(D3D.DeviceContext); if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyDome.ApexColour, SkyDome.CenterColour)) { return(false); } // Turn back face culling back on. D3D.TurnOnCulling(); // Enable additive blending so the clouds blend with the sky dome color. D3D.EnableSecondBlendState(); // Render the sky plane using the sky plane shader. SkyPlane.Render(D3D.DeviceContext); if (!SkyPlaneShader.Render(D3D.DeviceContext, SkyPlane.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyPlane.CloudTexture.TextureResource, SkyPlane.PerturbTexture.TextureResource, SkyPlane.m_Translation, SkyPlane.m_Scale, SkyPlane.m_Brightness)) { return(false); } // Turn off blending. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on. D3D.TurnZBufferOn(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Render the terrain using the terrain shader. TerrainModel.Render(D3D.DeviceContext); if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, TerrainModel.ColorTexture.TextureResource, TerrainModel.NormalMapTexture.TextureResource, Light.DiffuseColour, Light.Direction, 2.0f)) { return(false); } // Translate to the location of the water and render it. Matrix.Translation(240.0f, WaterModel.WaterHeight, 250.0f, out worldMatrix); WaterModel.Render(D3D.DeviceContext); if (!WaterShader.Render(D3D.DeviceContext, WaterModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, reflectionMatrix, ReflectionTexture.ShaderResourceView, RefractionTexture.ShaderResourceView, WaterModel.Texture.TextureResource, Camera.GetPosition(), WaterModel.NormalMapTiling, WaterModel.WaterTranslation, WaterModel.ReflectRefractScale, WaterModel.RefractionTint, Light.Direction, WaterModel.SpecularShininess)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix); // Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private bool RenderGraphics() { // First render the scene to a texture. if (!RenderSceneToTexture()) { return(false); } // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); //// Get the world, view, projection, ortho, and base view matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix cameraViewMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoD3DMatrix = D3D.OrthoMatrix; Matrix baseViewMatrix = Camera.BaseViewMatrix; // Render the terrain buffers. TerrainModel.Render(D3D.DeviceContext); // Render the terrain using the terrain shader. if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource, TerrainModel.DetailTexture.TextureResource)) { return(false); } ///// Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Put the debug window on the graphics pipeline to prepare it for drawing. if (!DebugWindow.Render(D3D.DeviceContext, 100, 60)) { return(false); } // Render the bitmap model using the texture shader and the render to texture resource. if (!TextureShader.Render(D3D.DeviceContext, DebugWindow.IndexCount, worldMatrix, baseViewMatrix, orthoD3DMatrix, RenderTexture.ShaderResourceView)) { return(false); } // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix)) { return(false); } // Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); /// Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public static void UpdateTime(TimeSpan time) { TerrainShader.SetValue("gameTime", (float)time.TotalSeconds); }