예제 #1
0
 /// <summary>
 /// Vertex Shader
 /// </summary>
 /// <param name="device"></param>
 /// <param name="name"></param>
 /// <param name="byteCode"></param>
 public VertexShader(Device device, string name, byte[] byteCode)
     : base(name, ShaderStage.Vertex)
 {
     shader = Collect(new global::SharpDX.Direct3D11.VertexShader(device, byteCode));
 }
예제 #2
0
        public override void Initialize(DeviceManager deviceManager)
        {
            base.Initialize(deviceManager);

            // Remove previous buffer
            if (this.constantBuffer != null)
            {
                this.constantBuffer.Dispose();
            }
            // RemoveAndDispose(ref constantBuffer);

            // Setup local variables
            var d3dDevice  = deviceManager.DeviceDirect3D;
            var d3dContext = deviceManager.ContextDirect3D;

            var path = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "HelixToolkit.UWP");

            // Loads vertex shader bytecode
            var vertexShaderByteCode = global::SharpDX.IO.NativeFile.ReadAllBytes(path + "\\MiniCube_VS.fxo");

            this.vertexShader = new global::SharpDX.Direct3D11.VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            this.pixelShader = new global::SharpDX.Direct3D11.PixelShader(d3dDevice, global::SharpDX.IO.NativeFile.ReadAllBytes(path + "\\MiniCube_PS.fxo"));

            // Layout from VertexShader input signature
            this.layout = new global::SharpDX.Direct3D11.InputLayout(
                d3dDevice,
                vertexShaderByteCode,
                new[]
            {
                new global::SharpDX.Direct3D11.InputElement("POSITION", 0, global::SharpDX.DXGI.Format.R32G32B32A32_Float, 0, 0),
                new global::SharpDX.Direct3D11.InputElement("COLOR", 0, global::SharpDX.DXGI.Format.R32G32B32A32_Float, 16, 0)
            });

            // Instantiate Vertex buffer from vertex data
            var vertices = global::SharpDX.Direct3D11.Buffer.Create(
                d3dDevice,
                global::SharpDX.Direct3D11.BindFlags.VertexBuffer,
                new[]
            {
                new global::SharpDX.Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 0.0f, 1.0f),         // Front
                new global::SharpDX.Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, 1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, 1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 0.0f, 1.0f),         // BACK
                new global::SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, -1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 0.0f, 1.0f, 1.0f),         // Top
                new global::SharpDX.Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, 1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 1.0f, 0.0f, 1.0f),         // Bottom
                new global::SharpDX.Vector4(1.0f, -1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, -1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 1.0f, 1.0f),         // Left
                new global::SharpDX.Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 1.0f, 1.0f),         // Right
                new global::SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, -1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, -1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, 1.0f, -1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new global::SharpDX.Vector4(1.0f, 1.0f, 1.0f, 1.0f), new global::SharpDX.Vector4(0.0f, 1.0f, 1.0f, 1.0f),
            });

            this.vertexBufferBinding = new global::SharpDX.Direct3D11.VertexBufferBinding(vertices, global::SharpDX.Utilities.SizeOf <global::SharpDX.Vector4>() * 2, 0);

            // Create Constant Buffer
            this.constantBuffer = new global::SharpDX.Direct3D11.Buffer(
                d3dDevice,
                global::SharpDX.Utilities.SizeOf <global::SharpDX.Matrix>(),
                global::SharpDX.Direct3D11.ResourceUsage.Default,
                global::SharpDX.Direct3D11.BindFlags.ConstantBuffer,
                global::SharpDX.Direct3D11.CpuAccessFlags.None,
                global::SharpDX.Direct3D11.ResourceOptionFlags.None,
                0);

            this.clock = new Stopwatch();
            this.clock.Start();
        }
예제 #3
0
 /// <summary>
 /// Vertex Shader
 /// </summary>
 /// <param name="device"></param>
 /// <param name="name"></param>
 /// <param name="byteCode"></param>
 public VertexShader(Device device, string name, byte[] byteCode)
     : base(name, ShaderStage.Vertex)
 {
     shader           = new global::SharpDX.Direct3D11.VertexShader(device, byteCode);
     shader.DebugName = name;
 }