Beispiel #1
0
        public SkySphere(float radius, int rings, int sectors, GxContext context)
        {
            mRadius         = radius;
            mBoundingSphere = new BoundingSphere(Vector3.Zero, radius);
            mSampler        = new Sampler(context);
            mMesh           = new Mesh(context);
            mMesh.AddElement("POSITION", 0, 3);
            mMesh.AddElement("TEXCOORD", 0, 2);
            mMesh.BlendState.BlendEnabled = false;
            mMesh.DepthState.DepthEnabled = true;
            mMesh.Stride = IO.SizeCache <SphereVertex> .Size;

            InitVertices(radius, rings, sectors);

            mMesh.VertexBuffer.UpdateData(mVertices);

            mMatrixBuffer = new ConstantBuffer(context);
            mMatrixBuffer.UpdateData(Matrix.Identity);

            var program = new ShaderProgram(context);

            program.SetVertexShader(Resources.Shaders.SkyVertex);
            program.SetPixelShader(Resources.Shaders.SkyPixel);

            mMesh.Program = program;
            mMesh.InitLayout(program);
        }
Beispiel #2
0
        private void InitMesh()
        {
            var program = new ShaderProgram(mContext);

            program.SetVertexShader(Shaders.TexturedQuadVertex);
            program.SetPixelShader(Shaders.TextureQuadPixel);

            mMesh = new Mesh(mContext)
            {
                IndexCount = 6, Stride = 16
            };

            mMesh.VertexBuffer.UpdateData(new[]
            {
                -1.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, -1.0f, 1.0f, 1.0f,
                -1.0f, -1.0f, 0.0f, 1.0f
            });
            mMesh.IndexBuffer.UpdateData(new uint[] { 0, 2, 1, 0, 3, 2 });
            mMesh.IndexBuffer.IndexFormat = SharpDX.DXGI.Format.R32_UInt;

            mMesh.AddElement("POSITION", 0, 2);
            mMesh.AddElement("TEXCOORD", 0, 2);
            mMesh.Program = program;
            mMesh.InitLayout(program);
            mMesh.DepthState.DepthEnabled = false;
            mMesh.BlendState.BlendEnabled = true;
        }
Beispiel #3
0
        public static void Initialize(GxContext context)
        {
            gNoBlendState = new BlendState(context)
            {
                BlendEnabled = false
            };
            gAlphaBlendState = new BlendState(context)
            {
                BlendEnabled = true
            };

            gNoCullState = new RasterState(context)
            {
                CullEnabled = false
            };
            gCullState = new RasterState(context)
            {
                CullEnabled = true
            };

            Sampler = new Sampler(context);

            InstanceBuffer = new ConstantBuffer(context);
            InstanceBuffer.UpdateData(Matrix.Identity); // preallocate space so the underlying buffer wont change anymore

            Mesh = new Mesh(context)
            {
                DepthState = { DepthEnabled = true },
                Stride     = IO.SizeCache <IO.Files.Models.WmoVertex> .Size
            };

            Mesh.AddElement("POSITION", 0, 3);
            Mesh.AddElement("NORMAL", 0, 3);
            Mesh.AddElement("TEXCOORD", 0, 2);
            Mesh.AddElement("COLOR", 0, 4, DataType.Byte, true);

            gNoBlendProgram = new ShaderProgram(context);
            gNoBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex);
            gNoBlendProgram.SetPixelShader(Resources.Shaders.WmoPixel);

            gBlendProgram = new ShaderProgram(context);
            gBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex);
            gBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelBlend);

            gIndoorNoBlendProgram = new ShaderProgram(context);
            gIndoorNoBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex);
            gIndoorNoBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelIndoor);

            gIndoorBlendProgram = new ShaderProgram(context);
            gIndoorBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex);
            gIndoorBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelBlendIndoor);

            Mesh.Program = gNoBlendProgram;

            Mesh.InitLayout(gNoBlendProgram);
        }
