Jump to content

Depth Culling Shader


Olgo
 Share

Recommended Posts

Hello everybodies,

 

I'm a (french) new member of BJS community (so sorry for my English)  :D .

 

One of my projects requires a custom shader that allow me to use an object as mask, ie every rendering behind my object must be discarded (but my object must stay invisible).

To do so, my idea is to disable the color buffer in the fragment shader with a function like glDrawBuffer(GL_NONE but maintain it in the depth buffer with a function like gl_FragDepth = gl_FragCoord.z

 

I have two problems with this technique :

 

- Writing the depth buffer directly in a fragment shader  is extremely not recommended

- This functions aren't compatible with webgl (which use opengl es 2.0, i guess)

 

Is there a better / simplest way to do this trick ? (I'm a newbie in shader programming)

 

hopefully,

Loïc.

 

 

Link to comment
Share on other sites

Ok, i have a new problem.

 

Deltakosh, when i test you're solution in the playground it works fine, but in my project i'm it don't.

 

In fact, the "mask object" need to be rendered first to work. This playground illustrate it :

 

http://www.babylonjs-playground.com/#134UKN

 

If you define "sphere" as mask object it works, however if you define "sphere2" it don't.

 

How can i choose the render order ?

Link to comment
Share on other sites

Sorry, it doesn't seems to be what i need.

 

mesh.renderingGroupId control the objects order into depth buffer, but not depending on their 3D positions.

 

I made a new playground to have a better example of my problem :

http://www.babylonjs-playground.com/#134UKN#3

 

In this example, we see that the mask (because of the creation order) is ok at some viewing angles and not at others. But if we create the mask object before every other objects, all is ok.

 

In my project case, the objects are provided by a blender export in .babylonjs, so i can't control the creation order.

Link to comment
Share on other sites

zOffset is the implementation in BabylonJS of a WebGL function called "Polygon Offset". Basically it's useful when you need to render polygons that are at the exact same place, but you still need some of them to be rendered above the others (typically for decals & stuff like that). Interesting thread about it.

 

I don't think this will really help you in that case though...

 

Now I tried to put the mask mesh manually in the first place in the meshes array, and it works: http://www.babylonjs-playground.com/#134UKN#6

I guess you could do that after having imported your meshes, by using the mesh id.

 

It's not a really "clean" way to do it, but without reordering meshes I think you'll have a hard time achieving what you're looking for. zOffset and Rendering Groups won't help you, and since your mask mesh will not have any pixel rendered on screen, anything that would have been drawn before behind it would need to be "erased".

Link to comment
Share on other sites

  • 5 months later...

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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...