Bumpmapping

Übersicht BlitzBasic Blitz3D

Neue Antwort erstellen

ChrisAttack

Betreff: Bumpmapping

BeitragSa, Mai 08, 2004 11:45
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo.

wie funktioniert bumpmapping und wie lässt es sich in blitzbasic umsetzen?
B3D
MSVC++
DX9SDK
 

YellowRider2

Gast

BeitragSa, Mai 08, 2004 13:13
Antworten mit Zitat
Auf http://www.3dconcept.ch/artikel/bump/ und auf http://www.tecchannel.de/hardware/425/5.html gibt es ein paar Infos zu BumbMapping.

Wild-Storm

BeitragSa, Mai 08, 2004 13:20
Antworten mit Zitat
Benutzer-Profile anzeigen
also bumpmapping wird in b3d nicht direkt unterstützt, da b3d keine shader hat/benutzen kann (b3d arbeitet ja auf dx7 basis und shader werden erst ab 8.1 richtig eingesetzt, glaub ich)
aber jetzt haben so schlaue köpfe natürlich bumpmapping auch in b3d umgesetzt, leider hab ich keinen link aber nen code (allerdings ohne modelle etc.)

ich hab ihn selber noch nich gscheid ausprobiert, kann also sein das bugs drinne sind

Code: [AUSKLAPPEN]


Type Dot3Light
   Field ent
   Field mul#
   Field typ
End Type

Graphics3D 800,600,32,2
WireFrame 0
cube=CreateCube()
ScaleEntity cube,5,.1,5
PositionEntity cube,0,-1,0
EntityColor cube,255,0,0

bump=LoadTexture( "normal.png",1)
MeshEntity=LoadMesh("mesh.b3d")
decl = CreateTexture(128,128)

;MeshEntity=CreateSphere(16)
;ScaleEntity Meshentity,.7,.7,.7
;ScaleTexture decl,.1,.1
;ScaleTexture bump,.1,.1

PositionEntity MeshEntity,0,0,1
ScaleEntity meshentity,0.0005,0.0005,0.0005
EntityFX MeshEntity,1+2
TextureBlend bump,4
EntityTexture MeshEntity,bump,0,0
Global piv=CreatePivot()

pivvy=CreatePivot()
light = Dot3_CreateLight(2,piv,1.0,1)
lighticon = CreateSphere(8,light)
EntityFX lighticon,1
ScaleEntity lighticon,0.01,0.01,0.01
Dot3_LightRange light,10

camera=CreateCamera()
CameraClsColor camera,100,120,130
PositionEntity camera,0,.2,-1.0

EntityParent camera,piv,1
EntityParent MeshEntity,piv,1

CameraRange camera,0.1,100

AmbientLight 100,100,100

declon = True
bumpon = True
doAnim=1
wire=1

While Not KeyHit(1)
   For d3l.dot3light = Each dot3light
      PositionEntity d3l\ent,Float((MouseX()-400))/200,-Float((MouseY()-300))/200,0,0
   Next
   
   If KeyHit(17)
      wire=Not wire
      WireFrame wire
   End If
   
   If KeyHit(57) doAnim=Not doAnim
   If KeyHit(2)
      If declon
         TextureBlend decl,0
      Else
         TextureBlend decl,2
      End If
      declon = Not declon
   End If
   If KeyHit(3)
      If bumpon
         TextureBlend bump,0
         EntityFX MeshEntity,0
      Else
         TextureBlend bump,4
         EntityFX MeshEntity,1+2
      End If
      bumpon = Not bumpon
   End If

   If KeyDown(4) TurnEntity MeshEntity,0,-1,0
   If KeyDown(5) TurnEntity MeshEntity,0,1,0
      
   If KeyDown(200) TurnEntity piv, 1,0,0
   If KeyDown(208) TurnEntity piv,-1,0,0
   
   If KeyDown(205) TurnEntity piv,0,-5,0
   If KeyDown(203) TurnEntity piv,0, 5,0
   
   If KeyDown(30) MoveEntity camera,0,0,0.05
   If KeyDown(44) MoveEntity camera,0,0,-0.05
   
   processtime=MilliSecs()
   If bumpon
      UpdateBumpNormals(MeshEntity,light,1)
   End If
   processtime=MilliSecs() - processtime
   
   UpdateWorld
   RenderWorld
   declstr$="OFF"
   If declon declstr$="ON "
   
   bumpstr$="OFF"
   If bumpon bumpstr$="ON "
      
   Text 10,20,"Process Time: "+processtime+"ms"
   Text GraphicsWidth()/2,0,"1 - Toggle Texture: "+declstr$+"   2 - Toggle Bumpmap: "+bumpstr$,True,False
   Text GraphicsWidth()/2,14,"A & Z to zoom in/out",True
   Text GraphicsWidth()/2,28,"3,4 Spins Sphere localy, cursors turns entire world except Cube ground",True
   
   Flip
