Texture2D.Resize and Shader

Hey everyone,

I would like to know how can I reduce the resolution of the grabbed screen texture using Texture2D.Resize and Texture2D.ReadPixels. This texture is used in a shader after being grabbed.

I am actually doing this :

    myTexture.Resize(Screen.width / factor,Screen.height / factor,TextureFormat.RGB24,false);
    myTexture.ReadPixels(newRect(0,0,Screen.width,Screen.height),0,0);
    myTexture.Apply();

I could use the RenderTexture.mipMapBias but I want to reduce the texture’s resolution.
Thank a lot !

You know, you should read the documents more often. More over, this is not a shader related question.

Thank you for your answer @aubergine . You’re right. But I thought I could use the same system as the RenderTexture. It seems quite heavy to scale the texture.
For me I should use texture scaling to reduce performance costs, but is it better to use ReadPixels or GetPixelBilinear and to an operation on every pixel…

If its a render texture, why dont you init your rendertexture with the intended smaller size in the first place?

It’s not a RenderTexture, but I would like to mimic the RenderTexture behaviour. I am actually doing this :

        myTexture.Resize(Screen.width / factor,Screen.height / factor,TextureFormat.RGB24,false);
        myTexture.ReadPixels(newRect(0,0,Screen.width,Screen.height),0,0);
        myTexture.Apply();

But I would like to offer the possibility to the user to optimize it by reducing the size of the screen grabbed texture.
But from what I understand I inevitably need to store the screen texture at full resolution using ReadPixels and then read from it, scale it and store it in a new scaled texture which is useless.

But maybe I missed something.

I dont understand what you want, doesnt make any sense.

If you want to resize an image whether a texture, texture2d or render texture, check my initial post.

I I’ll try to do my best to give you a better explanation.

In Unity Pro, I can easily reduce my RenderTexture scale like this.

RenderTexture.GetTemporary(width / factor, height / factor, ...

In Unity Free I want to grab my screen inside a texture and scale it. So here is what I do this after a camera render.

            myTexture.Resize(Screen.width / factor,Screen.height / factor,TextureFormat.RGB24,false);
            myTexture.ReadPixels(newRect(0,0,Screen.width,Screen.height),0,0);
            myTexture.Apply();

But from what I understand if I want to resize my texture, I need to apply the result of Texture2D.GetBilinear on a new texture. Just like in the example, you have a srctexture and a destTexture.

I would like to scale my texture because I want to reduce the performance costs of grabbing the full screen but what’s the point of reducing the scale of a texture if I need to store my full screen texture anyway at full resolution and next reduce it and save it in a new texture.

A good thing would be to directly compute a scaled version grabbed screen texture.

Do you see what I mean ?

any idea ?

My idea is that there is a reasonable reason unity pro costs 1500$