REQ: Ambient Occlusion - Page 2

REQ: Ambient Occlusion

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

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

Post 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.
Hacked
Posts: 116
Joined: 15 Aug 2008, 18:06

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

Post by Hacked »

ahh, thanks
infolog pointed me to lines "8 and 9"
so i was confused
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

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

Post by lurker »

of the shader :P
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

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

Post by jK »

Okay, I removed it from my webserver ...
I SAID IT IS A CODE EXAMPLE AND NOT A WIDGET
Gnomre
Imperial Winter Developer
Posts: 1754
Joined: 06 Feb 2005, 13:42

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

Post 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!
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

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

Post by jK »

1. THIS IS NOT A WIDGET!!!
2. IT IS NOT HOI'S BLOOM WIDGET!!!
User avatar
Falcrum
Posts: 149
Joined: 14 Nov 2007, 01:03

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

Post by Falcrum »

OMG... ok... close this topic... =/
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

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

Post 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.
Last edited by dizekat on 09 Nov 2008, 11:42, edited 2 times in total.
User avatar
clumsy_culhane
Posts: 370
Joined: 30 Jul 2007, 10:27

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

Post by clumsy_culhane »

lol jK calm the f*** down. That said, everyone i think needs to take a chill pill...
dizekat
Posts: 438
Joined: 07 Dec 2007, 12:10

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

Post 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:
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

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

Post 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:
Hacked
Posts: 116
Joined: 15 Aug 2008, 18:06

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

Post by Hacked »

jK wrote:1. THIS IS NOT A WIDGET!!!
wow great widget
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

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

Post 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
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Re: REQ: Ambient Occlusion

Post by REVENGE »

Image
You could really go places with this.
Hacked
Posts: 116
Joined: 15 Aug 2008, 18:06

Re: REQ: Ambient Occlusion

Post by Hacked »

whoa how did you do that?
jw how to make this more intense b/c im getting bored of it already =D
Ashnal
Posts: 104
Joined: 24 Jun 2008, 00:57

Re: REQ: Ambient Occlusion

Post by Ashnal »

It would be really nice for someone to finish this. The concept is pretty cool.
losbellos
Posts: 69
Joined: 31 Aug 2009, 00:26

Re: REQ: Ambient Occlusion

Post by losbellos »

does anybody still have this lua script?
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: REQ: Ambient Occlusion

Post by BrainDamage »

try reading 4 posts above yours
losbellos
Posts: 69
Joined: 31 Aug 2009, 00:26

Re: REQ: Ambient Occlusion

Post by losbellos »

THE create texture function expects number, but it doesnt get. Any clues, seems to be some syntax error?
losbellos
Posts: 69
Joined: 31 Aug 2009, 00:26

Re: REQ: Ambient Occlusion

Post by losbellos »

ok I got that problem solved by declaring the two variablesb but there is an other one with the createshader. Complicated shit.
Locked

Return to “Lua Scripts”