Example #1
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;

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

            if (this.RenderAsWireframe)
            {
                // render wireframe.
                program.SetUniform("renderWireframe", true);
                polygonMode.On();
                polygonOffsetState.On();
                method.Render();
                polygonOffsetState.Off();
                polygonMode.Off();
            }
            else
            {
                // render solid body.
                program.SetUniform("renderWireframe", false);
                method.Render();
            }
        }
Example #2
0
        protected override void DoRender(RenderEventArgs arg)
        {
            this.SetUniform("renderWireframe", false);
            base.DoRender(arg);

            polygonModeSwitch.On();
            lineWidthSwitch.On();
            // offsetSwitch.On();
            this.SetUniform("renderWireframe", true);
            base.DoRender(arg);
            //offsetSwitch.Off();
            lineWidthSwitch.Off();
            polygonModeSwitch.Off();
        }
Example #3
0
        public void ExtrudeShadow(ShadowVolumeExtrudeEventArgs arg)
        {
            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            var           method  = this.RenderUnit.Methods[(int)MethodName.extrudeShadow];
            ShaderProgram program = method.Program;

            program.SetUniform("gProjectionView", projection * view);
            program.SetUniform("gWorld", model);
            if (arg.Light is DirectionalLight)
            {
                var light = arg.Light as DirectionalLight;
                program.SetUniform("gLightPos", light.Direction);
                program.SetUniform("farAway", true);
            }
            else
            {
                program.SetUniform("gLightPos", arg.Light.Position);
                program.SetUniform("farAway", false);
            }

            // light info.
            directionalLight.SetBlinnPhongUniforms(program);
            // material.
            program.SetUniform("material.diffuse", new vec3(1, 0, 0));  //this.Color);
            program.SetUniform("material.specular", new vec3(1, 0, 0)); //this.Color);
            program.SetUniform("material.shiness", this.Shiness);

            fillFarOffsetSwitch.On();
            program.SetUniform("wireframe", false);
            method.Render();
            fillFarOffsetSwitch.Off();

            polygonModeSwitch.On();
            lineWidthSwitch.On();
            program.SetUniform("wireframe", true);
            method.Render();
            lineWidthSwitch.Off();
            polygonModeSwitch.Off();
        }
Example #4
0
        public void RenderBeforeChildren(RenderEventArgs arg)
        {
            if (!this.IsInitialized)
            {
                this.Initialize();
            }

            this.RotationAngle += this.RotateSpeed;

            ICamera camera     = arg.Camera;
            mat4    projection = camera.GetProjectionMatrix();
            mat4    view       = camera.GetViewMatrix();
            mat4    model      = this.GetModelMatrix();

            var           method  = this.RenderUnit.Methods[0]; // the only render unit in this node.
            ShaderProgram program = method.Program;

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

            if (this.RenderWireframe)
            {
                // render wireframe.
                program.SetUniform("renderWireframe", true);
                polygonMode.On();
                polygonOffsetState.On();
                method.Render();
                polygonOffsetState.Off();
                polygonMode.Off();
            }

            if (this.RenderBody)
            {
                // render solid body.
                program.SetUniform("renderWireframe", false);
                method.Render();
            }
        }