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

Thermal Vision Effect

Discussion in 'Shaders' started by David_Knopp, Dec 11, 2016.

  1. David_Knopp

    David_Knopp

    Joined:
    Jul 10, 2013
    Posts:
    10
    Hi!

    I'm trying to recreate a thermal vision effect like the one in this video:



    Some key components/limitations of the effect:
    - Rendered as an overlay with the actual image behind it (whether that be the default defuse color, or a separate night-vision effect - I'm only trying to achieve the thermal overlay here).
    - Only certain objects give off a heat signature.
    - Ability to have the effect confined to a portion of the screen.
    - Slight positional lag with quick movements.
    - Hopefully done in a way that doesn't require the use of camera layers.

    I'll be the first to admit that I'm no expert when it comes to shader programming, but here's my first (failed) approach:
    - Modified the standard shader to add an "EmissionType" tag and an emission texture for defining thermal signatures for objects.
    - Set up a 2nd camera that uses a replacement shader with the tag "EmissionType"="Thermal" that writes the thermal intensity from the emission texture to the color buffer as black and white. (Currently only using the red value of the texture for thermal).
    - Run an image effect that maps the 0-1 thermal intensity to some color gradient.

    Then the plan was to maybe apply some noise to that final image effect and lag it somehow, but using an image effect like this will be applied to the entire screen, and not just the heat overlay as I had hoped.
    How can I render an overlay that has effects applied to it without affecting the standard image behind it?

    I'd love to hear any feedback or alternate approaches :).
     
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,864
    I have a thermal vision effect (2 different effects infact) in this pack, which doesnt do what you exactly want. However, when you buy the package you will be entitled to get one customization for your needs and i shall do that.
     
  3. David_Knopp

    David_Knopp

    Joined:
    Jul 10, 2013
    Posts:
    10
    Hey, thanks for the offer, but I'm really hoping to further my understanding of shaders. Just looking for a nudge in the right direction ;).
     
  4. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,864
    Well, then it would be wise to check smiliar shaders and study their codes, such as the one i mentioned :)
     
    David_Knopp likes this.
  5. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,657
    @David_Knopp
    You might want to take a look here:



    This guy makes really good videos about everything shader related (and he doesn't try to sell you something ;))
    Best part of it: he releases the source code of the shaders he re-create free of charge.

    Maybe you can wack something up to achieve the effect showed in your video?
     
    Pengocat and David_Knopp like this.
  6. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    395
    Unfortunately I cannot see the video but I would say your first (failed case is on the right track)
    You should have your second camera render to a new render target.

    Then you can use this render target as a texture in the main pass. Your second camera can be cloned from your main camera and rendered right before your main camera with a script on the main camera. I forget onerender or prerender. Check the monobehavior docs.

    You can also control the resolution of this texture to give you some noise / less detail. Not to mention faster rendering for your extra pass.

    Depending on your platform and exact requirements you could also look at multi target output or writing to alpha possibly to encode your heat signature in a single pass.

    For the blur you will need an extra buffer you can use as a delay buffer. Which can just be a lerp between current frame and the other buffer basically for simple lag. You may need two actually to ping pong between as you accumulate the images.

    For a night vision effect I did a long time ago I also had gain and bias plus bloom. The gain and bias was auto controlled and had a fixed rate. So if all of a sudden it got really bright everything would be white for a while until the sensor could adjust. Plus some random noise coming from a noise texture to simulate some of the sensors properties.


    Oh a possible fake thermal might be able to just use the luminosity of the color data to simulate the temperature range. But having thermal texture would be better. A black car hood might still be hot.
     
    David_Knopp likes this.
  7. David_Knopp

    David_Knopp

    Joined:
    Jul 10, 2013
    Posts:
    10
    @Mauri, Thanks for linking this video! Definitely helps a lot with my exploration. His videos are super helpful and more people need to know about them :).

    @daxiongmao, awesome advice. I just started rendering to render textures and manipulating them, so your feedback makes me feel like I'm definitely heading in the right direction. Also love the ideas for adding noise and blurring. Thanks for all of your help!
     
    Mauri likes this.