XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Texture Blending (Splatting)

Last post 7/5/2009 10:30 PM by NightCreature. 2 replies.
  • 7/5/2009 7:54 PM

    Texture Blending (Splatting)

    Hi all

    I'm trying to blend 4 textures into one and then save the resulting texture in a new bitmap.

    Some more detail:

    I have 4 textures, Layer0 - Layer3 and 3 alphamaps, Alpha1 - Alpha3

    The blending basically works like this:

    Color = ((Layer0 * (1 - Alpha1) + Layer1 * Alpha1) * (1 - Alpha2) + Layer2 * Alpha2) * (1 - Alpha3) + Layer3 * Alpha3

    Or (in sequence):

    Color = Layer0
    Color = Color * (1 - Alpha1) + Layer1 * Alpha1
    Color = Color * (1 - Alpha2) + Layer2 * Alpha2
    Color = Color * (1 - Alpha3) + Layer3 * Alpha3

    All textures have the same size (2048x2048) and are bitmaps that I have in memory.

    I currently combine them by doing an iteration over all pixels and calculating the values. This takes 10 seconds (which is NOT acceptable).

    Can I do this using DirectX and then save the result? I need the result as a bitmap that I can save again, so having it only on the graphic card is not sufficient.

    Cheers

    Remo
  • 7/5/2009 8:48 PM In reply to

    Re: Texture Blending (Splatting)

    Use a 2048x2048 2D render target, then draw the 3 layers using the shader hardware. You might need to write a pixel shader to use the alpha maps.
    Then get the texture data out of the render target.
    Graphics Programmer,Sandswept Studios.http://www.sandswept.net
  • 7/5/2009 10:30 PM In reply to

    Re: Texture Blending (Splatting)

    You can actually copy the implementation of the splattingh you have in code into a pixelshader, except that you use "tex2D(textureSampler1, texCoord)" to get the actual color values.
Page 1 of 1 (3 items) Previous Next