예제 #1
0
        public void WriteToShader(string name, RendererShader shader)
        {
            var prefix = name += ".";

            shader.SetVector4(prefix + "DiffuseColor", DiffuseColor);
            shader.SetInt(prefix + "DiffuseMap", 0);
            shader.SetInt(prefix + "SpecularMap", 1);
            shader.SetFloat(prefix + "Ambient", Ambient);
            shader.SetFloat(prefix + "Shininess", Shininess);
            shader.SetFloat(prefix + "SpecularStrength", SpecularStrength);
        }
예제 #2
0
        protected void ApplyShaderParams(RendererShader shader)
        {
            foreach (var entry in ShaderParams)
            {
                var name  = entry.Key;
                var value = entry.Value;
                if (value == null)
                {
                    continue;
                }

                var type = value.GetType();
                if (type == typeof(int))
                {
                    shader.SetInt(name, (int)value);
                }
                else if (type == typeof(Vector3))
                {
                    shader.SetVector3(name, (Vector3)value);
                }
                else
                {
                    throw new NotSupportedException(type.Name);
                }
            }
        }
예제 #3
0
        private void RenderPass2(RenderContext context, Camera camera)
        {
            Pass = DeferredPass.Pass2;
            ObjectManager.PushDebugGroup("OnRender LightShader", this);

            _DefLightShader.Bind();

            GPosition.Bind(TextureUnit.Texture0);
            GNormal.Bind(TextureUnit.Texture1);
            GAlbedoSpec.Bind(TextureUnit.Texture2);
            GMaterial.Bind(TextureUnit.Texture3);

            if (Renderer.Current.UseShadows)
            {
                context.GetPipeline <DirectionalShadowRenderPipeline>().FrameBuffer.GetDestinationTexture().Bind(TextureUnit.Texture4);
                _DefLightShader.SetInt("DirectionalShadowMap", 4);
                context.GetPipeline <PointShadowRenderPipeline>().FrameBuffer.GetDestinationTexture().Bind(TextureUnit.Texture5);
                _DefLightShader.SetInt("PointShadowMap", 5);
            }

            _DefLightShader.SetVector3("ViewPos", camera.Position);
            _DefLightShader.SetFloat("FarPlane", camera.FarPlane);

            // TODO: Move to Pass1
            //_DefLightShader.SetMaterial("material", Material.Default);

            _DefLightShader.BindBlock("LightsArray", context.LightBinding);
            _DefLightShader.SetInt("LightCount", context.LightObjects.Count);

            context.GetPipeline <ForwardRenderPipeline>().FrameBuffer.Bind();
            vao.Bind();
            GL.Disable(EnableCap.DepthTest);
            vao.Draw();
            GL.Enable(EnableCap.DepthTest);

            ObjectManager.PopDebugGroup();
        }
예제 #4
0
        public void OnRender()
        {
            if (!(Context.CurrentPipeline is ScreenPipeline))
            {
                return;
            }

            vao.Bind();

            _shader.Bind();
            _shader.SetMatrix4("Model", GetModelMatrix());
            SourceTexture.Bind(0);
            _shader.SetInt("screenTexture", 0);

            GraphicsDevice.Default.CullFace = false;
            vao.Draw();
            GraphicsDevice.Default.CullFace = true;
        }
예제 #5
0
        public void OnRender()
        {
            //return;

            vao.Bind();
            _shader.Bind();

            _shader.SetMatrix4("View", Camera.GetViewMatrix(Vector3.Zero));
            _shader.SetMatrix4("Projection", Camera.ProjectionMatrix);

            txt.Bind(0);
            _shader.SetInt("Skybox", 0);

            GraphicsDevice.Default.DepthMask = false;
            //GL.DepthFunc(DepthFunction.Equal);
            GraphicsDevice.Default.DepthFunc = DepthFunction.Lequal;
            vao.Draw();
            GraphicsDevice.Default.DepthFunc = DepthFunction.Less;
            GraphicsDevice.Default.DepthMask = true;
        }
예제 #6
0
        public override void Init()
        {
            var width  = RenderContext.Current.ScreenPixelSize.X;
            var height = RenderContext.Current.ScreenPixelSize.Y;

            GBuffer             = new FrameBuffer(width, height);
            GBuffer.ObjectLabel = nameof(GBuffer);
            //GBuffer.InitNormal();

            // R11fG11fB10f --> rgba16f
            // Warning: R11fG11fB10f has no sign bit!

            GPosition = new RendererTexture(nameof(GPosition), TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb16f, width, height, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero);
            GPosition.SetNearestFilter();
            GBuffer.DestinationTextures.Add(GPosition);
            GBuffer.BindTexture(GPosition, FramebufferAttachment.ColorAttachment0);

            GNormal = new RendererTexture(nameof(GNormal), TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb16f, width, height, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero);
            GNormal.SetNearestFilter();
            GBuffer.DestinationTextures.Add(GNormal);
            GBuffer.BindTexture(GNormal, FramebufferAttachment.ColorAttachment1);

            GAlbedoSpec = new RendererTexture(nameof(GAlbedoSpec), TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GAlbedoSpec.SetNearestFilter();
            GBuffer.DestinationTextures.Add(GAlbedoSpec);
            GBuffer.BindTexture(GAlbedoSpec, FramebufferAttachment.ColorAttachment2);

            GMaterial = new RendererTexture(nameof(GMaterial), TextureTarget.Texture2D, 0, PixelInternalFormat.R11fG11fB10f, width, height, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero);
            GMaterial.SetNearestFilter();
            GBuffer.DestinationTextures.Add(GMaterial);
            GBuffer.BindTexture(GMaterial, FramebufferAttachment.ColorAttachment3);

            GL.DrawBuffers(4, new DrawBuffersEnum[]
            {
                DrawBuffersEnum.ColorAttachment0,
                DrawBuffersEnum.ColorAttachment1,
                DrawBuffersEnum.ColorAttachment2,
                DrawBuffersEnum.ColorAttachment3,
            });

            // var rboDepth = new RenderBuffer(gBuffer, RenderbufferStorage.DepthComponent, FramebufferAttachment.DepthAttachment);
            // rboDepth.ObjectLabel = nameof(rboDepth);

            // Attach default Forward Depth Buffer to this Framebuffer, so both share the same depth informations.
            var fwPipe = RenderContext.Current.GetPipeline <ForwardRenderPipeline>();

            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, fwPipe.FrameBuffer.RenderBuffer.Handle);

            GBuffer.Check();

            _DefLightShader = new RendererShader("Shaders/deferred-shading.vert", "Shaders/deferred-shading.frag", null, false);
            if (Renderer.Current.UseShadows)
            {
                _DefLightShader.SetDefine("USE_SHADOW");
            }
            _DefLightShader.Compile();
            _DefLightShader.SetInt("gPosition", 0);
            _DefLightShader.SetInt("gNormal", 1);
            _DefLightShader.SetInt("gAlbedoSpec", 2);
            _DefLightShader.SetInt("gMaterial", 3);

            vbo = new VertexBufferObject();
            vbo.Create();
            vbo.Bind();

            var layout = VertexLayoutDefinition.CreateDefinitionFromVertexStruct <VertexDataPos2UV>();

            vao = new VertexArrayObject(layout.BindToShader(_DefLightShader), vbo);
            vao.Create();

            vao.SetData(BufferData.Create(_vertices));
        }