Robs Normal Mapping Statue code and demo?

Blitz3D Forums/Blitz3D Programming/Robs Normal Mapping Statue code and demo?

IPete2(Posted 2008) [#1]
Can anyone please make this available for me to download?

[EDIT] I have spent most of the afternoon looking for normal mapping demos, but actually Bump Mapping demos would be more what I need on reflection, as I don't want to have to create high poly meshes.

Thanks if that's possible. If not anyone got anything similar? I want to try out normal mapping and that was the best example - which worked - that I ever saw.

I just want to give objects in a scene I'm developing some additional detail and I think this is the best way forwards.

I need to create the objects in 3DS Max then export via B3D Pipeline and... I have no idea.. pls help?

Thanks again.

IPete2.


Dreamora(Posted 2008) [#2]
you mean fredboards ... as long as you look for robs you won't find much ...
At least if you are talking of the normal mapped Arianna statue.

What I would suggest having a look at is the BSM renderer.
Allows normalmap with dynamic lights using a cubemap above it instead of altering the vertex color. this allows you to have brighter and darker meshes + normalmap and it works on animated models as well which normally is impossible


markcw(Posted 2008) [#3]
Hosted here as normaldemo.zip.

http://www.blitzmax.com/logs/userlog.php?user=8652&log=1737


IPete2(Posted 2008) [#4]
Dreamora,

I am begining to realise that what I really need is bump mapping, just additional noise on a surface to give it some detail, instead of flat textured stuff. Robs demo is ace, but I dont want to have to build a large polygon version to get the normal map, not for rocks and metal fragments anyway.

@markcw, many thanks for that -

So in addition had anyone got a bump map demo with source please?

IPete2.


Ross C(Posted 2008) [#5]
I'll get you one when i get home man.


IPete2(Posted 2008) [#6]
Ross - you are a real gent thanks,

Im taking my PC home tonight so I shall keep an eye out. What I am looking to do is add some noise or surface detail to rocks, metal fragments, and effectively crystals. SO I don't want to have to build very high poly versions to do that.

Thanks for any help.

IPete2.


Ross C(Posted 2008) [#7]
Do you need a movable light source?


Naughty Alien(Posted 2008) [#8]
is it based on any external lib, or you require pure b3d code?


IPete2(Posted 2008) [#9]
The objects will rotate in screen, I guess that means a movable source?

I don't mind as long as its all stable code. The simpler to use the better thanks.

IPete2.


Naughty Alien(Posted 2008) [#10]
try this..

Function ApplyBumpMap( Mesh, SearchTexture$, BumpMap, Frame=0, LightMapped=1 )
;this function changes the texture on a mesh so you can apply a bump/normal map
Local SurfS=CountSurfaces( Mesh )
Local SurfI=0
Local BlankBrush = CreateTexture( 64, 64 )
Local t0, t1, t2, t3

SetBuffer TextureBuffer( BlankBrush )
ClsColor 255, 255, 255
Cls
ClsColor 0, 0, 0
SetBuffer BackBuffer()

For SurfI=1 To Surfs
s=GetSurface( Mesh, SurfI )
b=GetSurfaceBrush(s)
t0=GetBrushTexture( b, 0 )
t1=GetBrushTexture( b, 1 )
t2=GetBrushTexture( b, 2 )

If Upper$( StripPath$( TextureName$( t0 ) ) ) = Upper$( SearchTexture$ )
BrushTexture b, BumpMap, Frame, 0
BrushTexture b, t0, Frame, 2

;lightmap is always on channel (index) 1
If LightMapped=0
BrushTexture b, BlankBrush, 0, 1
Else
BrushTexture b, t1, 0, 1
EndIf

PaintSurface s, b
EndIf

If t0<>0
FreeTexture t0
EndIf
Next

FreeTexture BlankBrush
End Function

Function StripPath$(file$)
;borrowed from Blitz Help file
If Len(file$)>0
For i=Len(file$) To 1 Step -1
mi$=Mid$(file$,i,1)
If mi$="\" Or mi$="/" Then Return name$ Else name$=mi$+name$
Next
EndIf

Return name$
End Function


Ross C(Posted 2008) [#11]
did NA's solution work for you?


IPete2(Posted 2008) [#12]
Hiya Ross and Naughty Alien,

Short answer is no, but it may be because I don't have a proper bump map from my 3d guy yet, or that I didn't use it right.

What is the BumpMap parameter in the function call for?

I tried a few variations, but I didnt see anything happen.

IPete2.


BlitzSupport(Posted 2008) [#13]
Found this on my hard drive, but I don't know who wrote it (apologies to whoever did). The filename in the code below is a link to the image... didn't expect that to work!

Graphics3D 640,480,0,2

bump=LoadTexture( "mynormal.jpg",1+8 )
cube=CreateSphere(16)
EntityFX cube,1+2
TextureBlend bump,4
EntityTexture cube,bump,0,0

light = CreateLight(2)
lighticon = CreateSphere(8,light)
EntityFX lighticon,1
ScaleEntity lighticon,0.1,0.1,0.1

camera=CreateCamera()
CameraClsColor camera,128,128,128
PositionEntity camera,0,0,-4.0

a# = 180.0

While Not KeyHit(1)

	a = a + 1
	If a = 360.0 Then a = 0
	PositionEntity light,Cos(a)*4,Sin(a*2)*1,Sin(a)*4
	
	If KeyDown(200) TurnEntity cube, 1,0,0
	If KeyDown(208) TurnEntity cube,-1,0,0
	
	If KeyDown(205) TurnEntity cube,0,-1,0
	If KeyDown(203) TurnEntity cube,0, 1,0
	
	If KeyDown(30) TranslateEntity camera,0,0,0.01
	If KeyDown(44) TranslateEntity camera,0,0,-0.01
	
	UpdateBumpNormals(cube,light)
		
	UpdateWorld
	RenderWorld
	Flip
Wend

Function UpdateBumpNormals(mesh,light)

	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
			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# = EntityX(light,True)-TFormedX()
			grn# = EntityY(light,True)-TFormedY()
			blu# = EntityZ(light,True)-TFormedZ()
			d# = Sqr(red*red + grn*grn + blu*blu)
			red = (red/d)
			grn = (grn/d)
			blu = (blu/d)
			dot# = red*nx + grn*ny + blu*nz
			If dot>0.0
				red = (1.0+(red*dot))*127.5
				grn = (1.0+(grn*dot))*127.5
				blu = (1.0+(blu*dot))*127.5			
				VertexColor surf,v,red,grn,blu
			Else
				VertexColor surf,v,127.5,127.5,127.5
			End If
		Next
	Next

End Function

End



Naughty Alien(Posted 2008) [#14]
BumpMap is your loaded normalmap you want to apply man..its working great here...


John Blackledge(Posted 2008) [#15]
Nice demo.
So how are normal maps produced?


Naughty Alien(Posted 2008) [#16]
use CrazyBump..you will love it..thing simply rocks

http://www.crazybump.com/


IPete2(Posted 2008) [#17]
Naughty,

Ah maybe thats why it does not work here, I dont have a normal map. I shall download crazybump and try it - many thanks.

[edit okay now that seem to work. I shall get the 3D artist to look it over next week and start using this technique where appropriate. Thanks guys! ]

IPete2.


John Blackledge(Posted 2008) [#18]
What! $299 - I don't think so.

Any others?


Naughty Alien(Posted 2008) [#19]
..sure, here is excellent one from ATI and free too..my suggestion is, dont us nVidia normalmap plug in for Photoshop..instead, use this one and you'll be happy

http://ati.amd.com/developer/sdk/radeonSDK/html/Tools/ToolsPlugIns.html

or this one for MAC lovers

http://homepage.mac.com/nilomarabese/Menu13.html


Ross C(Posted 2008) [#20]
To explain in a little more depth, changing the light direction of a normal map, involves you changing, either:

The entitycolor, or,
The vertex colors, or,
The texture blending with the normal map.

Alot of examples use the textureblending, as they can use a cubemap, with colour normal information stored on it. Basically, as the model moves/animates, the vertex normals of the model change. Since a cubemap adjusts the texturecoords dynamically, it automatically maps a certain part of the texture, for particular vertex normals of the cubemap. Therefore, this always shows the correct normal colour for mixing with the normalmap, providing the correct lighting.

For a rotatable lightsource, you actually have to the rotate the cubemap, which is an expensive process, so alot of codes use a very small cubemap, to reduce the rendering process of the new cubemap.

A simple way though for normalmaps, with a rotatable light source, is to use entity color, and change the red green and blue parts yourself, to determine a position(normal) for the light. 255 being 1, 128 being 0 and 0 being -1 (for normals)

However, you can only use this on static meshes, which do not move, as their normals would be incorrect.

Vertex colours can be used, but that would involve you looping through every vertex and calculating their light value, based on light direction. This gives you some ability to have spot light and omi lights too, depending on the numb er and distribution of vertices in the mesh.


mtnhome3d(Posted 2008) [#21]
heres another prog that can make normals and its free
http://www.xnormal.net/


Chroma(Posted 2008) [#22]
Hmm I gotta try this when I get home!