Page 2 of 4

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 03:45
by lurker

Code: Select all

        const float pm15 = gl_ProjectionMatrix[2][3];
        const float pm11 = gl_ProjectionMatrix[2][3];
Remove 'const' from those lines. Shouldn't hurt any.

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 03:53
by Hacked
ahh, thanks
infolog pointed me to lines "8 and 9"
so i was confused

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 04:07
by lurker
of the shader :P

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 09:48
by jK
Okay, I removed it from my webserver ...
I SAID IT IS A CODE EXAMPLE AND NOT A WIDGET

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 10:28
by Gnomre
jK wrote:Okay, I removed it from my webserver ...
I SAID IT IS A CODE EXAMPLE AND NOT A WIDGET
This widget will go GREAT with Hoi's bloom widget!

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 11:16
by jK
1. THIS IS NOT A WIDGET!!!
2. IT IS NOT HOI'S BLOOM WIDGET!!!

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 11:32
by Falcrum
OMG... ok... close this topic... =/

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 11:39
by dizekat
lol nubs
jK, can you put your code somewhere on pastebin maybe? I'm curious how it works, and theres no ways nubs will copypaste it into lua widget from pastebin.

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 11:40
by clumsy_culhane
lol jK calm the f*** down. That said, everyone i think needs to take a chill pill...

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 11:41
by dizekat
clumsy_culhane wrote:lol jK calm the f*** down. That said, everyone i think needs to take a chill pill...
you especially need to take a whole box :mrgreen:

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 14:44
by FLOZi
Gnome wrote:
jK wrote:Okay, I removed it from my webserver ...
I SAID IT IS A CODE EXAMPLE AND NOT A WIDGET
This widget will go GREAT with Hoi's bloom widget!
:lol: :mrgreen:

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 09 Nov 2008, 23:24
by Hacked
jK wrote:1. THIS IS NOT A WIDGET!!!
wow great widget

Re: REQ: Ambient Occlusion ( already done - download =) )

Posted: 10 Nov 2008, 01:16
by lurker
dizekat wrote:lol nubs
jK, can you put your code somewhere on pastebin maybe? I'm curious how it works, and theres no ways nubs will copypaste it into lua widget from pastebin.

Code: Select all

 depthcopy = gl.CreateTexture(vsx,vsy, {
    border = false,
    format = GL_DEPTH_COMPONENT24,
    min_filter = GL.NEAREST,
    mag_filter = GL.NEAREST,
  })

  ssaoShader = gl.CreateShader({
    vertex = [[
      varying vec2 normScreenCoord;

      void main()
      {
         normScreenCoord = gl_Vertex.xy;
         gl_Position = vec4( (gl_Vertex.xy-0.5)*2.0 ,1.0,1.0);
       }
    ]],
    fragment = [[
      uniform sampler2D tex0;

      varying vec2 normScreenCoord;

      //////////////////////////////////////////////////
      // Depth conversion

        const float pm15 = gl_ProjectionMatrix[2][3];
        const float pm11 = gl_ProjectionMatrix[2][3];
        float convertDepthToZ(float d) {
          return pm15 / (((d * 2.0) - 1.0) + pm11);
        }

        vec4 convertDepthToZ(vec4 d) {
          return pm15 / (((d * 2.0) - 1.0) + pm11);
        }

      //////////////////////////////////////////////////
      // Main

      void main(void)
      {
        float depth = convertDepthToZ( texture2D(tex0, normScreenCoord ).r );

        float texelScale = clamp(1.0-depth*0.002,0.0,1.0);

        vec2 texel = vec2(dFdx(normScreenCoord.s),dFdy(normScreenCoord.t))*3.0*texelScale;

        float ao = 0.0;
        float aoMultiplier = 0.3;
        float depthTolerance = 0.01;

        vec4 depths,depthsFix;
        depths.x = texture2D(tex0, normScreenCoord+vec2(texel.x,0.0) ).r;
        depths.y = texture2D(tex0, normScreenCoord+vec2(0.0,texel.y) ).r;
        depths.z = texture2D(tex0, normScreenCoord+vec2(-texel.x,0.0) ).r;
        depths.w = texture2D(tex0, normScreenCoord+vec2(0.0,-texel.y) ).r;
        depths = convertDepthToZ(depths);
        depths = (depth-depths-depthTolerance) * aoMultiplier;

        bvec4 facb = greaterThan( depths, vec4(0.3) );
        vec4 fac = vec4(float(facb.x),float(facb.y),float(facb.z),float(facb.w));
        depthsFix = smoothstep(0.3,0.8,depths);

        depths = smoothstep(0.0,0.2,depths) - fac*depthsFix;
        ao += depths.x + depths.y + depths.z + depths.w;

        texel*=2.0;
        aoMultiplier*=0.75;
        depths.x = texture2D(tex0, normScreenCoord+vec2(texel.x,0.0) ).r;
        depths.y = texture2D(tex0, normScreenCoord+vec2(0.0,texel.y) ).r;
        depths.z = texture2D(tex0, normScreenCoord+vec2(-texel.x,0.0) ).r;
        depths.w = texture2D(tex0, normScreenCoord+vec2(0.0,-texel.y) ).r;
        depths = convertDepthToZ(depths);
        depths = (depth-depths-depthTolerance) * aoMultiplier;

        facb = greaterThan( depths, vec4(0.3) );
        fac = vec4(float(facb.x),float(facb.y),float(facb.z),float(facb.w));
        depthsFix = smoothstep(0.3,0.8,depths);

        depths = smoothstep(0.0,0.2,depths) - fac*depthsFix;
        ao += depths.x + depths.y + depths.z + depths.w;

	  ao/=6.0;
	  ao=min(ao,0.5);
	
	  gl_FragColor = vec4(1.0-ao);
	  //gl_FragColor = vec4(texelScale);
	  //gl_FragColor = vec4(max(0.4,1.0-depth*0.002));
        //gl_FragColor.rga *= 0.5;
      }
    ]],
    uniformInt = {
      tex0 = 0,
    }
  })


function widget:DrawWorld()
  gl.CopyToTexture(depthcopy, 0, 0, 0, 0, vsx, vsy)

  gl.Blending(GL.ZERO,GL.SRC_COLOR)
  --gl.Blending(false)
  gl.UseShader(ssaoShader)
  gl.Texture(0,depthcopy)
  gl.TexRect(0,1,1,0)
  gl.Texture(0,false)
  gl.UseShader(0)
  gl.Blending(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
end

Re: REQ: Ambient Occlusion

Posted: 10 Nov 2008, 02:18
by REVENGE
Image
You could really go places with this.

Re: REQ: Ambient Occlusion

Posted: 10 Nov 2008, 11:37
by Hacked
whoa how did you do that?
jw how to make this more intense b/c im getting bored of it already =D

Re: REQ: Ambient Occlusion

Posted: 13 Jan 2009, 05:14
by Ashnal
It would be really nice for someone to finish this. The concept is pretty cool.

Re: REQ: Ambient Occlusion

Posted: 17 Aug 2010, 21:12
by losbellos
does anybody still have this lua script?

Re: REQ: Ambient Occlusion

Posted: 17 Aug 2010, 21:16
by BrainDamage
try reading 4 posts above yours

Re: REQ: Ambient Occlusion

Posted: 17 Aug 2010, 23:06
by losbellos
THE create texture function expects number, but it doesnt get. Any clues, seems to be some syntax error?

Re: REQ: Ambient Occlusion

Posted: 18 Aug 2010, 00:34
by losbellos
ok I got that problem solved by declaring the two variablesb but there is an other one with the createshader. Complicated shit.