Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (3 posts)

Gather (GatherRed, GatherGreen, GatherBlue, GatherAlpha) precision problem?

Last post 12/7/2017 11:09 AM by Julian Davis. 2 replies.
  • 1/5/2013 10:51 PM

    Gather (GatherRed, GatherGreen, GatherBlue, GatherAlpha) precision problem?

    Hi!

    I have a case here where I need to perform manual biliear filtering on a grayscale texture. This seems like a great excuse to use the new Texture.GatherXXX methods.
    Unfortunately, Im getting a little imprecision when using the Gather. Everything is fine when manually fetching the 4 texels.

    Seems like there is a disconnect between the bilinear weights I compute and the rounding that Gather does.

    What am I missing here? Is there some black-magic that happens under the hood when using Gather?  Is this an ATI-specific problem?

    Here is my code and a couple of screenshots.

    Good when manually fetching the 4 texels: http://s9.postimage.org/5b9lq65gv/manual_good.jpg
    Bad when using GatherRed: http://s2.postimage.org/sgguwatxl/gather4_bad.jpg

            float  MipLevel = GrayscaleTexture.CalculateLevelOfDetail(GrayscaleTextureSampler, GrayscaleCoordinates); 
            uint TexWidth, TexHeight, NumMipLevels; 
            GrayscaleTexture.GetDimensions(MipLevel, TexWidth, TexHeight, NumMipLevels); 
     
            // This version fetches the 4 texels manually, it is slower but creates no artefacts. 
            float4 GatheredPixels; 
            GatheredPixels.x = GrayscaleTexture.Load(int3(GrayscaleCoordinates * float2(TexWidth, TexHeight) + float2(-0.5f,  0.5f), MipLevel)); 
            GatheredPixels.y = GrayscaleTexture.Load(int3(GrayscaleCoordinates * float2(TexWidth, TexHeight) + float2( 0.5f,  0.5f), MipLevel)); 
            GatheredPixels.z = GrayscaleTexture.Load(int3(GrayscaleCoordinates * float2(TexWidth, TexHeight) + float2( 0.5f, -0.5f), MipLevel)); 
            GatheredPixels.w = GrayscaleTexture.Load(int3(GrayscaleCoordinates * float2(TexWidth, TexHeight) + float2(-0.5f, -0.5f), MipLevel)); 
             
            // This version uses GatherRed and creates artefacts (uncomment). 
            // GatheredPixels = GrayscaleTexture.GatherRed(GrayscaleTextureSampler, GrayscaleCoordinates, int2(0,0)); 
     
            // Manual bilinear interpolation. 
            float2 BilinearWeight = frac(GrayscaleCoordinates * float2(TexWidth, TexHeight) - 0.5f); 
     
            return lerp(lerp(GatheredPixels.wwww, GatheredPixels.zzzz, BilinearWeight.x), 
                        lerp(GatheredPixels.xxxx, GatheredPixels.yyyy, BilinearWeight.x), BilinearWeight.y); 

    -Mat
  • 1/7/2013 7:32 PM In reply to

    Re: Gather (GatherRed, GatherGreen, GatherBlue, GatherAlpha) precision problem?

    Can you clarify OS, HLSL complier version, shader profile, and feature level?
  • 12/7/2017 11:09 AM In reply to

    Re: Gather (GatherRed, GatherGreen, GatherBlue, GatherAlpha) precision problem?

    This problem is fairly well covered here:

    https://www.opengl.org/discussion_boards/showthread.php/200020-Custom-Bilinear-filtering-w-textureGather-problem

    based on the original discussion here:

Page 1 of 1 (3 posts) Previous Discussion Next Discussion