Search Unity

Help Wanted Raycast on mesh after shader graph displacement

Discussion in 'Shader Graph' started by asd234w4r5, Aug 5, 2019.

  1. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    886
    Hey there, I am not sure, if I am missing some docs or so that tell, that the displacement is only done for visual effect and does not actually displace the vertices on the object. I am trying to displace a sphere and if done, I am trying to find the farest point and instantiate something on it. Unfortunately it still has got the vertices from the standard sphere. Does anyone know how to either achieve this with the shader graph or how to displace that mesh by a texture and value and actually have that objet displaced on runtime. Here is a screen of the displacement and the orange outline, which is showing the actual model and the shadergraph

    Screenshot 2019-08-05 at 17.02.04.png

    Shadergraph
    Screenshot 2019-08-05 at 17.05.25.png
     
  2. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    886
    Noone's with an idea?
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,317
  4. A132LW

    A132LW

    Joined:
    Jun 21, 2017
    Posts:
    17
    As far as I know this cannot be done only with Shadergraph.
    The raycast is a physics subclass and thus only casts rays against the mesh collider. As the vertex displacement in shadergraph only exists for rendering and does not displace mesh vertices you cannot raycast against a vertex displaced sphere.

    As mgear suggested, you can use another camera to sample depth to get vertex position.

    You can also manually displace the vertices using c#. (Required for any mesh-based physics)

    Finally, if you can get Graphics.blit to work with Shadergraph, you can do the vertex displacement calculations there and use Graphics.blit to get this result into c# to manually displace vertices through script. (I am currently working on this for another project and will post if I find a solution.)

    Hope this helps.
     
  5. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    886
    Thank you both for your answers! I will look into the camera one first, maybe need two cameras then for back and front, but that looks quite promising. But I will also look into the blit one, as this seems to be the elegant way, if its possible. Actually I could do the shader stuff also in C#, but never worked with this in scripting environment about textures loading and modifying meshes in this way. Thank you again, will come back if I found a solution from my side :)
     
  6. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    886
    Damn, just read the first limitation which says "Not compatible with any Scriptable Render Pipelines"... Damn it but thank you. maybe I find a way to modify this for LWRP.