コード例 #1
0
        protected override void DoRender(RenderEventArgs arg)
        {
            // setup uniforms
            var   now  = DateTime.Now;
            float time = (float)now.Subtract(this.lastTime).TotalMilliseconds * 0.001f;

            this.SetUniform("time", time * timeElapsingSpeed);
            this.SetUniform("rainDrop", this.rainDrop);
            this.SetUniform("granularity", this.granularity);

            mat4 projection = arg.Camera.GetProjectionMatrix();
            mat4 view       = arg.Camera.GetViewMatrix();

            this.SetUniform("projectionMatrix", projection);
            this.SetUniform("viewMatrix", view);
            MarkableStruct <mat4> model = this.GetModelMatrix();

            if (this.modelTicks != model.UpdateTicks)
            {
                this.SetUniform("modelMatrix", model.Value);
                this.modelTicks = model.UpdateTicks;
            }

            base.DoRender(arg);
        }
コード例 #2
0
        protected override void DoRender(RenderEventArgs arg)
        {
            this.depthTestState.On();
            this.cullFaceState.On();

            // Reset atomic counter
            IntPtr data = this.atomicCountBuffer.MapBuffer(MapBufferAccess.WriteOnly);

            unsafe
            {
                var array = (uint *)data.ToPointer();
                array[0] = 0;
            }
            this.atomicCountBuffer.UnmapBuffer();

            // Clear head-pointer image
            this.headClearBuffer.Bind();
            this.headTexture.Bind();
            OpenGL.TexSubImage2D(TexSubImage2DTarget.Texture2D, 0, 0, 0, arg.CanvasRect.Width, arg.CanvasRect.Height, TexSubImage2DFormats.RedInteger, TexSubImage2DType.UnsignedByte, IntPtr.Zero);
            this.headTexture.Unbind();
            this.headClearBuffer.Unbind();
            //

            // Bind head-pointer image for read-write
            OpenGL.BindImageTexture(0, this.headTexture.Id, 0, false, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);

            // Bind linked-list buffer for write
            OpenGL.BindImageTexture(1, this.linkedListTexture.Id, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);

            mat4 projection = arg.Camera.GetProjectionMatrix();
            mat4 view       = arg.Camera.GetViewMatrix();

            this.buildListsRenderer.SetUniform("projection_matrix", projection);
            this.buildListsRenderer.SetUniform("view_matrix", view);
            this.resolve_lists.SetUniform("projection_matrix", projection);
            this.resolve_lists.SetUniform("view_matrix", view);
            MarkableStruct <mat4> model = this.GetModelMatrix();

            if (this.modelTicks != model.UpdateTicks)
            {
                this.buildListsRenderer.SetUniform("model_matrix", model.Value);
                this.resolve_lists.SetUniform("model_matrix", model.Value);
                this.modelTicks = model.UpdateTicks;
            }
            // first pass
            this.buildListsRenderer.Render(arg);
            // second pass
            this.resolve_lists.Render(arg);

            OpenGL.BindImageTexture(1, 0, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);
            OpenGL.BindImageTexture(0, 0, 0, false, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);

            this.cullFaceState.Off();
            this.depthTestState.Off();
        }
コード例 #3
0
        /// <summary>
        /// Get model matrix that transform this renderer from model space to world space.
        /// </summary>
        /// <returns></returns>
        public MarkableStruct<mat4> GetModelMatrix()
        {
            if (this.modelMatrixRecord.IsMarked())// this model matrix is updated.
            {
                // get matrix representing transform relative to parent node.
                mat4 matrix = IModelSpaceHelper.GetModelMatrix(this);
                this.modelMatrixRecord.CancelMark();
                // cascade parent's model matrix.
                SceneObject obj = this.BindingSceneObject;
                if (obj != null)
                {
                    ITreeNode<SceneObject> parent = obj.Parent;
                    if (parent != null)
                    {
                        RendererBase parentRenderer = parent.Content.Renderer;
                        if (parentRenderer != null)
                        {
                            // get parent's matrix representing transform relative to world space coordinate.
                            MarkableStruct<mat4> parentMatrix = parentRenderer.GetModelMatrix();
                            // get matrix means transform relative to world space coordinate for this renderer.
                            matrix = parentMatrix.Value * matrix;
                        }
                    }
                }
                // update this renderer's transform matrix relative to world space coordinate.
                this.modelMatrix.Value = matrix;
            }
            else // this model matrix is not updated.
            {
                SceneObject obj = this.BindingSceneObject;
                if (obj != null)
                {
                    SceneObject parent = obj.Parent.Content;
                    if (parent != null)
                    {
                        RendererBase parentRenderer = parent.Renderer;
                        if (parentRenderer != null)
                        {
                            // get parent's matrix representing transform relative to world space coordinate.
                            MarkableStruct<mat4> parentMatrix = parentRenderer.GetModelMatrix();
                            long ticks = parentMatrix.UpdateTicks;
                            if (this.parentMatrixTicks != ticks) // parent's model matrix is updated.
                            {
                                mat4 matrix = IModelSpaceHelper.GetModelMatrix(this);
                                this.modelMatrix.Value = parentMatrix.Value * matrix;
                                this.parentMatrixTicks = ticks;
                            }
                        }
                    }
                }
            }

            return this.modelMatrix;
        }
