Write text on Model

Hii Guys,

I wanted to write text on model. I am doing so by writing render layer to texture and then applying that texture to model.I don’t want any background color(background of text would be transparent) to text(draw text only).But text color is getting dull.

Any help would be appreciated.

Thanks in advance!!

Hi @Sachet and welcome,

It’s been a while since the last time I’ve done text rendering using canvas, are you able to share a sample project url? To take a look on your approach.

Hi Leonidas,

https://playcanvas.com/editor/scene/923524

Hi @Sachet,

So one way to fix this is to take into account the alpha value of the layer surface. Do the following changes in your project:

  1. Add an alpha channel to your render texture:
    var colorBuffer = new pc.Texture(this.app.graphicsDevice, {
        width: 512,
        height: 512,
        format: pc.PIXELFORMAT_R8_G8_B8_A8,
        autoMipmap: true
    });
  1. Prepare your material to use an Opacity map with blending set to alpha:

image

  1. Use the render texture in the Opacity map:
    var material = this.entity.model.model.meshInstances[0].material;
    material.diffuseMap = layer.renderTarget.colorBuffer;
    material.opacityMap = layer.renderTarget.colorBuffer;
    material.update();  

image

Thanks Leonidas.

But here one orange line is coming at all sides (left,right,top and bottom) which is not there in my text.How to fix that issue?

Hmm, indeed they are, I thought the following code will resolve this:

    colorBuffer.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
    colorBuffer.addressV = pc.ADDRESS_CLAMP_TO_EDGE;

But it seems that padding is coming from somewhere else.

Thanks Leonidas

Try submitting an issue about this in the engine repo, maybe someone might have an idea if there is a bug or workaround this.