https://kotlinlang.org logo
#korge
Title
# korge
s

Sahil Bajaj

05/25/2021, 7:49 AM
We at InVideo have been trying to render 2D Vector graphics with Korge. But I notice that ShapeView renders using Android Canvas to a bitmap and then renders it as a texture. Also, in my understanding, Shape2D apparently has tessellation implemented for Vector Path and so far it's being rasterized in Software... Is there some work done on rendering shapes on GPU (GLES)? If not, is there some potential to us trying it? Are there any major known hurdles or bottlenecks? (considering path computation and tessellation has been taken care of)
d

Deactivated User

05/25/2021, 9:12 AM
Indeed, vector graphics are rasterized as you described. There is no work done for triangulation/tessellation for that matter. KorMA has some work for triangulation but it is distributed as a separate artifact (korma-shape) IIRC, because it includes a Poly2tri port, that has a BSD license and not sure if it is fully compatible with MIT. I wanted at some point implement triangulation myself and provide it as MIT or public domain, but that is on the backlog and no ETA. If computation and tesellation is performed, shouldn't be any bottlenecks regarding to that, you should be able to scale and rotate, or apply any matrix transformation on the gpu as an uniform so it would be cheap. You might have to handle antialiasing yourself, but other than that it should be a plain batch drawing of triangles, and nothing special in terms of performance, the other thing to resolve is filling. There should be shaders for solid color, gradients (linear, circular, etc.) and texturing. That part shouldn't be specially complicated and should happen on the fragment shader
s

Sahil Bajaj

05/25/2021, 9:48 AM
Got it... So, we should be able to try it out.. By mapping the draw commands to gl renderer instead of Android Canvas renderer. And then figure out our own triangulation before we publish the app.
d

Deactivated User

05/25/2021, 9:54 AM
You can try indeed. Your best bet might be to use the batcher available in the rendering context and provide vertices there. Commands might include curves. There are mechanism to handle those. You could try to render a triangle fan, but have in mind that that would only work for context polygons. For non-context you will probably need to tesellate
s

Sahil Bajaj

05/26/2021, 5:13 AM
I'm not sure if I understand all of it.
Could you please share something I can skip through?
d

Deactivated User

05/26/2021, 7:22 AM
Sorry didn't remember the API of Shape2d. It seems that in the end they are a list of points representing straight lines: https://github.com/korlibs/korma/blob/6bb51f736e455fa20f339faba6779f7b130e8ef1/korma/src/commonMain/kotlin/com/soywiz/korma/geom/shape/Shape2d.kt No filling properties or other stuff, and no curves at all. I confused it with the VectorPath API that has curve information, and the Shape API that has information about curves, filling and stroke methods.
s

Sahil Bajaj

05/26/2021, 6:30 PM
yeah... So hopefully it should not cause a lot of problems (atleast for static content). Let's see. Thanks for for all the info. Will keep you posted.
👍 1
So, I did try it. And it sort of works...
🆒 1
Copy code
override fun renderInternal(ctx: RenderContext) {
        val currentPath = animatePath(frac)

        val shape = currentPath.path.strokeToFill(strokeThickness, outFill = VectorPath(winding = Winding.NON_ZERO))
        val trias = shape.triangulateFlat()
        readToDraw(trias)
        super.renderInternal(ctx)
}
Basically, this would still be incomplete coz I want to be able to do complex polygons as well. I'm trying to find some well engineered library or code reference for that.
d

Deactivated User

06/18/2021, 1:33 AM
I have included a triangulator in korge-next, and now you can draw vectors triangulating them. The only limitation right now is that only support flat colors (no gradients, or bitmap fills for now)
s

Sahil Bajaj

06/23/2021, 1:05 PM
Oh nice.. Checking.
hey Carlos, I think it doesn't work with when the resulting polygon is complex yet. Right?
d

Deactivated User

06/24/2021, 11:17 AM
It should. It uses the clipper library to simplify the polygons, then use the poly2tri. If not let me know your vector so we can figure out what's going on.
s

Sahil Bajaj

06/24/2021, 11:25 AM
...
Copy code
pts.add(IPoint(100.0, 100.0))
pts.add(IPoint(100.0, 400.0))
pts.add(IPoint(200.0, 150.0))
pts.add(IPoint(300.0, 400.0))
pts.add(IPoint(300.0, 100.0))
this (Simple) works
Copy code
pts.add(IPoint(100.0, 100.0))
pts.add(IPoint(100.0, 400.0))
pts.add(IPoint(200.0, 0.0))
pts.add(IPoint(300.0, 400.0))
pts.add(IPoint(300.0, 100.0))
this (complex) doesn't
the only change is the 3rd point's y coord. 150.0 (in 1st) and (0 in 2nd)
d

Deactivated User

06/24/2021, 12:47 PM
And how are you drawing it? Are you using korge-next?
s

Sahil Bajaj

06/24/2021, 12:48 PM
nope.. I just copied your latest source of kds and korma. built them.. published them locally and using it in my project
I'm rendering these using the batcher
BatchBuilder2D
d

Deactivated User

06/24/2021, 12:50 PM
Copy code
renderableView {
    ctx2d.path(buildPath {
        moveTo(100.0, 100.0)
        lineTo(100.0, 400.0)
        lineTo(200.0, 0.0)
        lineTo(300.0, 400.0)
        lineTo(300.0, 100.0)
        close()
    })
}
seems to produce this exception: com.soywiz.korma.triangle.poly2tri.Poly2Tri$PointError: poly2tri EdgeEvent: Collinear not supported! [(175, 100), (175, 100), (100, 100)]
can you create an issue at github?
s

Sahil Bajaj

06/24/2021, 12:50 PM
yup
exactly
cool.... I'll do that.
d

Deactivated User

06/24/2021, 12:50 PM
ty
s

Sahil Bajaj

06/24/2021, 12:50 PM
Thanks for the prompt response
d

Deactivated User

06/24/2021, 12:51 PM
np
29 Views