Jump to content
  • Advertisement
Sign in to follow this  

Post Processing In Hlsl To Find The Maximum Velocity

This topic is 867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

First, I render geometries and generate a velocity texture (1280 x 720 pixels) then I do a post-processing pass to find maximum velocity in each tile (a velocity texture is seperated into 32 x 18 tiles). Maximum velocity in each tile is output to an intermediate texture (32 x 18 pixels). This is similar to a downsampling pass. To do that, I do as follows:


1. Generate a velocity texture (1280 x 720).

2. Adjust the viewport size to 32 x 18 and render a full-screen quad to downsampl the velocity texture from 1280 x 720 to 32 x 18, each pixel in the output texture stores the maximum velocity of a tile in the velocity texture.


But It seems that I have a problem with texture coordinate (uv) as downsampling. In the pixel shader, I compute uv as following:

float texture_width // 1280
float texture_height // 720

float2 texel_size = 1.0f / float2(texture_width, texture_height);

// Offset a half texel
float2 uv_center = uv - texel_size * 0.5f;

for (uint col = 0; col < tile_size; col++) // tile_size is 40 x 40
   for (uint row = 0; row < tile_size; row++)
        float2 sample_pos = float2(uv_center + float2(col, row) * texel_size);
        float2 curr_velocity = texture.Sample(point_sampler, sample_pos);

        // Check and save the maximum velocity

The velocity texture is



But the maximum velocity texture is:



I am not sure that there is anything wrong with the texture cooridnates?

Share this post

Link to post
Share on other sites

The shader code looks good. Sure nothing's wrong with the CPU side setup of the texture? The location of the baby blue spot looks correct, but why would it sample blue from the texture in other locations..? Looks almost like the sampler is wrong (but it says point sampler so I'm assuming it's set up correctly) and filtering something from a lower mip level or something.


Just in case, have you tried using Load instead? (https://msdn.microsoft.com/en-us/library/windows/desktop/bb509694(v=vs.85).aspx)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!