How to downscale and upscale a grab pass texture in a shader

hey all. I’m working on a custom bloom shader.
It requires down sample and up sample steps.

I know this can be done in C#, eg:

int width = source.width / 2;
int height = source.height / 2;

RenderTexture currentDestination = RenderTexture.GetTemporary(
            width, height, 0
        );
       

Graphics.Blit(source, currentDestination, bloom, BoxDownPrefilterPass);

But i need this to be done in the shader.
Something like this:

GrabPass
{
     "_BackgroundTexture"
}

//this next line is just an example of what i'd like to do. is this possible?
_BackgroundTexture.setSize = halfSize;
col = tex2D(_BackgroundTexture, i.grabPos);

Thanks for any help all :slight_smile:

Not possible.

hey @bgolus , thanks for the reply.

Ending up doing this in the end:

            half4 frag(v2f i) : SV_Target
            {
                half4 col = 0;

                float2 newUVPos;

                //Sample the grab pass texture at the same point for multiple
                //fragments. Eg, if fragment is 0.0, 0.1, and 0.2, then sample
                //from the texture at uv 0.0. if 0.3, 0.4, 0.5, then sample
                //at 0.3 etc. this gives the effect of lower resolution.
               
                //uv coords start out 0 to 1. Multiply by 10X or more so
                //we get an integer. eg, uv.x = 0.51. X by 10 = 5.1;
                newUVPos.x = i.grabPos.x * _SmootherFactor;
                newUVPos.y = i.grabPos.y * _SmootherFactor;

                //then round to the nearest int. Eg 5.1 will be 5.0
                newUVPos.x = round(newUVPos.x);
                newUVPos.y  = round(newUVPos.y );

                //then convert back into a 0 to 1 uv coords range.
                //Eg 5.0 will become 0.5
                newUVPos.x /= _SmootherFactor;
                newUVPos.y  /= _SmootherFactor;

                //sample from the grab pass texture
                col = tex2D(_BackgroundTexture, newUVPos);
               
                return col;
               
            }