Jump to content
  • Advertisement
Sign in to follow this  

Hiz buffer generation in UE4

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

Currently, I was trying to use hiz occlusion query to tuning my engine. I make a implementation and compare it with UE4 implementation, I found some difference, and I can't figure why. So I was here to ask for help.



Here is implementation from UE4

const float2 InvSize = 1.0f / InputTextureSize;
const float2 InUV = RenderTargetUVAndScreenPos.xy;

UV[0] = InUV + float2(-0.25f, -0.25f) * InvSize;
UV[1] = InUV + float2( 0.25f, -0.25f) * InvSize;
UV[2] = InUV + float2(-0.25f,  0.25f) * InvSize;
UV[3] = InUV + float2( 0.25f,  0.25f) * InvSize;

Depth.x = Texture.SampleLevel( TextureSampler, UV[0], 0 ).r;
Depth.y = Texture.SampleLevel( TextureSampler, UV[1], 0 ).r;
Depth.z = Texture.SampleLevel( TextureSampler, UV[2], 0 ).r;
Depth.w = Texture.SampleLevel( TextureSampler, UV[3], 0 ).r;

This one is my implementation

const float2 InvSize = 1.0f / OutputTextureSize;
const float2 InUV = ScreenPos.xy / ViewportSize;
const float2 UvWithOffset = InUV + float2(-0.25f, -0.25f) * InvSize;
float4 Depth = Texture.GatherRed(TextureSampler, UvWithOffset);

There are two major differences:

  1. UE4 use InputTextureSize as denominator, but I use OutputTextureSize to calculate the InvSize. Let's go closer to talk about this, when I have a 1024x1024 sized input texture, output texture will be 512x512. When I evaluate the depth value for position(10,10). InUV will be (10.5,10.5), in this case, I want to sample texels (20.5,20.5),(21.5,20.5),(20.5,21.5),(21.5,21.5) from input texture. So from math perspective, I should evaluate new Uv with (10.5/512-0.25/512)*1024.
  2. UE4 use SampleLevel and I use GatherRed. I don't understand why they didn't use Gather API, in my opinion, Gather* should be faster than SampleLevel, right?


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!