public void Shutdown()
        {
            // Release the light object.
            Light = null;
            // Release the camera object.
            Camera = null;

            // Release the light shader object.
            LightShader?.ShutDown();
            LightShader = null;
            // Release the deferred shader object.
            DeferredShader?.ShutDown();
            DeferredShader = null;
            // Release the deferred buffers object.
            DeferredBuffers?.Shutdown();
            DeferredBuffers = null;
            // Release the full screen ortho window object.
            FullScreenWindow?.Shutdown();
            FullScreenWindow = null;
            // Release the tree object.
            Model?.Shutdown();
            Model = null;
            // Release the input object.
            Input?.Shutdown();
            Input = null;
            // Release the Direct3D object.
            D3D?.ShutDown();
            D3D = null;
        }
예제 #2
0
파일: Renderer.cs 프로젝트: asmboom/vengine
        private void Deferred()
        {
            var lights = Game.World.Scene.GetLights();

            DisableBlending();
            GL.CullFace(CullFaceMode.Back);

            for (int i = 0; i < lights.Count; i++)
            {
                var light = lights[i];
                if (light.ShadowMappingEnabled)
                {
                    light.UpdateShadowMap();
                }
            }
            EnableAdditiveBlending();
            GL.CullFace(CullFaceMode.Front);

            DeferredShader.Use();
            DeferredFramebuffer.Use();
            SetUniformsShared();

            for (int i = 0; i < lights.Count; i++)
            {
                var light = lights[i];

                Matrix4 mat = Matrix4.CreateScale(light.CutOffDistance) * Matrix4.CreateTranslation(light.Transformation.Position);
                if (light.ShadowMappingEnabled)
                {
                    light.BindShadowMap(20, 21);
                }
                light.SetUniforms();
                DeferredShader.SetUniform("ModelMatrix", mat);
                CubeMapSphere.Draw();
            }
            GL.CullFace(CullFaceMode.Back);
            DisableBlending();
            Game.CheckErrors("Deferred pass");
        }
        private bool RenderSceneToTexture()
        {
            // Set the render buffers to be the render target.
            DeferredBuffers.SetRenderTargets(D3D.DeviceContext);

            // Clear the render buffers.
            DeferredBuffers.ClearRenderTargets(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f);

            // Get the matrices from the camera and d3d objects.
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix cameraViewMatrix = Camera.ViewMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;

            // Update the rotation variable each frame.
            Rotate();

            // Rotate the world matrix by the rotation value so that the cube will spin.
            Matrix.RotationY(Rotation, out worldMatrix);

            // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            Model.Render(D3D.DeviceContext);

            // Render the model using the deferred shader.
            if (!DeferredShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, Model.Texture.TextureResource))
            {
                return(false);
            }

            // Reset the render target back to the original back buffer and not the render buffers anymore.
            D3D.SetBackBufferRenderTarget();

            // Reset the viewport back to the original.
            D3D.ResetViewPort();

            return(true);
        }
예제 #4
0
파일: Renderer.cs 프로젝트: asmboom/vengine
        public Renderer(int initialWidth, int initialHeight, int samples)
        {
            GlareTexture = new Texture(Media.Get("glaretex.png"));

            Voxelizer = new Voxel3dTextureWriter(256, 256, 256, new Vector3(22, 22, 22), new Vector3(0, 8, 0));

            CubeMapSphere = new Object3dInfo(Object3dManager.LoadFromObjSingle(Media.Get("cubemapsphere.obj")).Vertices);

            var cubeMapTexDefault = new CubeMapTexture(Media.Get("posx.jpg"), Media.Get("posy.jpg"), Media.Get("posz.jpg"),
                                                       Media.Get("negx.jpg"), Media.Get("negy.jpg"), Media.Get("negz.jpg"));

            CubeMaps.Add(new CubeMapInfo()
            {
                Texture      = cubeMapTexDefault,
                FalloffScale = 99999999.0f,
                Position     = Vector3.Zero
            });

            Width  = initialWidth;
            Height = initialHeight;


            Samples = samples;

            CreateBuffers();

            HDRShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "HDR.fragment.glsl");
            HDRShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                HDRShader.SetGlobal("USE_MSAA", "");
            }

            VXGIShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "VXGI.fragment.glsl");
            VXGIShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                VXGIShader.SetGlobal("USE_MSAA", "");
            }

            AmbientOcclusionShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "AmbientOcclusion.fragment.glsl");
            AmbientOcclusionShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                AmbientOcclusionShader.SetGlobal("USE_MSAA", "");
            }

            FogShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Fog.fragment.glsl");
            FogShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                FogShader.SetGlobal("USE_MSAA", "");
            }

            DeferredShader = ShaderProgram.Compile("PostProcessPerspective.vertex.glsl", "Deferred.fragment.glsl");
            DeferredShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                DeferredShader.SetGlobal("USE_MSAA", "");
            }

            EnvLightShader = ShaderProgram.Compile("PostProcessPerspective.vertex.glsl", "EnvironmentLight.fragment.glsl");
            EnvLightShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                EnvLightShader.SetGlobal("USE_MSAA", "");
            }

            CombinerShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Combiner.fragment.glsl");
            CombinerShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                CombinerShader.SetGlobal("USE_MSAA", "");
            }

            CombinerSecondShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "CombinerSecond.fragment.glsl");
            CombinerSecondShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                CombinerSecondShader.SetGlobal("USE_MSAA", "");
            }

            MotionBlurShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "MotionBlur.fragment.glsl");
            MotionBlurShader.SetGlobal("MSAA_SAMPLES", samples.ToString());
            if (samples > 1)
            {
                MotionBlurShader.SetGlobal("USE_MSAA", "");
            }

            BloomShader = ShaderProgram.Compile("PostProcess.vertex.glsl", "Bloom.fragment.glsl");

            PostProcessingMesh          = new Object3dInfo(VertexInfo.FromFloatArray(postProcessingPlaneVertices));
            PostProcessingMesh.DrawMode = PrimitiveType.TriangleStrip;
        }