Beispiel #4
0
        public static void Initialize()
        {
            var indices = new ushort[]
            {
                0, 1, 2,
                0, 2, 3,
                0, 1, 5,
                0, 5, 4,
                3, 0, 4,
                3, 4, 7,
                2, 3, 7,
                2, 7, 6,
                1, 2, 6,
                1, 6, 5,
                4, 5, 6,
                4, 6, 7
            };

            gIndexBuffer = new IndexBuffer(WorldFrame.Instance.GraphicsContext);
            gIndexBuffer.UpdateData(indices);
            gIndexBuffer.IndexFormat = Format.R16_UInt;

            var program = new ShaderProgram(WorldFrame.Instance.GraphicsContext);

            program.SetVertexShader(Resources.Shaders.BoundingBoxVertex);
            program.SetPixelShader(Resources.Shaders.BoundingBoxPixel);

            gMesh = new Mesh(WorldFrame.Instance.GraphicsContext)
            {
                IndexBuffer = gIndexBuffer,
                IndexCount  = 36,
                Stride      = 24,
                BlendState  = { BlendEnabled = true },
                DepthState  = { DepthEnabled = true }
            };

            gMesh.AddElement("POSITION", 0, 3);
            gMesh.AddElement("TEXCOORD", 0, 3);

            gMesh.Program = program;
            gMesh.InitLayout(program);
        }
Beispiel #5
0
        public static void Initialize(GxContext context)
        {
            Mesh = new Mesh(context)
            {
                IndexCount = 16 * 16 * 4 * 3,
                Stride     = IO.SizeCache <Vector3> .Size,
                DepthState = { DepthEnabled = false }
            };

            Mesh.AddElement("POSITION", 0, 3);

            var indices = new uint[16 * 16 * 12];

            for (var y = 0u; y < 16; ++y)
            {
                for (var x = 0u; x < 16; ++x)
                {
                    var i = y * 16 * 12 + x * 12;

                    indices[i + 0] = y * 33 + x;
                    indices[i + 2] = y * 33 + x + 1;
                    indices[i + 1] = y * 33 + x + 17;

                    indices[i + 3] = y * 33 + x + 1;
                    indices[i + 5] = y * 33 + x + 34;
                    indices[i + 4] = y * 33 + x + 17;

                    indices[i + 6] = y * 33 + x + 34;
                    indices[i + 8] = y * 33 + x + 33;
                    indices[i + 7] = y * 33 + x + 17;

                    indices[i + 9]  = y * 33 + x + 33;
                    indices[i + 11] = y * 33 + x;
                    indices[i + 10] = y * 33 + x + 17;
                }
            }

            Mesh.IndexBuffer.UpdateData(indices);
            Mesh.IndexBuffer.IndexFormat = SharpDX.DXGI.Format.R32_UInt;

            var program = new ShaderProgram(context);

            program.SetVertexShader(Resources.Shaders.MapLowVertex);
            program.SetPixelShader(Resources.Shaders.MapLowPixel);
            Mesh.Program = program;
            Mesh.InitLayout(program);
        }
