- Home /
Graphics.Blit with a 3D Texture?
Is it possible to get Graphics.Blit working with a 3D RenderTexture? I have tried but it seems like it only is working on the first layer. Does anyone know if this is possible? I have have made decent progress using the new CustomRenderTexture, but I can't seem to control the update timing with them as nicely as I want to. So I figured I could try to reproduce my progress with just RenderTextures but having some trouble. My textures are 64x64x64 so maybe I could just use one 512x512 texture instead? I would have to do some magic to set up the UV's in the shader probably but maybe I will try this next.
Thanks for the help :)
Answer by Buckslice · Nov 29, 2017 at 01:20 AM
I figured out how Graphics.Blit works and created my own version for 3D RenderTextures.
void Blit3D(RenderTexture tex, int size, Material blitMat) {
GL.PushMatrix();
GL.LoadOrtho();
for (int i = 0; i < size; ++i) {
// make sure tex.dimension is Tex3D. I think it works with Tex2DArray too
Graphics.SetRenderTarget(tex, 0, CubemapFace.Unknown, i);
// because i was using this for noise generation, I wanted the uvs to be strictly 0 to 1
// (i had to remap the x and y coords in the shader as well)
// but you may want to change it to how textures normally go
// (something like 0.5 -> size - 0.5)
float z = Mathf.Clamp01(i / (float)(size - 1));
blitMat.SetPass(0);
GL.Begin(GL.QUADS);
GL.TexCoord3(0, 0, z);
GL.Vertex3(0, 0, 0);
GL.TexCoord3(1, 0, z);
GL.Vertex3(1, 0, 0);
GL.TexCoord3(1, 1, z);
GL.Vertex3(1, 1, 0);
GL.TexCoord3(0, 1, z);
GL.Vertex3(0, 1, 0);
GL.End();
}
GL.PopMatrix();
}
May you code forever o7