Exemplo n.º 1
0
        public override void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.CameraStack.Peek();
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[(int)this.Mode];
            ShaderProgram program = method.Program;

            program.SetUniform("MVP", projection * view * model);
            program.SetUniform("time", time); time += this.DeltaTime;
            method.Render();
        }
Exemplo n.º 2
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[(int)this.Mode];
            ShaderProgram program = method.Program;

            program.SetUniform("mvpMat", projection * view * model);

            method.Render();
        }
Exemplo n.º 3
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera        = arg.Camera;
            mat4    projectionMat = camera.GetProjectionMatrix();
            mat4    viewMat       = camera.GetViewMatrix();
            mat4    modelMat      = this.GetModelMatrix();

            ModernRenderUnit unit    = this.RenderUnit;
            RenderMethod     method  = unit.Methods[0];
            ShaderProgram    program = method.Program;

            program.SetUniform("mvpMat", projectionMat * viewMat * modelMat);
            GL.Instance.Clear(GL.GL_DEPTH_BUFFER_BIT); // push this node to top front.
            method.Render();
        }
Exemplo n.º 4
0
        public void RenderAmbientColor(BlinnPhongAmbientEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("mvpMat", projection * view * model);
            program.SetUniform("ambientColor", arg.Ambient);

            method.Render();
        }
Exemplo n.º 5
0
        protected unsafe override void DoInitialize()
        {
            base.DoInitialize();
            // pbr: run a quasi monte-carlo simulation on the environment lighting to create a prefilter (cube)map.
            const uint maxMipLevels = 5;
            var        viewport     = new ViewportSwitch();

            for (int mip = 0; mip < maxMipLevels; ++mip)
            {
                // reisze framebuffer according to mip-level size.
                int mipWidth   = (int)(128 * Math.Pow(0.5, mip));
                int mipHeight  = (int)(128 * Math.Pow(0.5, mip));
                var captureFBO = new Framebuffer(mipWidth, mipHeight);
                captureFBO.Bind();
                var captureRBO = new Renderbuffer(mipWidth, mipHeight, GL.GL_DEPTH_COMPONENT24);
                captureFBO.Attach(FramebufferTarget.Framebuffer, captureRBO, AttachmentLocation.Depth);
                captureFBO.CheckCompleteness();
                captureFBO.Unbind();
                viewport.Width = mipWidth; viewport.Height = mipHeight;
                viewport.On();
                // NOTE: I added '/ 10' to make it a clearer visual effect.
                float         roughness = (float)mip / (float)(maxMipLevels - 1) / 5;
                RenderMethod  method    = this.RenderUnit.Methods[0];
                ShaderProgram program   = method.Program;
                program.SetUniform("roughness", roughness);
                program.SetUniform("projection", captureProjection);
                program.SetUniform("environmentMap", this.envCubemap);
                for (uint i = 0; i < 6; ++i)
                {
                    program.SetUniform("view", captureViews[i]);
                    CubemapFace face     = (CubemapFace)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
                    uint        location = 0;
                    //int level = 0;
                    captureFBO.Bind();
                    captureFBO.Attach(FramebufferTarget.Framebuffer, location, face, this.prefilterMap, mip);
                    captureFBO.CheckCompleteness();
                    captureFBO.Unbind();

                    captureFBO.Bind();
                    GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                    method.Render();
                    captureFBO.Unbind();
                }

                viewport.Off();
                captureFBO.Dispose();
            }
        }
Exemplo n.º 6
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();
            mat4    normal     = glm.transpose(glm.inverse(view * model));

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("gMVP", projection * view * model);
            program.SetUniform("gWorld", model);

            method.Render();
        }
Exemplo n.º 7
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            // matrix.
            program.SetUniform("mvpMat", projection * view * model);
            program.SetUniform("hiddenLength", this.HiddenLength);
            program.SetUniform("showSlice", this.ShowSlice);
            method.Render();
        }
