c++ - objects - opengl tutorial for beginners

OpenGL, How to create a “bumpy Polygon”? (4)

I am unsure of how to describe what I'm after, so I drew a picture to help:

My question, is it possible within OpenGL to create the illusion of those pixel looking bumps on a single polygon, without having to resort to using many polygons? And if it is, what's the method?

I think what you're after is bump mapping. The link goes to a simple tutorial.

I think what your looking for is actually Parallax mapping (Or Parallax Occlusion mapping).


Parralax mapping basically works by using the height map to alter the texture UV coordinate being used.

The main disadvantage to parallax is that anything that appears to be 'outside' the polygon will be clipped (think of looking at an image on a 3D tv), so it's best for things indented in a surface rather than sticking out of it (although you can reduce this by making the polygon lager than the visible texture area). It's also fairly complex and would need to be combined with other shader techniques for a good effect.

Bump mapping works by using a texture for normal's, this makes the light's shading appear to be 3D however it does not change 3D data depending on the position of the viewer only the shading. Bump mapping would also be fairly useless for the OP's sample image since the surface is all the same angle just at different heights, bump mapping relies on the changes in the surfaces angles. You would have to slope the edges like this.

Displacement mapping/tessellation uses a texture to generate more polygons rather than just being 1 polygon.

There's a video comparing all 3 here

EDIT: There is also Relief mapping, which is a similar to parallax. See demo. There's a comparison video too (it's a bit lowquality but relief looks like it gives better depth).

Of the techniques mentioned in other people's answers:

  • Bump mapping is the easiest to achieve, but doesn't do any occlusion.
  • Parallax mapping is probably the most complex to achieve, and doesn't work well in all cases.
  • Displacement mapping requires high-end hardware and drivers, and creates additional geometry.
  • Actually modeling the polygons is always an option.

It really depends on how close you expect the viewer to be and how prominent the bumps are. If you're flying down the Death Star trench, you'll need to model the bumps or use displacement mapping. If you're a few hundred meters up, bumpmapping should suffice.