Beispiel #6
0
        public static void Initialize(GxContext context)
        {
            gMesh = new Mesh(context)
            {
                Stride         = IO.SizeCache <M2Vertex> .Size,
                InstanceStride = IO.SizeCache <PerInstanceBuffer> .Size,
                DepthState     =
                {
                    DepthEnabled      = true,
                    DepthWriteEnabled = true
                }
            };

            gMesh.BlendState.Dispose();
            gMesh.IndexBuffer.Dispose();
            gMesh.VertexBuffer.Dispose();

            gMesh.BlendState   = null;
            gMesh.IndexBuffer  = null;
            gMesh.VertexBuffer = null;

            gMesh.AddElement("POSITION", 0, 3);
            gMesh.AddElement("BLENDWEIGHT", 0, 4, DataType.Byte, true);
            gMesh.AddElement("BLENDINDEX", 0, 4, DataType.Byte);
            gMesh.AddElement("NORMAL", 0, 3);
            gMesh.AddElement("TEXCOORD", 0, 2);
            gMesh.AddElement("TEXCOORD", 1, 2);

            gMesh.AddElement("TEXCOORD", 2, 4, DataType.Float, false, 1, true);
            gMesh.AddElement("TEXCOORD", 3, 4, DataType.Float, false, 1, true);
            gMesh.AddElement("TEXCOORD", 4, 4, DataType.Float, false, 1, true);
            gMesh.AddElement("TEXCOORD", 5, 4, DataType.Float, false, 1, true);
            gMesh.AddElement("COLOR", 0, 4, DataType.Float, false, 1, true);

            // all combinations are set in this one each time
            gCustomProgram = new ShaderProgram(context);
            gCustomProgram.SetVertexShader(Resources.Shaders.M2VertexInstanced_VS_Diffuse_T1);
            gCustomProgram.SetPixelShader(Resources.Shaders.M2Pixel_PS_Combiners_Opaque);

            gMesh.Program = gCustomProgram;

            // Old versions for temporary WOTLK compatibility.. can we figure out how to map these to the actual types??
            gNoBlendProgram = new ShaderProgram(context);
            gNoBlendProgram.SetVertexShader(Resources.Shaders.M2VertexInstancedOld);
            gNoBlendProgram.SetPixelShader(Resources.Shaders.M2PixelOld);

            gMaskBlendProgram = new ShaderProgram(context);
            gMaskBlendProgram.SetVertexShader(Resources.Shaders.M2VertexInstancedOld);
            gMaskBlendProgram.SetPixelShader(Resources.Shaders.M2PixelBlendAlphaOld);

            gPerPassBuffer = new ConstantBuffer(context);

            gPerPassBuffer.UpdateData(new PerModelPassBuffer()
            {
                uvAnimMatrix1   = Matrix.Identity,
                uvAnimMatrix2   = Matrix.Identity,
                uvAnimMatrix3   = Matrix.Identity,
                uvAnimMatrix4   = Matrix.Identity,
                modelPassParams = Vector4.Zero
            });

            gSamplerWrapU = new Sampler(context)
            {
                AddressU          = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressV          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressW          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter            = SharpDX.Direct3D11.Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            gSamplerWrapV = new Sampler(context)
            {
                AddressU          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressV          = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressW          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter            = SharpDX.Direct3D11.Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            gSamplerWrapBoth = new Sampler(context)
            {
                AddressU          = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressV          = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressW          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter            = SharpDX.Direct3D11.Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            gSamplerClampBoth = new Sampler(context)
            {
                AddressU          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressV          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressW          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter            = SharpDX.Direct3D11.Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            for (var i = 0; i < BlendStates.Length; ++i)
            {
                BlendStates[i] = new BlendState(context);
            }

            BlendStates[0] = new BlendState(context)
            {
                BlendEnabled = false
            };

            BlendStates[1] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.One,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.Zero,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.One,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero
            };

            gNoCullState = new RasterState(context)
            {
                CullEnabled = false
            };
            gCullState = new RasterState(context)
            {
                CullEnabled = true
            };
        }
Beispiel #7
0
        public static void Initialize(GxContext context)
        {
            Mesh = new Mesh(context)
            {
                Stride     = IO.SizeCache <M2Vertex> .Size,
                DepthState = { DepthEnabled = true }
            };

            Mesh.BlendState.Dispose();
            Mesh.IndexBuffer.Dispose();
            Mesh.VertexBuffer.Dispose();

            Mesh.AddElement("POSITION", 0, 3);
            Mesh.AddElement("BLENDWEIGHT", 0, 4, DataType.Byte, true);
            Mesh.AddElement("BLENDINDEX", 0, 4, DataType.Byte);
            Mesh.AddElement("NORMAL", 0, 3);
            Mesh.AddElement("TEXCOORD", 0, 2);
            Mesh.AddElement("TEXCOORD", 1, 2);

            var program = new ShaderProgram(context);

            program.SetVertexShader(Resources.Shaders.M2VertexPortrait);
            program.SetPixelShader(Resources.Shaders.M2PixelPortrait);

            Mesh.Program = program;

            Sampler = new Sampler(context)
            {
                AddressMode = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                Filter      = SharpDX.Direct3D11.Filter.MinMagMipLinear
            };

            for (var i = 0; i < BlendStates.Length; ++i)
            {
                BlendStates[i] = new BlendState(context);
            }

            BlendStates[0] = new BlendState(context)
            {
                BlendEnabled = false
            };

            BlendStates[1] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.One,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.Zero,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.One,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero
            };

            BlendStates[2] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha
            };

            BlendStates[3] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.SourceColor,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.DestinationColor,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.DestinationAlpha
            };

            BlendStates[4] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.One,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.One
            };

            BlendStates[5] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha
            };

            BlendStates[6] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.DestinationColor,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.SourceColor,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.DestinationAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha
            };

            gNoBlendProgram = program;

            gBlendProgram = new ShaderProgram(context);
            gBlendProgram.SetPixelShader(Resources.Shaders.M2PixelPortraitBlend);
            gBlendProgram.SetVertexShader(Resources.Shaders.M2VertexPortrait);

            gNoCullState = new RasterState(context)
            {
                CullEnabled = false
            };
            gCullState = new RasterState(context)
            {
                CullEnabled = true
            };
        }
