Ejemplo 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));
            }
        }
        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);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public void BindProjection(Renderer renderer)
 {
     if (_projectionMatrixBuffer.Value != LightFrustum.ProjectionMatrix)
     {
         _projectionMatrixBuffer.Value = LightFrustum.ProjectionMatrix;
     }
     renderer.ActiveShaderProgram.BindConstantBuffer(renderer, "CameraProjection", _projectionMatrixBuffer.GetBuffer(renderer));
 }
Ejemplo n.º 4
0
        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));
            }
        }