How to detect the lines based on their distance to camera?


https://www.babylonjs-playground.com/#40Y6CY#123 use transparent


https://www.babylonjs-playground.com/#40Y6CY#124 use back face

need some refactor step but if that is ok i can do that steps :slight_smile:

*** don’t notice the mesh builder step that is alpha version yet

also if you wanna find the better way to detect lines on camera side you most calculate vertex normal and you can use simple math formula for find the same direction with camera or not
but a lot situation you see after you have that same face behind the other face but right direction
in final you most detect all point of all face for have successful result i dont recommend that so less fps keep GPU solution always :smiley:

11 Likes

excellent !!! :slight_smile:

2 Likes

always i am wait for your feedback @jerome thanks

1 Like

Solution from @nasimiasl is great as it works without needing to create the edges beforehand.

However, as in the given we do have those lines, here’s my solution, which I think is simpler (less strain on the GPU):

https://www.babylonjs-playground.com/#S7NDM3#3

You can switch between white materials / normal materials by changing the const whiteMaterials.

You can change the number of dashes and the spacing between them by modifying this line in the fragment shader:

if (mod(sum, .33) < 0.12) discard;

Change the .33 and 0.12 values to increase/decrease the number of dashes/the space between dashes.

Note that I create the markers after all the other meshes so that they are displayed after the dashed lines: if dashed lines are displayed after, they overwrite the markers because z-test is disabled when drawing the dashes.

[EDIT]
To explain quickly how I do it:

  • I clone the lines and set a specific vertex/fragment shader that do a crude dash rendering
  • I disable the z-testing for those line meshes (engine.setDepthFunction(BABYLON.Engine.ALWAYS))
  • Those lines are rendered as usual. As they are displayed in the exact same position of the original lines, the dotted pattern where the lines are not hidden is not visible (you would see it if the cloned lines did not have the same colour than the original lines). And because z-testing is disabled, you do see the line “inside” meshes.

Note that you can change the alpha value from the last line of the fragment shader to dim the dashed lines.
[/EDIT]

16 Likes

@Evgeni_Popov I don’t know where you came from… but you are killing it and so far I love you.

3 Likes

Thanks :wink:

Coming from France, as a lot of people gravitating around Babylon it seems (@Deltakosh is french, after all)…

2 Likes

you look like good friend for us :slight_smile:

Thank you so much and sorry for my delay in getting back to you. Like your other projects, your solution looks great! well done. :+1:

WOW! I can’t believe it. This is awesome! This is the best answer I could imagine. Robust, clear and complete. I really do appreciate your help my friend.

You’re welcome, thanks to your thread I earned a nice badge (“Nice Reply” - Nice Reply badge on Babylon.js) :wink:

4 Likes

You deserve it : your solution was efficient, elegant, smart and well explained to the community :wink:
Great job !

4 Likes