Rendering curves

Hi!
Let’s discuss rendering curves (e.g. Bezier) in Defold. Any ideas?

So far I tried rendering via pixel shader: pass curve control points from vertex shader, use texture coordinate X as input to calculate point on curve and check with texture coordinate Y (with some offset) - if the pixel is on curve or not. Result is not so good :\

2 Likes

It should be the vertex shader, not pixel one.

Hmm, yes maybe I should try collada mesh & vertex shader.
I’m just afraid it will require a lot of polygons to make it smooth.

One of my todo project is nice vector shape rasterization with buffers via native extension. Something like Skia Graphics Library. This would support curves drawn fast with good accuracy, smoothing, and effects. You could investigate drawing curves to buffer with size of window and updating them with native extension code.

1 Like

Is it working in HTML ?

Buffers do work with HTML5 last time I tested. You don’t want to modify the buffers with Lua scripts but with native extensions. I don’t know if there would still be performance issues with HTML5 build even with NE modifying the buffer.

Yes, they work on all platforms.

It should be fairly performant as long as you reuse the buffer and don’t create a new one every frame. I’m manipulating buffers in Imp but that example/asset is recreating the buffer when the image processing is applied.

Any reasons why do you modify buffers in NE instead of vertex shader?

Oh, I see - you just fill buffer with mesh data in NE depending on the curve length, right?

Another way would be to use a sprites + special shader material to do it for you.
It would involve:

  • Calculate the bounding box of the spline segment (example)
  • Position & scale the sprite (gameobject) accordingly
  • Set the shader constants (example)
  • Render the sprites (with a new predicate in the render script)

It’s the same approach I tried ( if I understood you correct)
The sprite (or gui node, e.g. we can send data via color vector) should be square this way to make the line thickness constant.
Also, I have some doubts about performance of long curves.

1 Like

@britzl
Is it possible to modify mesh’s vertex buffer by native extension or any other way? E.g. by generating collada mesh in runtime and applying it to model?

1 Like

This is definitely something we want to add, we have had some experiments with it but nothing deliverable yet. The next step is to do a design with our experiments in mind, but I can’t say when it will be available. :confused:

5 Likes