Exemplo n.º 1
0
        public void Bind(SceneRenderer renderer, SceneNode root)
        {
            renderer.ActiveCamera = this;

            if (renderer.ActiveShaderProgram != null)
            {
                // upload projection matrix
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraProjection", _projectionMatrixBuffer.GetBuffer(renderer));

                // upload view matrix
                IConstantBuffer trans = this.GetInverseWorldTransformBuffer(root);
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraTransformation", trans.GetBuffer(renderer));
            }
        }
Exemplo n.º 2
0
        public bool Render(SceneRenderer renderer, SceneNode root)
        {
            if (this.Geometry != null && renderer.ActiveShaderProgram != null)
            {
                if (renderer.ActiveCamera != null && this.Geometry.IsCreated(renderer) && !renderer.ActiveCamera.IsInViewFrustum(this, root))
                {
                    // geometry is not in the view frustum of the camera
                    return(false);
                }

                // upload model matrix
                IConstantBuffer trans = this.GetWorldTransformBuffer(root);
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelTransformation", trans.GetBuffer(renderer));

                if (renderer.ActiveCamera != null)
                {
                    // upload model-view and normal matrix
                    trans = this.GetModelViewTransformBuffer(root, renderer.ActiveCamera);
                    renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelViewTransformation", trans.GetBuffer(renderer));
                }

                // render the geometry
                this.Geometry.Render(renderer);

                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        public bool RenderInstanced(SceneRenderer renderer, SceneNode root, int numInstances)
        {
            if (this.Geometry != null && renderer.ActiveShaderProgram != null)
            {
                // upload model matrix
                IConstantBuffer trans = this.GetWorldTransformBuffer(root);
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelTransformation", trans.GetBuffer(renderer));

                if (renderer.ActiveCamera != null)
                {
                    // upload model-view and normal matrix
                    trans = this.GetModelViewTransformBuffer(root, renderer.ActiveCamera);
                    renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ModelViewTransformation", trans.GetBuffer(renderer));
                }

                // render the geometry
                this.Geometry.RenderInstanced(renderer, numInstances);

                return(true);
            }

            return(false);
        }
        public void BindLightCamera(SceneRenderer renderer, SceneNode root, int shadowMapIdx)
        {
            renderer.ActiveCamera = this;
            _currentShadowMapIdx  = shadowMapIdx;

            if (renderer.ActiveShaderProgram != null)
            {
                // upload projection matrix
                _shadowCascades[_currentShadowMapIdx].BindProjection(renderer);

                // upload view matrix
                IConstantBuffer trans = this.GetInverseWorldTransformBuffer(root);
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraTransformation", trans.GetBuffer(renderer));
            }
        }