Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Trying to Implement Multiple skyboxes in my Unity scene

Discussion in 'General Graphics' started by ShawntheKlngofnothing, Mar 16, 2024.

  1. ShawntheKlngofnothing

    ShawntheKlngofnothing

    Joined:
    Jan 29, 2023
    Posts:
    17
    Hello, I'm working on a small project, and im trying to figure out how to create multiple smaller "Enviroments" in a Unity map.

    I have the basic skyrender(Skybox), and I have inverted cube objects that will be the mini enviroments.

    inside these Cubes will be the mini enviroments.
    I don't know how to create a entire sky inside these cubes, as I don't believe anyone uses proper sky "boxes" anymore.

    is there any options or advice you all can give me, to render multiple different sky enviroments in one map?
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,673
    Why not just change the RenderSettings.skybox depending on where the player is?
     
  3. Judgeking

    Judgeking

    Joined:
    Apr 15, 2017
    Posts:
    17
    You can add a Skybox component to a camera and it overrides the Env skybox. Maybe use it on the player's camera and change it at runtime. Or switch cameras.
     
  4. ShawntheKlngofnothing

    ShawntheKlngofnothing

    Joined:
    Jan 29, 2023
    Posts:
    17
    I figured I would reopen this thread as I'm still having this issue.

    any old dev's remember the old sky"boxes" we used to make with inverted cubes, and simply apply 6 seamless textures in them? what i need is a mini "world bubble" that has terriain and stuff in it, and then when a player goes throught a portal, they find themselves in a completely new world, with its own seperate skybox.

    Im seeing that "actual" skyboxes, and skyspheres are apparently a lost art lol.

    there are some assets on the store that allow you to use "sky domes" or Hemisphere meshes.
    https://assetstore.unity.com/packages/3d/environments/sci-fi-cosmos-sky-dome-250071
    or this
    Sky Domes - High Performance Skybox Alternative | 3D Environments | Unity Asset Store
    Does anyone have any options I can use to achieve similar results? can i invert a cube and map the textures from a cubemap simply onto the 6 sides like "in the old days"?
     
  5. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    1,007
    I think you are over complicating this. Your question basically boils down to: Can I draw a cube? Yes. Yes you can ;)

    First make your cube. Then invert the faces. You know that already of course. Now to texture it. I've honestly never written a shader that had to sample a cubemap but I don't see why it would be any different from sampling a normal texture. You'll probably have to setup the UVs appropriately but if you can handle inverting the cube faces then I'm sure you can handle that too. If it really turns out to be a hassle then just use six regular textures and create a texture atlas in photoshop that can easily be UV mapped as needed. It's a skybox so you don't need anything fancy for shaders. You can probably get away with a regular unlit one. If you do need something more dynamic then you'll have to dive in to that for yourself.

    Once you have your cube, pop it in your scene, scale it appropriately, and write a script to center it around your camera. Or if you want to be fancier with it, use a second camera that never moves position but matches the rotation of the main camera every frame and use layers to cull everything but the skybox. Then layer that camera's output so that it is always rendered behind the contents of the main camera (how you do this depends on the pipeline you are using but it shouldn't be hard to look up how to layer multiple cameras for whichever one you need).
     
  6. POOKSHANK

    POOKSHANK

    Joined:
    Feb 8, 2022
    Posts:
    366
    here's a shader you can apply to a built in unity cube to make it an inverted skybox cube

    Code (CSharp):
    1. Shader "Custom/_Skybox"
    2. {
    3.     Properties
    4.     {
    5.         [HDR] _Color("Tint Color", Color) = (.5, .5, .5, 1)
    6.         [NoScaleOffset] _MainTex("Cubemap", Cube) = "grey" {}
    7.     }
    8.  
    9.         SubShader
    10.     {
    11.  
    12.         Tags { "Queue" = "Background" "RenderType" = "Background" "PreviewType" = "Skybox" }
    13.  
    14.         Pass
    15.         {
    16.  
    17.             Name "Skybox"
    18.  
    19.             CULL FRONT
    20.             ZWRITE OFF
    21.  
    22.             CGPROGRAM
    23.             #pragma vertex vert
    24.             #pragma fragment frag
    25.  
    26.             #include "UnityCG.cginc"
    27.  
    28.             samplerCUBE _MainTex;
    29.             half3 _Color;
    30.  
    31.             struct appdata
    32.             {
    33.                 float4 vertex : POSITION;
    34.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    35.             };
    36.  
    37.             struct v2f
    38.             {
    39.                 float4 pos : SV_POSITION;
    40.                 float3 cubeUV : TEXCOORD0;
    41.                 UNITY_VERTEX_OUTPUT_STEREO
    42.             };
    43.  
    44.             v2f vert(appdata v)
    45.             {
    46.                 v2f o;
    47.                 UNITY_SETUP_INSTANCE_ID(v);
    48.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    49.                 o.pos = UnityObjectToClipPos(v.vertex);
    50.                 o.cubeUV = v.vertex.xyz;
    51.  
    52.                 return o;
    53.             }
    54.  
    55.             fixed4 frag(v2f i) : SV_Target
    56.             {
    57.                 return fixed4(texCUBE(_MainTex, i.cubeUV).rgb *_Color.rgb, 1);
    58.             }
    59.  
    60.             ENDCG
    61.         }
    62.     }
    63. }
    remove the [NoScaleOffset] if you want to be able to change the size of the skybox without resizing the cube
     
    Last edited: Apr 16, 2024