Time for action—implementing a cartoon cow
The cartoon shading is a simple non-photorealistic effect which changes abruptly between tones. To archive a cartoon shader, we only have to transform the vertex to built-in gl_Position
variables in the vertex shader, and then calculate and select a tone by using the normal and light direction in the fragment shader. After that, we may apply it to a loaded model, for instance, a pretty cow.
- Include the necessary headers:
#include <osg/Program> #include <osgDB/ReadFile> #include <osgViewer/Viewer>
- We'd like to write the vertex shader source using strings. It passes a normal varying variable to the fragment shader, besides setting the
gl_Position:
static const char* vertSource = { "varying vec3 normal;\n" ...
Get OpenSceneGraph 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.