Exemplo n.º 8
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            // reset image
            {
                // Activate the compute program and bind the output texture image
                RenderMethod  method  = this.RenderUnit.Methods[0];
                ShaderProgram program = method.Program;
                program.SetUniform("reset", true);
                program.Bind();
                program.PushUniforms();
                uint imageUnit = 0;
                glBindImageTexture(imageUnit, outputTexture.Id, 0, false, 0, GL.GL_WRITE_ONLY, GL.GL_RGBA32F);
                glDispatchCompute(maxX, maxY, maxZ);
                program.Unbind();
            }
            //{
            //    var image = this.outputTexture.GetImage(256, 256);
            //    image.Save("x0.png");
            //}
            {
                // Activate the compute program and bind the output texture image
                RenderMethod  method  = this.RenderUnit.Methods[0];
                ShaderProgram program = method.Program;
                program.SetUniform("reset", false);
                program.Bind();
                program.PushUniforms();
                uint imageUnit = 0;
                glBindImageTexture(imageUnit, outputTexture.Id, 0, false, 0, GL.GL_WRITE_ONLY, GL.GL_RGBA32F);
                glDispatchCompute(GroupX, GroupY, GroupZ);
                program.Unbind();
            }
            {
                ICamera camera     = arg.Camera;
                mat4    projection = camera.GetProjectionMatrix();
                mat4    view       = camera.GetViewMatrix();
                mat4    model      = mat4.identity();

                RenderMethod  method  = this.RenderUnit.Methods[1];
                ShaderProgram program = method.Program;
                program.SetUniform("projectionMatrix", projection);
                program.SetUniform("viewMatrix", view);
                program.SetUniform("modelMatrix", model);
                program.SetUniform("output_image", this.outputTexture);

                method.Render();
            }
        }
Exemplo n.º 9
0
        protected unsafe override void DoInitialize()
        {
            base.DoInitialize();
            ViewportSwitch viewportSwitch = new ViewportSwitch(0, 0, 512, 512);
            // pbr: setup framebuffer
            var captureFBO = new Framebuffer(512, 512);

            captureFBO.Bind();
            var captureRBO = new Renderbuffer(512, 512, GL.GL_DEPTH_COMPONENT24);

            captureFBO.Attach(FramebufferTarget.Framebuffer, captureRBO, AttachmentLocation.Depth);
            captureFBO.CheckCompleteness();
            captureFBO.Unbind();

            // pbr: convert HDR equirectangular environment map to cubemap equivalent
            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("equirectangularMap", this.texHDR);
            program.SetUniform("projection", captureProjection);
            viewportSwitch.On();
            for (uint i = 0; i < 6; ++i)
            {
                program.SetUniform("view", captureViews[i]);
                CubemapFace face     = (CubemapFace)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
                uint        location = 0;
                int         level    = 0;
                captureFBO.Bind();
                captureFBO.Attach(FramebufferTarget.Framebuffer, location, face, this.environmentMap, level);
                captureFBO.CheckCompleteness();
                captureFBO.Unbind();

                captureFBO.Bind();
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                method.Render();
                captureFBO.Unbind();

                this.environmentMap.GetImage(face, 512, 512).Save(string.Format("texEnvCubemap.{0}.mip{1}.png", face, 0));
            }
            viewportSwitch.Off();
            captureFBO.Dispose();

            this.environmentMap.Bind();
            glGenerateMipmap(GL.GL_TEXTURE_CUBE_MAP);
            this.environmentMap.Unbind();
        }
Exemplo n.º 10
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            foreach (var item in this.attractorsSource.Attractors)
            {
                mat4 model = glm.translate(mat4.identity(), new vec3(item));
                program.SetUniform("mvpMat", projection * view * model);

                method.Render();
            }
        }
Exemplo n.º 11
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();
            mat4    normal     = glm.transpose(glm.inverse(view * model));

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("projection", projection);
            program.SetUniform("view", view);
            program.SetUniform("model", model);
            if (this.AlbedoMap != null)
            {
                program.SetUniform("albedoMap", this.AlbedoMap);
            }
            if (this.NormalMap != null)
            {
                program.SetUniform("normalMap", this.NormalMap);
            }
            if (this.MetallicMap != null)
            {
                program.SetUniform("metallicMap", this.MetallicMap);
            }
            if (this.RoughnessMap != null)
            {
                program.SetUniform("roughnessMap", this.RoughnessMap);
            }
            if (this.AOMap != null)
            {
                program.SetUniform("aoMap", this.AOMap);
            }
            {
                program.SetUniform("albedo", Albedo);
                program.SetUniform("metallic", Metallic);
                program.SetUniform("roughness", Roughness);
                program.SetUniform("ao", AO);
            }
            program.SetUniform("lightPositions", lightPositions);
            program.SetUniform("lightColors", lightColors);
            program.SetUniform("camPos", camera.Position);

            method.Render();
        }
