コード例 #1
0
 private void BuildGraphicsResources()
 {
     VertexPosition2Texture[] fullscreenQuadVertices =
     {
         new VertexPosition2Texture(new Vector2(-1.0f,  1.0f), new Vector2(0.0f, 0.0f)),
         new VertexPosition2Texture(new Vector2(3.0f,   1.0f), new Vector2(2.0f, 0.0f)),
         new VertexPosition2Texture(new Vector2(-1.0f, -3.0f), new Vector2(0.0f, 2.0f))
     };
     _fullscreenQuadVao = StaticVao.New(_engine.Device, fullscreenQuadVertices, VertexPosition2Texture.Layout, PrimitiveType.TriangleStrip);
 }
コード例 #2
0
        private void BuildGraphicsResources()
        {
            VertexPosition2Texture[] fullscreenQuadVertices =
            {
                new VertexPosition2Texture(new Vector2(-1.0f, 1.0f),  new Vector2(0.0f, 0.0f)),
                new VertexPosition2Texture(new Vector2(3.0f, 1.0f), new Vector2(2.0f, 0.0f)),
                new VertexPosition2Texture(new Vector2(-1.0f, -3.0f), new Vector2(0.0f, 2.0f))
            };
            _fullscreenQuadVao = StaticVao.New(_engine.Device, fullscreenQuadVertices, VertexPosition2Texture.Layout);

            _bsLightMap = new BlendState
            {
                ColorBlendFunction = BlendFunction.Add,
                ColorSourceBlend = Blend.Zero,
                ColorDestinationBlend = Blend.SourceColor,

                AlphaBlendFunction = BlendFunction.Add,
                AlphaSourceBlend = Blend.Zero,
                AlphaDestinationBlend = Blend.SourceAlpha,

                ColorWriteChannels = ColorWriteChannels.All
            };
        }
コード例 #3
0
ファイル: LightRenderer.cs プロジェクト: Gitspathe/penumbra
        private void BuildGraphicsResources()
        {
            // We build the quad a little larger than required in order to be able to also properly clear the alpha
            // for the region. The reason we need larger quad is due to camera rotation.
            var d = (float)(1 / Math.Sqrt(2));

            // Quad.
            VertexPosition2Texture[] quadVertices =
            {
                new VertexPosition2Texture(new Vector2(0.0f - d, 1.0f + d), new Vector2(0.0f - d, 0.0f - d)),
                new VertexPosition2Texture(new Vector2(1.0f + d, 1.0f + d), new Vector2(1.0f + d, 0.0f - d)),
                new VertexPosition2Texture(new Vector2(0.0f - d, 0.0f - d), new Vector2(0.0f - d, 1.0f + d)),
                new VertexPosition2Texture(new Vector2(1.0f + d, 0.0f - d), new Vector2(1.0f + d, 1.0f + d))
            };

            _quadVao = StaticVao.New(_engine.Device, quadVertices, VertexPosition2Texture.Layout, PrimitiveType.TriangleStrip);

            // Circle.
            const int   circlePoints      = 12;
            const float radius            = 1.0f;
            const float rotationIncrement = MathHelper.TwoPi / circlePoints;

            var vertices = new VertexPosition2Texture[circlePoints + 1];
            var indices  = new int[circlePoints * 3];

            var center = new VertexPosition2Texture(Vector2.Zero, Vector2.One);

            vertices[0] = center;
            for (int i = 1; i <= circlePoints; i++)
            {
                var angle = rotationIncrement * i;
                vertices[i] = new VertexPosition2Texture(new Vector2((float)Math.Cos(angle) * radius, (float)Math.Sin(angle) * radius), Vector2.Zero);

                int indexStart = (i - 1) * 3;
                indices[indexStart++] = 0;
                indices[indexStart++] = i;
                indices[indexStart]   = i + 1;
            }
            indices[indices.Length - 1] = 1;

            _circleVao = StaticVao.New(_engine.Device, vertices, VertexPosition2Texture.Layout, PrimitiveType.TriangleList, indices);

            // Render states.
            _bsLight = new BlendState
            {
                ColorBlendFunction    = BlendFunction.Add,
                ColorSourceBlend      = Blend.DestinationAlpha,
                ColorDestinationBlend = Blend.One,
                //ColorDestinationBlend = Blend.InverseSourceColor, // Blends lights a little softer.
                ColorWriteChannels    = ColorWriteChannels.All,
                AlphaBlendFunction    = BlendFunction.Add,
                AlphaSourceBlend      = Blend.One,
                AlphaDestinationBlend = Blend.Zero
            };
            _dssOccludedLight = new DepthStencilState
            {
                DepthBufferEnable = false,

                StencilEnable    = true,
                StencilWriteMask = 0xff,
                StencilMask      = 0x00,
                StencilFunction  = CompareFunction.Always,
                StencilPass      = StencilOperation.Zero
            };
        }