Beispiel #8
0
        public static void Initialize(GxContext context)
        {
            gDepthWriteState = new DepthState(context)
            {
                DepthEnabled      = true,
                DepthWriteEnabled = true
            };

            gDepthNoWriteState = new DepthState(context)
            {
                DepthEnabled      = true,
                DepthWriteEnabled = false
            };

            gMesh = new Mesh(context)
            {
                Stride     = IO.SizeCache <M2Vertex> .Size,
                DepthState = gDepthNoWriteState
            };

            gMesh.BlendState.Dispose();
            gMesh.IndexBuffer.Dispose();
            gMesh.VertexBuffer.Dispose();

            gMesh.BlendState   = null;
            gMesh.IndexBuffer  = null;
            gMesh.VertexBuffer = null;

            gMesh.AddElement("POSITION", 0, 3);
            gMesh.AddElement("BLENDWEIGHT", 0, 4, DataType.Byte, true);
            gMesh.AddElement("BLENDINDEX", 0, 4, DataType.Byte);
            gMesh.AddElement("NORMAL", 0, 3);
            gMesh.AddElement("TEXCOORD", 0, 2);
            gMesh.AddElement("TEXCOORD", 1, 2);

            // all combinations are set in this one each time
            gCustomProgram = new ShaderProgram(context);
            gCustomProgram.SetVertexShader(Resources.Shaders.M2VertexSingle_VS_Diffuse_T1);
            gCustomProgram.SetPixelShader(Resources.Shaders.M2Pixel_PS_Combiners_Mod);

            gMesh.Program = gCustomProgram;

            gNoBlendProgram = new ShaderProgram(context);
            gNoBlendProgram.SetPixelShader(Resources.Shaders.M2PixelOld);
            gNoBlendProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld);

            gBlendProgram = new ShaderProgram(context);
            gBlendProgram.SetPixelShader(Resources.Shaders.M2PixelBlendOld);
            gBlendProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld);

            gBlendTestProgram = new ShaderProgram(context);
            gBlendTestProgram.SetPixelShader(Resources.Shaders.M2PixelBlendAlphaOld);
            gBlendTestProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld);

            g2PassProgram = new ShaderProgram(context);
            g2PassProgram.SetPixelShader(Resources.Shaders.M2Pixel2PassOld);
            g2PassProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld);

            g3PassProgram = new ShaderProgram(context);
            g3PassProgram.SetPixelShader(Resources.Shaders.M2Pixel3PassOld);
            g3PassProgram.SetVertexShader(Resources.Shaders.M2VertexSingleOld);

            gPerDrawCallBuffer = new ConstantBuffer(context);
            gPerDrawCallBuffer.UpdateData(new PerDrawCallBuffer()
            {
                instanceMat = Matrix.Identity
            });

            gPerPassBuffer = new ConstantBuffer(context);

            gPerPassBuffer.UpdateData(new PerModelPassBuffer()
            {
                uvAnimMatrix1   = Matrix.Identity,
                uvAnimMatrix2   = Matrix.Identity,
                uvAnimMatrix3   = Matrix.Identity,
                uvAnimMatrix4   = Matrix.Identity,
                modelPassParams = Vector4.Zero
            });

            gSamplerWrapU = new Sampler(context)
            {
                AddressU          = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressV          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressW          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter            = SharpDX.Direct3D11.Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            gSamplerWrapV = new Sampler(context)
            {
                AddressU          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressV          = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressW          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter            = SharpDX.Direct3D11.Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            gSamplerWrapBoth = new Sampler(context)
            {
                AddressU          = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressV          = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressW          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter            = SharpDX.Direct3D11.Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            gSamplerClampBoth = new Sampler(context)
            {
                AddressU          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressV          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressW          = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter            = SharpDX.Direct3D11.Filter.Anisotropic,
                MaximumAnisotropy = 16
            };

            for (var i = 0; i < BlendStates.Length; ++i)
            {
                BlendStates[i] = new BlendState(context);
            }

            BlendStates[0] = new BlendState(context)
            {
                BlendEnabled = false
            };

            BlendStates[1] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.One,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.Zero,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.One,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.Zero
            };

            BlendStates[2] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha
            };

            BlendStates[3] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.SourceColor,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.DestinationColor,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.DestinationAlpha
            };

            BlendStates[4] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.One,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.One
            };

            BlendStates[5] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.SourceAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.InverseSourceAlpha
            };

            BlendStates[6] = new BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = SharpDX.Direct3D11.BlendOption.DestinationColor,
                DestinationBlend      = SharpDX.Direct3D11.BlendOption.SourceColor,
                SourceAlphaBlend      = SharpDX.Direct3D11.BlendOption.DestinationAlpha,
                DestinationAlphaBlend = SharpDX.Direct3D11.BlendOption.SourceAlpha
            };

            gNoCullState = new RasterState(context)
            {
                CullEnabled = false
            };
            gCullState = new RasterState(context)
            {
                CullEnabled = true
            };
        }
