Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Calculate neighbor texel offset.

  1. #1
    Newbie Newbie
    Join Date
    May 2016
    Posts
    2

    Calculate neighbor texel offset.

    Hey!

    I have searched for two days now on Google and I can't find any useful information about how to manually calculate the texels offset.
    I need to calculate 4 neighbor texel offsets for each processed fragment while:

    Option 1.) Downsampling(From full resolution to half resolution).
    Option 2.) Upsampling(From half resolution to full resolution).
    Option 3.) On the same level, i.e. both textures have the same size.

    I need to downsample a depth texture and find the maximum depth. I also need to upsample another texture and at the same time preserve some details with the help of depth buffers.

    I know how to calculate the offsets while performing the gaussian blur.
    Example:
    Code :
    const float OFFSETS[4] = float[](0.0, 1.0, 2.0, 3.0);
    in vec2 texCoordFS;
     
    for(int i = 1; i < 4; i++)
    {
    	vec2 uv0 = texCoordFS + vec2(OFFSETS[i] / textureWidth, 0.0);
    	vec2 uv1 = texCoordFS - vec2(OFFSETS[i] / textureWidth, 0.0);
    }
     
    for(int i = 1; i < 4; i++)
    {
    	vec2 uv0 = texCoordFS + vec2(0.0, OFFSETS[i] / textureHeight);
    	vec2 uv1 = texCoordFS - vec2(0.0, OFFSETS[i] / textureHeight);
    }


    Let us assume that we are going to render a fullscreen quad and we have UV-coordinates for each corner.

    For option nr 1(sample 4 times from the full resolution texture), nr 2(sample 4 times from the half resolution texture) and nr 3, I have no idea which of the following I need to use for option 1, 2, 3:

    Code :
     
    const vec2 OFFSETS0[4] = vec2[]
    (
        vec2(0.0, 0.5),
        vec2(0.5, 0.0),
        vec2(-0.5, 0.0),
        vec2(0.0, -0.5)
    );
     
    const vec2 OFFSETS1[4] = vec2[]
    (
        vec2(0.0, 1.0),
        vec2(1.0, 0.0),
        vec2(-1.0, 0.0),
        vec2(0.0, -1.0)
    );
     
    const vec2 OFFSETS2[4] = vec2[]
    (
    	vec2(-1.0, -1.0),
    	vec2(-1.0, 1.0),
    	vec2(1.0, -1.0),
    	vec2(1.0, 1.0)
    );
     
    const vec2 OFFSETS3[4] = vec2[]
    (
    	vec2(-0.5, -0.5),
    	vec2(-0.5, 0.5),
    	vec2(0.5, -0.5),
    	vec2(0.5, 0.5)
    );

    I guess on option nr 3, I can use OFFSETS1 or OFFSETS2 ?
    Last edited by zippoL; 05-30-2016 at 06:01 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •