I want to upscale only one layer. I have two cameras:
The main camera that renders all layers except the one I want to upscale, which is called “ZakymVoda,” Secondary camera that renders only the “ZakymVoda” layer. I save the output of this second camera to a render texture, which I resize to 320x180 for upscaling. I render this render texture using a canvas raw image. The problem is that all objects are stuttering (when the cameras move, everything in the ZakymVoda layer stutters). How can I solve this problem?
Your R2T camera movement and/or rendering may need to happen in LateUpdate() instead of Update(). Usually when I encounter render stuttering it’s due to some Update/LateUpdate mismatch.
And if any of your assets are using FixedUpdate(), that makes things more complicated.
I tried LateUpdate but it does the same thing. The problem is that the resolution of the main camera is larger than the texture rendering. For example, the resolution of the main camera is 1920x1080, but I am using a size of 320x180 for the texture rendering, and I upscale it to my resolution of 1920x1080 using a canvas (raw image). The problem is that when the camera that renders the output to the texture moves, it starts to stutter because of the small size of the 320x180 texture, as if the texture were trying to snap in certain parts. How do I fix this? I want to render the upscaled texture on larger resolutions without stuttering.
So the stutter is caused by the 320x180 image pixel-shifting? Because at those relative resolutions, a 1-pixel shift of the 320x180 image would jump 6 pixels on the 1080p screen.
You may have to us a higher-res render target, then render it with a scaled-down sprite; but I’m not sure what your intent is in using an r2t (rather than just a second camera rendering specific layers).
I use a rendered texture that I downsize to 320x180 because I need to downscale a 2D dynamic water mesh. I want the mesh that renders the 2D dynamic water to have pixel art behavior (vertices move in pixels), but I also want to use a higher resolution so that the player’s movement is smooth. I can’t stack multiple cameras because I’m using URP with a pixel-perfect camera. So, I have two cameras - one main camera that doesn’t render the “ZakymVoda” layer and a secondary camera that only renders the “ZakymVoda” layer. I output the secondary camera’s output to a render texture. I set the size of this render texture to 320x180 and use a canvas raw image to draw the render texture into the main camera, which has a higher resolution, such as 1920x1080. The render texture of 320x180 is upscaled into the main camera using a canvas.
What if you add another image layer on top of the canvas raw image, and use it as a Mask for the r2t image? It looks like if you mask off the left-/right-most 6 pixels, it would hide the stuttering effect from the low-res image shifting left and right.
This is not a good solution because it only cuts pixels from the rendered texture’s mask (the render texture is on the entire viewport of the main camera). I am now trying another solution where I use a secondary camera that renders the layer I need to upscale. This camera copies the movement of the main camera with the difference that I round it down (using Math.Floor) at regular intervals (320x180 grid snapping is every 0.125 unit). So, the secondary camera movement is always rounded after 0.125 steps. Then I create a material from the render texture (whose size is 320x180), which I draw into a raw image, and I add an offset to it until the next snap of 0.125 steps, and the movement becomes smooth (Here’s a video for better understanding
). I still need to calculate the exact offset to make it completely smooth because I have some errors in the code, but it works this way.