Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Pixel Shader for Drawing 3D Lines

Author
Message
Sun Spire
1
Years of Service
User Offline
Joined: 12th Jan 2023
Location:
Posted: 12th Jan 2023 11:49
Hello!

I decided to share a small shader that is designed to draw 3D lines on the screen. This is an alternative to the standard DrawLine method. Perhaps someone will find it useful.

This can be used to draw paths, or to display the wireframe of an object (if you get the coordinates of all vertices using a memblock).

Any suggestions to optimize or improve the shader code are welcome

Below is a small demo showing the shader in action. Shader files are generated directly from the AppGameKit code for convenience.

Transformation of 3D -> 2D coordinates is carried out in the shader itself. As initial data, we can set the coordinates of 2 points of the 3D line, as well as its color. It is also possible to set the line width in pixels, but I did not output this as an input parameter.

Attachments

Login to view attachments
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 12th Jan 2023 23:00
I suggest using SetObjectDepthReadMode(testob2,7) so that the object always passes the depth test.
And then you use a plane object and make it a fullscreen quad object with your shader, so I suggest using the built in quad object instead since it has fewer indices and only one face.
This way you can just use a fullscreen shader and ignore the vertex shader as it will then be automatically generated by AGK.
It's interesting to use it for wireframes because it doesn't need to be applied to the wireframe object itself but can be easily overlaid.
But I think it would be verry hard to match the the quality of an per object wireframe that way.
Thanks for sharing.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 12th Jan 2023 23:24
You could use GetScreenX/YFrom3D() and then use DrawLine()
Sun Spire
1
Years of Service
User Offline
Joined: 12th Jan 2023
Location:
Posted: 13th Jan 2023 10:28
Thanks Janbo!

Yes, I have already thought about how to display this image in Quad, although I have not worked with full-screen shaders before. I will need to read the help.

Sun Spire
1
Years of Service
User Offline
Joined: 12th Jan 2023
Location:
Posted: 13th Jan 2023 10:34
Thank you blink0k.

In my project (simulation of the CNC Machine) it is required to draw a large number of tool paths (thousands and tens of thousands of elements). Now this is implemented by 3D objects (extruded box). I'm looking for a more optimal and efficient method.

I understand that using this shader will not give the desired result, because for each trajectory, you will have to create your own instance of Quad. Or draw everything in one Quad object, but a very large array will have to be passed to the shader.

So this method, as well as DrawLine(), is not suitable for drawing paths...
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Jan 2023 11:57
And a Wireframe effect would also be pretty performance intensive to do it with a fullscreen shader on dynamic objects let alone on animated ones.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 18th Jan 2023 00:41 Edited at: 18th Jan 2023 00:43
What I fail to understand is why an array can't be passed to the glsl shader.

an array with a glsl shader example


ideally what ide like to see achieved where 2 could be left []
fubarpk
https://fubarpk.itch.io/
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 19th Jan 2023 16:50
Arrays can be passed but not as a struct/type in AppGameKit only everywhere else it works ^^

Login to post a reply

Server time is: 2024-03-03 19:48:58
Your offset time is: 2024-03-03 19:48:58