public void Render(RenderContext rc, string pipelineStage)
        {
            Matrix4x4 orthoProjection = Matrix4x4.CreateOrthographicOffCenter(
                0f,
                rc.Viewport.Width,
                rc.Viewport.Height,
                0f,
                -1.0f,
                1.0f);
            Matrix4x4 proj = orthoProjection;

            _projectionMatrixBuffer.SetData(ref proj, 64);

            float     width = _imageWidth;
            Matrix4x4 world = Matrix4x4.CreateScale(width)
                              * Matrix4x4.CreateTranslation(rc.Viewport.Width - width - 20, 20, 0);

            _worldMatrixBuffer.SetData(ref world, 64);

            rc.VertexBuffer = _vertexBuffer;
            rc.IndexBuffer  = _indexBuffer;
            _material.Apply(rc);
            rc.SetConstantBuffer(0, _worldMatrixBuffer);
            rc.SetConstantBuffer(1, _projectionMatrixBuffer);
            rc.SetTexture(2, SharedTextures.GetTextureBinding("ShadowMap"));
            rc.SetDepthStencilState(_depthDisabledState);
            rc.DrawIndexedPrimitives(6, 0);
            rc.SetDepthStencilState(rc.DefaultDepthStencilState);
        }
            public void Render(RenderContext rc, string stage)
            {
                rc.VertexBuffer = _vb;
                rc.IndexBuffer  = _ib;
                if (stage == "ShadowMap")
                {
                    _shadowmapMaterial.Apply(rc);
                    rc.SetConstantBuffer(0, _buffersDict["LightProjMatrix"]);
                    rc.SetConstantBuffer(1, _buffersDict["LightViewMatrix"]);
                    _worldProvider.SetData(_worldBuffer);
                    rc.SetConstantBuffer(2, _worldBuffer);
                }
                else
                {
                    _regularMaterial.Apply(rc);

                    rc.SetConstantBuffer(0, _buffersDict["ProjectionMatrix"]);
                    rc.SetConstantBuffer(1, _buffersDict["ViewMatrix"]);
                    rc.SetConstantBuffer(2, _buffersDict["LightProjMatrix"]);
                    rc.SetConstantBuffer(3, _buffersDict["LightViewMatrix"]);
                    rc.SetConstantBuffer(4, _buffersDict["LightInfo"]);
                    _worldProvider.SetData(_worldBuffer);
                    rc.SetConstantBuffer(5, _worldBuffer);
                    _inverseWorldProvider.SetData(_inverseTransposeWorldBuffer);
                    rc.SetConstantBuffer(6, _inverseTransposeWorldBuffer);

                    rc.SetTexture(7, _textureBinding);
                    rc.SetSamplerState(8, rc.Anisox4Sampler);
                    rc.SetTexture(9, SharedTextures.GetTextureBinding("ShadowMap_Preview"));
                    rc.SetSamplerState(10, rc.PointSampler);
                }

                rc.DrawIndexedPrimitives(_elementCount, 0);
            }
Exemple #3
0
        public void Render(RenderContext rc, string pipelineStage)
        {
            rc.VertexBuffer = _vb;
            rc.IndexBuffer  = _ib;

            Matrix4x4 worldData =
                Matrix4x4.CreateScale(Scale)
                * Matrix4x4.CreateFromQuaternion(Rotation)
                * Matrix4x4.CreateTranslation(Position);

            _worldBuffer.SetData(ref worldData, 64);

            Matrix4x4 inverseTransposeData = Utilities.CalculateInverseTranspose(worldData);

            _inverseTransposeWorldBuffer.SetData(ref inverseTransposeData, 64);


            if (pipelineStage == "ShadowMap")
            {
                _shadowPassMaterial.Apply(rc);
                rc.SetConstantBuffer(0, SharedDataProviders.LightProjMatrixBuffer);
                rc.SetConstantBuffer(1, SharedDataProviders.LightViewMatrixBuffer);
                rc.SetConstantBuffer(2, _worldBuffer);
            }
            else
            {
                Debug.Assert(pipelineStage == "Standard");

                _regularPassMaterial.Apply(rc);
                rc.SetConstantBuffer(0, SharedDataProviders.ProjectionMatrixBuffer);
                rc.SetConstantBuffer(1, SharedDataProviders.ViewMatrixBuffer);
                rc.SetConstantBuffer(2, SharedDataProviders.LightProjMatrixBuffer);
                rc.SetConstantBuffer(3, SharedDataProviders.LightViewMatrixBuffer);
                rc.SetConstantBuffer(4, SharedDataProviders.LightInfoBuffer);
                rc.SetConstantBuffer(5, _worldBuffer);
                rc.SetConstantBuffer(6, _inverseTransposeWorldBuffer);

                rc.SetTexture(7, _surfaceTextureBinding);
                rc.SetSamplerState(8, rc.Anisox4Sampler);
                rc.SetTexture(9, SharedTextures.GetTextureBinding("ShadowMap"));
                rc.SetSamplerState(10, _shadowMapSampler);
            }

            rc.DrawIndexedPrimitives(_meshData.Indices.Length, 0);
        }