Normalmaps in miniB3D
BlitzMax Forums/MiniB3D Module/Normalmaps in miniB3D
| ||
![]() I'm not quite sure but I think I've found a very simple and easy to use normalmap solution - I found it while studying Rob's old statue demo and playing around with it in my current pastime project. I have a central star at 0,0,0 and a spaceship with a normalmap/colormap applied to it in this way: Global Model:TMesh=LoadAnimMesh("models/hornet/hornet.b3d") Global dot:TTexture=LoadTexture("models/hornet/normalmap.png") Global col:TTexture=LoadTexture("models/hornet/colormap.png") TextureBlend dot,4 TextureBlend col,5 EntityTexture Model,dot,0,0 EntityTexture Model,col,0,1 EntityFX Model,1 Then in the main loop, I use this little piece of code to recolor the fullbright model to simulate the lighting. It just needs two pivots at the light and ship position which is very easy to use. It only works with the fullbright flag, 1+2 results in a black model, unfortunately. ' model clone Local piv1:TPivot=CreatePivot() PositionEntity piv1,EntityX(model,1),EntityY(model,1),EntityZ(model,1) ' light clone Local piv2:TPivot=CreatePivot() PositionEntity piv2,EntityX(light,1),EntityY(light,1),EntityZ(light,1) Local dist:Float=EntityDistance(piv1,piv2) PointEntity piv1,piv2 RotateEntity piv2,EntityPitch(piv1),EntityYaw(piv1),EntityRoll(piv1) MoveEntity piv2,0,0,1 Local r:Int=(EntityX(piv2)+1.0)*127.5 Local g:Int=(EntityZ(piv2)+1.0)*127.5 EntityColor Model,r,g,Normalize(dist,0,10000,128,128-16) '128 FreeEntity piv1 FreeEntity piv2 Additional, here is my normalize function but 128 for blue is sufficient for the effect, I only simulate a pointlight here that the spaceship receives "less" light according to its distance to the sun: Function Normalize:Float(value:Float=128.0,value_min:Float=0.0,value_max:Float=255.0,norm_min:Float=0.0,norm_max:Float=1.0) ' normalize Local result:Float=((value-value_min)/(value_max-value_min))*(norm_max-norm_min)+norm_min ' limit If value>norm_max Then value=norm_max Else If value<norm_min Then value=norm_min Return result End Function I do not fully understand what happens but it really works as far as I can see from different angles and positions in space: ![]() ![]() ![]() ![]() ![]() ![]() Oh, by the way - the demo is running at stunning 160 FPS with 10000 asteroid quads here on my old 9600M GT and uses my "Planet Creator" routines and the current small fixes miniB3D version (vanilla). It's not finished yet so no download at this time. Last edited 2012 |
| ||
looks great. :) |
| ||
looks great! And, yes, that's pretty much how its done. The trick is just getting the right angle from world space to object tangent space. More info: http://www.3dkingdoms.com/tutorial.htm Your trick works for distant lights, but probably not for point lights close to the object, but it's good enough! |