Exemplo n.º 12
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            //ICamera camera = arg.CameraStack;
            //mat4 projection = camera.GetProjectionMatrix();
            //mat4 view = camera.GetViewMatrix();
            //mat4 model = this.GetModelMatrix();

            RenderMethod method = this.RenderUnit.Methods[(int)this.Mode];

            if (this.Mode == RenderMode.Final)
            {
                ShaderProgram program = method.Program;
                program.SetUniform("vBackgroundColor", this.scene.ClearColor);
            }

            method.Render();
        }
Exemplo n.º 13
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();
            mat4    normal     = glm.transpose(glm.inverse(view * model));

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("projection", projection);
            program.SetUniform("view", view * model);
            program.SetUniform("environmentMap", this.envCubemap);

            method.Render();
        }
Exemplo n.º 14
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            TransformFeedbackObject tfo = transformFeedbackObjects[(currentIndex + 1) % 2];
            // update
            {
                if (this.firstRendering)
                {
                    this.lastTime       = DateTime.Now;
                    this.firstRendering = false;
                }

                var   now     = DateTime.Now;
                float seconds = (float)now.Subtract(this.lastTime).TotalSeconds;
                this.lastTime = now;

                GL.Instance.Enable(GL.GL_RASTERIZER_DISCARD);

                RenderMethod  method  = this.RenderUnit.Methods[currentIndex];
                ShaderProgram program = method.Program;
                // set the uniforms
                program.SetUniform("gravity", gravity);
                program.SetUniform("deltaTime", seconds);
                method.Render(tfo); // update buffers and record output to tf's binding.

                GL.Instance.Disable(GL.GL_RASTERIZER_DISCARD);
            }
            // render
            {
                RenderMethod  method     = this.RenderUnit.Methods[(currentIndex + 1) % 2 + 2];
                ShaderProgram program    = method.Program;
                ICamera       camera     = arg.Camera;
                mat4          projection = camera.GetProjectionMatrix();
                mat4          view       = camera.GetViewMatrix();
                mat4          model      = this.GetModelMatrix();

                program.SetUniform("projectionMat", projection);
                program.SetUniform("viewMat", view * model);
                //unit.Render(); // this method requires specified vertes count.
                tfo.Draw(method); // render updated buffers without specifying vertex count.
            }
            // exchange
            {
                currentIndex = (currentIndex + 1) % 2;
            }
        }
Exemplo n.º 15
0
        public override void RenderBeforeChildren(RenderEventArgs arg)
        {
            RenderMethod  method     = this.RenderUnit.Methods[0];
            ShaderProgram program    = method.Program;
            ICamera       camera     = arg.CameraStack.Peek();
            mat4          projection = camera.GetProjectionMatrix();
            mat4          view       = camera.GetViewMatrix();
            mat4          model      = this.GetModelMatrix();
            mat4          normal     = glm.transpose(glm.inverse(view * model));

            program.SetUniform(projectionMatrix, projection);
            program.SetUniform(viewMatrix, view);
            program.SetUniform(modelMatrix, model);
            program.SetUniform(normalMatrix, normal);
            program.SetUniform(lightPosition, new vec3(view * new vec4(light.Position, 1.0f)));

            method.Render();
        }
Exemplo n.º 16
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();
            mat4    normal     = glm.transpose(glm.inverse(view * model));

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("mvpMat", projection * view * model);
            program.SetUniform("modelMat", model);
            program.SetUniform("eyeWorldPos", camera.Position);
            program.SetUniform("light.direction", -(camera.Position - camera.Target).normalize());

            method.Render();
        }
Exemplo n.º 17
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            mat4 mv        = view * model;
            vec3 cameraPos = new vec3(glm.inverse(mv) * new vec4(0, 0, 0, 1));

            RenderMethod  method  = this.RenderUnit.Methods[(int)this.CurrentMode];
            ShaderProgram program = method.Program;

            program.SetUniform("MVP", projection * view * model);
            program.SetUniform("camPos", cameraPos);

            method.Render();
        }
