Example #1
0
        public Effect(SharpDX.Direct3D11.Device Device, string ShaderCode)
        {
            // Load vertex shader
            SharpDX.D3DCompiler.CompilationResult result = SharpDX.D3DCompiler.ShaderBytecode.Compile(ShaderCode, VertexShaderEntrypoint, "vs_4_0");
            SharpDX.D3DCompiler.ShaderBytecode    vsb    = result.Bytecode;
            VertexShader = new VertexShader(Device, vsb);

            // Load pixel shader
            result = SharpDX.D3DCompiler.ShaderBytecode.Compile(ShaderCode, PixelShaderEntrypoint, "ps_4_0");
            SharpDX.D3DCompiler.ShaderBytecode psb = result.Bytecode;
            PixelShader = new PixelShader(Device, psb);
            psb.Dispose();

            // Create constant buffer
            ConstantBuffer = new SharpDX.Direct3D11.Buffer(Device, Utilities.SizeOf <ConstantBufferData>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);

            // Create input layout. This tells the input-assembler stage how to map items from our vertex structures into vertices for the vertex shader.
            // It is validated against the vertex shader bytecode because it needs to match properly.
            InputLayout = new InputLayout(Device, vsb, new Vertex().InputElements);
            vsb.Dispose();
        }