I have a cube that can be rotated using mouse navigation in PyOpenGL. I want to create small sections on each face of the cube and render the different sections with different colors/illumination. It is like having a certain light source and the cube is considered as a room being illuminated with the light source. How do I set my desired values for each section ? Is it possible to do so ?
2 Answers
Extend your fragment shader to expect some kind of interpolated value (Either just add "face coordinates" to your vertices that goes from 0 to 1 across the face, or by transforming your texture uv coordinates if you have them). Then you can just use if-else inside the fragment shader. i.e.
if (coords.x < 0.5 && coords.y < 0.5) // one quarter of the face
Lightning=...
FragColor=...
else if ...

- 175
- 6
You could use a geometry shader
and some exponential function to distribute the colors in each face. If i undertand correcltly you want something like this:
In this case you will pass the colors you want as vertex attributes for the face you want and in the geometry shader you will compute the distance from each face-vertex to the face's center. Then you will pass that distance to the fragment shader. Passing the distance to the Fshader will interpolate the value for each fragment.