Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Sprites with fog

Discussion in 'Shaders' started by stickadtroja, Jul 11, 2017.

  1. stickadtroja

    stickadtroja

    Joined:
    Oct 25, 2015
    Posts:
    33
    I have a 3d game with 2d sprites, i guess you call 2,5d, and i want to have fog in it. the standard one, distance fog. i dont know how though. i have some basic understanding of the unity shaders, but i dont know what is required to make sprite work with fog. so any suggestions and help would be appriciated!
    also i tried searching for an answer, but none of the posts or unity answers work.
     
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,469
    Fog is simply mixing a color based on the distance to the screen, so basically camera.position - object position, you might need to divide by a max distance, clamp the result to the max, which would give you a number between 0 and 1, use that number as a way to blend two colors together with a lerp, I mean the color of your object's pixel and the color of the fog. Since the depth buffer is such a distance, you can use that to have that blending color.
     
  3. stickadtroja

    stickadtroja

    Joined:
    Oct 25, 2015
    Posts:
    33
    but how do i get the color of the global fog? maybe some shader pro would like to show some code?
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    If you knew how to use fog you'd realise it's in the lighting window and fully documented and you do not need to be a shader pro.
     
    hahahpizza likes this.
  5. stickadtroja

    stickadtroja

    Joined:
    Oct 25, 2015
    Posts:
    33
    i know that, but my problem is it doesnt work with the default sprite shader. so how do i get sprites with the global fog? i think i need a custom shader. and i dont really know much about shader writing in unity, so if anybody already made a solution, or feel super generous and wants to write me an example, i would be super grateful!