Bumpmaps

Blitz3D Forums/Blitz3D Programming/Bumpmaps

How would one go about making a bumpmap?

http://www.katsbits.com/htm/tutorials/creating_bumpmaps_from_images.htm

Here's a tutorial on creating the bumpmap image from a real photograph or picture of an object.

And..umm....how do I load one into blitz3d and apply it to an object?

You need the DX7TEST.DLL from Tom and a userlib that goes with DX7TEST.DLL. Also, you need a fancy little bumpmap example, like the one below:
Graphics3D 800,600,32,2

;Must let the DLL know a few things about Blitz3D!
d3d=SystemProperty$("Direct3D7")
dev7=SystemProperty$("Direct3DDevice7")
draw7=SystemProperty$("DirectDraw7")
hwnd=SystemProperty$("AppHWND")
instance=SystemProperty$("AppHINSTANCE")
If DX7_SetSystemProperties(d3d,dev7,draw7,hwnd,instance) RuntimeError "Error setting 1 or more System Propertys!"

;Does the hardware support bump mapping, and luminance bump mapping?
If Not DX7_SupportsBumpMapping() Then RuntimeError("No Hardware support for Bump Mapping!")
If Not DX7_SupportsLumiBumpMapping() Then RuntimeError("No Hardware support for Luminance Bump Mapping!")

; Camera.. Light(s).. Action!
cam=CreateCamera()
PositionEntity cam,0,0,-2
CameraRange cam,.01,10
CameraClsColor cam,100,120,200
sphere=CreateSphere(32)
RotateEntity sphere,0,90,0
colorTex = CreateTexture(1,1)
SetBuffer TextureBuffer(colorTex)
c=255
Color 155,120,20
Rect 0,0,1,1,True
SetBuffer BackBuffer()

;Load a bump map. Bump maps for this type of bump mapping are nothing
;more than normal maps. The blue channel/pixels can be used to set the
;Luminance is the bump mode is 0 (see below)
bumpTex = LoadTexture("bumpmap.png",1+256)

;cubemap
envTex=LoadTexture("cubemap\cloudyhills.jpg",1+128+256)

;Set blend mode for cubemap to Add
TextureBlend envTex,3

;Apply the 3 textures
EntityTexture sphere,colorTex,0,0
EntityTexture sphere,bumpTex,0,1
EntityTexture sphere,envTex,0,2

;The bump settings
;If bumpMode = 0, the luminance is taken from the textures Blue channel/pixels
;If bumpMode = 1, luminance is set via lumScale and lumOffset
bumpMode=1
lumScale#=1.5
lumOffset#=0
m00#=1:m10#=-1
m01#=-1:m11#=1

MoveMouse 400,300

fps=0
counter=0
timer=MilliSecs()
While Not KeyDown(1)

	If MouseDown(1) TurnEntity sphere,0,-.05,0

	v#=.001
	If KeyDown(42) v=.0005
	If KeyDown(30) MoveEntity cam,-v,0,0
	If KeyDown(32) MoveEntity cam,v,0,0
	If KeyDown(17) MoveEntity cam,0,0,v
	If KeyDown(31) MoveEntity cam,0,0,-v
	
	RotateEntity cam,(400+MouseY())*.5, -(MouseX()-400)*.5,0
	If KeyHit(57)
		m00=0:m01=0
		m10=0:m11=0
	End If

	s#=.002
	If KeyDown(2)
		m00=m00 - s
		m01=m01 + s
	End If
	
	If KeyDown(3)
		m00=m00 + s
		m01=m01 - s
	End If

	If KeyDown(4)
		m10=m10 - s
		m11=m11 + s
	End If
	
	If KeyDown(5)
		m10=m10 + s
		m11=m11 - s
	End If

	If KeyDown(200) lumScale=lumScale+.001
	If KeyDown(208) lumScale=lumScale-.001
	If KeyDown(205) lumOffset=lumOffset+.001
	If KeyDown(203) lumOffset=lumOffset-.001
	
	DX7_SetBumpInfo m00,m01,m10,m11,lumScale,lumOffset,bumpMode
	;This function forces settings for the next geometry rendered
	;It makes texture layer 1 use bump mapping
	DX7_EnableRenderBumpTexture

	RenderWorld

	;Return texture layer 1 to normal Blitz3D settings
	DX7_DisableRenderBumpTexture


	;Update FPS counter
	counter=counter+1
	If MilliSecs() - timer > 999
		fps=counter
		counter=0
		timer=MilliSecs()
	End If

	Color 0,0,0
	Text 0,0,"FPS: "+fps
	Text 0,12,"w,s,a,d,mouse to move/look, LMB to spin sphere"

	Text 0,40,"1,2 and 3,4 adjust the bump matrix. Cursors adjust scale & offset"
	Text 0,52,"SPACE sets the bump matrix to 0,0,0,0"

	Text 0,64,"m00: "+m00+" , m01: "+m01
	Text 0,76,"m10: "+m10+" , m11: "+m11
	Text 0,88,"scale: "+lumScale
	Text 0,100,"offset: "+lumOffset
	
	Flip 0
	Wend
End


I am getting a 'function not found' at

If DX7_SetSystemProperties(d3d,dev7,draw7,hwnd,instance) RuntimeError "Error setting 1 or more System Propertys!"


and how can I tell if I have dx7test.dll or not, and if not how do I get it.

Bumpmaps are not supported natively in Blitz3d (only DOT3, which is an emboss). If you want to put bumpmaps in your projects, you'll need to add this to Blitz with a DLL function set that permits doing what you ask for.

But to help you start off, get to know "Blitz3D/userlibs" in your Program Files. That is where to put DLLs and DECLS files that are to be used for your project.

I'm sorry, can't help more than this.

EDIT: Also, I forgot to note that this test comes with some media files, it can't be run without them. But it should give you the basis of a bumpmap code, simply.

Cheers.

I think there is also some kind of bumpmapping in native blitz3D, called dot3. There may be some examples on how to use it around here.

The dx7test.dll is part of one of "tomspeed"'s releases
Search your computer for the dll, then this website, then the web :)

Note: I just tried to find his page and I hate to say it, but it seems the site is dieing right now.
THe URL http://www.tomspeed.com/ redirects to the provider and says "Domain expired ... If you are the owner of this domain name you should contact account@... at once."

We should create a fund to pay the bill for his site, Probably that's still possible. He had a lot of nice goodies on his server: bumpmapping, stencil shadows with shadowvolumes and and and.

Or is there a mirror somewhere? Google didn't find anything so far.

Yeh that bill's at the bottom of my list at the moment :)

BumpMapping is hacky because of how RenderWorld() works. Trust me, it hides a lot of brainache from you guys!

The DLL has been a never ending work in progress, It sucks because it creates problems version to version due to changes. I'll try and get a package together soon with something actualy usable.

At the moment I'm toying with homebrew rendering as an alternative to using RenderWorld(), most of the guts of the functions are kept inside B3D so anyone can tweak the code. It means of course you can setup texture layers & vertex buffers however you please.

It's at least as fast as Blitz renders and allows for a lot of tweaking. You can use more or less than 2 sets of UVs, more texture blending modes, automatic texture UV generation (automatic projected textures, useful for shadow mapping), e.t.c.

uuh tom, this sounds great!!!

..whoa..Tom, thats great..hurryyy :)

cool bump Fx _33!
a doubt: Using the Dx7 dll could make my .exe less compatible than a Blitz3D standard executable?

z4g0: It's actually something that Tom wrote that I pasted here. I never personally used any bump FX's yest! LOL! But I tought it was quite appropriate here.