Jump to content

Recommended Posts

Posted

Some changes to the SSAO filter from the Workshop:

---------------------------------------------------------------------------

-- SSAO (Screen-Space Ambient Occlusion) by Igor Katrich 26/02/20015

-- Email: igorbgz@outlook.com

---------------------------------------------------------------------------

 

function Script:Start()

self.shader = Shader:Load("Shaders/PostEffects/SSAO/ssao.shader")

self.combine = Shader:Load("Shaders/PostEffects/SSAO/ssao_combine.shader")

self.noise = Texture:Load("Shaders/PostEffects/SSAO/noise.tex")--do this in start function

end

 

function Script:Render(camera,context,buffer,depth,diffuse,normals)

 

--Check to see if buffer size has changed

if self.buffer~=nil then

if buffer:GetWidth()~=self.buffer:GetWidth() or buffer:GetHeight()~=self.buffer:GetHeight() then

self.buffer:Release()

self.buffer=nil

end

end

 

if self.buffer==nil then

self.buffer=Buffer:Create(buffer:GetWidth(),buffer:GetHeight())

self.buffer:GetColorTexture():SetFilter(Texture.Smooth)

end

 

if self.shader

and self.combine

and camera:GetScale().y==1 then

self.buffer:Enable()

self.shader:Enable()

 

if self.noise~=nil then

self.noise:Bind(10)

end

 

depth:Bind(1)

normals:Bind(2)

context:DrawImage(diffuse,0,0,buffer:GetWidth(),buffer:GetHeight())

 

buffer:Enable()

diffuse:Bind(1) --Color

self.buffer:GetColorTexture():Bind(2) --SSAO

self.combine:Enable()

context:DrawImage(diffuse,0,0,buffer:GetWidth(),buffer:GetHeight())

end

end

 

function Script:Detach()

--Release shaders

if self.shader then

self.shader:Release()

self.shader = nil

end

if self.combine then

self.combine:Release()

self.combine = nil

end

--Release buffer

if self.buffer~=nil then

self.buffer:Release()

end

--Release noise texture

if self.noise~=nil then

self.noise:Release()

end

end

Let's build cool stuff and have fun. :)

Posted

Small typo I think, compare self.buffer to buffer size, not context, or self.buffer will recreate each loop

 

if buffer:GetWidth()~=self.buffer:GetWidth() or buffer:GetHeight()~=self.buffer:GetHeight() then

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Posted

I think this effect can also be performed in a single pass, and it will be a lot faster than two full-screen passes.

 

Small typo I think, compare self.buffer to buffer size, not context, or self.buffer will recreate each loop

 

if buffer:GetWidth()~=self.buffer:GetWidth() or buffer:GetHeight()~=self.buffer:GetHeight() then

Oh, you are right.

Let's build cool stuff and have fun. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...