- Home /
Ways to blit into a texture? (iOS compatible)
I'm working a drawing app, and my current solution of using Graphics.Blit() to draw the brush on the canvas works perfectly on editor but it doesn't work on iOS.
My rendertexture turns black as soon as I use a material in the Blit() method when running on iOS. I was wondering if there are other ways to blit into a texture.
Thanks,
Do you have the Pro license for exporting to iOS from Unity?
Answer by RC-1290 · Mar 30, 2014 at 02:09 AM
When you use a material with a custom shader for blit, you need to make sure that it handles depth correctly. In DX9, any shader seems to work, but it is important for DX11 and apparently OpenGL ES.
If you look at the built-in blit shader (DefaultResources/Internal-BlitCopy.shader) you see that it uses ZTest Always to make sure that the texture gets written, regardless of what's in the depth buffer. It also does some other useful things such as disabling fog with Fog { Mode Off }.
About other ways to blit to a texture: Blit draws a full screen quad with the given material to the active RenderTexture, which is something you could do manually.
Thanks for answering, actually the problem was that the renderTexture was drawing to a set depth which wasn't initialized , I set it to 0 and now it works.
The ZTest Always insstruction did not result in any changes for me.
Answer by cupsster · Jul 21, 2014 at 04:17 PM
When you initialise 'RenderTexture' and want it to work on iOS you need to set depth to 0. I figured it out the hard way... Wasted one week to find workaround for this.
Does that happen with a shader that uses ZTest Always? Because if it doesn't have ZTest Always, the depth of the RenderTexture might be initialized as closer to the camera than the Screen Space Quad that is rendered by Graphics.Blit.
@cupsster When you say "set depth to 0", is that equivalent to setting "Depth Buffer" to "No depth buffer" in the Inspector?
And in code, would it be equivalent to passing depth=0 into the RenderTexture constructor, or setting RenderTexture.depth=0 to force the bits to 0?
Were you able to get Graphics.Blit working on iOS with a RenderTexture created in the inspector (vs code)...? I'm having a "wasted week of pain" here, similar to you, in Unity 5.3.0f4 :-)
my project if you're interested, RT$$anonymous$$anager is doing the Graphics.Blit
Your answer
Follow this Question
Related Questions
Graphics/RenderTexture Alpha Brush 0 Answers
How Blit internally works? 2 Answers
How to get smooth renderer on IOS game? 0 Answers
Blit isn't writing to render texture 1 Answer
Drawing onto a render texture in OnGUI 0 Answers