Quick and Dirty Bumpmapping?

BlitzMax Forums/BlitzMax Programming/Quick and Dirty Bumpmapping?

zoqfotpik(Posted 2014) [#1]
Does anybody know of a hack to do fast bumpmapping in software? Seems like there was one, wasn't there?

By that I mean a 2D surface with lights over the top of it.

Can you bake a tile with 8 lighting angles and then alphablend between them?


ImaginaryHuman(Posted 2014) [#2]
You can just think of it as a displacement of texture coordinates. If you put the `light` into a texture ie an image of the light, then at each pixel of the background tiles etc have an `offset` value for x and y, which simply displaces the coordinates that you lookup in the light texture to copy pixel values from. ie WritePixel(tile,x,y,ReadPixel(light,xoffset,yoffset)) .... after having also read the xoffset and yoffset from your `displacement map`.

Of course you have to `precalculate` the values for the diplacement by basically emulating the bouncing of light direction, e.g. angle of surface as it strikes a parallel plane, but then you can encode the results of that in your displacement map for quick lookup.

I made a whole asset tool for Unity based on this simple method, albeit that the displacement happens in a shader.

https://www.assetstore.unity3d.com/en/#!/content/9854

You could alternatively use a normal-map generator software and then just use the output from that to displace your light texture.


zoqfotpik(Posted 2014) [#3]
What sort of texture would you use for a light, a circle faded off in the alpha?


BlitzSupport(Posted 2014) [#4]
Have a look at this (and read the thread):

http://www.blitzbasic.com/codearcs/codearcs.php?code=1425

The image referenced can be found here:

https://web.archive.org/web/20061128034523/http://www.oat.ee/andres/projects/tenok.gif

No idea how well it works (and you'll probably have to figure out what values to feed in as bumpmap), though if Filax was impressed it must have been alright!


zoqfotpik(Posted 2014) [#5]
Awesome.

At the tail end of 2d we have to take glitz where we can get it. I figure if this isn't fast enough I will use it to bake a bunch of light angles for floor tiles and perhaps blend between them. I'm using 24x24 sprites and with a 2048x2048 sprite sheet that yields well over 8000 sprites so I should be able to do good things with baking. Cheers!