Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Nighttime effect shader

Discussion in 'Shaders' started by SavedByZero, Dec 1, 2022.

  1. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    I'm fairly new to shaders and have just started making some simple unlit shaders. I'm trying to make a "nighttime effect" shader, and so far I've got this:
    Code (CSharp):
    1. fixed4 frag (v2f i) : SV_Target
    2.             {
    3.                 // sample the texture
    4.                 fixed4 col = tex2D(_MainTex, i.uv);
    5.                 // apply fog
    6.                 UNITY_APPLY_FOG(i.fogCoord, col);
    7.                 col.r -= 0.3;
    8.                 col.b += 0.3;
    9.                 return col;
    10.             }
    I'm adding a little blue and removing a little red from each pixel here, doing a simple color temperature change. I like the look of it. But I feel like this is so simplistic that I've got to be missing something to make it more real. What could I do to improve it?
     
    Last edited: Dec 1, 2022
  2. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    This is something of an art question, and depends a lot on the look you're going for.

    First, this is also going to depend on your lighting setup. Just using a night skybox ( https://polyhaven.com/hdris/night ) with environment reflections can go a long way (and/or mess with your ambient probe). And of course, play with moonlight, shadows, and your other lights.

    On to the shader portion. Unless it's for learning purposes or your own pipeline, Unity already has a lot of these effects built-in, so there's no reason to make your own shader. See...
    I'm no artist, but I'd recommend a reduced color temperature foir your white balance (basically does the same thing as your blue filter), reducing saturation in low-luminescence (human eyes see less color at night), and messing with shadows/midtones/highlights to fine-tune it at different light levels. But crafting a good LUT is like a whole art in itself (see all the different ReShade profiles for AAA games).
     
    SavedByZero likes this.
  3. SavedByZero

    SavedByZero

    Joined:
    May 23, 2013
    Posts:
    124
    Yeah, this is for a simple 2D game with unlit shaders -- nighttime effect for a map screen.