We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is there a way to disable the nice smooth shading in P3D sketches? For example, to look like this:
When making files for 3D printing, I find it's nice to have just flat shading, so you can see all the triangles.
Answers
Post some code.
You can probably get flat shading by defining your own normals for each vertex. But that does mean having to define each triangle individually and not as part of a strip / fan.
Oh, actually, there is a global enable flag in opengl that might be turn-offable. glsmooth?
https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glShadeModel.xml
Um, gl2.1...
First of all you can set flat/smooth shading in you 3D modeling tool and then export it
Yes, koogs is right, you should run some processing exampels, so you get a feeling of it.
https://processing.org/tutorials/pshader/
I created a little scetch, ftw
// output (note this gif is compressed)
Thanks @nabr and @koogs! I didn't include code because it's embedded in a really complex project. I'm using a combination of primitives, the Shapes3D library, and some custom shapes generated with
TRIANGLE_STRIP
.But ideally, this would be something that could be applied like a
hint()
command insetup()
... maybe that's asking for too much :)@nabr's shader works well! But I'd have to change my entire code for applying color to various shapes. I'll file this away for future projects.
(Did some research this topic on processing, their is no answer todate. So i post my some of my discoveries for the benefit of the community)
@jeffthompson Hello
glShadeModel(GL_FLAT) is deprecated since then 10 years, this is how things work befor shaders were introduced.
You can also compute the hole thing on the CPU.
It should (untested) work with Processing Version <= 2.2.1
Pseudocode https://github.com/processing/processing/wiki/Advanced-OpenGL-in-Processing-2.x
Second:
Pseudocode
hahah too complex. :)
And as i already wrote.Its a modern shader approach transpose inverse of Camera/Object View Matrix (MatrixMath is done on the CPU previously). For backward compatibility, use an older version shader, you can find tones of them on the web.
see here: (works on browsers, should work everywhere)
https://github.com/glslify/glsl-face-normal
If you think about the graphicpipeline. Cube, or what ever shape, will create you some Buffers and then everything is send to shaders, in order to change the color, you have to tweek the shader. https://processing.org/tutorials/pshader/
Probably also there is a way to implement flat shading direct into Shapes3D library.
Thanks @nabr, this is super helpful. Filling away to use in future projects. I feel like I need to make an automated project-builder that includes basic settings for camera, lights, and flat shading. Add to the to-do list...