private void InitializeSharpDXRendering(DXScene dxScene) { var device = dxScene.Device; // DirectX device, back buffer, render targets and other resources are initialized by DXEngine // So here we only initialize things that are added by this sample // Code from SharpDX MiniCube sample: //// Compile Vertex and Pixel shaders //var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.hlsl", "VS", "vs_4_0"); //var vertexShader = new VertexShader(device, vertexShaderByteCode); //var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.hlsl", "PS", "ps_4_0"); //var pixelShader = new PixelShader(device, pixelShaderByteCode); var vertexShaderByteCode = System.IO.File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Shaders\MiniCube.vs")); _vertexShader = new VertexShader(device, vertexShaderByteCode); var pixelShaderByteCode = System.IO.File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Shaders\MiniCube.ps")); _pixelShader = new PixelShader(device, pixelShaderByteCode); // Code from SharpDX MiniCube sample: //var signature = ShaderSignature.GetInputSignature(vertexShaderByteCode); //// Layout from VertexShader input signature //var layout = new InputLayout(device, signature, new[] // { // new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), // new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) // }); _layout = new InputLayout(device, vertexShaderByteCode, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) }); // Instantiate Vertex buffer from vertex data var vertexBuffer = CustomRenderingStep1.GetSharpDXBoxVertexBuffer(); _vertices = Buffer.Create(device, BindFlags.VertexBuffer, vertexBuffer); // Create Constant Buffer _constantBuffer = new Buffer(device, SharpDX.Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); // We need to disable calculating near and far plane distanced based on the objects in 3D scene. // Without that the objects rendered with SharpDX could be clipped because their size is not accounted in the near and far plane calculations. // By default OptimizeNearAndFarCameraPlanes is set to true because this greatly improves the resolution of the depth buffer and // therefore reduces the possibility of Z-fighting artifacts. dxScene.OptimizeNearAndFarCameraPlanes = false; }
private void InitializeSharpDXRendering(DXScene dxScene) { var device = dxScene.Device; // DirectX device, back buffer, render targets and other resources are initialized by DXEngine // So here we only initialize things that are added by this sample // Code from SharpDX MiniCube sample: //// Compile Vertex and Pixel shaders //var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.hlsl", "VS", "vs_4_0"); //var vertexShader = new VertexShader(device, vertexShaderByteCode); //var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.hlsl", "PS", "ps_4_0"); //var pixelShader = new PixelShader(device, pixelShaderByteCode); var vertexShaderByteCode = System.IO.File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Shaders\MiniCube.vs")); _vertexShader = new VertexShader(device, vertexShaderByteCode); var pixelShaderByteCode = System.IO.File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Shaders\MiniCube.ps")); _pixelShader = new PixelShader(device, pixelShaderByteCode); // Code from SharpDX MiniCube sample: //var signature = ShaderSignature.GetInputSignature(vertexShaderByteCode); //// Layout from VertexShader input signature //var layout = new InputLayout(device, signature, new[] // { // new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), // new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) // }); _layout = new InputLayout(device, vertexShaderByteCode, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) }); // Instantiate Vertex buffer from vertex data var vertexBuffer = CustomRenderingStep1.GetSharpDXBoxVertexBuffer(); _vertices = Buffer.Create(device, BindFlags.VertexBuffer, vertexBuffer); // Create Constant Buffer _constantBuffer = new Buffer(device, SharpDX.Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); }