- Home /
How Blit internally works?
I'm using Blit to resize a small RenderTexture into a bigger RenderTexture, and got good results. But I would like to know what is happening behind the scenes. Assuming both RT have same parameters but width and height...
Does Blit result in a nearest neighbor resize?
Or it interpolates somehow (bilinear, bicubic, etc)?
The resize method depends on RenderTexture/Graphics/Pipeline configuration?
It's behaviour is platform dependant?
I tried to research it online but I didn't get any useful information... Maybe I'm formulating the wrong questions.
Thank you!
Answer by renderist · May 27 at 01:39 PM
When you execute Blit() without a specified shader Unity will use one of its built in shaders, Internal-Blit*.shader.
You can find the built in shader package here under the Downloads popup for each platform: https://unity3d.com/get-unity/download/archive
The blit shaders are in the DefaultResourcesExtra folder.
For resizing operations Blit() will use bilinear interpolation - that is the default interpolation method used when sampling textures with tex2d().
Answer by Bunny83 · Sep 03, 2021 at 09:03 AM
The exact implementation is of course not know. However when you read the documentation you should get all the information you're looking for.
Copies source texture into destination render texture with a shader.
Blit sets dest as the render target, sets source _MainTex property on the material, and draws a full-screen quad.
So the result depends on the settings of the source texture as well as the used material / shader. We don't know what default material / shader is used when none is provided. Though it probably will do a usual bilinear interpolation.
I know your question was specifically about rendertextures. However if you want to rescale a Texture2d, I've written a CPU based bilinear texture sampler.for this question over here. Note that the TextureTools.cs on my dropbox now also contains a version that does apply a letterbox instead of cropping parts of the image.
Blit can be called without shader/material, so I suppose there is a default unknown material... There is also the possibility of Unity relying on GPU specific software or hardware for blitting. Thats why I asked...
May I ask why is probably a bilinear interpolation? Also, thank you for the script, but it would be too slow for our requirements, as it executes on CPU.
Thank you for your answer!