Beispiel #1
0
        public Renderer.Texture2D       CreateTextureCube(Renderer.Device _Device)
        {
            if (m_Opts.m_type != ImageOptions.TYPE.TT_CUBIC)
            {
                throw new Exception("The image is not a cube map texture!");
            }

            ImageUtility.PIXEL_FORMAT     textureFormat = ImageUtility.PIXEL_FORMAT.UNKNOWN;
            ImageUtility.COMPONENT_FORMAT componentFormat;
            m_Opts.m_format.GetEquivalentRendererFormat(out textureFormat, out componentFormat);

            uint ArraySize = 6 * m_Opts.m_arraySize;
            uint MipsCount = m_Opts.m_curNumLevels;
            uint PixelSize = m_Opts.m_format.BitsCount >> 3;

            List <Renderer.PixelsBuffer> Content = new List <Renderer.PixelsBuffer>();

            for (uint SliceIndex = 0; SliceIndex < ArraySize; SliceIndex++)
            {
                for (uint MipLevelIndex = 0; MipLevelIndex < MipsCount; MipLevelIndex++)
                {
                    ImageSlice Slice = m_Slices[MipLevelIndex * ArraySize + SliceIndex];                        // Stupidly stored in reverse order!

                    Renderer.PixelsBuffer Pixels = new Renderer.PixelsBuffer((uint)(Slice.m_Width * Slice.m_Height * PixelSize));
                    Content.Add(Pixels);

                    using (BinaryWriter Writer = Pixels.OpenStreamWrite())
                        Writer.Write(Slice.m_Content);
                }
            }

            Renderer.Texture2D Result = new Renderer.Texture2D(_Device, m_Opts.m_curWidth, m_Opts.m_curHeight, -6 * (int)m_Opts.m_arraySize, m_Opts.m_curNumLevels, textureFormat, componentFormat, false, false, Content.ToArray());
            return(Result);
        }
Beispiel #2
0
        private void LoadHeightMap( System.IO.FileInfo _FileName )
        {
            try {
                panelParameters.Enabled = false;

                // Dispose of existing resources
                if ( m_imageSourceHeight != null )
                    m_imageSourceHeight.Dispose();
                m_imageSourceHeight = null;

                if ( m_textureTarget_CPU != null )
                    m_textureTarget_CPU.Dispose();
                m_textureTarget_CPU = null;
                if ( m_textureTarget0 != null )
                    m_textureTarget0.Dispose();
                m_textureTarget0 = null;
                if ( m_textureTarget1 != null )
                    m_textureTarget1.Dispose();
                m_textureTarget1 = null;
                if ( m_textureSourceHeightMap != null )
                    m_textureSourceHeightMap.Dispose();
                m_textureSourceHeightMap = null;

                // Load the source image
                // Assume it's in linear space
                m_SourceFileName = _FileName;
                m_imageSourceHeight = new ImageUtility.ImageFile( _FileName );
                outputPanelInputHeightMap.Bitmap = m_imageSourceHeight.AsBitmap;

                W = m_imageSourceHeight.Width;
                H = m_imageSourceHeight.Height;

                // Build the source texture
                float4[]	scanline = new float4[W];

                Renderer.PixelsBuffer	SourceHeightMap = new Renderer.PixelsBuffer( W*H*4 );
                using ( System.IO.BinaryWriter Wr = SourceHeightMap.OpenStreamWrite() )
                    for ( uint Y=0; Y < H; Y++ ) {
                        m_imageSourceHeight.ReadScanline( Y, scanline );
                        for ( uint X=0; X < W; X++ ) {
                            Wr.Write( scanline[X].y );
                        }
                    }

                m_textureSourceHeightMap = new Renderer.Texture2D( m_device, W, H, 1, 1, Renderer.PIXEL_FORMAT.R32_FLOAT, false, false, new Renderer.PixelsBuffer[] { SourceHeightMap } );

                // Build the target UAV & staging texture for readback
                m_textureTarget0 = new Renderer.Texture2D( m_device, W, H, 1, 1, Renderer.PIXEL_FORMAT.R32_FLOAT, false, true, null );
                m_textureTarget1 = new Renderer.Texture2D( m_device, W, H, 1, 1, Renderer.PIXEL_FORMAT.R32_FLOAT, false, true, null );
                m_textureTarget_CPU = new Renderer.Texture2D( m_device, W, H, 1, 1, Renderer.PIXEL_FORMAT.R32_FLOAT, true, false, null );

                panelParameters.Enabled = true;
                buttonGenerate.Focus();

            } catch ( Exception _e ) {
                MessageBox( "An error occurred while opening the image:\n\n", _e );
            }
        }
Beispiel #3
0
        private void LoadNormalMap( System.IO.FileInfo _FileName )
        {
            try {
                // Dispose of existing resources
                if ( m_imageSourceNormal != null )
                    m_imageSourceNormal.Dispose();
                m_imageSourceNormal = null;

                if ( m_TextureSourceNormal != null )
                    m_TextureSourceNormal.Dispose();
                m_TextureSourceNormal = null;

                // Load the source image
                // Assume it's in linear space (all normal maps should be in linear space, with the default value being (0.5, 0.5, 1))
                m_imageSourceNormal = new ImageUtility.ImageFile( _FileName );
                imagePanelNormalMap.Bitmap = m_imageSourceNormal.AsBitmap;

                uint	W = m_imageSourceNormal.Width;
                uint	H = m_imageSourceNormal.Height;

                // Build the source texture
                float4[]	scanline = new float4[W];

                Renderer.PixelsBuffer	SourceNormalMap = new Renderer.PixelsBuffer( W*H*4*4 );
                using ( System.IO.BinaryWriter Wr = SourceNormalMap.OpenStreamWrite() )
                    for ( int Y=0; Y < H; Y++ ) {
                        m_imageSourceNormal.ReadScanline( (uint) Y, scanline );
                        for ( int X=0; X < W; X++ ) {
                            float	Nx = 2.0f * scanline[X].x - 1.0f;
                            float	Ny = 1.0f - 2.0f * scanline[X].y;
                            float	Nz = 2.0f * scanline[X].z - 1.0f;
                            Wr.Write( Nx );
                            Wr.Write( Ny );
                            Wr.Write( Nz );
                            Wr.Write( 1.0f );
                        }
                    }

                m_TextureSourceNormal = new Renderer.Texture2D( m_device, W, H, 1, 1, Renderer.PIXEL_FORMAT.RGBA32_FLOAT, false, false, new Renderer.PixelsBuffer[] { SourceNormalMap } );

            } catch ( Exception _e ) {
                MessageBox( "An error occurred while opening the image:\n\n", _e );
            }
        }
Beispiel #4
0
        private void clearNormalToolStripMenuItem_Click( object sender, EventArgs e )
        {
            if ( m_TextureSourceNormal != null )
                m_TextureSourceNormal.Dispose();
            m_TextureSourceNormal = null;
            imagePanelNormalMap.Bitmap = null;

            // Create the default, planar normal map
            Renderer.PixelsBuffer	SourceNormalMap = new Renderer.PixelsBuffer( 4*4 );
            using ( System.IO.BinaryWriter Wr = SourceNormalMap.OpenStreamWrite() ) {
                Wr.Write( 0.0f );
                Wr.Write( 0.0f );
                Wr.Write( 1.0f );
                Wr.Write( 1.0f );
            }

            m_TextureSourceNormal = new Renderer.Texture2D( m_device, 1, 1, 1, 1, Renderer.PIXEL_FORMAT.RGBA32_FLOAT, false, false, new Renderer.PixelsBuffer[] { SourceNormalMap } );
        }