Search Unity

Rain/snow particles colliding with world outside screen space using external camera for depth map.

Discussion in 'Visual Effect Graph' started by Lex4art, Oct 18, 2021.

  1. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
    Help, please: trying to create a rain/snow VFX graph that will be blocked by roofs and other constructions (outside of player screen space) by using external camera for depth map generation (camera is in orthographic projection mode). Unfortunately it's working only when VFX graph + its orthographic camera are located at 0.0.0. world coords (movement impossible - see video), while the idea is that rain emitter + it's depth cam will be following Player:


    And VFX graph itself:
    VFX Graph - rain.png

    No idea how to make this rain/snow VFX Graph work with Player movement, feels like depth input never updates + even if I place this emitter + camera in different position it's act like depth camera still in 0.0.0 coords; moving objects in the scene without moving VFX graph also shows that depth map is not updated - snow/rain still bouncing from place where object was before. This scene is attached to this post if you're willing to try [Unity 2022.1a12+ is required].

    P.S. Also, a lot of console errors (not always, but often) about some kind of null ref exception + Editor crashing often... should I report on this or this caused by mistakes in my setup?
     

    Attached Files:

    Last edited: Oct 18, 2021
  2. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
  3. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
    Nope, latest Master branch didn't fix that, so I've reported this as bug (Case 1377200)...
    For now I have only screen space collisions, but rain will be inside cover/buildings:
     
    Last edited: Oct 31, 2021
  4. gabriel-delacruz

    gabriel-delacruz

    Unity Technologies

    Joined:
    May 19, 2021
    Posts:
    37
    Hi Lex4art,

    I had a chance to take a look at your problem. It seems that we are not correctly handling the coordinate spaces in the camera binder.

    As a workaround, can you set your exposed camera to work in World space? It shouldn't change anything else.

    upload_2021-11-9_14-57-46.png

    I hope that helps :)
     
    Lex4art and Vita- like this.
  5. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
    Thanks, didn't knew that it can be changed there - now in world space this setup seems to be working fine and further experiments possible. Hell yeah!
     
    Last edited: Nov 9, 2021
    gabriel-delacruz likes this.
  6. Lex4art

    Lex4art

    Joined:
    Nov 17, 2012
    Posts:
    445
    After all it's possible to create very tricky VFX Graph setup to have rain/snow that can be blocked by world objects + use another VFX Graph + render texture camera on separate layer to generate mask to limit wetness effect for areas that are currently under rain influence and use it in simple custom Shader Graph shader for decal projector. So, this rain implementation has quite some limitations (vertical surfaces not taken into account when wetness effect mask calculated, rain can be only straight from top direction (probably bugreport case 1377200 will fix that), you can run out of area of effect and need to wait till particles update wetness mask, glass not blocking rain (this one I can fix via coding hack, probably...)), also not that fps-friendly but here it is:


    Some numbers for RTX 2080Ti with ray tracing enabled for GI, reflections and shadows:
    - 30...35fps on average. Disabling all ray tracing effects didn't increase fps much, so this rain setup is heavy.
    - 1M rain drops around player (most of those cut by frustum culling), emitter is the circle at 20m above player with 180m diameter (player in the center of it, so 90meters of rain in every direction on horizontal level).
    - 1M rain splashes around player (most of those cut by frustum culling), produced on dying via GPU event for each rain drop.
    - 1.6M particles for rain wetness effect (just spawn quads other world geometry to create point representation of current scene around, then use blur post effect volume on this camera to make it smooth). Emitter is the same 180m disk so there 90 meters of wetness in all direction, slowly updating because if particles fall faster than 2-3 m/s they are appears at random height above surface and then more the speed than more random placement).
    - 1500x1500px depth map from separate top-down camera (to make rain drops collide on world outside of screen space).
    - 1024x512px render texture from another camera (with strong bloom post effect to make it smooth) that located in same position as main camera. Used as screen space mask for wetness decal shader graph to limit wetness effect only where rain hits objects.
     
    Last edited: Nov 19, 2021