Search Unity

Resolved Procedural grid pattern on procedural mesh

Discussion in 'Shader Graph' started by DevDunk, Sep 10, 2022.

  1. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    I am making a custom grid shader for AR generated meshes (using LiDAR or Lightship ARDK).
    These meshes are generated in runtime, but my shader does not work on it.

    My color is applied properly to the mesh, but the shader graph grid (and brick) samples do not work for me. I use the output of the grid for alpha clipping, but there is no clipping happening on the procedural meshes.

    A guess is that the UVs are not generated with the mesh generation, which is used by the grid node.

    How could I get a grid pattern working on these generated materials?


    Shader graph for alpha: upload_2022-9-10_17-47-18.png

    Desired output for all meshes: upload_2022-9-10_17-47-43.png

    Output on generated meshes:
    upload_2022-9-10_17-48-5.png
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Update:

    Found out the mesh indeed does not have a UV. Looking into a grid based on X and Z position now
     
  3. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Update:
    Ended up using the positon compared to a sine wave in order to render the grid, which is fine for my use case!

    upload_2022-9-10_19-47-26.png
     
    bo222 likes this.
  4. bo222

    bo222

    Joined:
    Apr 12, 2020
    Posts:
    6
    Hi @DevDunk ,

    Could you please explain a little bit more about how you fixed this problem? I'm sorry, I'm quite new to Shader coding in Unity. As I follow the tutorial below. for normal mesh, everything is working fine but for generated mesh, I'm facing the same problem as you mentioned.

     
    Last edited: Oct 5, 2022
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    I use the position node, get 1 axis, add it into a sin wave to loop a value between -1 and 1, then put the alpha at 1 when it's above 0 (or another value) and 0 when below, then put that into the alpha channel.

    The only downside is that it will use the hard XZ positions, so it will not perfectly scale when you have vertical surfaces, so not all models will work perfectly
     
    bo222 likes this.
  6. bo222

    bo222

    Joined:
    Apr 12, 2020
    Posts:
    6
    @DevDunk
    Thank you very much for your fast reply. It seems that this would be a little difficult to apply to my situation because the generated mesh that I'm working with is from LiDAR sensor so It will have all kinds of shapes and sizes. If you know any method that could be applied in my situation please let me know. Once again thank you very much.
     
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Mine also was made for LiDAR and worked great with it, but I disabled rendering of the shader when the angle was high. You might be able to add a 3rd axis somehow, or maybe use a different node depending on the object?
    Let me know if you find a better solution!
     
    bo222 likes this.
  8. bo222

    bo222

    Joined:
    Apr 12, 2020
    Posts:
    6
    So your was also for LiDAR, May I ask if is it okay for you to show a small picture of the result? to be honest, I very much appreciate your reply above but I don't understand much of it. I will need to do some research to understand it. Right now I am trying different assets such as spatial shader, blender grid material, and more. But haven't got any luck yet. I will definitely let you know if I found a better solution.
     
  9. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    This was it on a terrain.
    LiDAR was a bit more chaotic but worked as well
     

    Attached Files:

    bo222 likes this.
  10. bo222

    bo222

    Joined:
    Apr 12, 2020
    Posts:
    6
    Thank you, it looks amazing. Have you tried the spatial shader for the LiDAR-generated mesh?
     
  11. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    I have not, where can I get this shader?
     
  12. bo222

    bo222

    Joined:
    Apr 12, 2020
    Posts:
    6
    @DevDunk,

    Sorry for the late reply. This is a paid asset but I believe you can find it free somewhere on the internet. The name of the asset is HoloLens Shader Pack.

    I also found an alternative free asset that may look and work like the one I mentioned above.


    If you can make it work. Please kindly let me know.
     
  13. bo222

    bo222

    Joined:
    Apr 12, 2020
    Posts:
    6