Wend


Function UpdateBumpNormals(mesh,light,lighttype=0)
   EP=GetParent(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
         grn2# = 0
         blu2# = 0
         For d3l.Dot3Light = Each Dot3Light
            lx#=EntityX(d3l\ent,True)
            ly#=EntityY(d3l\ent,True)
            lz#=EntityZ(d3l\ent,True)
   
            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      
               ; Vertex Normal in World coordinates
               TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0
               Vnx# = TFormedX()
               Vny# = TFormedY()
               Vnz# = TFormedZ()
               
               ; Vertex > Light Vector in World coordinates
               TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,0
               Lvx# = lx - TFormedX()
               Lvy# = ly - TFormedY()
               Lvz# = lz - TFormedZ()

               
               ; Normalize Vertex > Light Vector
               d# = Sqr(Lvx*Lvx + Lvy*Lvy + Lvz*Lvz)
               Lvx   =   Lvx / d
               Lvy = Lvy / d
               Lvz = Lvz / d
            End If

            ; Theta Angle between Vertex Normal & Vertex>Light Normal
            dot# = (Lvx*Vnx + Lvy*Vny + Lvz*Vnz)

            ; Clamp Colors to 0
            If dot<0.0 Then dot# = 0
            
            ; If the Mesh had a Parent, Convert Light Vector into that Parents Local coordinates
            ; unsure if this'll work with multiple hierarchy
            If EP
               TFormNormal Lvx,Lvy,Lvz,0,EP
               Lvx# = TFormedX()
               Lvy# = TFormedY()
               Lvz# = TFormedZ()
            End If
            
            red# = ( (1.0+(  Lvx * dot)) * 127) * d3l\mul
            grn# = ( (1.0+(  Lvy * dot)) * 127) * d3l\mul
            blu# = ( (1.0+( -Lvz * dot)) * 127) * d3l\mul
            
            red2# = red2+red
            grn2# = grn2+grn
            blu2# = blu2+blu
         Next
         VertexColor surf,v,red2,grn2,blu2
      Next
   Next
End Function





Function Dot3_CreateLight(typ=1,parent=0,mul#=1.0,real=True)
   
   d3l.Dot3Light = New Dot3Light
   
   If real
      d3l\ent = CreateLight(typ,parent)
      LightRange d3l\ent,50
   Else
      d3l\ent = CreatePivot(parent)
   End If
   PositionEntity d3l\ent,.4,.5,-2


   d3l\typ = typ
   d3l\mul = mul
   
   Return d3l\ent

End Function

Function Dot3_LightRange(ent,range#)
   For d3l.dot3light = Each dot3light
      If d3l\ent = ent
         If Lower$(EntityClass(d3l\ent))="light"
            LightRange d3l\ent,range
            Return
         End If
      End If
   Next
   
End Function

Function Dot3_LightIntensity(ent,intens#)
   For d3l.dot3light = Each dot3light
      If d3l\ent = ent
         d3l\mul = intens
         If Lower$(EntityClass(d3l\ent))="light"
            LightColor d3l\ent,d3l\mul*255.0,d3l\mul*255.0,d3l\mul*255.0
         End If         
         Return
      End If
   Next
End Function


End
Visit http://www.next-dimension.org
-------------------------------------------------
Freeware Modelle, Texturen & Sounds:
http://www.blitzforum.de/forum...hp?t=12875

Neue Antwort erstellen


Übersicht BlitzBasic Blitz3D

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group