Convert Texture2D to RenderTexture without Blit or Copy?

My android Device does not support CopyTexture and by extension does not support Blit.
So, I am forced to go a different rout. What I want to do is compare the current web-camera frame with one a few frames ago. My current solution is to copy the Color32[ ] for each frame then compare them. I want to display the Color32[ ] image on the mainCamera. I am thinking I need to rend the altered Color32[ ] to the RenderTexture but not sure how to do it. Any ideas?

Or send the Color32[ ] to a RawImage would be fine too.

BTW. I always give likes to answers… :wink:

  • Note I figured out sending it to RawImage. Rawimage has a texture assigned to it, so all I did was create a Texture2D then did SetPixels(Color) and Apply(). Then set the RawImage.Texture to the Texture2D.

I would still like to know how to do this to the camera though.

Texture2D to RenderTexture should not be that hard to do. Just render a plane (or a teapot even) with the Texture2D applied using projective texturing. For projective texturing:

  • In the vertex shader
  • Take the clip space position x and y (the output position)
  • Change the range from -1 to 1 into 0 to 1 (0.5 + 0.5 * pos_clip.xy)
  • Add a half pixel offset for platforms before DirectX 10 (+= 0.5 * _ScreenParams.zw)
  • Flip the y coordinate if needed
  • Pass x, y and w to the pixel shader
  • In the pixel shader
  • Output the texture using xy / w as uv

Then make sure the object in question is in front of (every) camera. You can use the onPreCull callback for that.

1 Like

Thanks, I’ll give that a go.
Ultimately all I want is to send 2 Texture2D’s to my shader and update them in the shader each frame.
I thought Graphics.Copy or Blit was the only way.