コード例 #4
0
        private void BuildGraphicsResources()
        {
            // We build the quad a little larger than required in order to be able to also properly clear the alpha
            // for the region. The reason we need larger quad is due to camera rotation.
            var d = (float) (1 / Math.Sqrt(2));

            // Quad.
            VertexPosition2Texture[] quadVertices =
            {
                new VertexPosition2Texture(new Vector2(0.0f - d, 1.0f + d), new Vector2(0.0f - d, 0.0f - d)),
                new VertexPosition2Texture(new Vector2(1.0f + d, 1.0f + d), new Vector2(1.0f + d, 0.0f - d)),
                new VertexPosition2Texture(new Vector2(0.0f - d, 0.0f - d), new Vector2(0.0f - d, 1.0f + d)),
                new VertexPosition2Texture(new Vector2(1.0f + d, 0.0f - d), new Vector2(1.0f + d, 1.0f + d))
            };

            _quadVao = StaticVao.New(_engine.Device, quadVertices, VertexPosition2Texture.Layout);

            // Circle.
            const int circlePoints = 12;
            const float radius = 1.0f;
            const float rotationIncrement = MathHelper.TwoPi / circlePoints;

            var vertices = new VertexPosition2Texture[circlePoints + 1];
            var indices = new int[circlePoints * 3];

            var center = new VertexPosition2Texture(Vector2.Zero, Vector2.One);
            vertices[0] = center;
            for (int i = 1; i <= circlePoints; i++)
            {
                var angle = rotationIncrement * i;
                vertices[i] = new VertexPosition2Texture(new Vector2((float)Math.Cos(angle) * radius, (float)Math.Sin(angle) * radius), Vector2.Zero);

                int indexStart = (i - 1) * 3;
                indices[indexStart++] = 0;
                indices[indexStart++] = i;
                indices[indexStart] = i + 1;
            }
            indices[indices.Length - 1] = 1;

            _circleVao = StaticVao.New(_engine.Device, vertices, VertexPosition2Texture.Layout, indices);

            // Render states.
            _bsLight = new BlendState
            {
                ColorBlendFunction = BlendFunction.Add,
                ColorSourceBlend = Blend.DestinationAlpha,
                ColorDestinationBlend = Blend.One,
                //ColorDestinationBlend = Blend.InverseSourceColor, // Blends lights a little softer.
                ColorWriteChannels = ColorWriteChannels.All,
                AlphaBlendFunction = BlendFunction.Add,
                AlphaSourceBlend = Blend.One,
                AlphaDestinationBlend = Blend.Zero
            };
            //_dssOccludedLight = new DepthStencilState
            //{
            //    DepthBufferEnable = false,

            //    StencilEnable = true,
            //    StencilWriteMask = 0xff,
            //    StencilMask = 0x00,
            //    StencilFunction = CompareFunction.Always,
            //    StencilPass = StencilOperation.Zero
            //};
        }