コード例 #1
0
ファイル: Sobel.cs プロジェクト: ishkang/Gorgon
        /// <summary>
        /// Initializes a new instance of the <see cref="Sobel"/> class.
        /// </summary>
        /// <param name="graphics">The graphics interface to use.</param>
        /// <param name="sobelShader">The shader for sobel edge detection.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or the <paramref name="sobelShader"/> parameter is <b>null</b>.</exception>
        public Sobel(GorgonGraphics graphics, GorgonComputeShader sobelShader)
        {
            if (sobelShader == null)
            {
                throw new ArgumentNullException(nameof(sobelShader));
            }

            _compute   = new GorgonComputeEngine(graphics);
            _sobelData = new GorgonConstantBuffer(graphics,
                                                  new GorgonConstantBufferInfo("SobelData")
            {
                Usage       = ResourceUsage.Dynamic,
                SizeInBytes = 16
            });

            _dispatchBuilder = new GorgonDispatchCallBuilder();
            _dispatchBuilder.ConstantBuffer(_sobelData.GetView())
            .ComputeShader(sobelShader);
        }
コード例 #2
0
ファイル: VolumeRenderer.cs プロジェクト: ishkang/Gorgon
        /// <summary>
        /// Function used to build the resources required by the volume renderer.
        /// </summary>
        public void CreateResources()
        {
            _cubeVs        = GorgonShaderFactory.Compile <GorgonVertexShader>(_graphics, Resources.VolumeRenderShaders, "VolumeVS", true);
            _cubePosShader = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics, Resources.VolumeRenderShaders, "VolumePositionPS", true);
            _cubeDirShader = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics, Resources.VolumeRenderShaders, "VolumeRayCastPS", true);
            _inputLayout   = GorgonInputLayout.CreateUsingType <CubeVertex>(_graphics, _cubeVs);
            _cube          = new Cube(_graphics, _inputLayout);

            _cubeTransform = new GorgonConstantBuffer(_graphics, new GorgonConstantBufferInfo
            {
                SizeInBytes = DX.Matrix.SizeInBytes
            });

            _volumeRayParams = new GorgonConstantBuffer(_graphics, new GorgonConstantBufferInfo
            {
                SizeInBytes = Unsafe.SizeOf <VolumeRayParameters>()
            });

            _volumeScaleFactor = new GorgonConstantBuffer(_graphics, new GorgonConstantBufferInfo
            {
                SizeInBytes = DX.Vector4.SizeInBytes
            });

            // Our camera is never changing, so we only need to define it here.
            DX.Matrix.Translation(0, 0, 1.5f, out _view);
            ResizeRenderRegion();

            UpdateCubeTransform();

            var pipelineBuilder = new GorgonPipelineStateBuilder(_graphics);
            var drawBuilder     = new GorgonDrawIndexCallBuilder();

            pipelineBuilder
            .PixelShader(_cubePosShader)
            .VertexShader(_cubeVs);

            // Position draw calls.
            _cubePosDrawCull = drawBuilder
                               .ConstantBuffer(ShaderType.Vertex, _cubeTransform.GetView())
                               .ConstantBuffer(ShaderType.Vertex, _volumeScaleFactor.GetView(), 1)
                               .PipelineState(pipelineBuilder)
                               .IndexBuffer(_cube.IndexBuffer, indexCount: _cube.IndexBuffer.IndexCount)
                               .VertexBuffer(_inputLayout, _cube.VertexBuffer[0])
                               .Build();

            pipelineBuilder
            .RasterState(GorgonRasterState.CullFrontFace);

            _cubePosDrawFrontCull = drawBuilder
                                    .PipelineState(pipelineBuilder)
                                    .Build();

            // Raycasting draw call.
            pipelineBuilder
            .PixelShader(_cubeDirShader)
            .RasterState(GorgonRasterState.Default);

            _cubeDirDrawCall = drawBuilder
                               .ConstantBuffer(ShaderType.Pixel, _volumeRayParams.GetView(), 0)
                               .PipelineState(pipelineBuilder)
                               .Build();
        }