Пример #1
0
        public void Shutdown()
        {
            Camera = null;
            Timer  = null;
            Light  = null;

            foreach (KeyValuePair <int, IRenderer> model in Assets)
            {
                model.Value?.Shutdown();
            }

            Assets = null;
            D3D?.Shutdown();
            D3D = null;
        }
Пример #2
0
 public bool InitScene(int width, int height)
 {
     Camera          = new Camera();
     Camera.Position = new Vector3(0, 0, 15);
     Camera.SetProjectionMatrix(width, height);
     ClearRenderStack();
     Light = new LightClass();
     Light.SetAmbientColor(0.5f, 0.5f, 0.5f, 1f);
     Light.SetDiffuseColour(0.5f, 0.5f, 0.5f, 1f);
     Light.Direction = new Vector3(-0.2f, -1f, -0.3f);
     Light.SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
     Light.SetSpecularPower(255.0f);
     Input = new InputClass();
     Input.Init();
     return(true);
 }
Пример #3
0
        public virtual void InitCBuffersFrame(DeviceContext context, Camera camera, WorldSettings settings)
        {
            var cameraBuffer = new DCameraBuffer()
            {
                cameraPosition = camera.Position,
                padding        = 0.0f
            };

            ConstantBufferFactory.UpdateVertexBuffer(context, ConstantCameraBuffer, 1, cameraBuffer);

            if (previousLighting == null || !previousLighting.Equals(settings.Lighting))
            {
                LightBuffer lightbuffer = new LightBuffer()
                {
                    ambientColor   = settings.Lighting.AmbientColor,
                    diffuseColor   = settings.Lighting.DiffuseColour,
                    LightDirection = settings.Lighting.Direction,
                    specularColor  = settings.Lighting.SpecularColor,
                    specularPower  = settings.Lighting.SpecularPower
                };
                previousLighting = settings.Lighting;
                ConstantBufferFactory.UpdatePixelBuffer(context, ConstantLightBuffer, 0, lightbuffer);
            }
        }
Пример #4
0
        public override void InitCBuffersFrame(DeviceContext deviceContext, Camera camera, LightClass light)
        {
            DataStream mappedResource;

            #region Constant Camera Buffer
            deviceContext.MapSubresource(ConstantCameraBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);
            var cameraBuffer = new DCameraBuffer()
            {
                cameraPosition = camera.Position,
                padding        = 0.0f
            };
            mappedResource.Write(cameraBuffer);
            deviceContext.UnmapSubresource(ConstantCameraBuffer, 0);
            int bufferSlotNumber = 1;
            deviceContext.VertexShader.SetConstantBuffer(bufferSlotNumber, ConstantCameraBuffer);
            #endregion
            #region Constant Light Buffer
            if (lighting == null || !lighting.Equals(light))
            {
                deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);
                LightBuffer lightbuffer = new LightBuffer()
                {
                    ambientColor   = light.AmbientColor,
                    diffuseColor   = light.DiffuseColour,
                    LightDirection = light.Direction,
                    specularColor  = light.SpecularColor,
                    specularPower  = light.SpecularPower
                };
                mappedResource.Write(lightbuffer);
                deviceContext.UnmapSubresource(ConstantLightBuffer, 0);
                bufferSlotNumber = 0;
                deviceContext.PixelShader.SetConstantBuffer(bufferSlotNumber, ConstantLightBuffer);
                lighting = light;
            }
            #endregion
        }
Пример #5
0
        public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
        {
            if (boundingBox != null)
            {
                boundingBox.Render(device, deviceContext, camera, light);
            }

            if (lines != null)
            {
                for (int i = 0; i < lines.Count; i++)
                {
                    lines[i].Render(device, deviceContext, camera, light);
                }
            }
        }
Пример #6
0
 public override void InitCBuffersFrame(DeviceContext context, Camera camera, LightClass light)
 {
     //throw new System.NotImplementedException();
 }
Пример #7
0
 public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
 {
     throw new NotImplementedException();
 }
