public void Shutdown() { // Release the position object. Position = null; // Release the FPS object. FPS = null; // Release the camera object. Camera = null; // Release the foliage object. Foliage?.ShutDown(); Foliage = null; // Release the ground model object. GroundModel?.Shutdown(); GroundModel = null; // Release the user interface object. UserInterface?.ShutDown(); UserInterface = null; // Release the shader manager object. ShaderManager?.ShutDown(); ShaderManager = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private bool RenderSceneToTexture() { // Set the render target to be the render to texture. RenderTexture.SetRenderTarget(D3D.DeviceContext); // Clear the render to texture. RenderTexture.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f); // Get the world matrix from the d3d object. Matrix worldMatrix = D3D.WorldMatrix; // Generate the light view matrix based on the light's position. Light.GenerateViewMatrix(); // Get the view and orthographic matrices from the light object. Matrix lightViewMatrix = Light.ViewMatrix; Matrix lightOrthoMatrix = Light.OrthoMatrix; // Translate to the position of the tree. Vector3 treePosition = TreeModel.GetPosition(); Matrix.Translation(treePosition.X, treePosition.Y, treePosition.Z, out worldMatrix); // Render the tree trunk with the depth shader. TreeModel.RenderTrunk(D3D.DeviceContext); if (!DepthShader.Render(D3D.DeviceContext, TreeModel.TrunkIndexCount, worldMatrix, lightViewMatrix, lightOrthoMatrix)) { return(false); } // Render the tree leaves using the depth transparency shader. TreeModel.RenderLeaves(D3D.DeviceContext); if (!TransparentDepthShader.Render(D3D.DeviceContext, TreeModel.LeafIndexCount, worldMatrix, lightViewMatrix, lightOrthoMatrix, TreeModel.LeafTexture.TextureResource)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Translate to the position of the ground model. Vector3 groundPosition = GroundModel.GetPosition(); Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix); // Render the ground model with the depth shader. GroundModel.Render(D3D.DeviceContext); if (!DepthShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, lightViewMatrix, lightOrthoMatrix)) { return(false); } // Reset the render target back to the original back buffer and not the render to texture anymore. D3D.SetBackBufferRenderTarget(); // Reset the viewport back to the original. D3D.ResetViewPort(); return(true); }
[Test] public void TestEq2() { var a = new GroundModel(); var b = new GroundModel(); o(a != b); }
void OnCollisionEnter2D(Collision2D collider) { if (collider.gameObject.tag == "Ground") { GroundModel GM = collider.gameObject.GetComponent <GroundModel>(); if (GM.myColor != this.myColor) { gp.GameOver(); } ContactPoint2D point = collider.GetContact(0); Vector2 dist = -point.point + (Vector2)transform.position; float a = Vector2.Angle(rb.velocity, point.normal); if (a <= 90 && a >= 80 && rb.velocity.magnitude > 520 && ad.inAir == true) { Accelaration(); #if !UNITY_EDITOR Handheld.Vibrate(); #endif ad.inAir = false; } this.isGrounded = true; ad.inAir = false; } }
void Awake() { model = new GroundModel(); int n = 0; if (!useProps) { model.ClearProps(); } for (int x = 0; x < 11; x++) { for (int z = 0; z < 11; z++) { switch (model[n++]) { case 0: AddBlock(x, z); break; case 1: /* no-op */ break; default: throw new Ex($"Bad val: {model[n-1]}"); } } } foreach (var k in model.props) { AddProp(k); } }
void CreateNewPath(int count = 20) { List <GroundModel> newPath = new List <GroundModel>(); GameObject go; GroundModel gm; int counter = 0; for (int i = 0; i < count; i++) { if (i == 0) { go = Instantiate(details[0], Vector3.zero, Quaternion.identity); gm = go.GetComponent <GroundModel>(); gm.myRenderer.material.color = gp.curentColors[(int)Colors.First]; gm.myColor = Colors.First; startLine = gm; //newPath.Add(gm); } else { go = Instantiate(details[Random.Range(1, details.Length)], beginPosition, Quaternion.identity); gm = go.GetComponent <GroundModel>(); if (i == 1) { gm.Setup(startLine); } else { gm.Setup(newPath[i - 2]); } gm.ChangeColor(); newPath.Add(gm); //Instantiate color switcher counter = Random.Range(0, 2); for (int k = 0; k < counter; k++) { int x = Random.Range(0, 800); int y = Random.Range(400, 600); Instantiate(colorSwitcher, gm.transform.position + new Vector3(x, y, 0), Quaternion.identity, gm.transform); } //Instantiate coins counter = Random.Range(0, 2); for (int t = 0; t < counter; t++) { int x2 = Random.Range(0, 1000); int y2 = Random.Range(400, 600); Instantiate(coin, gm.transform.position + new Vector3(x2, y2, 0), Quaternion.identity, gm.transform); } } } alltPath = newPath.ToArray(); centralGround = alltPath[alltPath.Length / 2]; }
public void Shutdown() { // Release the light object. Light = null; Light2 = null; // Release the camera object. Camera = null; // Release the second render to texture object. RenderTexture2?.Shutdown(); RenderTexture2 = null; // Release the shadow shader object. ShadowShader?.ShutDown(); ShadowShader = null; // Release the depth shader object. DepthShader?.ShutDown(); DepthShader = null; /// Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the ground model object. GroundModel?.Shutdown(); GroundModel = null; // Release the sphere model object. SphereModel?.Shutdown(); SphereModel = null; // Release the cube model object. CubeModel?.Shutdown(); CubeModel = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public void Shutdown() { // Release the light object. Light = null; // Release the view point object. ViewPoint = null; // Release the camera object. Camera = null; // Release the projection texture object. ProjectionTexture?.ShutDown(); ProjectionTexture = null; // Release the projection shader object. ProjectionShader?.ShutDown(); ProjectionShader = null; // Release the ground model object. GroundModel?.Shutdown(); GroundModel = null; // Release the cube model object. CubeModel?.Shutdown(); CubeModel = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private void ShiftArrayLeft() { GroundModel firstGameModel = alltPath[0]; for (int i = 0; i < alltPath.Length - 1; i++) { alltPath[i] = alltPath[i + 1]; } alltPath[alltPath.Length - 1] = firstGameModel; centralGround = alltPath[alltPath.Length / 2]; }
private bool Render() { // Clear the buffers to begin 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, and projection matrices from the camera and d3d objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Get the view and projection matrices from the view point object. Matrix viewMatrix2 = ViewPoint.ViewMatrix; Matrix projectionMatrix2 = ViewPoint.ProjectionMatrix; // Setup the translation for the ground model. Matrix.Translation(0.0f, 1.0f, 0.0f, out worldMatrix); // Render the ground model using the projection shader. GroundModel.Render(D3D.DeviceContext); if (!ProjectionShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, GroundModel.Texture.TextureResource, Light.AmbientColor, Light.DiffuseColour, Light.Position, viewMatrix2, projectionMatrix2, ProjectionTexture.TextureResource)) { return(false); } // Reset the world matrix and setup the translation for the cube model. worldMatrix = D3D.WorldMatrix; Matrix.Translation(0.0f, 2.0f, 0.0f, out worldMatrix); // Render the cube model using the projection shader. CubeModel.Render(D3D.DeviceContext); if (!ProjectionShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, CubeModel.Texture.TextureResource, Light.AmbientColor, Light.DiffuseColour, Light.Position, viewMatrix2, projectionMatrix2, ProjectionTexture.TextureResource)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private bool Render() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 1.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; Matrix baseViewMatrix = Camera.BaseViewMatrix; // Render the ground model. GroundModel.Render(D3D.DeviceContext); ShaderManager.RenderTextureShader(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, GroundModel.ColourTexture.TextureResource); // Turn on the alpha-to-coverage blending. D3D.EnableSecondBlendState(); // Render the foliage. Foliage.Render(D3D.DeviceContext); if (!ShaderManager.RenderFoliageShader(D3D.DeviceContext, Foliage.VertexCount, Foliage.InstanceCount, viewCameraMatrix, projectionMatrix, Foliage.Texture.TextureResource)) { return(false); } // Turn off the alpha blending. D3D.TurnOffAlphaBlending(); // Render the user interface. UserInterface.Render(D3D, ShaderManager, worldMatrix, baseViewMatrix, orthoMatrix); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public void Shutdown() { // Release the light object. Light = null; // Release the camera object. Camera = null; // Release the water shader object. WaterShader?.ShutDown(); WaterShader = null; // Release the refraction shader object. RefractionShader?.ShutDown(); RefractionShader = null; /// Release the render to texture object. RenderReflectionTexture?.Shutdown(); RenderReflectionTexture = null; // Release the render to texture object. RenderRefractionTexture?.Shutdown(); RenderRefractionTexture = null; // Release the light shader object. LightShader?.ShutDown(); LightShader = null; // Release the model object. GroundModel?.Shutdown(); GroundModel = null; // Release the model object. WallModel?.Shutdown(); WallModel = null; // Release the model object. BathModel?.Shutdown(); BathModel = null; // Release the model object. WaterModel?.Shutdown(); WaterModel = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public void ShutDown() { DPerfLogger.ShutDown(); // Release the light object. Light = null; // Release the position object. Position = null; // Release the timer object. Timer = null; // Release the camera object. Camera = null; // Release the shadow shader object. ShadowShader?.ShutDown(); ShadowShader = null; // Release the transparent depth shader object. TransparentDepthShader?.ShutDown(); TransparentDepthShader = null; // Release the depth shader object. DepthShader?.ShutDown(); DepthShader = null; // Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the tree object. TreeModel?.Shutdown(); TreeModel = null; // Release the model object. GroundModel?.Shutdown(); GroundModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private bool RenderSceneToTexture2() { // Set the render target to be the render to texture. RenderTexture2.SetRenderTarget(D3D.DeviceContext); // Clear the render to texture. RenderTexture2.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f); // Generate the light view matrix based on the light's position. Light2.GenerateViewMatrix(); // Get the world matrix from the d3d object. Matrix worldMareix = D3D.WorldMatrix; // Get the view and orthographic matrices from the light object. Matrix lightViewMatrix = Light2.ViewMatrix; Matrix lightOrthoMatrix = Light2.ProjectionMatrix; // Setup the translation matrix for the cube model. Vector3 cubePosition = CubeModel.GetPosition(); Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMareix); // Render the cube model with the depth shader. CubeModel.Render(D3D.DeviceContext); if (!DepthShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMareix, lightViewMatrix, lightOrthoMatrix)) { return(false); } // Reset the world matrix. worldMareix = D3D.WorldMatrix; // Setup the translation matrix for the sphere model. Vector3 spherePosition = SphereModel.GetPosition(); Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMareix); // Render the sphere model with the depth shader. SphereModel.Render(D3D.DeviceContext); if (!DepthShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMareix, lightViewMatrix, lightOrthoMatrix)) { return(false); } // Reset the world matrix. worldMareix = D3D.WorldMatrix; // Setup the translation matrix for the ground model. Vector3 groundPosition = GroundModel.GetPosition(); Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMareix); // Render the ground model with the depth shader. GroundModel.Render(D3D.DeviceContext); if (!DepthShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMareix, lightViewMatrix, lightOrthoMatrix)) { return(false); } // Reset the render target back to the original back buffer and not the render to texture anymore. D3D.SetBackBufferRenderTarget(); // Reset the viewport back to the original. D3D.ResetViewPort(); return(true); }
public bool Render() { // First render the scene to a texture. if (!RenderSceneToTexture()) { return(false); } // Render the scene to texture again but use the second light's view point. if (!RenderSceneToTexture2()) { return(false); } // Clear the buffers to begin the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Generate the light view matrix based on the light's position. Light.GenerateViewMatrix(); // Do the same for the second light. Light2.GenerateViewMatrix(); // Get the world, view, and projection matrices from the camera and d3d objects. Matrix viewMatrix = Camera.ViewMatrix; Matrix worldMatrix = D3D.WorldMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Get the light's view and projection matrices from the light object. Matrix lightViewMatrix = Light.ViewMatrix; Matrix lightProjectionMatrix = Light.ProjectionMatrix; // Do the same for the second light. Matrix lightViewMatrix2 = Light2.ViewMatrix; Matrix lightProjectionMatrix2 = Light2.ProjectionMatrix; // Setup the translation matrix for the cube model. Vector3 cubePosition = CubeModel.GetPosition(); Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMatrix); // Put the cube model vertex and index buffers on the graphics pipeline to prepare them for drawing. CubeModel.Render(D3D.DeviceContext); // Render the model using the shadow shader. if (!ShadowShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, CubeModel.Texture.TextureResource, RenderTexture.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour, lightViewMatrix2, lightProjectionMatrix2, RenderTexture2.ShaderResourceView, Light2.Position, Light2.DiffuseColour)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Setup the translation matrix for the sphere model. Vector3 spherePosition = SphereModel.GetPosition(); Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMatrix); // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. SphereModel.Render(D3D.DeviceContext); if (!ShadowShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, SphereModel.Texture.TextureResource, RenderTexture.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour, lightViewMatrix2, lightProjectionMatrix2, RenderTexture2.ShaderResourceView, Light2.Position, Light2.DiffuseColour)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Setup the translation matrix for the ground model. Vector3 groundPosition = GroundModel.GetPosition(); Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix); // Render the ground model using the shadow shader. GroundModel.Render(D3D.DeviceContext); if (!ShadowShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, GroundModel.Texture.TextureResource, RenderTexture.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour, lightViewMatrix2, lightProjectionMatrix2, RenderTexture2.ShaderResourceView, Light2.Position, Light2.DiffuseColour)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
[SetUp] public void Setup() => ground = new GroundModel();
private bool Render() { // Render the depth of the scene to a texture. if (!RenderSceneToTexture()) { return(false); } // Clear the scene to Grey D3D.BeginScene(0.0f, 0.5f, 0.8f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Generate the light view matrix based on the light's position. Light.GenerateViewMatrix(); // Get the matrices from the camera and d3d objects. Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix worldMatrix = D3D.WorldMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Get the light's view and projection matrices from the light object. Matrix lightViewMatrix = Light.ViewMatrix; Matrix lightOrthoMatrix = Light.OrthoMatrix; // Set the light color attributes. Light.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); Light.SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f); // Translate to the position of the ground model. Vector3 groundPosition = GroundModel.GetPosition(); Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix); // Render the ground model using the shadow shader. GroundModel.Render(D3D.DeviceContext); if (!ShadowShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, lightViewMatrix, lightOrthoMatrix, GroundModel.Texture.TextureResource, RenderTexture.ShaderResourceView, Light.Direction, Light.AmbientColor, Light.DiffuseColour)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Translate to the position of the tree model. Vector3 treePosition = TreeModel.GetPosition(); Matrix.Translation(treePosition.X, treePosition.Y, treePosition.Z, out worldMatrix); // Render the tree trunk. TreeModel.RenderTrunk(D3D.DeviceContext); if (!ShadowShader.Render(D3D.DeviceContext, TreeModel.TrunkIndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, lightViewMatrix, lightOrthoMatrix, TreeModel.TrunkTexture.TextureResource, RenderTexture.ShaderResourceView, Light.Direction, Light.AmbientColor, Light.DiffuseColour)) { return(false); } // Enable blending and D3D.TurnOnAlphaBlending(); // Render the tree leaves. TreeModel.RenderLeaves(D3D.DeviceContext); if (!ShadowShader.Render(D3D.DeviceContext, TreeModel.LeafIndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, lightViewMatrix, lightOrthoMatrix, TreeModel.LeafTexture.TextureResource, RenderTexture.ShaderResourceView, Light.Direction, Light.AmbientColor, Light.DiffuseColour)) { return(false); } // Turn off Alpha Blending. D3D.TurnOffAlphaBlending(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private bool RenderScene() { // Generate the view matrix based on the camera position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; #region Render Ground Model // Translate to where the ground model will be rendered. Matrix.Translation(0f, 1f, 0f, out worldMatrix); // Put the ground model vertex and index buffers on the graphics pipeline to prepare them for drawing. GroundModel.Render(D3D.DeviceContext); // Render the ground model using the light shader. if (!LightShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, GroundModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Wall Model // Translate to where the ground model will be rendered. Matrix.Translation(0f, 6f, 8f, out worldMatrix); // Put the wall model vertex and index buffers on the graphics pipeline to prepare them for drawing. WallModel.Render(D3D.DeviceContext); // Render the wall model using the light shader. if (!LightShader.Render(D3D.DeviceContext, WallModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, WallModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Bath Model // Translate to where the bath model will be rendered. Matrix.Translation(0f, 2f, 0f, out worldMatrix); // Put the bath model vertex and index buffers on the graphics pipeline to prepare them for drawing. BathModel.Render(D3D.DeviceContext); // Render the bath model using the light shader. if (!LightShader.Render(D3D.DeviceContext, BathModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, BathModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Water Model // Get the camera reflection view matrix. var reflectionMatrix = Camera.ReflectionViewMatrix; // Translate to where the water model will be rendered. Matrix.Translation(0f, WaterHeight, 0f, out worldMatrix); // Put the water model vertex and index buffers on the graphics pipeline to prepare them for drawing. WaterModel.Render(D3D.DeviceContext); // Render the bath model using the light shader. if (!WaterShader.Render(D3D.DeviceContext, WaterModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix, RenderReflectionTexture.ShaderResourceView, RenderRefractionTexture.ShaderResourceView, WaterModel.TextureCollection.Select(item => item.TextureResource).First(), WaterTranslation, 0.1f)) // was 0.01f for scale originally. { return(false); } #endregion return(true); }
private bool RenderBlackAndWhiteShadows() { // Set the render target to be the render to texture. BlackWhiteRenderTexture.SetRenderTarget(D3D.DeviceContext); // Clear the render to texture. BlackWhiteRenderTexture.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Generate the light view matrix based on the light's position. Light.GenerateViewMatrix(); // Get the world, view, and projection matrices from the camera and d3d objects. Matrix cameraViewMatrix = Camera.ViewMatrix; Matrix worldMatrix = D3D.WorldMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Get the light's view and projection matrices from the light object. Matrix lightViewMatrix = Light.ViewMatrix; Matrix lightProjectionMatrix = Light.ProjectionMatrix; // Setup the translation matrix for the cube model. Vector3 cubePosition = CubeModel.GetPosition(); Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMatrix); // Render the cube model using the shadow shader. CubeModel.Render(D3D.DeviceContext); if (!ShadowShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, RenderTexture.ShaderResourceView, Light.Position)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Setup the translation matrix for the sphere model. Vector3 spherePosition = SphereModel.GetPosition(); Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMatrix); // Render the sphere model using the shadow shader. SphereModel.Render(D3D.DeviceContext); if (!ShadowShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, RenderTexture.ShaderResourceView, Light.Position)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Setup the translation matrix for the ground model. Vector3 groundPosition = GroundModel.GetPosition(); Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix); // Render the ground model using the shadow shader. GroundModel.Render(D3D.DeviceContext); if (!ShadowShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, RenderTexture.ShaderResourceView, Light.Position)) { return(false); } // Reset the render target back to the original back buffer and not the render to texture anymore. D3D.SetBackBufferRenderTarget(); // Reset the viewport back to the original. D3D.ResetViewPort(); return(true); }
public bool Render() { // First render the scene to a texture. if (!RenderSceneToTexture()) { return(false); } // Next render the shadowed scene in black and white. if (!RenderBlackAndWhiteShadows()) { return(false); } // Then down sample the black and white scene texture. if (!DownSampleTexture()) { return(false); } // Perform a horizontal blur on the down sampled texture. if (!RenderHorizontalBlurToTexture()) { return(false); } // Now perform a vertical blur on the texture. if (!RenderVerticalBlurToTexture()) { return(false); } // Finally up sample the final blurred render to texture that can now be used in the soft shadow shader. if (!UpSampleTexture()) { return(false); } // Clear the buffers to begin 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, and projection matrices from the camera and d3d objects. Matrix viewMatrix = Camera.ViewMatrix; Matrix worldMatrix = D3D.WorldMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Setup the translation matrix for the cube model. Vector3 cubePosition = CubeModel.GetPosition(); Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMatrix); // Render the cube model using the soft shadow shader. CubeModel.Render(D3D.DeviceContext); if (!SoftShadowShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, CubeModel.Texture.TextureResource, UpSampleTexure.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Setup the translation matrix for the sphere model. Vector3 spherePosition = SphereModel.GetPosition(); Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMatrix); // Render the sphere model using the soft shadow shader. SphereModel.Render(D3D.DeviceContext); if (!SoftShadowShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, SphereModel.Texture.TextureResource, UpSampleTexure.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Setup the translation matrix for the ground model. Vector3 groundPosition = GroundModel.GetPosition(); Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix); // Render the ground model using the shadow shader. GroundModel.Render(D3D.DeviceContext); if (!SoftShadowShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, GroundModel.Texture.TextureResource, UpSampleTexure.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
[SetUp] public void Setup() { ground = new GroundModel(); ground.Clear(); }
public void Shutdown() { // Release the light object. Light = null; // Release the camera object. Camera = null; // Release the soft shadow shader object. SoftShadowShader?.ShutDown(); SoftShadowShader = null; // Release the full screen ortho window object. FullScreenWindow?.Shutdown(); FullScreenWindow = null; // Release the up sample render to texture object. UpSampleTexure?.Shutdown(); UpSampleTexure = null; // Release the vertical blur shader object. VerticalBlurShader?.ShutDown(); VerticalBlurShader = null; // Release the vertical blur render to texture object. VerticalBlurTexture?.Shutdown(); VerticalBlurTexture = null; // Release the horizontal blur shader object. HorizontalBlurShader?.ShutDown(); HorizontalBlurShader = null; // Release the horizontal blur render to texture object. HorizontalBlurTexture?.Shutdown(); HorizontalBlurTexture = null; // Release the texture shader object. TextureShader?.ShutDown(); TextureShader = null; // Release the small ortho window object. SmallWindow?.Shutdown(); SmallWindow = null; // Release the down sample render to texture object. DownSampleTexure?.Shutdown(); DownSampleTexure = null; // Release the shadow shader object. ShadowShader?.ShutDown(); ShadowShader = null; // Release the black and white render to texture. BlackWhiteRenderTexture?.Shutdown(); BlackWhiteRenderTexture = null; // Release the depth shader object. DepthShader?.ShutDown(); DepthShader = null; /// Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the ground model object. GroundModel?.Shutdown(); GroundModel = null; // Release the sphere model object. SphereModel?.Shutdown(); SphereModel = null; // Release the cube model object. CubeModel?.Shutdown(); CubeModel = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public void Setup(GroundModel gm) { transform.position = gm.connectorRight.position; }