Search Unity

How to substitute GrabPass with RenderTexture for Glass Stained Bump Distort?

Discussion in 'Shaders' started by darreney, Aug 17, 2019.

  1. darreney

    darreney

    Joined:
    Oct 9, 2018
    Posts:
    34
    Hi, i do not have much knowledge on shaders, just read up stuffs here and there and try apply them.. I am wondering what is the method to get the pixel colors from another sprite? I'm guessing i will have to pass in the positions and texture, but not sure how to go about coding for it to be transformed into the local object's space.


    So here are my use cases:

    #1. I would like to apply chromatic aberration on a single sprite, and this sprite is dynamically changing, and i have it in a rendertexure. Applying the effect to just the sprite alone does nothing because it is fully blue in color and doesn't have any red. So i need to read the backgroud (B in pic1) to combine the colors before applying the effect. But i also do not want the effect on the edges of the rectangle box but just the sprite itself, so will need to discard the pixels that are transparent in the sprite A.

    #2. I have objects that will intersect with the dynamic shape (same rendertexture from case 1) and parts that have intersected, i will want to display the colors from a secondary texture instead of the _mainTex. So i will need to read the intersected pixels to check its alpha value.
    [Edit: Will solve using Stencil Buffer]

    I am thinking that these intersecting concept is quite similar to masking? so should be achievable?
    Thank you for reading and any help is appreciated!

    Edit: decided not to have the feature in case #1.
     

    Attached Files:

    Last edited: Aug 20, 2019
  2. darreney

    darreney

    Joined:
    Oct 9, 2018
    Posts:
    34
    Hi, I am trying to implement a bump distortion shader, similar to the Fx/Glass/Stained Bump Distort,
    but using RenderTexture instead of GrabPass, as I have read that GrabPass will affect the performance on mobile.

    https://github.com/kw0006667/Unity3D/blob/master/Assets/Standard Assets/Glass Refraction (Pro Only)/Sources/Shaders/Glass-Stained-BumpDistort.shader

    The difficulty I am facing is just like my above post, not knowing how to deal with the different transformations so that I can read the pixels of the RenderTexture that has different positions &/ size as my local object (which the shader applies to)
    The use case is as per attached illustration.
    I'm using RenderTexture size that covers the area where my object will roam around, instead of using full screen that hopefully saves on render time.

    What is the usual practise for such case? is it to use full screen rendertexture? or do i create a rendertexture that is same size as my object and let it follow its position?
     

    Attached Files: