Line Level of Detail?

Hello,
I am having some issues with the detail of lines. I am using the line class, which is essentially a mesh with 2 endpoints and the mode of “lines”. I get this level of detail currently: http://prntscr.com/fppak0. It would be better if these faded more into the distance, but I am unsure of how to do that. I don’t believe that LOD will fix that as there are only 2 vertices, so “removing” vertices doesn’t seem to help. I know the line width is constant, which I am guessing is the source of the problem. Even a 1px line height will create this provided there are enough lines. Is there any way to get around this? I was thinking perhaps a custom fragment shader, but I am not sure how to do that, or if it’s even possible. Thanks!

1 Like
        Line line = new Line(start, end);
        Geometry geo = new Geometry("", line);
        Material material = new Material(Main.getApp().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
        material.setColor("Color", ColorRGBA.Black);
        material.getAdditionalRenderState().setDepthTest(false);
        geo.setMaterial(material);
        geo.setQueueBucket(RenderQueue.Bucket.Transparent);
        node.attachChild(geo);

Here is the code. Nothing special.

1 Like

One way to make the lines “fade” would be to break them into short segments and draw each segment in a different color, depending on how far it is from the camera.

1 Like

Shader based “fog” would work, too… but requires shader hacking. There have been a few forum posts about it, though. It’s not hard to hack into lighting or unshaded.

1 Like

Thanks for these ideas!

2 Likes

If you still want to know a shader approach, or you want a gradual fade out so lines up close aren’t transparent at all (waaay easier with custom shader than messing with verts etc.) I think this would get you started on that…

//Vertex shader
varying vec4 positionProjectionSpace;
...
positionProjectionSpace = gl_Position; //Send to frag shader, declare the same varying

positionProjectionSpace.z = distance

Use a value calculated from that to set a variable value for gl_FragColor.a (alpha).

1 Like

Thank you for the starting blocks. This will help out greatly!

1 Like