Exemplo n.º 18
0
        public override void RenderBeforeChildren(RenderEventArgs arg)
        {
            GL.Instance.ClearStencil(0x0);
            GL.Instance.Clear(GL.GL_STENCIL_BUFFER_BIT); // this seems not working. I don't know why.(2017-12-13)
            GL.Instance.Enable(GL.GL_STENCIL_TEST);
            GL.Instance.StencilFunc(GL.GL_ALWAYS, 0, 0xFF);
            GL.Instance.StencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
            GL.Instance.StencilMask(0xFF);
            GL.Instance.DepthMask(false);
            GL.Instance.ColorMask(false, false, false, false);

            RenderMethod method = this.RenderUnit.Methods[0];

            method.Render();

            GL.Instance.ColorMask(true, true, true, true);
            GL.Instance.DepthMask(true);
        }
Exemplo n.º 19
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            //ICamera camera = arg.CameraStack;
            //mat4 projection = camera.GetProjectionMatrix();
            //mat4 view = camera.GetViewMatrix();
            //mat4 model = this.GetModelMatrix();

            RenderMethod method = this.RenderUnit.Methods[(int)this.Mode];

            if (this.Mode == RenderMode.Final)
            {
                ShaderProgram program    = method.Program;
                var           clearColor = new float[4];
                GL.Instance.GetFloatv((uint)GetTarget.ColorClearValue, clearColor);
                var value = new vec4(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
                program.SetUniform("vBackgroundColor", value);
            }

            method.Render();
        }
Exemplo n.º 20
0
        public override void RenderBeforeChildren(CSharpGL.RenderEventArgs arg)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            ICamera camera           = arg.CameraStack.Peek();
            mat4    projectionMatrix = camera.GetProjectionMatrix();
            mat4    viewMatrix       = camera.GetViewMatrix();
            mat4    modelMatrix      = this.GetModelMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform(mvpMatrix, projectionMatrix * viewMatrix * modelMatrix);
            program.SetUniform(skybox, this.texture);

            method.Render();
        }
Exemplo n.º 21
0
        public override void RenderBeforeChildren(RenderEventArgs arg)
        {
            RenderMethod  method     = this.RenderUnit.Methods[0];
            ShaderProgram program    = method.Program;
            ICamera       camera     = arg.CameraStack.Peek();
            mat4          projection = camera.GetProjectionMatrix();
            mat4          view       = camera.GetViewMatrix();
            mat4          model      = this.GetModelMatrix();
            mat3          normal     = new mat3(glm.transpose(glm.inverse(view * model)));

            program.SetUniform(MVP, projection * view * model);
            program.SetUniform(normalMatrix, normal);
            vec3 lightDir = new vec3(view * new vec4(this.Light.Direction, 0.0f));

            program.SetUniform(lightDirection, lightDir);
            var cameraDrection = new vec3(0, 0, 1); // camera direction in eye/view/camera space.

            program.SetUniform(halfVector, (lightDir + cameraDrection).normalize());

            method.Render();
        }
Exemplo n.º 22
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            // gets mvpMatrix.
            ICamera camera        = arg.Camera;
            mat4    projectionMat = camera.GetProjectionMatrix();
            mat4    viewMat       = camera.GetViewMatrix();
            mat4    modelMat      = this.GetModelMatrix();
            mat4    mvpMatrix     = projectionMat * viewMat * modelMat;
            // a render uint wraps everything(model data, shaders, glswitches, etc.) for rendering.
            ModernRenderUnit unit = this.RenderUnit;
            // gets render method.
            // There could be more than 1 method(vertex shader + fragment shader) to render the same model data. Thus we need an method array.
            RenderMethod method = unit.Methods[0];
            // shader program wraps vertex shader and fragment shader.
            ShaderProgram program = method.Program;

            //set value for 'uniform mat4 mvpMatrix'; in shader.
            program.SetUniform("mvpMatrix", mvpMatrix);
            // render the cube model via OpenGL.
            method.Render();
        }
