multiple lights for dot3?
Blitz3D Forums/Blitz3D Programming/multiple lights for dot3?
| ||
The last weeks i was dealing with dot3 code. I've seen Fredborgs demo and a demo of a guy who's name i forgot. It demonstrates Bumpmapping on a floor plane with three lights... i think the ones who saw it, too, know what i mean... I just didn't know how to get halos code, it seems to be lost or something. well... All the demos i've seen had some important features left out, some of them didn't allow more than one dot3-light, some didn't regard the lights direction, some didn't regard the normalmapped mesh's direction and some ignored the lights range in their caclulations. Yesterday i coded an own method from scratch... I tried to regard most of the features. It works pretty well in most situations. Only thing is i didn't get multiple lights to add to each other. It's always the last light only, that's regarded. Here's the code: Global redd#, greend#, blued# Global bumpvec = CreatePivot() Type bumpmesh Field mesh ;bumpmapped mesh's handle End Type Type d3light Field light ;dot3 light's handle Field rng# ;dot3 light's range End Type Function graphics_Dot3_Normalupdate() For bm.bumpmesh = Each bumpmesh redd = 0 greend= 0 blued =0 For n = 1 To CountSurfaces(bm\mesh) surf = GetSurface(bm\mesh,n) For v = 0 To CountVertices(surf)-1 For d.d3light= Each d3light TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),bm\mesh,0 x# = TFormedX() - EntityX(d\light) y# = TFormedY() - EntityY(d\light) z# = TFormedZ() - EntityZ(d\light) TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),bm\mesh,0 dist# = Sqr(x*x+y*y+z*z) Intens# = 1.0 - (dist/(d\rng*8)) If intens < 0 Then intens = 0 PositionEntity bumpvec,TFormedX(),TFormedY(),TFormedZ(),1 AlignToVector bumpvec,TFormedX(),TFormedY(),TFormedZ(),3,1 RotateEntity bumpvec,EntityPitch(bumpvec,1),EntityYaw(bumpvec,1),0,1 TFormNormal x,y,z,0,bumpvec redd = redd+(1.0-TFormedX())*127 greend = greend+(1.0-TFormedY())*127 blued = blued+((1.0-TFormedZ())*127)*Intens Next Next VertexColor surf,v,redd,greend,blued Next Next End Function Raitsun |
| ||
How about a complete demo to show how well it works? |
| ||
That's how i got it right now.... but i need help with using multiple lights...Graphics3D 1024, 768, 32, 1 SetBuffer BackBuffer() Global bumpvec = CreatePivot() Global redd#, greend#, blued# AmbientLight 0,0,0 a# = 1.0 ;------------ Initialise dot3-types ---------------------- Type bumpmesh Field mesh ;bumpmapped mesh's handle End Type Type d3light Field light ;dot3 light's handle Field rng# ;dot3 light's range End Type ;------------------------------------------------------------ ;---------- Setting up the light ---------------------- pivot = CreatePivot() light = graphics_Dot3_CreateBumpLight(10, pivot) ;lightx = CreateSphere(8, light) ;EntityFX lightx, 1 ;ScaleEntity lightx, 0.1, 0.1, 0.1 ;EntityColor lightx, 255,255,255 MoveEntity light, 0, 0, -6 ;------ creating the mesh and apply normal map --------------------- mesh = CreateCube() ScaleEntity mesh, 2, 2, 2 graphics_dot3_applybumpmesh(mesh, "boden_diffuse.jpg", "boden.jpg") UpdateNormals mesh ;--------- create a camera -------------------------------- camera = CreateCamera() PositionEntity camera,0,0,-9.0 CameraRange camera,0.1,110 CameraClsColor camera,0,0,0 ;--------- Main loop ----------------------------------------- While Not KeyHit(1) ;FPS tt=MilliSecs() fps#=1000/(tt-ttold) ttold=tt ;turn the mesh with cursor-keys If KeyDown(200) TurnEntity mesh, 70/fps,0,0 If KeyDown(208) TurnEntity mesh,-70/fps,0,0 If KeyDown(205) TurnEntity mesh,0,-70/fps,0 If KeyDown(203) TurnEntity mesh,0, 70/fps,0 ;move the light while space is pressed If KeyDown(57) Then a = a + 1 If a = 360.0 Then a = 0 PositionEntity light,Cos(a)*5,Sin(a)*5,-9 EndIf ;Updates graphics_dot3_Normalupdate() UpdateWorld() RenderWorld() Text 10,10,"FPS: "+Int(fps#) Flip Wend ;---------------- Functions ------------------------------------- Function graphics_Dot3_CreateBumpLight(range#, parent) ;create a light regarded by the dot3-system d.d3light = New d3light d\light = CreatePivot(parent) d\rng = range Return d\light End Function Function graphics_Dot3_ApplyBumpMesh(mesh, diffuse$, bump$) ;apply a mesh to be a normal mapped mesh (diffusemap = colormap without shades) bm.bumpmesh = New bumpmesh difftex = LoadTexture(diffuse, 1+256) bumptex = LoadTexture(bump, 1+256) bm\mesh = mesh TextureBlend bumptex, 4 EntityTexture mesh, bumptex, 0, 0 EntityTexture mesh, difftex, 0, 1 EntityFX mesh, 3 End Function Function graphics_dot3_Normalupdate() For bm.bumpmesh = Each bumpmesh For d.d3light= Each d3light For n = 1 To CountSurfaces(bm\mesh) surf = GetSurface(bm\mesh,n) For v = 0 To CountVertices(surf)-1 TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),bm\mesh,0 x# = TFormedX() - EntityX(d\light) y# = TFormedY() - EntityY(d\light) z# = TFormedZ() - EntityZ(d\light) TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),bm\mesh,0 dist# = Sqr(x*x+y*y+z*z) Intens# = 1.0 - (dist/(d\rng*8)) If intens < 0 Then intens = 0 PositionEntity bumpvec,TFormedX(),TFormedY(),TFormedZ(),1 AlignToVector bumpvec,TFormedX(),TFormedY(),TFormedZ(),3,1 RotateEntity bumpvec,EntityPitch(bumpvec,1),EntityYaw(bumpvec,1),0,1 TFormNormal x,y,z,0,bumpvec redd = (1.0-TFormedX())*127 greend = (1.0-TFormedY())*127 blued = ((1.0-TFormedZ())*127)*Intens VertexColor surf,v,redd,greend,blued Next Next Next Next End Function You'll need this pics: boden.jpg: boden_diffuse.jpg: (b.t.w.: boden is the german word for floor) Raitsun (These Pictures are from Ben Cloward Homepage: http://www.monitorstudios.com/bcloward/index.html) |
| ||
I modify before Fredborgs demo and I run around with 20 different lights at same time..and working well.. |