Ssgi

very cool

there is no way to minimize the noise?

hey martin, first of all you are a genius. i want to ask you if that SSAO shown in the picture is the same you have implemented some times ago, because to me it looks very different and better.

Martinish love your shader but I Don’t think you should consider with as a color. In real life there is not such a thing as white color bleeding.

keep us updated.

no it is not the same, and it is not mine. It uses same technique, but the result is blurred with noise, increasing occlusion radius.

white color, or light is actually Red + Green + Blue, so if a material absorbs Green and Blue spectre of light, the reflected light is Red, so our brain consider the the surface as Red :). Same happens with color bleeding - if the room is white and light is white, the reflected color is white, the color bleed just shows up as a brighter spot.

an example picture:

ok let’s admit this a real phenomenon here a picture http://www.cemyuksel.com/research/gihair/title.jpg showing this effect. From what I can see the white color is mixed with the overall light bouncing/ Radiosity which make the white color less obvious.

Hmm yeah youre right about that. In the filter the white color makes the colored wall whiter, not brighter. Thats odd.

the blendfile is gone. seems like you should probably put it back up so this thread will always be a good resource…

bump, new blend file?

yeah, i`ll revisit the ssgi code, see if i could make it more efficient…

Good to hear.
You should get in touch with Moguri.
Maybe he can implement some of your work into the display settings some how with his GSoC BGE shader project.
http://blenderartists.org/forum/showthread.php?t=186571
That would be very nice to start have this right in the viewport.

http://www.pasteall.org/blend/2752
the code is not nearly perfect, and the color bleeding is not quite right. but it is working.

Yea I`ve been chatting with Moguri for almost a year :slight_smile: he is making really awesome improvements for BGE.

that would be very impressive, to have these shaders in the bge, not just … eh … strapped in.

i should also add that it seems to have the same problems on my card as it does on ATIs - my darn geForce 6200 card is just too old (though, admittedly, it’s much better than my previous geforce 2 mx :slight_smile: )

Nice Martinsh, but i dont saw any collor bleed, I dont know if is my Graphic card, but for me no color bleed.
Nice statue model, i like that.
Thanks

leonnn, what graphics card? i recommend an nvidia 7 series at least, if not 8.

I have a nvidia GTX 260 but I don saw it!

i see. i assume you pressed ‘2’ to start the shader?

Yes i did, I think that the color bleed as martinsh said is not quite right, maybe the collor bleed isn t totally functional yet, maybe I m a idiot , i ll wait to see the next improvement, hehe.
thanks blendmaster for the help!

Here I fixed a few implicit casts that made it not work on ATI cards, also I changed a few numbers here and there to exagerate the effect, it looks cool and fast, It’s just my or it kind of makes artifacts? Some lights seem to get some kind of “star-glow” on them too.

uniform sampler2D bgl_DepthTexture;  // Depth texture  
uniform sampler2D bgl_RenderedTexture; // Color texture 
uniform float bgl_RenderedTextureWidth;
uniform float bgl_RenderedTextureHeight;

float samples = 32.0;
float radius = 0.4;

uniform vec2 camerarange = vec2(0.1, 100.0);
      
   float pw = radius/(bgl_RenderedTextureWidth); 
   float ph = radius/(bgl_RenderedTextureHeight);  

float rand(in vec2 coord) //generating random noise
{
	//float noiseX = clamp(fract(sin(dot(coord ,vec2(12.9898,78.233))) * 43758.5453),0.0,1.0)*0.2+0.7;
	float noiseX = ((fract(1.0-coord.s*(bgl_RenderedTextureWidth/2.0))*0.25)+(fract(coord.t*(bgl_RenderedTextureHeight/2.0))*0.5));
	return noiseX;
}

   float readDepth(in vec2 coord)  
   {  
     if (coord.x<0.0||coord.y<0.0) return 1.0;
      float nearZ = camerarange.x;  
      float farZ =camerarange.y;  
      float posZ = texture2D(bgl_DepthTexture, coord).x;   
      return (2.0 * nearZ) / (nearZ + farZ - posZ * (farZ - nearZ));  
   }   

   vec3 readColor(in vec2 coord)  
   {  
     return texture2D(bgl_RenderedTexture, coord).xyz;  
   } 

   float compareDepths(in float depth1, in float depth2)  
   {  
     float gauss = 0.0; 
     float diff = (depth1 - depth2)*100.0; //depth difference (0-100)
     float gdisplace = 0.2; //gauss bell center
     float garea = 3.0; //gauss bell width

     //reduce left bell width to avoid self-shadowing
     if (diff<gdisplace) garea = 0.2; 

     gauss = pow(2.7182,-2.0*(diff-gdisplace)*(diff-gdisplace)/(garea*garea));

     return max(0.2,gauss);  
   }  

   vec3 calAO(float depth,float dw, float dh, inout float ao)  
   {  
     float temp = 0.0;
     vec3 bleed = vec3(0.0,0.0,0.0);
     float coordw = gl_TexCoord[0].x + dw/depth;
     float coordh = gl_TexCoord[0].y + dh/depth;

     if (coordw  < 1.0 && coordw  > 0.0 && coordh < 1.0 && coordh  > 0.0){

     	vec2 coord = vec2(coordw , coordh);
     	temp = compareDepths(depth, readDepth(coord)); 
        bleed = readColor(coord); 
 
     }
     ao += temp;
     return temp*bleed;  
   }   
     
   void main(void)  
   {  
     //randomization texture:
     float random = rand(gl_TexCoord[0].st);
     //random = random*2.0-(1.0);

     //initialize stuff:
     float depth = readDepth(gl_TexCoord[0].st);
     vec3 gi = vec3(0.0,0.0,0.0);  
     float ao = 0.0;
  	
	float dx0 = pw;
  	float dy0 = ph;
  	float ang = 0.0;

for (int i = 0; i < int(samples); ++i)
  {
    float dzx =  float(dx0 * random);
    float dzy =  float(dx0 * random);

    float a = radians(ang);

    float dx = cos(a)*dzx-sin(a)*dzy;
    float dy = sin(a)*dzx+cos(a)*dzy;
    
    gi += calAO(depth,  dx, dy, ao);
    
    dx0 += pw;
    dy0 += ph;

    ang+=360.0/6.0;
  }  
     

     //final values, some adjusting:

	vec3 lumcoeff = vec3(0.299,0.587,0.114);
	vec3 color = vec3(readColor(gl_TexCoord[0].st));
	float lum = dot(color, lumcoeff);
	vec3 luminance = vec3(lum, lum, lum);
	vec3 white = vec3(1.0,1.0,1.0);
	vec3 black = vec3(0.0,0.0,0.0);
	vec3 treshold = vec3(0.3,0.3,0.3);
	
	vec3 finalAO = vec3(1.0-(ao/samples));
    vec3 finalGI = (gi/samples);
	
	vec3 mask = clamp(max(black,luminance-treshold)+max(black,luminance-treshold)+max(black,luminance-treshold),0.0,1.0);
	gl_FragColor = vec4(color*mix(finalAO/3*2+7*finalGI,white,mask),1.0);
	//gl_FragColor = vec4(mix(finalAO+finalGI,white,mask),1.0);
	//gl_FragColor = vec4(color*finalAO+finalGI*0.6,1.0);
	
}  

so this is based on your new SSAO, right ?

some fragment shader …
nice