Skip to main content
GameDev.net gamedev.net
🔒 Locked

Overlapping textures in deferred renderer

Started by blubberbert Jan 22, 2012 at 1:52 PM 1 replies 1.3k views
Original Post
blubberbert
blubberbert
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);
for(int i = 0; i < 8; i++)
gi += getGI(texCoord1 + offsets * 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!
V-man
V-man
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.
Hodgman
Hodgman
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-+-+-...-+--+--+--+--+--...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.