- Home /
Blit camera targetTexture to screen
My main camera has a script attached to it that sets its targetTexture to mainRT. Whatever the camera sees is rendered to it.
Then, I blend another RT particlesRT via Graphics.Blit(particlesRT, mainRT, blendMaterial); in OnPostRender()
I want to blit the resulting mainRT to the screen. Going by Unity's documentation, I thought using null for the destination render texture would do it, i.e., Graphics.Blit(mainRT, null as RenderTexture);
I tried using it in both OnPostRender and OnRenderImage. I end up with a blank screen in both cases. When I comment out OnRenderImage, I see that things are blended nicely into mainRT. But the blit to screen doesn't work. When OnRenderImage exists (i.e., the function isn't commented), chaos happens, and mainRT seems to have been cleared.
Can I not blit a camera's render texture to screen?
Answer by raja-bala · Oct 04, 2014 at 12:39 AM
After some experimentation, I ended up not using OnRenderImage() (completely removed the function)
Instead I did the following:
RenderTexture mainSceneRT;
RenderTexture rayMarchRT;
...
void OnPreRender() {
camera.targetTexture = mainSceneRT;
// this ensures that w/e the camera sees is rendered to the above RT
}
void OnPostrender() {
... // render to secondary render target
Graphics.Blit(rayMarchRT, mainSceneRT, matDepthBlend);
// You have to set target texture to null for the Blit below to work
camera.targetTexture = null;
Graphics.Blit(mainSceneRT, null as RenderTexture);
}
this is uber late, but yes, i have pro (4.*). In 5.0+, RenderTexture is part of the personal edition
No matter how i try it, I can't get this code to work. 1. I assume mainSceneRT is a fullscreen rendertexture, and 'camera' is the main camera. 2. where is the source for ray$$anonymous$$archRT? It suddenly just gets dropped into a function without any initialisation. I found this part confusing. 3. The way I understand the code, the OP is taking the main camera's output, blending it with ray$$anonymous$$archRT, disabling the targettexture, and then using Graphics.Blit to render the final mainSceneRT. 4. With this understanding I am unable to set up the scene to work. The blit just does not work and it just shows what the main camera originally sees.
I too have spent hours struggling with this, can you give a simple demo project?
Umm, the solution posted above was supposed to be it :) Do message or link to your question and I'll see if i can help.
Answer by hearstzhang · Jun 19, 2019 at 06:18 AM
I‘ve seen your answer, but if you attach another script with OnRenderImage, everything becomes noisy again.
Your answer