THESE IMAGES ARE OUTDATED, OFFICIAL THREAD HERE
I have been working on this nice Global illumination filter wich is based on a VPL-ish approach for a couple of days and it was all going quite smoothly. I even got some nice rsults to show for it!
No SSGI:
With SSGI:
As you can see it gives off a pretty neat effect but… i was looking at it and i noticed that nothing was getting any bounced light from the coloured walls, wich seemed a bit odd at first.
I tested some things out in my code and it turns out that the filter is only gathering information from the 4 pixels in the exact corners of the rendered image, wich strikes me as VERY FUCKING ODD.
I am trying to fix this but i haven’t had any results so far. I will post in this thread as soon as i figure out and fix what’s wrong but, in the meantime you can try and fix the filter yourself, here’s the code:
uniform sampler2D bgl_RenderedTexture;uniform sampler2D bgl_DepthTexture;
uniform float bgl_RenderedTextureWidth;
uniform float bgl_RenderedTextureHeight;
float width = bgl_RenderedTextureWidth;
float height = bgl_RenderedTextureHeight;
vec2 texCoord = gl_TexCoord[0].st;
vec4 direct = vec4(texture2D(bgl_RenderedTexture,texCoord));
vec4 bounced = vec4(0,0,0,1);
vec4 sample = vec4(0,0,0,1);
/* martin start */
vec2 canCoord = gl_TexCoord[0].st;
float aspectratio = 0.75;
float znear = 0.1; //camera clipping start
float zfar = 50.0; //camera clipping end
float getDepth(vec2 coord){
float zdepth = texture2D(bgl_DepthTexture,coord).y;
return -zfar * znear / (zdepth * (zfar - znear) - zfar);
}
vec3 getViewPosition(vec2 coord, vec2 cancoord){
vec3 pos;
pos = vec3((cancoord.s*2.0-1.0),(cancoord.t*2.0-1.0)/aspectratio ,1.0);
return (pos*getDepth(coord));
}
vec3 getViewNormal(vec2 coord, vec2 cancoord){
vec3 p1 = getViewPosition(coord+vec2(1.0/width,0.0), cancoord+vec2(1.0/width,0.0)).xyz;
vec3 p2 = getViewPosition(coord+vec2(0.0,1.0/height), cancoord+vec2(0.0,1.0/height)).xyz;
vec3 dx = p1-getViewPosition(coord,cancoord);
vec3 dy = p2-getViewPosition(coord,cancoord);
return normalize(cross( dx , dy ));
}
/* martin end */
void main(void){
vec3 viewPos = getViewPosition(texCoord,canCoord);
vec3 viewNormal = getViewNormal(texCoord,canCoord);
vec3 lightDir = vec3(0,0,0);
vec3 viewPos2 = vec3(0,0,0);
float amount = 0;
vec2 screenCoord = vec2(0,0);
while(screenCoord.y < height){
while(screenCoord.x < width){
if(screenCoord.x != texCoord.x && screenCoord.y != texCoord.y){
viewPos2 = getViewPosition(screenCoord,canCoord);
lightDir = viewPos - viewPos2;
amount = dot(lightDir,viewNormal)/(length(lightDir)*length(viewNormal));
sample = texture2D(bgl_RenderedTexture,screenCoord) * amount;
bounced += sample;
}
screenCoord.x += width/30;
}
screenCoord.y += height / 40;
}
bounced = bounced / (30*40/8);
gl_FragColor = direct + bounced;
}
PD: some of these things are based on Martin Upitis’ deffered shading filter