0
\$\begingroup\$

I work in a broadcast environment that delivers video signals over SDI as Fill (RGB) and Key (A) signals. My SDI rendering method produces a Texture for each SDI input and applies it to a material. I'm currently using a shader to populate two texture slots on the material in order to use the Key signal as an alpha mask.

This works pretty well, but it would be ideal to produce a single RGBA Texture from the two, and feed the material with the single Texture. A shader would not produce a new Texture I could get a handle on, so I'm looking for an alternate solution. So far, my google-fu has only produced shader-based approaches, or use somewhat inefficient getPixel/setPixel loops. Is there any affordance for generating a new Texture and defining channel-based inputs?

\$\endgroup\$
  • 2
    \$\begingroup\$ A shader-based approach can indeed produce a new Texture that you can then use. Look up RenderTexture, Graphics.Blit, and ReadPixels for the building blocks you need. Keeping the heavy lifting on the GPU is likely to be more efficient, particularly if your textures are large or if you don't need to read the result back to the CPU. \$\endgroup\$ – DMGregory Jun 9 '16 at 23:09
1
\$\begingroup\$

There are two main ways that you can approach this:

  1. Use a shader, which will take advantage of the GPU and generally be the most efficient solution all around. You would do this by creating a material that points to a shader and using Graphics.Blit to write to your destination texture using the shader.
  2. Use Texture2D.ReadPixels to read the array of pixels from the two images, average the value of every pixel in image1 with the coorsponding pixel in image2, and then use Texture2D.SetPixels to save them.
\$\endgroup\$
  • \$\begingroup\$ I think you mean GetPixels. ReadPixels pulls the contents of the current render target into the texture. \$\endgroup\$ – DMGregory Jun 10 '16 at 18:18
0
\$\begingroup\$

is it possible to render to a texture? In that case you could use a shader to combine the textures, then use the composite texture.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.