Search Unity

Looking for high-level overview of what shaders can do and what I should research

Discussion in 'Shaders' started by Martin_H, Aug 28, 2015.

  1. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Hi, I'm very new to shader programming and I'm looking for a high-level overview of what can be done with shaders (and what kind of shaders ) to give me a better understanding of what can be achieved and how I can approach concrete problems.

    One of the usecases I was wondering about is something like this (please zoom to 100% size):


    Let's say I have an isometric view on a city and buildings are (partly) obscuring a player controlled mech and enemy vehicles in the streets. How could I make the buildings transparent with a blurred and dithered mask of the player mech and how could I draw colored and transparent silhouettes or outlines of enemies wherever they are covered by a building?

    And how (if at all) could I modify the standard pbr shader to output 1 or 2 more "buffers" (is that what those are called?) of data (e.g. surface temperature information defined by a texture) that can be accessed and processed in fullscreen post effect shaders to render things light heat distortion over hot objects or a thermal nightvision effect.

    I do realize that those are probably all very advanced topics that may or may not be possible at all. I'm a little lost on where I should start reading and what to google to get a grasp on those things.


    What I have managed so far is adapting some code I found into a bayer matrix dithering effect overlay to simulate the aesthetic of pixelated and dithered low bit-depth retro graphics. I'm sure I can find info on how to blur a mask of a silhouette of the player mech (once I find out how to render such a mask - I believe "stencil buffer" is the magic keyword here) and I probably could adapt the code to dither the soft border of the mask from there. But how do I get the two passes I need to combine with the mask to get a see-through effect? Or do I need to do this on the material shader in screenspace? I'd be happy if you could point me in the right direction or tell me what to google. Thanks!
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    As with most things complex there are usually more than a few ways to do it. Or not. .. but either way, what you want to do isn't super advanced, but it does have various pieces to it. You'd do well to learn about the graphics rendering `pipeline`.. just google about shader pipelines or whatever. Learn about what a vertex shader is, what a fragment shader is, and where it fits in the pipeline. There are other parts to the pipeline like the blending hardware, color channel masks, textures and other stuff that you would need to handle.
     
    Martin_H likes this.
  3. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    472
    Martin_H likes this.
  4. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Hey guys, Thanks a lot for your input! This was really helpful and I have already found a few good starting points. I'm posting them here in case others stumble over this thread looking for something similar:






    The last video is really close to what I need I believe. But I have to watch it again when I'm less distracted by other work. Had it running in the background yesterday.

    @imaginaryhuman: I'm glad to hear what I try to do isn't super advanced. :)
    It's gonna be a while till I get to implement it, but if I get good results maybe I'll post em here.