4
\$\begingroup\$

I'm looking for a technique to render an object with multiple texture sources. One texture is static, the other is generated dynamically (it's a render target). For example, say I was rendering a TV. The frame of the TV is a static texture and the image comes from a render-to-texture pass.

It doesn't sound difficult but I've been unable to find a decent approach. Some of my ideas are:

  1. Instead of rendering to a unique texture I render to a part of the other texture (so the part with the TV screen is overwritten, the frame remains). This doesn't work if I want to combine multiple textures (two TVs with different frames, same show playing)

  2. Create a two-part object: render the TV frame as one-object then render the image as another. This would require leaving a hole in the one model, or putting the other model slightly on top. Is there a drawback to this approach?

Is there another approach that works well?

\$\endgroup\$
3
\$\begingroup\$

There are three ways to do this that I know of.

The first is to use three source textures. One is the standard diffuse texture, one is the video texture, and the third is a mask texture. You sample all three but then use the mask to decide which of the first two textures you actually use to generate your output color. You generally need two sets of texture coordinates.

The second is to do the same as the above but to use a vertex attribute as your mask. This lets you mark which vertices are part of the TV display and which aren't.

The third is to use two models like your second suggestion. This requires less model data (you don't need two sets of texture coordinates, don't need a mask, and need less duplicated vertices). However, while the data is smaller, it requires one extra draw call.

Which is faster is going to depend on a lot of details we can't predict, but in general I'd go with the third option. Especially since in the case of a TV you likely want a lot more differences between the screen and the TV itself given that TV screen give off light and that you might want some extra shader effects on the TV screen.

\$\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.