- Home /
[Pro] How do I make programmatic Render-to-Texture work?
Simple scene, one camera, to which I attach this script:
using UnityEngine;
public class BzSetupCam : MonoBehaviour {
private RenderTexture rtt;
void Start () {
camera.layerCullSpherical = true;
rtt = new RenderTexture(Screen.width / 4, Screen.height / 4, 16, RenderTextureFormat.Default, RenderTextureReadWrite.Default);
rtt.filterMode = FilterMode.Point;
// rtt.wrapMode = TextureWrapMode.Clamp;
rtt.anisoLevel = 0;
rtt.antiAliasing = 1;
camera.targetTexture = rtt;
}
void OnDestroy() {
Destroy(rtt);
}
void OnPreRender() {
if (!rtt.IsCreated()) {
if (!rtt.Create()) {
Debug.LogError("Failed to create RTT");
}
}
}
}
Since the only cam has thusly been re-targeted from "screen" to "render texture", I now see nothing, this was to be expected.
Now what's the smartest way to blit this to the screen when the render texture is completed?
Do I need a 2nd camera with an orthographic quad mesh bound to a material that's linking a simple Tex2d-sampling pixel shader?
Or is there a one-liner command for stuff like this?
Just need to show the render texture scaled to full screen to get dat pixelated style the "cheap way" (rather than post-pixelating a full 1080p screen image after the fact via image-effect as many seem to do).
Answer by DaveA · Aug 15, 2013 at 12:26 AM
I have used the first way, with a 2nd ortho camera, for doing this. I would like to hear about a better way if there is one. Maybe some param on the camera itself, or setting the screen-res lower (would also affect GUI etc) and go full screen.
Your answer
Follow this Question
Related Questions
RenderTexture not working when in Editor 1 Answer
Irregular shape window to a different background world? 0 Answers
What is difference between Camera.SetTargetBuffers and setting Camera.targetTexture? 1 Answer
Skinned Meshes cutted out on Render Texture 1 Answer
What does the GrabPass capture? 1 Answer