示例#1
0
        public static InputLayout GetLayout(GxContext context, InputElement[] elements, Mesh mesh, ShaderProgram program)
        {
            Dictionary<ShaderProgram, InputLayout> meshEntry;
            InputLayout layout;

            if (Layouts.TryGetValue(mesh, out meshEntry))
            {
                if (meshEntry.TryGetValue(program, out layout))
                    return layout;

                layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements);
                meshEntry.Add(program, layout);
                return layout;
            }

            bool hasInstance = false, hasVertex = false;

            for(var i = 0; i < elements.Length; ++i)
            {
                if (hasInstance && hasVertex)
                    break;

                if(elements[i].Classification == InputClassification.PerInstanceData && hasInstance == false)
                {
                    elements[i].AlignedByteOffset = 0;
                    hasInstance = true;
                    continue;
                }

                if(elements[i].Classification == InputClassification.PerVertexData && hasVertex == false)
                {
                    elements[i].AlignedByteOffset = 0;
                    hasVertex = true;
                }
            }

            layout = new InputLayout(context.Device, program.VertexShaderCode.Data, elements);
            meshEntry = new Dictionary<ShaderProgram, InputLayout>()
            {
                {program, layout}
            };

            Layouts.Add(mesh, meshEntry);
            return layout;
        }
示例#2
0
        public SkySphere(float radius, int rings, int sectors, GxContext context)
        {
            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;
        }
示例#3
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};
        }
示例#4
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;
        }
示例#5
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;
        }
示例#6
0
 public static void Initialize(GxContext context)
 {
     ChunkMesh = new Mesh(context);
     InitMesh(context);
 }