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

Match line drawing orientation to primitive face #5906

Merged
merged 1 commit into from
Dec 17, 2022
Merged

Match line drawing orientation to primitive face #5906

merged 1 commit into from
Dec 17, 2022

Conversation

inaridarkfox4231
Copy link
Contributor

Line drawing in p5.js is done by creating a rectangle with both vertices offset slightly in the direction perpendicular to the line.
In doing so, the orientation of the triangles that make it up is the opposite of the orientation of the faces of primitives (sphere, box, and so on).
This orientation can be matched by reversing the direction of the normals used to shift the vertices in the shader.

Resolves #5877

Changes:

here: src/webgl/shaders/line.vert
Reverses the direction of vertices that are displaced when drawing lines.
This ensures that culling the FRONT to draw only the front face does not cause the lines to disappear.

Screenshots of the change:

sampleCode
left: before, right: after

let gl;

function setup(){
  createCanvas(400, 400, WEBGL);
  
  gl = this._renderer.GL;
  gl.enable(gl.CULL_FACE);
  gl.cullFace(gl.FRONT);
  
  background(128);
  fill(255, 128, 0);
  stroke(255);
  strokeWeight(3);
  directionalLight(255, 255, 255, 0, 0, -1);
  ambientLight(128);
  rotateX(TAU/8);
  rotateY(TAU/12);

  box(120);
}

sample0

PR Checklist

  • WebGL

Line drawing in p5.js is done by creating a rectangle with both vertices offset slightly in the direction perpendicular to the line. 
In doing so, the orientation of the triangles that make it up is the opposite of the orientation of the faces of primitives (sphere, box, and so on). 
This orientation can be matched by reversing the direction of the normals used to shift the vertices in the shader.
Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Nice work!

@davepagurek davepagurek merged commit b23a14f into processing:main Dec 17, 2022
@inaridarkfox4231 inaridarkfox4231 deleted the inaridarkfox4231-patch-1 branch December 18, 2022 00:08
@inaridarkfox4231
Copy link
Contributor Author

thanks very much!('ω')

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.

strokes disappear when culling is enabled
2 participants