This project is an introduction to tesselation shaders for me. In this project I have implemented pn-triangles subdivision algorithm and and bezier surfaces using OpenGL's tesselation shaders. I have also wrote a very simple set of fur rendering shaders.
Required libraries to build:
- glfw3
- glew
- glm
- OpenGL 4.6
Just clone the repository to a directory and run
make
and it will compiled and ready to run.
If you want to run the program in deafult mode which is pn-triangles mode you can just type
./main
or if you want to change the rendered object to another object should execute the command
./main --pn <.obj filename>
example
./main --pn bunny.obj
if you fail to provide the filename correctly program will report this and ignore the given filename and render the bunny.obj file. I have provided following .obj models
bunny.obj
teapot.obj
suzanne.obj
armadillo.obj
but you can give other .obj files as well but they have to have vertex normals and their vertex id and vertex normal id must match. The program will render the objects far and start with view dependant tesselation enabled from eye so that the user can see how moving towards/away from the object or zooming in or out affects tesselation. To disable view dependant tesselation or use other keybinds see keybinds
Program can be invoked in bezier patch mode this mode will render a Utah teapot modelled by bezier patches this is provided to compare it with pn triangles. Since it has it's limitations it was needed. I have mentioned those limitations in my blog post about this project Tesselation Shaders
To run the program in bezier teapot mode execute the program with following arguments
./main --bezier
For now this mode only renders one objects which is the Utah teapot but it can be easily extended to render other objects.
Or if you want to see 4 different objects at the same time you can run
./main --pn-all
which will render all 4 objects att the same time so that you can compare how pn-triangles work on different meshes.
You can also run the program in split screen mode with the following line for comparing two tesselation models(pn-triangles and bezier approximation) again it is only avaliable for Utah teapot.
./main --teapot-cmp
Teapot generated by PN triangles will be rendered on the left and the bezier approximated model will be on the right side of the screen like the screenshot below. (Bezier approximated looks worse on this screenshot but if you read the blogpost or increase the level of detail by using keybindings I have provided you will see that it can achieve much more smoother surfaces and much nicer shading results.).
The program is also able to render fur. To enable/disable fur rendering on the object press the key G and you will get fluffy results.
You can also change fur settings with keybinds. To see the full controls keybinds
If you want you can even give color to furs. The good part about it is, furs are colored by the good old perlin noise so we have interesting, maybe even psychedelic, looking bunnies.
Firstly you can change the gaze direction by moving the mouse around while holding the right mouse button and use the mouse scroll for zooming in or out. You can also use the Z and X keys for zooming out or in perpectively.
Full controls are explained below.
-
General Controls
- To exit press ESCAPE
- To toggle enable/disable view dependant tesselation press 1
- To toggle wireframe mode press 2
- To toggle backface culling press 3
-
Camera Controls
- To zoom out/in press/hold Z and X keys or mouse scroll
- To change the gaze direction Move the mouse around while holding right mouse button
- To move the camera along the up vector direction up and down press E/Q respectively
- To move the camera along right vector press D or press A to move left
- To add the camera along the positive gaze direction press W for negative direction press S
- notice that the keys above move the camera slightly and stops when you stop pressing them but W/S keys changes camera speed so in order to stop the camera you have to add equal amount of speed in the opposite direction or you can just press C and camera speed will be set to 0
- To stop the camera press C (sets the camera speed to 0)
-
Level of detail controls
- To toggle enable/disable view dependant tesselation press 1
- To decrease/increase the overall level of detail use keys O/P respectively
- To only decrease/increase only outer level of tesselation use R/T
- To only decrease/increase only inner level of tesselation use Y/U
note: general level of detail is a multiplier that is applied to all tesselated objects
- Fur Controls
- To enable/disable furs toggle G
- To enable/disable perlin noise on fur's color press 0
- To decrease/increase turbulance value of perlin noise press 8/9
- To decrease/increase fur length use K/L
- To decrease/increase number of hairs per triangle press H/J
- To decrease/increase level of detail on only furs press V/B
- To decrease/increase the curvature of the furs press N/M