<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Olhovsky &#187; alpha8</title>
	<atom:link href="http://www.olhovsky.com/tag/alpha8/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.olhovsky.com</link>
	<description>Programming, meet art.</description>
	<lastBuildDate>Mon, 23 Jan 2012 05:19:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Convert greyscale images to Alpha8 format with a Custom Content Processor in XNA 3.1.</title>
		<link>http://www.olhovsky.com/2009/09/convert-greyscale-images-to-alpha8-format-with-a-custom-content-processor-in-xna-3-1/</link>
		<comments>http://www.olhovsky.com/2009/09/convert-greyscale-images-to-alpha8-format-with-a-custom-content-processor-in-xna-3-1/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 01:34:31 +0000</pubDate>
		<dc:creator>olhovsky</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[alpha8]]></category>
		<category><![CDATA[content pipeline]]></category>
		<category><![CDATA[custom content processor]]></category>

		<guid isPermaLink="false">http://www.olhovsky.com/?p=62</guid>
		<description><![CDATA[I noticed that at least two terrain engine examples in XNA are reading heightmap images into 4 channel textures instead of single channel textures. To create a custom content processor that will permit you to convert any Texture2D compatible input &#8230; <a href="http://www.olhovsky.com/2009/09/convert-greyscale-images-to-alpha8-format-with-a-custom-content-processor-in-xna-3-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I noticed that at least two terrain engine examples in XNA are reading heightmap images into 4 channel textures instead of single channel textures.</p>
<p>To create a custom content processor that will permit you to convert any Texture2D compatible input format into an Alpha8 format texture, do the following:</p>
<p>Right click your game solution -> add new item<br />
Under XNA 3.1 select Custom Content Pipeline, and replace the default class in this solution with this code:</p>
<pre class="brush:c#">
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Graphics.PackedVector;
using Microsoft.Xna.Framework;
using System.ComponentModel;

namespace ContentPipelineExtension1
{
    [ContentProcessor]
    [DesignTimeVisible(true)]
    class HeightMapTextureProcessor : ContentProcessor<TextureContent,TextureContent>
    {
        ///
<summary>
        /// Process converts displacement maps to Alpha8 textures.
        /// </summary>

        public override TextureContent Process(TextureContent input,
            ContentProcessorContext context)
        {
            // Convert to data that we can work with:
            input.ConvertBitmapType(typeof(PixelBitmapContent<Vector4>));

            // Select first mipmap, there should only be one:
            MipmapChain mipmapChain = input.Faces[0];

            // There should only be one bitmap, but it doesnt hurt to write this loop:
            foreach (PixelBitmapContent<Vector4> bitmap in mipmapChain)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    for (int y = 0; y < bitmap.Height; y++)
                    {
                        Vector4 pixel = bitmap.GetPixel(x, y);

                        // Move R channel to A channel:
                        bitmap.SetPixel(x, y, new Vector4(0, 0, 0, pixel.X));
                    }
                }
            }

            // Alpha8 contains values from 0 - 1 in the W channel.
            input.ConvertBitmapType(typeof(PixelBitmapContent<Alpha8>));

            input.GenerateMipmaps(false);
            return input;
        }
    }
}
</pre>
<p>Now add a reference to your CustomContentPipeline1 solution in the &#8220;Content&#8221; module in your game solution.</p>
<p>Right click on the heightmap file(s) that you wish to be converted to Alpha8 and select the HeightMapTextureProcessor as the content processor.</p>
<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olhovsky.com/2009/09/convert-greyscale-images-to-alpha8-format-with-a-custom-content-processor-in-xna-3-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

