Example of Normal Mapping

After picking up Codea again after a few months, I finally decided to take a dive into shaders. Getting a crude knowledge after experimenting with the glsl API in yoyogame’s GameMaker and playing with editing the shaders in Codea, I decided it was time I tried something cool: Normal mapping! I know it’s been done before, I just wanted to try it and it seemed like a good way to get into shaders.



The idea of using a high resolution mesh’s normal map on a low resolution for better lighting is a trick that game developers have been using for years to give the impression of an extremely high poly count. The borders of the object (in camera space) still appear low res, but with lighting trickery, everything in between has bumps and curves.

Not wanting to dive completely into 3D yet (although it wouldn’t be too hard) I whipped up this quick example using:

Here is the so desired code


Links for images I used:

Color map :: https://www.dropbox.com/s/wsuddjobx3ozynj/bricks_indented_texture_9181161_COLOR.png

Normal map :: https://www.dropbox.com/s/gi7q3qh35qndsb4/bricks_indented_texture_9181161_NRM.png

Sorry about the lack of comments inside of the code. If you want to know more, use the tutorial linked above.

@1980geeksquad - if you search the forum for normal mapping, you’ll find others have explored it in the past.

But it’s great to have examples like this, thank you. I’m looking forward to going through it =D>

@Ignatz I didn’t really search the forums. I was just excited that I finally got it to work and had to share it. I’ll remove the “possibly new to Codea”

@1980geeksquad - lol, don’t worry. What interests me is how this can be used in practice, and how to create the maps.

I can see how it enables faster drawing by faking details, but I’m wondering if there is any practical use for it in Codea, except for demos.

@Ignatz My roommate wanted me to work it into the 3d flappy bird project that I threw together in GameMaker (http://sandbox.yoyogames.com/games/225432-flap-3d) and it would be cool to try to get it to run in 3d in Codea. I’m not sure how practical it would be on an iPad. Another idea that I had was some sort of 2d top down game with this shader running giving the game a really cool 3d with minimal work.

My old one is here:

It’s fun stuff to play with…