Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Render child node in front of parent node
#1
I'd like to be able to render a child object in front of its parent. To be specific I have a cylinder with a little cube inside, but I need the cube to render in front of the cylinder. This can't be solved using the OverlayRenderingLayer because the cylinders in front need to obscure the cylinders behind.

https://ibb.co/4VhPSTg (a picture)

Our current workaround is to offset the cube towards the camera so that it's always in front of the cylinder, but this is not ideal.

Do you have any ideas as to how we might solve this?
#2
Ihis is an interesting problem.

It would be possible to create a special vertex shader that would get an offset (in world coordinates) and move all the vertices closer to the camera. Using a Vulkan's depth bias would hardly work because the values there are in the homogenous coordinates and it would be hard to get the correct value that would work for all the cylinders.

Having a custom vertex shader would work very fast because it would not require any updates of the objects when the camera changes. 

But the problem with that solution would be that hit testing would not work correctly - the cubes would not be considered in front of the cylinders in the hit testing code. However, this could be solved in the following way:
if you get a hit test on the cylinder, then you can execute a hit test on the related cube (call cubeModelNode.GetClosestHitResult and pass the ray from the camera to the method). If you got the hit on the cube, you can manually adjust the value of the DistanceToRayOrigin for the offset.

Another solution to this problem is that you manually adjust the positions of the cube on each camera change (as you are currently doing). If you do not have a lot of cylinders, I think that this is actually a good solution (adjusting offsets in a vertex shader and altering hit testing is more hacky to me). But if you have many cylinders than this solution may be slow because you need to adjust the positions of each cube after each camera change.

I am currently testing the SharpEngine v2.0 and preparing everything for the official release next week. Therefore I have no time to do some custom coding. But if you are interested in having a custom vertex shader I may do some custom coding for you after the release (please write me an email or private message and I will provide you with the price). You can also try to develop that custom shader by yourself - see the new "Advanced / Custom Effect" sample that provides full source code (including shaders) for the FogEffect.
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
1 Guest(s)