コード例 #1
0
ファイル: SkyboxObject.cs プロジェクト: AximoGames/AxEngine
        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));
        }
コード例 #2
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));
        }
コード例 #3
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));
        }
コード例 #4
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));
        }
コード例 #5
0
        public void Render()
        {
            //--
            var ubo = new UniformBufferObject();

            ubo.Create();
            // if (RenderContext.LightObjects.Count >= 2)
            // {
            //     var lightsData = new GlslLight[2];
            //     lightsData[0].Position = RenderContext.LightObjects[0].Position;
            //     lightsData[0].Color = new Vector3(0.5f, 0.5f, 0.5f);
            //     lightsData[0].ShadowLayer = RenderContext.LightObjects[0].ShadowTextureIndex;
            //     lightsData[0].DirectionalLight = RenderContext.LightObjects[0].LightType == LightType.Directional ? 1 : 0;
            //     lightsData[0].LightSpaceMatrix = Matrix4.Transpose(RenderContext.LightObjects[0].LightCamera.ViewMatrix * RenderContext.LightObjects[0].LightCamera.ProjectionMatrix);
            //     lightsData[0].Linear = 0.1f;
            //     lightsData[0].Quadric = 0f;

            //     lightsData[1].Position = RenderContext.LightObjects[1].Position;
            //     lightsData[1].Color = new Vector3(0.5f, 0.5f, 0.5f);
            //     lightsData[1].ShadowLayer = RenderContext.LightObjects[1].ShadowTextureIndex;
            //     lightsData[1].DirectionalLight = RenderContext.LightObjects[1].LightType == LightType.Directional ? 1 : 0;
            //     lightsData[1].LightSpaceMatrix = Matrix4.Transpose(RenderContext.LightObjects[1].LightCamera.ViewMatrix * RenderContext.LightObjects[1].LightCamera.ProjectionMatrix);
            //     lightsData[1].Linear = 0.1f;
            //     lightsData[1].Quadric = 0f;
            //     ubo.SetData(BufferData.Create(lightsData));

            //     ubo.SetBindingPoint(RenderContext.LightBinding);
            // }

            if (RenderContext.LightObjects.Count > 0)
            {
                var lightDataList = new List <GlslLight>();
                foreach (var light in RenderContext.LightObjects)
                {
                    var lightData = new GlslLight();
                    lightData.Position         = light.Position;
                    lightData.Color            = light.Color;
                    lightData.ShadowLayer      = light.ShadowTextureIndex;
                    lightData.DirectionalLight = light.LightType == LightType.Directional ? 1 : 0;
                    lightData.LightSpaceMatrix = Matrix4.Transpose(light.LightCamera.ViewMatrix * light.LightCamera.ProjectionMatrix);
                    lightData.Linear           = light.Linear;
                    lightData.Quadric          = light.Quadric;
                    lightData.FarPlane         = light.LightCamera.FarPlane;
                    lightData.Direction        = light.Direction.Normalized();
                    lightDataList.Add(lightData);
                }
                ubo.SetData(BufferData.Create(lightDataList.ToArray()));
                ubo.SetBindingPoint(RenderContext.LightBinding);
            }

            //--
            GL.Enable(EnableCap.DepthTest);

            //--

            RenderContext.InitRender();
            RenderContext.Render();
            RenderContext.OnWorldRendered();

            //--

            // Configure

            // Render objects

            // Render Screen Surface

            //CheckForProgramError();

            ubo.Free();

            if (FlushRenderBackend == FlushRenderBackend.End)
            {
                GL.Finish();
            }
        }