コード例 #1
0
ファイル: VolumeRenderer.cs プロジェクト: ishkang/Gorgon
        /// <summary>
        /// Function to update the cube transform and send it to the GPU.
        /// </summary>
        private void UpdateCubeTransform()
        {
            _rotationAngle += GorgonTiming.Delta * 30.0f;

            if (_rotationAngle > 360.0f)
            {
                _rotationAngle = 360.0f - _rotationAngle;
            }

            // Build our world/view/projection matrix to send to
            // the shader.
            _cube.RotateXYZ(_rotationAngle, _rotationAngle, 0);

            DX.Matrix.Multiply(ref _cube.WorldMatrix, ref _view, out DX.Matrix temp);
            DX.Matrix.Multiply(ref temp, ref _projection, out DX.Matrix wvp);
            DX.Matrix.Transpose(ref wvp, out wvp);

            _cubeTransform.SetData(ref wvp);
        }
コード例 #2
0
ファイル: VolumeRenderer.cs プロジェクト: ishkang/Gorgon
        /// <summary>
        /// Function to assign the volume texture to render.
        /// </summary>
        /// <param name="texture">The volume texture to render.</param>
        public void AssignTexture(GorgonTexture3DView texture)
        {
            _textureView = texture;

            var   size      = new DX.Vector3(texture.Width, texture.Height, texture.Depth);
            float maxSize   = texture.Width.Max(texture.Height).Max(texture.Depth);
            var   volParams = new VolumeRayParameters
            {
                Steps = new DX.Vector3(1.0f / texture.Width,
                                       1.0f / texture.Height,
                                       1.0f / texture.Depth) * 0.5f,
                Iterations = (int)(maxSize * 2.0f)
            };

            _volumeRayParams.SetData(ref volParams);

            var scaleFactor = new DX.Vector4(1.0f, 1.0f, 1.0f / (maxSize / size.Z), 1.0f);

            _volumeScaleFactor.SetData(ref scaleFactor);

            RebuildVolumeData();
        }
コード例 #3
0
ファイル: Sobel.cs プロジェクト: ishkang/Gorgon
        /// <summary>
        /// Function to process a texture into the output texture.
        /// </summary>
        /// <param name="texture">The texture to process.</param>
        /// <param name="outputTexture">The output texture that will receive the processed texture.</param>
        /// <param name="thickness">The thickness of the sobel lines.</param>
        /// <param name="threshold">The threshold used to determine an edge.</param>
        public void Process(GorgonTexture2DView texture, GorgonTexture2DReadWriteView outputTexture, int thickness, float threshold)
        {
            if ((texture == null) ||
                (outputTexture == null))
            {
                return;
            }

            if ((_dispatch == null) || (_dispatch.ShaderResources[0] != texture) || (_dispatch.ReadWriteViews[0].ReadWriteView != outputTexture))
            {
                _dispatch = _dispatchBuilder.ReadWriteView(new GorgonReadWriteViewBinding(outputTexture))
                            .ShaderResource(texture)
                            .Build();
            }

            _sobelOptions[0] = thickness;
            _sobelOptions[1] = threshold;
            _sobelData.SetData(_sobelOptions);

            // Send 32 threads per group.
            _compute.Execute(_dispatch, (int)(texture.Width / 32.0f).FastCeiling(), (int)(texture.Height / 32.0f).FastCeiling(), 1);
        }