Exemplo n.º 1
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.º 2
0
        public override void Bind(SceneRenderer renderer, SceneNode root)
        {
            renderer.ActiveLight = this;

            if (renderer.ActiveShaderProgram != null && renderer.ActiveCamera != null)
            {
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightParameters", _lightParamsBuffer.GetBuffer(renderer));

                Matrix4 worldTrans  = this.GetWorldTransform(root) ?? Matrix4.Identity;
                Matrix4 invCamTrans = renderer.ActiveCamera.GetInverseWorldTransform(root) ?? Matrix4.Identity;
                Matrix4 finalTrans  = invCamTrans * worldTrans;

                Vector4 position = finalTrans * new Vector4(0, 0, 0, 1);
                position /= position.W;

                Vector3 spotDir = (finalTrans * new Vector4(SpotDirection, 0)).Normalized.XYZ;

                if (_lightTransBuffer.Value.Position != position || _lightTransBuffer.Value.SpotDirection != spotDir)
                {
                    _lightTransBuffer.Value = new LightTransformation()
                    {
                        Position      = position,
                        SpotDirection = spotDir
                    };
                }
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightTransformation", _lightTransBuffer.GetBuffer(renderer));
            }
        }
        public void Bind(SceneRenderer renderer, SceneNode root)
        {
            if (renderer.ActiveShaderProgram != null)
            {
                ClipPlaneParameters parameters = new ClipPlaneParameters();
                parameters.ClipPlaneWorldMatrix = this.GetWorldTransform(root).Value;
                parameters.UseClipPlane         = true;
                _cbuffer.Value = parameters;

                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "ClipPlaneParameters", _cbuffer.GetBuffer(renderer));
            }
        }
Exemplo n.º 4
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));
            }
        }
        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));
            }
        }
        public override void Bind(SceneRenderer renderer, SceneNode root)
        {
            renderer.ActiveLight = this;

            if (renderer.ActiveShaderProgram != null && renderer.ActiveCamera != null)
            {
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightParameters", _lightParamsBuffer.GetBuffer(renderer));

                Matrix4 worldTrans  = this.GetWorldTransform(root) ?? Matrix4.Identity;
                Matrix4 invCamTrans = renderer.ActiveCamera.GetInverseWorldTransform(root) ?? Matrix4.Identity;
                Matrix4 finalTrans  = invCamTrans * worldTrans;

                Vector4 position = finalTrans * new Vector4(0, 0, -1, 0);
                Matrix4 viewProj = _projectionMatrix * GetInverseWorldTransform(root) ?? Matrix4.Identity;
                if (_lightTransBuffer.Value.Position != position || _lightTransBuffer.Value.ViewProjection != viewProj)
                {
                    _lightTransBuffer.Value = new LightTransformation()
                    {
                        Position       = position,
                        ViewProjection = viewProj,
                    };
                }
                renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightTransformation", _lightTransBuffer.GetBuffer(renderer));

                if (this.CastShadow)
                {
                    if (_shadowParametersBuffer.Value != _shadowParameters)
                    {
                        _shadowParametersBuffer.Value = _shadowParameters;
                    }
                    renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "LightShadowParameters", _shadowParametersBuffer.GetBuffer(renderer));

                    for (int i = 0; i < this._shadowCascades.Count; i++)
                    {
                        _shadowCascades[i].BindShadowMap(renderer);
                    }
                }
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 public abstract void Bind(SceneRenderer renderer, SceneNode root);