예제 #1
0
        public void Render(Light light)
        {
            EffectTechnique fxTech = light.ApplyEffectParams(this);

            Matrix wvp;

            Matrix.Multiply(ref light.LocalToWorld, ref _engine.Camera.ViewProjection, out wvp);

            _engine.Device.DepthStencilState = DepthStencilState.None;
            _engine.Device.DepthStencilState = light.ShadowType == ShadowType.Occluded
                ? _dssOccludedLight
                : DepthStencilState.None;
            _engine.Device.BlendState      = _bsLight;
            _engine.Device.RasterizerState = _engine.Rs;
            _engine.Device.SetVertexArrayObject(_quadVao);
            _fxLightParamWvp.SetValue(wvp);
            fxTech.Passes[0].Apply();
            _engine.Device.DrawPrimitives(_quadVao.PrimitiveTopology, 0, _quadVao.PrimitiveCount);

            if (_engine.Debug)
            {
                _engine.Device.BlendState      = BlendState.Opaque;
                _engine.Device.RasterizerState = _engine.RsDebug;

                // Draw debug quad.
                //const float factor = 0.41f;
                //wvp.M11 = wvp.M11 * factor;
                //wvp.M22 = wvp.M22 * factor;

                //_fxLightParamWvp.SetValue(wvp);
                //_fxDebugLightTech.Passes[0].Apply();
                //_engine.Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, _quadVao.VertexCount - 2);

                Matrix world = Matrix.Identity;
                // Scaling.
                world.M11 = light.Radius;
                world.M22 = light.Radius;
                // Translation.
                world.M41 = light.Position.X;
                world.M42 = light.Position.Y;
                Matrix.Multiply(ref world, ref _engine.Camera.ViewProjection, out wvp);

                _engine.Device.SetVertexArrayObject(_circleVao);
                _fxLightParamWvp.SetValue(wvp);
                _fxDebugLightTech.Passes[0].Apply();
                _engine.Device.DrawIndexedPrimitives(_circleVao.PrimitiveTopology, 0, 0, _circleVao.PrimitiveCount);
            }
        }
        public void Render(Light light)
        {
            EffectTechnique fxTech = light.ApplyEffectParams(this);

            Matrix wvp;
            Matrix.Multiply(ref light.LocalToWorld, ref _engine.Camera.ViewProjection, out wvp);

            _engine.Device.DepthStencilState = DepthStencilState.None;
            //_engine.Device.DepthStencilState = light.ShadowType == ShadowType.Occluded
            //    ? _dssOccludedLight
            //    : DepthStencilState.None;
            _engine.Device.BlendState = _bsLight;
            _engine.Device.RasterizerState = _engine.Rs;
            _engine.Device.SetVertexArrayObject(_quadVao);
            _fxLightParamWvp.SetValue(wvp);
            fxTech.Passes[0].Apply();
            _engine.Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, _quadVao.VertexCount - 2);

            if (_engine.Debug)
            {
                _engine.Device.BlendState = BlendState.Opaque;
                _engine.Device.RasterizerState = _engine.RsDebug;

                // Draw debug quad.
                //const float factor = 0.41f;
                //wvp.M11 = wvp.M11 * factor;
                //wvp.M22 = wvp.M22 * factor;

                //_fxLightParamWvp.SetValue(wvp);
                //_fxDebugLightTech.Passes[0].Apply();
                //_engine.Device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, _quadVao.VertexCount - 2);

                Matrix world = Matrix.Identity;
                // Scaling.
                world.M11 = light.Radius;
                world.M22 = light.Radius;
                // Translation.
                world.M41 = light.Position.X;
                world.M42 = light.Position.Y;
                Matrix.Multiply(ref world, ref _engine.Camera.ViewProjection, out wvp);

                _engine.Device.SetVertexArrayObject(_circleVao);
                _fxLightParamWvp.SetValue(wvp);
                _fxDebugLightTech.Passes[0].Apply();
                _engine.Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _circleVao.VertexCount, 0, _circleVao.IndexCount / 3);
            }
        }