Search Unity

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,493
    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

    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!