• Advertisement
Sign in to follow this  

Rendering glow lines in OpenGL ES 2.0

Recommended Posts

i'd like to have a little control on how the lines will be rendered, ex: texturing it or adding a glow, ive been around the thread also in gamedev.net and they suggested that to have a full control in rendering we will not use the default GL_LINES but instead rendered it as triangles, I cant find any tutorials on how to do this or atleast a sample,

can you guys give me a code snippet on how to do this? what i have right now are points rendered using GL_LINES and pairs of X,Y screen coordinates (ortho/2d projection) from mouse click. example, (0,0) (10,10), (10,10), (20,20), ...

if you guys can point me to any tutorials, code snippets, please do

i want to achieve line like this (drawn using mouse):

https://www.gamedev.net/uploads/monthly_2017_11/S2.png.202e4f4c3d4255fe5ded81438a6e79b7.png

Share this post


Link to post
Share on other sites
Advertisement

When I did this, admittedly a while back, I did something like pass 4 coordinate pairs in per line -- two at each end. I then used the vertex shader to spread them "out" from the line along a vector which is at right angles to the line and the eye vector (passed in as a uniform). That makes a billboard covering the line's projected position. The vertices have texture coords set up to run (0,0) -> (1,1) across the space with one axis running up/down the line and the other "across" it. The pixel shader can then use the proximity to (0.5,whatever) to put the glow in.

It's performant enough to run on mobile devices without too much aggro.

It's not *quite* technically right, because you're supposed to use the vector between the point and the eye (rather than just the direction the eye is pointing) which changes across the FoV, but if the FoV is relatively narrow, no-one notices. It's also a bit unstable if the lines are close to the camera, but... don't do that?

 

For picking the lines, I cheated some more and used a transform feedback array -- the lines fill in their depth if they think their projected points are close enough to the point clicked and the CPU then just scans the array looking for the nearest close result (Grabbing a transform feedback is expensive, but if you're only doing it on clicks it's not too bad.)

You could pass in the XY of the last click and have the vertex shader check the position to see if it's close before deciding whether to add glow & expand out the endpoints.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement