Search Unity

Question Is it possible to sample pixel color behind specific texture?

Discussion in 'Shaders' started by nTu4Ka, Mar 26, 2023.

  1. nTu4Ka

    nTu4Ka

    Joined:
    Jan 27, 2014
    Posts:
    69
    Hello,


    I'm completely new to shaders.
    I'm working on 2D combat game with multiple characters. Each character consists of several layers of sprite animations. Each layer represents a part of character (e.g. body, weapon, visual effects).
    All characters are layered depending on how "close" they are to the screen. Something similar to "Don't Starve".

    I'm trying to resolve following issue.
    I need to blend (e.g. multiply color blend) visual effect sprites with everything behind the object that contains these VFX sprites. While ignoring everything that is above.

    Is there a way to sample pixel color behind specific pixel on texture with shader?
    This behind pixel should consider everything rendered on the screen (behind the object with shader).
    In order to blend VFX texture color with everything behind this texture.

    I understood there is a solution to use cameras and RenderTexture.
    Theoretically it's possible thought I'm slightly concerned to have 10 cameras and RenderTextures on the scene working at the same time.

    Is there some other, maybe more straightforward way?


    Thank you in advance.


    nTu4Ka