Exemplo n.º 23
0
        public override void RenderBeforeChildren(RenderEventArgs arg)
        {
            TransformFeedbackObject tf = transformFeedbackObjects[(currentIndex + 1) % 2];
            // update
            {
                GL.Instance.Enable(GL.GL_RASTERIZER_DISCARD);

                RenderMethod  method  = this.RenderUnit.Methods[currentIndex];
                ShaderProgram program = method.Program;
                // set the uniforms
                program.SetUniform("center", center);
                program.SetUniform("radius", radius);
                program.SetUniform("g", g);
                program.SetUniform("dt", dt);
                program.SetUniform("bounce", bounce);
                program.SetUniform("seed", random.Next());
                method.Render(ControlMode.ByFrame, tf); // update buffers and record output to tf's binding.

                GL.Instance.Disable(GL.GL_RASTERIZER_DISCARD);
            }
            // render
            {
                RenderMethod  method     = this.RenderUnit.Methods[(currentIndex + 1) % 2 + 2];
                ShaderProgram program    = method.Program;
                ICamera       camera     = arg.CameraStack.Peek();
                mat4          projection = camera.GetProjectionMatrix();
                mat4          view       = camera.GetViewMatrix();
                mat4          model      = this.GetModelMatrix();

                program.SetUniform("Projection", projection);
                program.SetUniform("View", view * model);
                //unit.Render(); // this methos must specify vertes count.
                tf.Draw(method); // render updated buffersi without specifying vertex count.
            }
            // exchange
            {
                currentIndex = (currentIndex + 1) % 2;
            }
        }
Exemplo n.º 24
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            Viewport viewport = arg.Param.Viewport;

            if (this.width != viewport.width || this.height != viewport.height)
            {
                this.Resize(viewport.width, viewport.height);

                this.width  = viewport.width;
                this.height = viewport.height;
            }
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();

            this.UpdateRotation();
            mat4 model = this.GetModelMatrix();
            mat4 mvp   = projection * view * model;
            {
                RenderMethod  method  = this.RenderUnit.Methods[0];// backface.
                ShaderProgram program = method.Program;
                program.SetUniform("MVP", mvp);

                // render to texture
                this.framebuffer.Bind(FramebufferTarget.Framebuffer);
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
                {
                    method.Render();
                }
                this.framebuffer.Unbind(FramebufferTarget.Framebuffer);
            }
            {
                RenderMethod  method  = this.RenderUnit.Methods[1];// raycasting.
                ShaderProgram program = method.Program;
                program.SetUniform("MVP", mvp);

                method.Render();
            }
        }
Exemplo n.º 25
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            ICamera camera        = arg.Camera;
            mat4    projectionMat = camera.GetProjectionMatrix();
            mat4    viewMat       = camera.GetViewMatrix();
            mat4    modelMat      = this.GetModelMatrix();

            WorldPosition = camera.Position;

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform(mvpMat, projectionMat * viewMat * modelMat);
            program.SetUniform(skybox, this.texture);

            method.Render();
        }
Exemplo n.º 26
0
        public override void RenderBeforeChildren(RenderEventArgs arg)
        {
            var viewport = new int[4]; GL.Instance.GetIntegerv((uint)GetTarget.Viewport, viewport);

            if (this.width != viewport[2] || this.height != viewport[3])
            {
                Resize(viewport[2], viewport[3]);

                this.width  = viewport[2];
                this.height = viewport[3];
            }
            ICamera camera     = arg.CameraStack.Peek();
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();

            this.UpdateRotation();
            mat4 model = this.GetModelMatrix();
            mat4 mvp   = projection * view * model;
            {
                RenderMethod  method  = this.RenderUnit.Methods[0];
                ShaderProgram program = method.Program;
                program.SetUniform("MVP", mvp);

                // render to texture
                this.framebuffer.Bind(FramebufferTarget.Framebuffer);
                GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
                {
                    method.Render();
                }
                this.framebuffer.Unbind(FramebufferTarget.Framebuffer);
            }
            {
                RenderMethod  method  = this.RenderUnit.Methods[1];
                ShaderProgram program = method.Program;
                program.SetUniform("MVP", mvp);

                method.Render();
            }
        }
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera        = arg.Camera;
            mat4    projectionMat = camera.GetProjectionMatrix();
            mat4    viewMat       = camera.GetViewMatrix();
            mat4    modelMat      = this.GetModelMatrix();

            ModernRenderUnit unit    = this.RenderUnit;
            RenderMethod     method  = unit.Methods[0];
            ShaderProgram    program = method.Program;

            program.SetUniform("mvpMat", projectionMat * viewMat * modelMat);
            if (this.firstRun)
            {
                lastTime      = DateTime.Now;
                this.firstRun = false;
            }

            DateTime now           = DateTime.Now;
            float    timeInSeconds = (float)(now.Subtract(this.lastTime).TotalSeconds);

            //this.lastTime = now;

            Assimp.Scene     scene     = this.nodePointModel.scene;
            Assimp.Matrix4x4 transform = scene.RootNode.Transform;
            transform.Inverse();
            mat4[] boneMatrixes = GetBoneMatrixes(scene, timeInSeconds, this.nodePointModel.allBoneInfos);
            //mat4[] boneMatrixes = null;
            program.SetUniform("animation", boneMatrixes != null);
            if (boneMatrixes != null)
            {
                program.SetUniform("bones", boneMatrixes);
            }

            GL.Instance.Enable(GL.GL_VERTEX_PROGRAM_POINT_SIZE);
            GL.Instance.Clear(GL.GL_DEPTH_BUFFER_BIT); // push this node to top front.
            method.Render();
        }