コード例 #4
0
        protected override void DoRender(RenderEventArgs arg)
        {
            this.SetUniform("projectionMatrix", arg.Camera.GetProjectionMatrix());
            this.SetUniform("viewMatrix", arg.Camera.GetViewMatrix());
            MarkableStruct <mat4> model = this.GetModelMatrix();

            if (this.modelTicks != model.UpdateTicks)
            {
                this.SetUniform("modelMatrix", model.Value);
                this.modelTicks = model.UpdateTicks;
            }

            base.DoRender(arg);
        }
コード例 #5
0
        protected override void DoRender(RenderEventArgs arg)
        {
            mat4 projection = arg.Camera.GetProjectionMatrix();
            mat4 view       = arg.Camera.GetViewMatrix();

            this.SetUniform("projectionMatrix", projection);
            this.SetUniform("viewMatrix", view.ToArray());// test uniform array variable.
            MarkableStruct <mat4> model = this.GetModelMatrix();

            if (this.modelTicks != model.UpdateTicks)
            {
                this.SetUniform("modelMatrix", model.Value);
                this.modelTicks = model.UpdateTicks;
            }
            base.DoRender(arg);

            this.groundRenderer.Render(arg);
        }
コード例 #6
0
        protected override void DoRender(RenderEventArgs arg)
        {
            mat4 projection = arg.Camera.GetProjectionMatrix();
            mat4 view       = arg.Camera.GetViewMatrix();

            this.SetUniform("projectionMatrix", projection);
            this.SetUniform("viewMatrix", view);
            MarkableStruct <mat4> model = this.GetModelMatrix();

            if (this.modelTicks != model.UpdateTicks)
            {
                this.SetUniform("modelMatrix", model.Value);
                this.modelTicks = model.UpdateTicks;
            }

            //this.SetUniform("uniformColor", this.uniformColor);

            base.DoRender(arg);
        }
コード例 #7
0
        protected override void DoRender(RenderEventArgs arg)
        {
            mat4 projection = arg.Camera.GetProjectionMatrix();
            mat4 view       = arg.Camera.GetViewMatrix();

            this.SetUniform("transformMatrix.projection", projection);
            this.SetUniform("transformMatrix.view", view);
            MarkableStruct <mat4> model = this.GetModelMatrix();

            if (this.modelTicks != model.UpdateTicks)
            {
                this.SetUniform("transformMatrix.model", model.Value);
                this.modelTicks = model.UpdateTicks;
            }

            base.DoRender(arg);

            this.groundRenderer.Render(arg);
        }
コード例 #8
0
        protected override void DoRender(RenderEventArgs arg)
        {
            mat4 projection = arg.Camera.GetProjectionMatrix();
            mat4 view       = arg.Camera.GetViewMatrix();

            this.SetUniform("CameraRight_worldspace", new vec3(
                                view[0][0], view[1][0], view[2][0]));
            this.SetUniform("CameraUp_worldspace", new vec3(
                                view[0][1], view[1][1], view[2][1]));
            MarkableStruct <mat4> model = this.GetModelMatrix();

            if (this.modelTicks != model.UpdateTicks)
            {
                this.SetUniform("billboardCenter_worldspace", this.WorldPosition);
                this.modelTicks = model.UpdateTicks;
            }
            //this.TargetRenderer.Position + this.Offset);
            this.SetUniform("BillboardSize", new vec2(this.Width, this.Height));
            if (this.percentageRecord.IsMarked())
            {
                this.SetUniform("BillboardSizeInPercentage", this.Percentage);
                this.percentageRecord.CancelMark();
            }
            if (this.pixelSizeRecord.IsMarked())
            {
                this.SetUniform("BillboardSizeInPixelSize", this.PixelSize);
                this.pixelSizeRecord.CancelMark();
            }
            int[] viewport = OpenGL.GetViewport();
            this.SetUniform("ScreenSizeinPixelSize", new vec2(viewport[2], viewport[3]));
            this.SetUniform("billboardType", (float)(this.Type));
            float lifeLevel = (float)(Math.Sin(currentTime) * 0.4 + 0.5); currentTime += 0.1;

            this.SetUniform("LifeLevel", lifeLevel);
            this.SetUniform("projection", projection);
            this.SetUniform("view", view);

            base.DoRender(arg);
        }
コード例 #9
0
        protected override void DoRender(CSharpGL.RenderEventArgs arg)
        {
            mat4 projection = arg.Camera.GetProjectionMatrix();
            mat4 view       = arg.Camera.GetViewMatrix();

            this.SetUniform("projectionMatrix", projection);
            this.SetUniform("viewMatrix", view);
            MarkableStruct <mat4> model = this.GetModelMatrix();

            if (this.modelTicks != model.UpdateTicks)
            {
                this.SetUniform("modelMatrix", model.Value);
                this.modelTicks = model.UpdateTicks;
            }
            if (this.pointColorRecord.IsMarked())
            {
                this.SetUniform("PointColor", this.pointColor);
                this.pointColorRecord.CancelMark();
            }

            base.DoRender(arg);
        }