Search Unity

Question A type of "billboard", rotate vertices to "face" camera angle around global's vertical 0

Discussion in 'Shader Graph' started by CommonSensei, Jul 30, 2021.

  1. CommonSensei

    CommonSensei

    Joined:
    Oct 19, 2016
    Posts:
    1
    Hi, I've been trying to get this working for a while but I'm just not proficient enough at maths and Unity's engine. I fear it might be a rather large ask due to how awkward it's been to search help.

    I want to get all vertices in my scene to rotate around a vertical global 0 at their feet to "face" the camera, or rather simply share the same angle. It's proving difficult not only because I'm no good with matrix transformation but also since I'm limited by SpriteRenderers apparently having a batching system of sorts, that shares data at world origin somehow and that messes up a lot of the basic coordinate twisting I could manage on my own?
    Here's a video showing partly what I'm trying to achieve and also what I suspect is the batching messing things up


    A thing to note is that a normal billboard would face camera but doing so by presumably rotating their vertices around their origin in localspace, so moving a billboard straight up actually moves it straight up. However I'm looking to have all upward and downward motion on globalspace to be translated to match the camera angle, projected so to say, along this skewed plane. So that if I had a prefab made up of several sprites with animation in various scales, rotations and most importantly heights don't appear to separate themselves. One reason I'm trying to rely on shaders is due to the water effects seen in the video, were I'm hoping that each camera can render props with different shaders eventually, making one camera see the props as is and another sees them mirrored by the 0 origin on vertical axis, to texture certain ground materials with. In my efforts it seems straightforward enough to get a global horizontal position and insert a 0 vertically on each vertex for a desired point to start rotating them around (again batching usually botches getting this point) but how to get them to lean down from there based on a camera angle and rotation and all I cannot figure out.

    To clarify, I don't actually need vertices to twist to face the cameras on any horizontal plane I think, I can entirely rely on gameobject scripts to achieve that. Besides animations might not play nice with shaders trying to affect any other axis than vertical? Maybe? Incidentally, I was wondering how to increase the frustum culling on a camera since Unity infamously likes to unrender unruly vertex transformations, I suppose covering a whole 180 vertically. And if shader graphs even can have different types of shaders based on camera? Otherwise a shader graph could perhaps still help me understand what transforms to apply so I can look into translating it into real code at a later time, since I think I at least heard rumours of written code being able to change shader based on camera. Thanks for any input