Fredborgs Dot3 code
Blitz3D Forums/Blitz3D Programming/Fredborgs Dot3 code
| ||
Sorry.... but i didn't find any thread concerning Fredborgs Dot3 Code.... Well i think there should be thread to comment it... so here it is ^^ The downloadlink to Fredborgs Dot3 Code http://home1.stofanet.dk/mfredborg/DotMyBot.zip This is damned good work... it helped me a lot to understand dot3... But i really didn't know what to do with the part of your update-Function that should handle directional lights. There is no bump effect. And i couldn't see what red2, grn2 and blu2 are for... So I changed this directional-light part a bit, so it's more useful for me... i used red2, grn2 and blu2 for this: Function graphics_Dot3_UpdateBumpNormals(mesh) n_surf = CountSurfaces(mesh) For s = 1 To n_surf surf = GetSurface(mesh,s) n_vert = CountVertices(surf)-1 For v = 0 To n_vert red2# = 0.0 grn2# = 0.0 blu2# = 0.0 For d3l.Dot3Light = Each Dot3Light If d3l\typ = 1 ; Directional light TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0 red2# = TFormedX()-EntityX(d3l\ent,True) grn2# = TFormedY()-EntityY(d3l\ent,True) blu2# = TFormedZ()-EntityZ(d3l\ent,True) d2# = Sqr(red2*red2 + grn2*grn2 + blu2*blu2) red2 = red2*d2 grn2 = grn2*d2 blu2 = blu2*d2 TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0 nx# = -TFormedX() ny# = -TFormedY() nz# = -TFormedZ() TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,0 red# = TFormedX()-EntityX(d3l\ent,True) grn# = TFormedY()-EntityY(d3l\ent,True) blu# = TFormedZ()-EntityZ(d3l\ent,True) d# = Sqr(red*red + grn*grn + blu*blu) red = red/d grn = grn/d blu = blu/d ElseIf d3l\typ = 2 ; Point light TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0 nx# = -TFormedX() ny# = -TFormedY() nz# = -TFormedZ() TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,0 red# = TFormedX()-EntityX(d3l\ent,True) grn# = TFormedY()-EntityY(d3l\ent,True) blu# = TFormedZ()-EntityZ(d3l\ent,True) d# = Sqr(red*red + grn*grn + blu*blu) red = red/d grn = grn/d blu = blu/d Else RuntimeError "Lighttype not supported!" End If dot# = (red*nx + grn*ny + blu*nz) If dot<0.0 Then dot = 0.0 red# = ((1.0+(red*dot))*127.5)*d3l\mul grn# = ((1.0+(grn*dot))*127.5)*d3l\mul blu# = ((1.0+(blu*dot))*127.5)*d3l\mul If red<0 Then red = 0 If grn<0 Then grn = 0 If blu<0 Then blu = 0 red2# = red2+red grn2# = grn2+grn blu2# = blu2+blu Next VertexColor surf,v,red2,grn2,blu2 Next Next End Function Well... dunno if this change is really useful... mfg Raitsun |
| ||
Function UpdateBumpNormals(mesh,light,lighttype=0) n_surf = CountSurfaces(mesh) For s = 1 To n_surf surf = GetSurface(mesh,s) n_vert = CountVertices(surf)-1 For v = 0 To n_vert red2# = 0.0 grn2# = 0.0 blu2# = 0.0 For d3l.Dot3Light = Each Dot3Light If d3l\typ = 1 ; Directional light TFormVector 0,0,1,d3l\ent,0 nx# = TFormedX() ny# = TFormedY() nz# = TFormedZ() TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0 red# = TFormedX() grn# = TFormedY() blu# = TFormedZ() ElseIf d3l\typ = 2 ; Point light TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0 nx# = -TFormedX() ny# = -TFormedY() nz# = -TFormedZ() TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,0 red# = TFormedX()-EntityX(d3l\ent,True) grn# = TFormedY()-EntityY(d3l\ent,True) blu# = TFormedZ()-EntityZ(d3l\ent,True) d# = Sqr(red*red + grn*grn + blu*blu) red = red/d grn = grn/d blu = blu/d Else RuntimeError "Do it yourself, will ya?" End If dot# = (red*nx + grn*ny + blu*nz) If dot<0.0 Then dot = 0.0 red# = ((1.0+(red*dot))*127.5)*d3l\mul grn# = ((1.0+(grn*dot))*127.5)*d3l\mul blu# = ((1.0+(blu*dot))*127.5)*d3l\mul If red<0 Then red = 0 If grn<0 Then grn = 0 If blu<0 Then blu = 0 red2# = red2+red grn2# = grn2+grn blu2# = blu2+blu Next VertexColor surf,v,red2,grn2,blu2 Next Next End Function Here is the original Code.... For that you can compare it easier.. |
| ||
The red, green and blue, change the normals of the light direction basically :o) |
| ||
o.O i just found out that my version is crap... It does almost exatly what the point-light part does.... |
| ||
I have now written a completely new Function for applying vertexcolors.... I used Fredborgs code as base so the Function for dot3 light creation and the function for applying lightrange to this lights are still fredborgs... I also used his Type-Field for the lights.. But the important code, the update-function, is completely new... Lightrange is now regarded by the function that applies vertex colors... This code is slower than fredborg's... i still work on getting it faster... As this code could be interesting for somebody i post the functions here: Type Dot3Light Field ent Field rng# End Type Function graphics_Dot3_CreateLight(typ=1,parent=0) d3l.Dot3Light = New Dot3Light d3l\ent = CreateLight(typ,parent) d3l\rng = 1 Return d3l\ent End Function Function graphics_Dot3_LightRange(ent,range#) For d3l.dot3light = Each dot3light If d3l\ent = ent If Lower$(EntityClass(d3l\ent))="light" LightRange d3l\ent,range d3l\rng = range Return End If End If Next End Function Global red# Global green# Global blue# Function graphics_Dot3_UpdateNormalmap(mesh) bumpVec=CreatePivot() surf = GetSurface(mesh, 1) For v=0 To CountVertices(surf)-1 red=0 blue=0 green=0 For d3l.dot3light=Each dot3light vx#=VertexX(surf,v) vy#=VertexY(surf,v) vz#=VertexZ(surf,v) TFormPoint vx,vy,vz,mesh,0 vx=TFormedX() vy=TFormedY() vz=TFormedZ() PositionEntity bumpVec,vx,vy,vz d#=EntityDistance(d3l\ent,bumpVec) PointEntity bumpVec,d3l\ent m#=1+(((d-0.15)*-1)/(d3l\rng-0.15)) If m>1 Then m=1 If m<0 Then m=0 MoveEntity bumpVec,0,0,m red=red+(EntityX(bumpVec)-vx) blue=blue+(EntityY(bumpVec)-vy) green=green+(EntityZ(bumpVec)-vz) Next red2=((red+1)*255)/2 green2=((green-1)*255)/-2 blue2=((blue+1)*255)/2 VertexColor surf,v,red2,green2,blue2 Next End Function @ Ross C: I know... but i wondered what the variables red2, grn2 and blu2 were for in fredborgs original code... they don't actually affect they vertexcolor as they're set to 0.. He could have used "vertexcolor surf, v, red, grn, blu" instead... I'd really like feedbeack ^^ |
| ||
Here is the code in action: after the light was moved a bit: and one shot more: and the scene "wireframe(true)": this is the normal map i used: mfg Raitsun |