Exemplo n.º 28
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();
            mat4    normal     = glm.transpose(glm.inverse(view * model));

            if (this.RenderModel)
            {
                RenderMethod  method  = this.RenderUnit.Methods[0];
                ShaderProgram program = method.Program;

                var source = this.TextureSource;
                if (source != null)
                {
                    program.SetUniform(tex, source.BindingTexture);
                }

                program.SetUniform(projectionMatrix, projection);
                program.SetUniform(viewMatrix, view);
                program.SetUniform(modelMatrix, model);
                program.SetUniform(normalMatrix, normal);

                method.Render();
            }

            if (this.RenderNormal)
            {
                RenderMethod  method  = this.RenderUnit.Methods[1];
                ShaderProgram program = method.Program;
                program.SetUniform(projectionMatrix, projection);
                program.SetUniform(viewMatrix, view);
                program.SetUniform(modelMatrix, model);

                method.Render();
            }
        }
Exemplo n.º 29
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            var  camera     = arg.Camera;
            mat4 projection = camera.GetProjectionMatrix();
            mat4 view       = camera.GetViewMatrix();
            mat4 model      = this.GetModelMatrix();

            RenderMethod  method  = this.RenderUnit.Methods[0];
            ShaderProgram program = method.Program;

            program.SetUniform("mvpMat", projection * view * model);
            program.SetUniform("color", this.Color);
            //var clearColor = new int[4];
            //GL.Instance.GetIntegerv((uint)GetTarget.ColorClearValue, clearColor);
            var clearColor = new float[4];

            GL.Instance.GetFloatv((uint)GetTarget.ColorClearValue, clearColor);
            var background = new vec4(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);

            program.SetUniform("backgroundColor", background);

            method.Render(IndexAccessMode.Random);
        }
Exemplo n.º 30
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            // reset image
            {
                RenderMethod  method  = this.RenderUnit.Methods[0];
                ShaderProgram program = method.Program;
                program.Bind();
                glBindImageTexture(0, outputTexture.Id, 0, false, 0, GL.GL_WRITE_ONLY, GL.GL_RGBA32F);
                glDispatchCompute(maxX, maxY, maxZ);
                program.Unbind();
            }

            {
                // Activate the compute program and bind the output texture image
                RenderMethod  method  = this.RenderUnit.Methods[1];
                ShaderProgram program = method.Program;
                program.Bind();
                glBindImageTexture(0, outputTexture.Id, 0, false, 0, GL.GL_WRITE_ONLY, GL.GL_RGBA32F);
                glDispatchCompute(GroupX, GroupY, GroupZ);
                program.Unbind();
            }
            {
                ICamera camera     = arg.Camera;
                mat4    projection = camera.GetProjectionMatrix();
                mat4    view       = camera.GetViewMatrix();
                mat4    model      = mat4.identity();

                RenderMethod  method  = this.RenderUnit.Methods[2];
                ShaderProgram program = method.Program;
                program.SetUniform("projectionMatrix", projection);
                program.SetUniform("viewMatrix", view);
                program.SetUniform("modelMatrix", model);

                method.Render();
            }
        }