Search Unity

[SOLVED] Best way to implement dynamic skybox?

Discussion in 'General Discussion' started by Danjb1, Sep 3, 2020.

  1. Danjb1

    Danjb1

    Joined:
    Jun 25, 2019
    Posts:
    7
    I would like a skybox with the following properties:
    • Sun and moon that move across the sky
    • Colour that can vary over time
    • Texture that can vary over time (e.g. clouds during the day, stars at night)
    • Distant land texture at the horizon (as seen here)
    Here are the options I have considered:

    Procedural Skybox
    This is somewhat configurable in terms of colour, and comes with a moving sun, but does not support a texture or a moon.

    Texture / Cubemap
    This allows a sky texture and can be tinted different colours, but I believe it is essentially static; I can't see a way to translate or transition between textures, and the sun and moon would be in fixed positions.

    Physical GameObjects
    I could add physical objects to the world to represent the sun, moon, clouds, etc., but this comes with a whole host of problems, e.g. requiring a very distant camera clipping plane, objects becoming obscured by fog, objects intersecting distant geometry, etc.

    Custom Shader
    I imagine a custom shader could take care of all of these requirements, but this is likely to be a last resort for me since it is currently far beyond my skill level.

    So, how do people typically solve these problems? Is this an accurate summary, or have I missed anything?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,569
    No, it doesn't come with a whole host of problmes.

    You can either use two camera setup and set skyboxx on separate set of layers used by the camera... or you can utilize shader rendering order.
    https://docs.unity3d.com/Manual/SL-SubShaderTags.html

    Setting object tag to "Background" will make it render before anything else, and if it doesn't write into zbuffer, it won't obscure anything that is rendered after it.

    Your entire skybox can be 1 meter large sphere centered around camera. The idea is to make sure it doesn't affect depth buffer so the rest of the scene can be rendered normally.
     
  3. Ukounu

    Ukounu

    Joined:
    Nov 2, 2019
    Posts:
    208
    By using one of sky/weather packages from the Asset Store, which have already everything you listed.
     
  4. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,023
    Like neginfinity said, just use a second camera. You can create incredible skyboxes just by adding objects and particle effects in front of it. Trying to make one shader render an entire dynamic background is just adding a ton of unnecessary complexity.
     
  5. Danjb1

    Danjb1

    Joined:
    Jun 25, 2019
    Posts:
    7
    Thanks, this is exactly what I was looking for! Using 2 cameras and making the various sky components into physical GameObjects has solved all my problems.

    Very valid suggestion, but I am still curious to understand how these things work, and I learn a lot more by implementing it for myself.
     
  6. BikramKumar

    BikramKumar

    Joined:
    Mar 7, 2022
    Posts:
    3
    This is just a lazy and uncreative answer to the question. The assets in Asset Store are also created by people, and OP wants the technique to learn. You should tell about that and not just suggest to use premade stuffs.
     
  7. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    BTW the examen image is daggerfall unity, which is open source and accessible on github as a unity project, you can probably use that to learn.
     
  8. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    I downloaded and messed around with daggerfall unity project a while ago, I suggest you don't -- everything is spawned at runtime from disk, scene view doesn't work for the game without going in-game, and a host of other weird unusual workflows.

    Not what you might be used to for a unity project.
    Also, No scenes.
     
    neoshaman likes this.
  9. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Good to know. But you made more interested now, because I'm slowly evolving towards "weird workflow", like I have a need to reimplement my own scene manager due to limitations I'm bumping into lol.
     
  10. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Those "weird unusual workflows" make perfect sense given the use case. My understanding is that they haven't recreated the Daggerfall content, they've made a Unity app which can load and run that content. I also vaguely recall that Daggerfall heavily uses procedural generation. So editing stuff as typical Unity scenes likely wouldn't make sense - it's all just data fed into algos, and the whole point of the project was to use data which already existed and thus requires little (or ideally no) editing.
     
  11. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    It's offline and baked.

    Also level design (dungeon) has a very convoluted system of module that actually have many structure (of the same type, a single structure can contain many "room" or "corridor") that aren't necessarily connected in the final map, all to save space by grouping similar stuff together and reusing them (ie rotate to align the relevant one to the active one used in the map). Old games do wild wild stuff as optimization.