Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thick Lines and Varying Point Sizes for Programmable Renderer #8019

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

NickHardeman
Copy link
Contributor

@NickHardeman NickHardeman commented Jun 14, 2024

This PR attempts to mimic some of the original line and point drawing functionality allowed by earlier versions of GL for the Programmable GL Renderer pipeline while introducing some simple additional functionality.

Lines

This PR aims to enable varying line width for the following:

  • ofMesh with mode GL_LINES, GL_LINE_STRIP or GL_LINE_LOOP
  • ofPolyline
  • ofPath ( which draws the poly lines and sets the width from the stroke width on the path )
  • ofDrawLine(x,y)

Currently supported attributes:

  • Color per line point
  • Textures (y coord is 0 -> tex height )
  • Global color

The approach for the thick lines involves adding additional points per vertex to a vbo mesh that feeds additional VAO attributes to a shader.

  • Allows for referencing next and previous vertex references
  • Does not require a geometry shader ( not available in all instances or platforms )
  • Renders 4 vertices per source vertex for mitered lines (GL_LINE_STRIP, GL_LINE_LOOP) and 2 vertices for GL_LINES
  • Can set screen space width (pixel width) regardless of distance to camera or world width ( size attenuation )

This PR currently does not intend to do the following

  • Add end caps, round or otherwise
  • Address self intersection

Example Code:

path.setStrokeWidth(mLineWidth);
path.draw();
ofSetLineWidth(mLineWidth);
mesh.setMode(OF_PRIMITIVE_LINES);
mesh.draw();

Points

Points can vary in size based of a newly introduced function ofSetPointSize(pointSize);
Supports

  • Per point color
  • Textures ( single texture for all points )
  • Smoothing via a shader

Example code:

ofSetPointSize(pointSize);
ofEnablePointSprites();
texture.bind();
mesh.drawVertices();
texture.unbind();

Core functionality to the GL Programmable Renderer has been changed and thus requires extensive testing.

TODO:

  • Optimizations
  • Thorough testing
  • Cleaning up and comments
  • Update examples/gl/pointsAsTexturesExample
  • Create lines example ( in examples/graphics since Cairo also supports line width, not sure if it should be in examples/gl).

Fixes #8011

Screenshot 2024-06-13 at 10 53 04 PM

Screenshot 2024-06-15 at 9 16 29 PM

@dimitre
Copy link
Member

dimitre commented Jun 14, 2024

Wowww marvellous work @NickHardeman

@ofTheo
Copy link
Member

ofTheo commented Jun 14, 2024

Yay! Wow, nice work @NickHardeman!

@NickHardeman
Copy link
Contributor Author

This PR will close #8021

…esh when custom shader or material is bound. Simplify texture coords for lines, enable for texture rect.
@NickHardeman
Copy link
Contributor Author

NickHardeman commented Jun 21, 2024

When drawing an ofPolyline and a texture is bound, the tex coords get added so that the first point has texcoord.x == 0.0 and the last point has texcoord.x == texture.width.
The y coord gets set between 0 and texture height based on the side of the line the dynamic points get added ( for poly lines and meshes ).
Should there be a way to control the texture coordinates for an ofPolyline?

See the example via emscripten
https://nickhardeman.com/temp/OFExamples/linesExample/

Screenshot 2024-06-20 at 9 30 26 PM

@NickHardeman
Copy link
Contributor Author

NickHardeman commented Jun 21, 2024

Without changing the vertices of miters, they can look like it does below, here they are clamped, but it doesn't look right with smaller angles between lines. Notice the colored lines.
Screenshot 2024-06-19 at 10 57 33 PM

The idea for sanding down the miters comes from this post by Matt Stobbs. It has been expanded upon to remove the if statement and implement a smooth transition between the miter and the sanded miter.

MiterToSanded mov

@NickHardeman NickHardeman self-assigned this Jun 21, 2024
@NickHardeman NickHardeman marked this pull request as ready for review June 25, 2024 01:11
@NickHardeman
Copy link
Contributor Author

NickHardeman commented Jun 25, 2024

Notice the new example in examples/graphics/linesExample and the updated one here: examples/gl/pointsAsTexturesExample
Some relevant discussions:
#730
#7689
Fixes #3460

@danoli3 danoli3 self-requested a review June 26, 2024 15:32
Copy link
Member

@danoli3 danoli3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, yeah just rebase onto latest master and lets check ci

@NickHardeman
Copy link
Contributor Author

Thank you @danoli3. I can update next week when I am back at a computer 😀

@NickHardeman NickHardeman requested a review from danoli3 July 4, 2024 01:34
@danoli3
Copy link
Member

danoli3 commented Jul 9, 2024

Wicked, we should just take a bunch of snapshots of gl / visual examples first draw frame:

  • pre
  • with changes

@ofTheo
Copy link
Member

ofTheo commented Jul 9, 2024

I'd be good to merge this now - so we can get it in front of people.
Especially as it's fixing something that didn't work before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drawing ofMesh with Vertex Colors is not cleared for next mesh draw without colors
4 participants