Letters blurred while using dynamic texture

I have searched for similar problems, but i couldnt see them fixing my issue. Thats the reason why iam posting this ques.

My requirement is mainly to write inside the cells(cell id). These cells were drawn according to the data from an excel sheet. When i tried it seems to be blurred.

Relevant Code below:

grdHeight = 3200;
grdWidth = 4600;
var ground = BABYLON.MeshBuilder.CreateGround(“ground”, {width:grdWidth, height:grdHeight});
ground.position.x = 2300;
ground.position.z = 1600;

var textureResolution = 256;
var textureGround = new BABYLON.DynamicTexture(“dynamic texture”, textureResolution, scene);
var textureContext = textureGround.getContext();

var materialGround = new BABYLON.StandardMaterial("Mat", scene);    				
materialGround.diffuseTexture = textureGround;
ground.material = materialGround;

var img = new Image();
img.src = "/textures/floor.jpg";
img.onload = function() {
    //Add image to dynamic texture
    textureContext.drawImage(this, 0, 0);

    //Add text to dynamic texture
    var font = "bold 5px Arial";
    textureGround.drawText("Grass", 75, 135, font, "white", null, true, true);
    textureGround.drawText("Grass11", 150, 135, font, "white", null, true, true);

Possible to have a PG (repro)? To me, it looks like your ‘context’ does not do what it’s likely supposed to do.
The way I see it, you are projecting over the entire ground/scene a 256 resolution for drawText, which would likely give this result. I can’t be sure but it really looks like it.

I think it will take little time reprod this project… but will do for sure…

and what you said in the second point was correct.

And how can we read data from excel in PG?

1 Like

Don’t bother. It doesn’t matter here. It could be any data. Just make a simple and hard coded PG. That will be enough.

1 Like

I have tried to draw it. but somehow lines are not showing up

this is my original screen

1 Like

@JohnK could you check this one if you have time?

1 Like

OK, it’s not what I thought. It’s kind of more problematic. You will need to look for another method.
I first tried to isolate the dynamicTexture from the grass, did set the width and height to the full size (3200x4600pp) and got the exact same result. Didn’t understand why at first. Then I bounced on the 5px size of font. Created a same size image in photoshop 3200x4600 px at 72pp resolution and there goes, same result.

The resolution at this size is not enough to draw a 5px text as image on the texture.

Edit: Quickly drafted this for comparison using advancedDynamicTexture for mesh at 2048 resolution

Oh okay,. so what can be the possibilities to fix this? or are there any workaround which i can try?

May be @JohnK has a trick to have this work with your method. I don’t, I’m sorry.
Else, the method above (see PG) would work even with 4096 resolution and low impact on performance, I believe. It would however require you to somewhat rework this part. May be wait to see if others have a better solution (that would not require so much work to redo)…

Sure, then :slight_smile: thank you

What am I checking? The are a number of issues you raise.
Let me try to answer the title ‘Letters blurred while using dynamic texture’.

Here is a very crude PG that shows that the larger the width and height of the dynamicTexture there are more pixels to write on so text remains clearer when shrunk to fit the ground.

Try different values for the parameters for createGroundAndTexture(index, fontSize, z)

Index set the power of 2 used (up to 8), fontSize as it says, z positions the ground

Have a read through the PG code and work out what each line is doing.


Amazing. I didn’t know of that at all. Works beautifully. Bookmarked it. Thx and have a great weekend :smiley:

i increased the ground dimensions and got this. - https://playground.babylonjs.com/#5ZCGRM#2625

what im i doing wrong here?

There is a limit to the size of the dynamicTexture as indicated by

Since in the PG the dynamicTexture is based on groundWidth and groundHeight by increasing these sizes 100 times you reach the limit when the index is 1.

In your project you need to find the best balance between ground width and height, the dynamicTexture width and height, and font size.

1 Like

I was just wondering. Why not separate it from the actual ground texture/image and work it as an overlay.
Eventually split in 2 or 4? I guess that would work, wouldn’t it?

1 Like

I tried to add an image also. what went wrong?

It’d be great if u can explain me these points, as im not able to understand.

  1. Whats the diff between passing a resolution value and passing height, width to the dynamic texture?
  2. what should be relation or how it should be calculated, bw the plane or ground w.r.t dynamic texture?

Sorry, if i have asked a blunder question, as im completely not understanding here.

They are alternatives. A single resolution value produces a square dynamicTexture, a width and height give a rectangular one.

It makes sense if your dynamicTexture and ground have the same width, height ratio

thank you, and also can you check the pg? i tried to render an image using dynamic texture, but it wasnt working

I also tried to add the image into the diffuseTexture. but it was not working