Jump to content

  • Log In with Google      Sign In   
  • Create Account


Texture splatting on the GPU?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Rectangle   Members   -  Reputation: 161

Like
0Likes
Like

Posted 24 April 2013 - 11:35 AM

I'm using HGEPP to handle the rendering of a 2D, top-down tile map.

To create a more organic feel, I decided to implement texture splatting.

When a tileset is allocated, it checks each tile for a property which determines if it can be splatted against other tiles.

Once an array of "splattable" tile graphics has been made, I create new tiles which implement transistions in each and all directions for each other "splattable" graphic.

This is incredibly time consuming, and was wondering if it would be possible to move this functionality into a DX9-compatible pixel shader.

 

Just as a quick example, I'm trying to do the following:

ZIyNE.png + 2PWKNbp.png + ygbKah7.png = t6aOMf8.png

 

With the third image as an alpha map, how could this be implemented in a DX9-compatible pixel shader to "blend" between the first two images, creating an effect similar to the fourth image?

Furthermore, how could this newly created texture be given back to the CPU, where it could be placed back inside the original array of textures?


Edited by Rectangle, 24 April 2013 - 02:09 PM.


Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2156

Like
0Likes
Like

Posted 24 April 2013 - 03:29 PM

There is plenty of example on the net which goes something like this:

 

...

 

float4 Alpha = tex2D(AlphaMap, Texture_Coord_Alpha);
float4 Texture1 = tex2D(TextureOne, Texture_Coord);
float4 Texture2 = tex2D(TextureTwo, Texture_Coord);

 

retur lerp(Texture1, Texture2, Alpha.a);

 

that's about all it takes to blend 2 textures with alpha map. I assume that you haven't searched google, since there are plenty of vertex/pixel shaders for D3D9 to perform alpha masked splatting.

 

Cheers!



#3 Rectangle   Members   -  Reputation: 161

Like
0Likes
Like

Posted 24 April 2013 - 04:56 PM

If you look at the my original (unedited) post, you will see that I've spent countless hours researching, experimenting and trying to figure this out.

However, I wasn't using the correct search terms, and only found examples in GLSL. To complicate matters even further, I had to make it specific to HGE, since there is limited support for shaders and other D3D functions without modifying the HGE source.

I also had no knowledge of a linear interpolation function, and even had I known it would've failed to render properly in FX Composer without a proper vertex shader (which would seem pointless for my purposes).

After someone from StackOverflow mentioned a similar answer, I tested it in Visual Studio's Shader Designer and was able to produce the desired output.

I was coming here to confirm that it works, but you beat me to the punch.

 

In any regard, thanks for the help.


Edited by Rectangle, 24 April 2013 - 08:30 PM.


#4 kauna   Crossbones+   -  Reputation: 2156

Like
0Likes
Like

Posted 25 April 2013 - 09:23 AM

The lerp function is just for optimization / convenience. The lerp function is equal to Texture1 + (Texture2 - Texture1) * Alpha.a, although shader compiler may be able to use a specific lrp instruction. Linear interpolation is very useful (and simple as shown earlier) in graphics programming. The MSDN page about lerp gives the same description. 

 

With "texture splatting hlsl" the first link I get in Google has vertex and pixel shader examples which will give the results you are searching. All those important words can be found on your first message. 

 

Please, don't expect the answers to be 100% suitable for your needs. I gave you the pixel shader code which you were looking for. I assumed that you are able to program a vertex shader which outputs position and 2 vertex coordinate sets. 

 

Best regards!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS