• Advertisement
Sign in to follow this  

Calculating pixel sum for texture

This topic is 683 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

Hi!

I`ve got problem with calculation of pixel sum. How can I get current pixel coordinates from PS/FS and get texel using  these ones.  I want to take texel using Load method and I should do it carefully, becase I have not to take neighbour pixel instead current. It makes my program less efficient.

Thank you!

Share this post


Link to post
Share on other sites
Advertisement

In D3D pixel shader takes system variable SV_Position, which contains screen space position of your pixel + 0.5 offset to the pixel center.

 

In other words, SV_Position variable will take the values in the range:

x: [0 + 0.5, (ViewportWidth - 1) + 0.5], that is 0.5, 1.5, 2.5, etc

y: [0 + 0.5, (ViewportHeight - 1) + 0.5]

 

float3 screenSpacePos : SV_Position - pixel shader input

 

Load function on the HLSL Texture object takes integer screen space coordinates as an input.

// Convert float screen space pos to integer to get rid of 0.5 offset

int3 texScreenSpacePos = int2(screenSpacePos.xy,  0);

float3 result = myTexture2D.Load(texScreenSpacePos);

 

If you would like to work in texture space or use sample filtering

float2 texSpacePos = screenSpacePos.xy * rcp(float2(ViewportWidth, ViewportHeight)); // screenSpacePos with 0.5 offset

float3 result = myTexture2D.Sample(mySampler, texSpacePos);

Edited by _void_

Share this post


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

  • Advertisement