How do you use RenderTargetTexture as a diffuse texture?

I’d like to use a RenderTargetTexture as a diffuse texture for a project I’m working on. As a first step, I forked the sandbox demo from the documentation and (naively?) changed this:

rttMaterial.emissiveTexture = renderTarget;

To this:

rttMaterial.diffuseTexture = renderTarget;

Now it’s black. Here’s the URL to the modified sandbox:

https://www.babylonjs-playground.com/#69DRZ1#31

Anyone know what I’m doing wrong?

you are disabling the lighting so the material is black.

Turn your lighting back on and the diffuse channel will be seen.

2 Likes

Good call, Pryme8!

By disabling lighting, I think what you were trying to do was make the material unlit; if so, it might be easier to use a PBR material, which works out of the box with a direct translation of the code you have.

https://www.babylonjs-playground.com/#69DRZ1#32

Best of luck!

1 Like

Or he could leave it in the emissiveTexture and keep the lighting disabled

1 Like

Thanks everyone! You are both correct. That was very helpful.

The context is I’m trying to render BMFonts to a texture in a scene loaded from glTF (so yes to PBR materials). I’ve already done an experimental port of the MSDF text renderer from three-bmfont-text. I have it rendering to plane meshes, one for each glyph.

Oct-02-2020 12-15-24

Now I need to render that text together onto a single, arbitrary, non-plane geometry, and I think RenderTextureTarget is the way to do it. (Feel free to suggest other ways of going about it.)

I’m fairly new to graphics programming, so I’m still learning some basics and making a lot of mistakes as I go. In this case, I took the original sandbox from the RenderTextureTarget documentation and completely missed line 51:

rttMaterial.disableLighting = true;