Posts: 738
Threads: 8
Joined: Sep 2009
Reputation:
41
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