Color for Linesmesh not applied properly

Hi ,
I have applied color to lines using standard material.

But color for lines are always white.

I didnt want to use “colors array” as I want to apply different color on picking or highlighting.
(The optional parameter colors is an array of successive Color4, one per line point).

Hi G!

Lines like these… also have a master .color property… which you can easily set to a Color3-type value. In the above PG, I start green, then turn red after 5 secs, then turn white after another 5 secs.

StandardMaterial doesn’t work on these babies.

As a side-note, I’m not sure you can “pick” a line… but you can certainly highlightLayer and glowLayer them. Both of those… have colors of their own, too… so you can leave the lines white, but then when glowLayer or highlightLayer activates, it will “appear” to change the line color… to the glow/highlight color.

Lots of options, but… standardMaterial colors is not one. :slight_smile: Sorry. Stay tuned for more comments, as I could have said something wrong, and I might need correcting. (common for me)


Yep @Wingnut is right. The LineMeshes are rendered using a specific material (for perf reason)

1 Like

Hi, if I want to make a LineMesh (basically a drawArray with line type) using my own vertex and fragment shader, what is the best approach with BJS?

Hello you can simply replace the shader with your code. Original ones:

Simply replace the code in BABYLON.Effect.ShadersStore[“LineVerteShader”] and BABYLON.Effect.ShadersStore[“LinePixelShader”]

Hi thanks for the answer. I tried to modify the ShaderStore but it did not seem to work. Then I looked at Babylon.js/linesMesh.ts at master · BabylonJS/Babylon.js · GitHub and it seems to use other shaders: color.vertex and color.fragment and the _colorShader material seems private with no setter. I could not find in the code where “LineVertexShader” is used.

can you repro in the PG? will just be easy to fix your code :slight_smile:


Here is a simple PG modifying the content of the ShaderStore that should show a green line:

But I don’t think the line shader is read from the ShaderStore.


Sorry I’m stupid (this release is killing me :))

It works, thanks!

I might have various line objects using different vertex shaders.
The example seem to modify a global VS for lines. Is there a way to handle multiple version of VS for lines? Like having my own custom material for LineMesh the same way that I have for the other Mesh types.

Note: in the VS I need to write, the data defining the positions of the points come from computation on float textures and is animated with time. Different VS adapted to their specific data are required.

I just need to do a normal mesh having a ShaderMaterial with a Line fillMode and fill it with dummy vertices. (or better, subclass the Mesh object and modify its _draw method to avoid having to fill a vertex array with dummy vertices).

That’s correct :slight_smile: good job!!