Reputation: 41
I'm trying to concatenate/add a texture into a bigger one but I fail to keep the result of the bigger texture.
I have a shader that takes some variables like a position for the smaller texture within the bigger one, the smaller texture itself and of course the bigger one.
Basically, my shader works correctly ( I think ), in the result I see the smaller texture in the bigger one at the right position. However my bigger texture is never saved, so all the precedent pass is ignored.
How can I save the result to send it again into the shader to concatenate all the small textures into it?
I try this : Graphics.Blit(_RTConcat, _RTConcat, _concat);
RTConcat
is my bigger texture, it's a RenderTexture
, I've tried to create it both in editor or in script but the result is the same and _concat
is the material using the shader.
PS : I'm using unity 4.5.3 and can't upgrade, it's a pro version.
Edit / Update :
I "success" to made something that look like what I want, but I don't understand why it work.
In my main script I init a resulting renderTexture and set it to a mat which apply it on a plane
_radarVision = new RenderTexture(_radarTextureWidth, _renderHeight, 24);
_renderHeight, 24);
_radarScreen.SetTexture("_MainTex", _radarVision);
_radarVision
and _radarScreen
are never edit again in my scripts.
The Graphics.Blit
is now in a new script attach on a camera create only to run a single script :
`void OnRenderImage(RenderTexture source, RenderTexture destination) {
Graphics.Blit(save, save, _concat);
rttmp = RenderTexture.GetTemporary(camera.targetTexture.width, camera.targetTexture.height);
save = rttmp;
camera.targetTexture = save;
RenderTexture.ReleaseTemporary(rttmp);
}`
There is nothing else and it made my stuff working but I'm still bemused because it shouldn't be working... no?
Upvotes: 2
Views: 1751
Reputation: 1
Using RenderTexture, Blit and Material combo is not the best solution. Too much overhead here. You must call Blit twice because you can not read and render to the same render texture at once I guess. I believe the direct and best solution is:
subTex = ... ;// Initialize the sub tex
subTex.Apply(); // Upload elementTex to the Gpu
Graphics.CopyTexture(subTex, offset, size, globalTex, offset, size); // the subTex will be copied to globalTex in both GPU, and CPU. This is a GPU->GPU and a CPU ->CPU copy so it's very quick without any additional drawcall at all.
Upvotes: 0
Reputation: 41
And the best solution I've found is :
Graphics.Blit(save, save1, _concat);
Graphics.Blit(save1, save, _concat);
I don't understand why a single Graphics.Blit
don't work but a double work "perfectly", it only bother me because it require to call twice a same shader (who work with really big texture like 16384*4092) but whereas my last solution, I can apply a last shader to my texture without ruin everything.
The use of GetTemporary
cause a problem when apply a second shader to texture `save, I'm guessing a story with buffer.
I'm always open to suggestions for a better way, but for now my solution solve totally my problem eventhough it gave me a cancer
Upvotes: 1