Beispiel #9
0
        public static void Initialize(GxContext context)
        {
            gGraphics = System.Drawing.Graphics.FromImage(Bitmap);

            gSampler = new Sampler(context)
            {
                AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter   = Filter.MinMagMipLinear
            };

            gSampler2D = new Sampler(context)
            {
                AddressU = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressV = SharpDX.Direct3D11.TextureAddressMode.Wrap,
                AddressW = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                Filter   = Filter.MinMagMipPoint
            };

            gBlendState = new Graphics.BlendState(context)
            {
                BlendEnabled          = true,
                SourceBlend           = BlendOption.SourceAlpha,
                DestinationBlend      = BlendOption.InverseSourceAlpha,
                SourceAlphaBlend      = BlendOption.SourceAlpha,
                DestinationAlphaBlend = BlendOption.InverseSourceAlpha
            };

            gRasterState = new RasterState(context)
            {
                CullEnabled = false
            };

            gDepthState = new DepthState(context)
            {
                DepthEnabled      = true,
                DepthWriteEnabled = false
            };

            gNoDepthState = new DepthState(context)
            {
                DepthEnabled      = false,
                DepthWriteEnabled = false
            };

            gVertexBuffer = new VertexBuffer(context);

            gMesh = new Mesh(context)
            {
                Stride = IO.SizeCache <WorldTextVertex> .Size
            };

            gMesh.DepthState.Dispose();
            gMesh.BlendState.Dispose();
            gMesh.IndexBuffer.Dispose();
            gMesh.VertexBuffer.Dispose();

            gMesh.RasterizerState = gRasterState;
            gMesh.BlendState      = gBlendState;
            gMesh.VertexBuffer    = gVertexBuffer;
            gMesh.DepthState      = gDepthState;

            gMesh.AddElement("POSITION", 0, 3);
            gMesh.AddElement("TEXCOORD", 0, 2);

            gWorldTextShader = new ShaderProgram(context);
            gWorldTextShader.SetVertexShader(Resources.Shaders.WorldTextVertex);
            gWorldTextShader.SetPixelShader(Resources.Shaders.WorldTextPixel);

            gWorldTextShader2D = new ShaderProgram(context);
            gWorldTextShader2D.SetVertexShader(Resources.Shaders.WorldTextVertexOrtho);
            gWorldTextShader2D.SetPixelShader(Resources.Shaders.WorldTextPixel);
            gMesh.Program = gWorldTextShader;
            gMesh.InitLayout(gWorldTextShader);

            gPerDrawCallBuffer = new ConstantBuffer(context);
            gPerDrawCallBuffer.UpdateData(new PerDrawCallBuffer
            {
                matTransform = Matrix.Identity
            });
        }