Jump to content

  • Log In with Google      Sign In   
  • Create Account

Overlapping textures in deferred renderer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 blubberbert   Members   -  Reputation: 236

Like
0Likes
Like

Posted 22 January 2012 - 07:52 AM

im currently working on a deferred renderer with SSGI and came across a problem:

iam doing 4 passes to render the final image, but i want to reuse one Gbuffer wich is written in the 1st and read in the 2nd pass to be written in the 3rd and read in the 4th pass
that rendertarget stores the indirect illumination color and the ao.
however since my good old ATI 4650M isnt that fast, i compute the SSGI on a 4 times smaller resolution.
so after the third pass, some of the rendertarget holds the new SSGI data, while some part still stores the data written in the 1st pass wich is not needed anymore.

it would look like this:
OOOO
OOOO
NNOO
NNOO
where O is old data and N new data

the problem is that now when i read the SSGI data (N) in the 4th pass, i get some artifacts when i read data from the right or top border, because im actually reading 'O' data, wich is not what i want...

the shader for the fourth pass looks like this:

uniform sampler2D ssdiMap;
uniform sampler2D ssgiMap;
varying vec2 texCoord0;
varying vec2 texCoord1;

vec4 getGI(in vec2 coord)
{
    coord = clamp(coord, 0.0, 0.25);
    return texture2D(ssgiMap, coord);
}

void main()
{
    float rad = 0.0005;
    vec2 offsets[8] = vec2[8](vec2(rad,rad),vec2(-rad,rad),vec2(-rad,-rad),vec2(rad,-rad),
    vec2(0.0,rad),vec2(0.0,-rad),vec2(rad,0.0),vec2(-rad,0.0));
    vec4 gi = vec4(0.0);
    for(int i = 0; i < 8; i++)
        gi += getGI(texCoord1 + offsets[i]);
    for(int i = 0; i < 8; i++)
        gi += getGI(texCoord1 + offsets[i] * 2.0);
    gi /= 16.0;
    vec4 di = texture2D(ssdiMap, texCoord0);
    vec3 final = (di.xyz*gi.w) + gi.xyz; //gi.xyz is GI color, gi.w is AO
    gl_FragColor = vec4(final, 1.0);
}

------------------------------
Join the revolution and get a free donut!

Sponsor:

#2 V-man   Members   -  Reputation: 805

Like
0Likes
Like

Posted 23 January 2012 - 04:40 AM

GL uses texel centers to sample the textures.
If you use 0.25 and your texture size is 256, then
0.25* 256 + 0.5 = 65
or something like that, however, you wanted to sample 64.
The solution is to offset a little
0.25 - 0.375/tex_width.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#3 Hodgman   Moderators   -  Reputation: 31968

Like
0Likes
Like

Posted 23 January 2012 - 06:04 AM

GL uses texel centers to sample the textures. If you use 0.25 and your texture size is 256, then 0.25* 256 + 0.5 = 65 or something like that, however, you wanted to sample 64. The solution is to offset a little 0.25 - 0.375/tex_width.

0.25* 256 = 64, which is the exact border between two pixels.
(0.25 + 0.5/256) (which *256 == 64.5) will give you the exact centre of that pixel.

If you picture the texture as a number-line that goes from 0 to the texture resolution, the texels begin and end on integer boundaries. The centre of a texel is always some number + 0.5.
If the 'x' is the middle of the pixel that begins at [0,64], then it's UV coordinate is (0.5/256, 64.5/256)
0-1-2-...-63-64-65-66-67-...-256
| | | ... |  | x|  |  |			|
1-+-+-...-+--+--+--+--+--...
| | | ... |  |  |  |  |			|
2-+-+-...-+--+--+--+--+--...





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS