Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public override void Init()
        {
            UsePipeline <ForwardRenderPipeline>();

            _shader = new RendererShader("Shaders/skybox.vert", "Shaders/skybox.frag");
            //txt = Texture.LoadCubeMap("Textures/desert-skybox/#.tga");
            txt = RendererTexture.LoadCubeMap("Textures/water-skybox/#.jpg");

            vao = new VertexArrayObject(VertexLayoutDefinition.CreateDefinitionFromVertexStruct <VertexDataPos>().BindToShader(_shader));
            vao.SetData(BufferData.Create(_vertices));
        }
Ejemplo n.º 4
0
        public override void Init()
        {
            UsePipeline <ScreenPipeline>();

            _shader = new RendererShader("Shaders/screen.vert", "Shaders/screen.frag");

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

            vao = new VertexArrayObject(layout.BindToShader(_shader));
            vao.SetData(BufferData.Create(_vertices));
        }
Ejemplo n.º 5
0
        public override void Init()
        {
            UsePipeline <ForwardRenderPipeline>();

            _shader = new RendererShader("Shaders/forward.vert", "Shaders/white.frag");

            var layout = VertexLayoutDefinition.CreateDefinitionFromVertexStruct <VertexDataPosNormalUV>().BindToShader(_shader);

            vao = new VertexArrayObject(layout);
            vao.SetData(BufferData.Create(_vertices));
        }
Ejemplo n.º 6
0
 public void CreateShaders()
 {
     if (Shader == null)
     {
         Shader = new RendererShader("Shaders/forward.vert", "Shaders/forward.frag");
     }
     if (DefGeometryShader == null)
     {
         DefGeometryShader = new RendererShader("Shaders/deferred-gbuffer.vert", "Shaders/deferred-gbuffer.frag");
     }
     if (ShadowShader == null)
     {
         ShadowShader = new RendererShader("Shaders/shadow-directional.vert", "Shaders/shadow-directional.frag", "Shaders/shadow-directional.geom");
     }
     if (CubeShadowShader == null)
     {
         CubeShadowShader = new RendererShader("Shaders/shadow-cube.vert", "Shaders/shadow-cube.frag", "Shaders/shadow-cube.geom");
     }
 }
Ejemplo n.º 7
0
 public VertexLayoutBinded BindLayoutToShader(RendererShader shader) => Layout.BindToShader(shader);
Ejemplo n.º 8
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));
        }