Пример #8
0
        public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
        {
            if (!DoRender)
            {
                return;
            }

            instance.SetTransform(Transform);
            instance.Render(device, deviceContext, camera, light);


            //unique to instanced collision; we need to do this rather than the usual, because otherwise all instanced collisions will show as being selected.
            if (isSelected)
            {
                if (instance.GetType() == typeof(RenderStaticCollision) || instance.GetType() == typeof(RenderModel))
                {
                    (instance as RenderStaticCollision).BoundingBox.DoRender = true;
                    (instance as RenderStaticCollision).BoundingBox.Render(device, deviceContext, camera, light);
                    (instance as RenderStaticCollision).BoundingBox.DoRender = false;
                }
            }
        }
Пример #9
0
 public override void InitCBuffersFrame(DeviceContext context, Camera camera, LightClass light)
 {
     base.InitCBuffersFrame(context, camera, light);
 }
Пример #10
0
        public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
        {
            if (!DoRender)
            {
                return;
            }

            //if (camera.CheckBBoxFrustrum(BBox))
            //    return;

            deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <VertexLayouts.NormalLayout.Vertex>(), 0));
            deviceContext.InputAssembler.SetIndexBuffer(indexBuffer, SharpDX.DXGI.Format.R16_UInt, 0);
            deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            deviceContext.PixelShader.SetShaderResource(2, AOTexture);
            for (int i = 0; i != LODs[0].ModelParts.Length; i++)
            {
                LODs[0].ModelParts[i].Shader.SetShaderParamters(device, deviceContext, LODs[0].ModelParts[i].Material);
                LODs[0].ModelParts[i].Shader.SetSceneVariables(deviceContext, Transform, camera);
                LODs[0].ModelParts[i].Shader.Render(deviceContext, PrimitiveTopology.TriangleList, (int)(LODs[0].ModelParts[i].NumFaces * 3), LODs[0].ModelParts[i].StartIndex);
            }
            BoundingBox.Render(device, deviceContext, camera, light);
        }
        public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
        {
            if (!DoRender)
            {
                return;
            }

            BoundingBox.Render(device, deviceContext, camera, light);
            deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <VertexLayouts.CollisionLayout.Vertex>(), 0));
            deviceContext.InputAssembler.SetIndexBuffer(indexBuffer, SharpDX.DXGI.Format.R32_UInt, 0);
            deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            Shader.SetSceneVariables(deviceContext, Transform, camera);
            Shader.SetShaderParameters(device, deviceContext, new BaseShader.MaterialParameters(null, SelectionColour));
            Shader.Render(deviceContext, PrimitiveTopology.TriangleList, Indices.Length, 0);
        }
Пример #12
0
 public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
 {
     if (DoRender != false)
     {
         BBox.Render(device, deviceContext, camera, light);
         Path.Render(device, deviceContext, camera, light);
     }
 }
Пример #13
0
        public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
        {
            if (!DoRender)
            {
                return;
            }

            Spline.Render(device, deviceContext, camera, light);

            foreach (Render2DPlane plane in towardLanes)
            {
                plane.Render(device, deviceContext, camera, light);
            }

            foreach (Render2DPlane plane in backwardLanes)
            {
                plane.Render(device, deviceContext, camera, light);
            }
        }
Пример #14
0
        public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
        {
            if (!DoRender)
            {
                return;
            }

            deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <VertexLayouts.BasicLayout.Vertex>(), 0));
            deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineStrip;

            shader.SetSceneVariables(deviceContext, Transform, camera);
            shader.Render(deviceContext, PrimitiveTopology.LineStrip, vertices.Length, 0);
        }
Пример #15
0
 public abstract void InitCBuffersFrame(DeviceContext context, Camera camera, LightClass light);
Пример #16
0
 public abstract void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light);
        public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
        {
            if (!DoRender)
            {
                return;
            }

            deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <VertexLayouts.BasicLayout.Vertex>(), 0));
            deviceContext.InputAssembler.SetIndexBuffer(indexBuffer, SharpDX.DXGI.Format.R16_UInt, 0);
            deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;

            shader.SetSceneVariables(deviceContext, Transform, camera);
            shader.Render(deviceContext, PrimitiveTopology.LineList, 36, 0);
        }
Пример #18
0
        public override void Render(Device device, DeviceContext deviceContext, Camera camera, LightClass light)
        {
            if (!DoRender)
            {
                return;
            }

            if (Boundary != null)
            {
                Boundary.Render(device, deviceContext, camera, light);
            }

            if (Splines != null)
            {
                foreach (var spline in Splines)
                {
                    spline.Render(device, deviceContext, camera, light);
                }
            }
        }