Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

depth buffer doesn't work with post effects?


Recommended Posts

I put together this depth buffer model shader but it doesn't work when I put post effects up. What causes this? How do I fix it/get around the problem? I assume there's a way around it because the depth part of the shader I got right from Josh's water shader. I think it must have something to do with the script, then...something I"m not doing right. Here's the script:

function Script:Start()
    depthbuffer = Buffer:Create(context:GetWidth(),context:GetHeight(),0,1)
    depth = depthbuffer:GetDepthTexture()
    surface = self.entity:GetFace(0)
    mat = surface:GetMaterial()
    mat:SetBlendMode(Blend.Alpha)
    mat:SetTexture(depth,4)
end

function Script:UpdateWorld()
    depthbuffer:Enable()
    self.entity:Hide()
    world:Render()
    self.entity:Show()
    Context:SetCurrent(context)
end

Link to post
Share on other sites
  • 2 weeks later...

I am not too certain what's happening, but from what I know, Post Effects = after rendering scene = will be on top. You didn't specify what your depth is doing, so I am just assuming that the post effect is rendering on top of everything. If it's backwards, then that'll be odd.

Link to post
Share on other sites

Try it with the null shader. If it still doesn't work, then it has something to do with the final result. Might want to ask Josh directly about this.

Null Post Shader - Game Art - Leadwerks Community

Adding Postprocessing shaders does something. Probes don't work right without an effect loaded to the camera, and it might also be the cause of your shader not working.

Really interested in this, I could use it in my project.

Link to post
Share on other sites

It might have something to do with the fragData. Not an expert on shaders but I suggest you load the null shader and figure out what's causing the conflict. 

out vec4 fragData0;

void main(void)
{
	vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
	if (isbackbuffer) icoord.y = 1.0 - icoord.y;
	fragData0 = texture(texture1,icoord);
}

 

Link to post
Share on other sites

That's what I did. I loaded your null shader. Same results as other posteffect shaders. No line. It's the depth from the Leadwerks water shader, which works while there are posteffects running from what I can tell. So it seems to me there is something that is enabled or present somewhere in water mode that I'm not aware of .

Link to post
Share on other sites

So this works but it eats up the FPS constantly loading and deleting the shader. Bloom effect brought me all the way down to a constant 7 FPS. Not sure exactly why this works but there's got to be a better way. Anyone?

 

function Script:UpdateWorld()
    self.world = World:GetCurrent()
    if self.camera==nil then
        for i=0,self.world:CountEntities()-1 do
            if self.world:GetEntity(i):GetClass()==Object.CameraClass then
                self.camera=self.world:GetEntity(i)
                tolua.cast(self.camera,"Camera")
                return
            end
        end
    end
    depthbuffer:Clear()
    depthbuffer:Enable()
    self.camera:ClearPostEffects()  <---
    world:Render()
    depthbuffer:Disable()
    self.camera:AddPostEffect("Shaders/PostEffects/bloom.lua")  <---
    Context:SetCurrent(context)
end

Link to post
Share on other sites
  • 2 weeks later...

That's ok. I"m not a shader expert either.  I appreciate you taking a stab at it. It would be nice to solve it just because it irritates me to find this apparent limitation. I'm hoping someone will read this and be able to tell me at least why it happens.

It seems if I set the player (camera) in the scene then create the depth buffer object I can get away with putting the camera variable in the Start() function. But when I turn the player's head the depth buffer wobbles around in odd ways. If I remove the player and put him back in the scene, the depth buffer stops moving around but I then have to grab the camera in the UpdateWorld() function. I don't know if that has to do with the problem and might offer a clue, or if it's just a whole other problem.

 

Link to post
Share on other sites

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...