Center Zoom

Good night.
I want to zoom in on a Render Image, but when I multiply its UV by a constant value, the zone is applied in one direction (left diagonal).

Code:

float lightIntensity(float2 fxUV, float thr) {
    float4 colorChannel = GetSource(float2(fxUV.x * 1 / thr,fxUV.y * 1/thr));
    float greyscale = (colorChannel.r + colorChannel.g + colorChannel.b) / 3.0f;
    return greyscale;
}

GetSource:

float4 GetSource(float2 fxUV) {
    return SAMPLE_TEXTURE2D(_PostFXSource, sampler_PostFXSource, fxUV);
}

PostFXSource = image from camera backBuffer

I want the zoom to be centered. I believe I have to add an offSet to fix this.
I have no idea how to do this offset.


I know that and the same thing, I left to add a multiplier in the future.
As I reduced the image by 2x, I have to move 1/2. But it didn’t work, bro.
For some reason it keeps going to the left
6191937--678987--ezgif-6-614571fa4b5d.gif

What I wanted to do is this cut here:

So I can get only the object that the player is looking at.

I tried this too:

    return SAMPLE_TEXTURE2D(_PostFXSource, sampler_PostFXSource, float2(fxUV.x * 1 / thr, fxUV.y * 1 / thr) + float2(fxUV.x / thr + ((fxUV.x / thr) * 0.5) , fxUV.y / thr + ((fxUV.y / thr) * 0.5)));

Did not work

you have old resolution 1500,900 and you need read centered pixels 3 times zoomed so you read between 500 - 1000 on X and 300 - 600 on Y… Center is 750,450 so just make 750 - 1500 = -750 what is start offset from center and divide it by “thr” so -750 / 3 = -250. Now you know where start on X when you zoomed 3x and you starting on 750 + (-250) = 500 as on your picture

// my pseudocode
float2 center = float2(screen.width / 2, screen.height / 2 );
float zoom = 3;
float2 startingPointOffest = center - float2(screen.width, screen.height);
float2 zoomedStartPosition = center + startingPointOffset / zoom ;
float4[,] zoomedColors;    // 500,300
for(y = 0; y < screen.height/ zoom; y++){
    for(x = 0; x < screen.width / zoom; x++){
     zoomedColor[x,y] = GetColor(zoomedStartPosition.x + x, zoomedStartPosition.y + y);
    }
}

Texture2D = zoomedColors;

Texture UVs in a shader are normalized to a 0.0 to 1.0 range on the x and y. (0.0, 0.0) is the bottom left, (1.0, 1.0) is the top right. Multiplying 0.0 by any value is 0.0, so it doesn’t change, hence the zoom into the corner. If you want to zoom into the center, the easiest way to do that by offsetting the UVs by 0.5 so that (0.0, 0.0) is now the center, multiplying, and then counter offsetting by 0.5 afterwards.

float2 zoomedUV = (uv - 0.5) / zoom + 0.5;
1 Like