Graphics.Blit produces transparent texture when passing a Material (bug?)

(Using Unity 2021.1.7 and URP 11):
For a background blur effect, I render the current camera view minus UI to a RenderTexture, pass the contents to a Texture2D via Texture2D.ReadPixels and Blit that Texture2D to another RenderTexture using a material with a blur shader. All this works in the Editor but not in the WebGL build, where it seems that the resulting RenderTexture is fully transparent (I can’t see it when applied to a RawImage but can see another image placed behind it). Testing the steps individually, I found that the problem is tied to calling Graphics.Blit with a Material as third parameter. The shader doesn’t seem to be the root of the problem as I also tried Unlit/Texture, UI/Unlit/Transparent, Universal Render Pipeline/Unlit, Universal Render Pipeline/2D/Sprite-Lit-Default with the same result. Omitting the Material parameter produces a fully opaque texture as expected (minus the desired blur effect of course).
I don’t know how to proceed, is this due to some platform-specific limitation I’m unaware of, should I turn to the issue tracker or is there some other way to get a blurred version of my RenderTexture?

Hello,

Are there any errors in the browser console when you use a material when calling Graphics.Blit?
On a side note, I think you can get rid of the Texture2D.ReadPixels step and directly use the RenderTexture as the input of the Graphics.Blit. Depending on the platform calling Texture2D.ReadPixels can be inefficient as it copies data from graphics memory to CPU memory and back to graphics memory to update the texture.

Best wishes

Marcel

Hi, thanks for replying!
There aren’t any error messages in the console, but I’ll leave the OpenGL log stuff below in case that helps.
Regarding the extra Texture2D.ReadPixels step: I could have sworn I looked into that and found that Graphics.Blit doesn’t accept a RenderTexture, but of course RenderTexture subclasses Texture, so thanks, don’t know how I missed that.
OpenGL log

Initialize engine version: 2021.1.7f1 (d91830b65d9b)
test.loader.js:1 Creating WebGL 2.0 context.
test.framework.js:2 Renderer: WebKit WebGL
test.framework.js:2 Vendor: WebKit
test.framework.js:2 Version: OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium))
test.framework.js:2 GLES: 3
test.framework.js:2 EXT_color_buffer_float GL_EXT_color_buffer_float EXT_color_buffer_half_float GL_EXT_color_buffer_half_float EXT_disjoint_timer_query_webgl2 GL_EXT_disjoint_timer_query_webgl2 EXT_float_blend GL_EXT_float_blend EXT_texture_compression_bptc GL_EXT_texture_compression_bptc EXT_texture_compression_rgtc GL_EXT_texture_compression_rgtc EXT_texture_filter_anisotropic GL_EXT_texture_filter_anisotropic EXT_texture_norm16 GL_EXT_texture_norm16 KHR_parallel_shader_compile GL_KHR_parallel_shader_compile OES_texture_float_linear GL_OES_texture_float_linear WEBGL_compressed_texture_s3tc GL_WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb GL_WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info GL_WEBGL_debug_renderer_info WEBGL_debug_shaders GL_WEBGL_debug_shaders WEBGL_lose_context GL_WEBGL_lose_context WEBGL_multi_draw GL_WEBGL_multi_draw OVR_multiview2 GL_OVR_multiview2

Is there any update regarding this issue? I have the exact same problem that webgl produces a transparent rendertexture when providing a material in the Graphics.Blit statement.
I tried many things but had no success so far

1 Like

Okay this is definatly a bug … i just found out that if i build the exact same project on MacEditor for WebGL everything works as expected … same Project state built on WindowsEditor for WebGL its like described renders only Transparent.
I submitted this bug some days ago … had no feedback yet … but i did not include the mac windows difference since i just learned about it.

Good to hear I’m not alone with this problem and that it does in fact seem to be a bug. I don’t have any news, but could you post a link to the bugtracker entry? Might help getting more traction.

1 Like

I will share the bugtracker url as soon as i get one form unity. currently i only have a ticket number and its still open

Any news?

I am having trouble with this suddenly after upgrading to 2021.2 and later. Graphics.Blit with 3 arguments (material) produces a white texture. Submitted a bug

Getting the same error, glad to see it’s not just me at least. Makes passing through Render Textures with alpha impossible.

So it’s been a few months, has anyone gotten feedback on the bug reports? Or found that the problem has been fixed in some newer version? Still looking for some kind of fix and I can’t find related bug reports on the issue tracker.

1 Like

I am also having this issue!

I am also having this issue. Surprised I haven’t seen a fix yet, I hope I just missed it.

Still waiting for fix.

Can anyone link me to a bug report on this issue? I see a couple of people who said they submitted them, are there links to them?

That this bug https://issuetracker.unity3d.com/issues/blit-material-hidden-slash-kronnect-slash-beautify-slash-beautify-uses-dest-texture-as-input-its-an-undefined-behaviour-consider-using-double-buffering-dot-is-thrown-when-a-blit-is-executed-in-an-image-effect Still happening on 2021.3.26

In the shader of the material passed in Graphics.Blit(src, dst, mat), set ZTest to Always.
If your material for some reason needs ZTest LEqual, then make sure the textures being passed to the material have no depth data.
One way is to get a temporary RenderTexture with RenderTexture.GetTemporary(width, height, 0) where 0 = depth.
Then Blit your source texture to the temporary RT with Graphics.Blit(src, tempRT).
Now you can pass it to the material.
Do this to the src tex or RT being passed to the material, as well as to tex or RT being passed to with mat.SetTexture();

I also have seen some people posting that changing ZTest to Always has not solved the issue until they passed a texture with no depth data. So you might want to do both to be sure.

2 Likes

This solved things for me on 2021.3.16f
I was Blitting to and from a temp texture back to the camera and webgl would output a black screen until this fix