YABQ - Yet another Bumpmap Question - FREDBORG

Blitz3D Forums/Blitz3D Programming/YABQ - Yet another Bumpmap Question - FREDBORG

Murphy(Posted 2004) [#1]
hi there!

I'm writing on the bump/normal-system for my game. (atm bump the levels)
i use Fredborgs DotMyBot example, and have a 'il question....

First of all the code

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


Everything works fine over here, but i don't know how i could turn/rotate the dot3_light.... it only shines in one direction, no matter in witch direction the cam looks - but i want it to shine in the direction the camera (or better, it's pivot) looks.
with the whole TFormNrmal, TFormPoit etc Stuff i'm not that good friend, you know ;)
maybe fredborg read this, and know a solution?

'have fun'


Ross C(Posted 2004) [#2]
To change the direction of the light on normal maps, you need to alter the EntityColor, for direction light.

Red = the x position the light
Green = the y position of the light
Blue = the z position of the light

The range is from 0 to 255, with 128 being central. So:

EntityColor mesh,128,255,128


Will make the light appear to be from the directly above the model.

EntityColor mesh,128,128,255


Will make the light shine from the front of the model.

This is assuming that the example uses directional light only. Point light, you will have to fiddle around with vertex lights :)


Murphy(Posted 2004) [#3]
yeah... already tried the directional light (tried robs example too). but there is the problem, that ALL the same wall with the same texture have the same 'light-position'.

that why, i tried the point light - and really love the effect (a lil doom3-taste - will post screenies later).
but if i use pointlight, i also have to use lightmaps on my map - that is where the next problem starts... :(
is it possible to use lightmaps AND Dot3 lights?
(normalmap on TexIndex 0, textures on TexIndex 1 with (clearly) blendmode 4 on the TexIndex 0)...

@RossC
=============

you got some resources where i can read a lil about vertex lights...?

P.S.: still hoping on fredborg's opinion... :)


TartanTangerine (was Indiepath)(Posted 2004) [#4]
Are you using Tangentspace mapping or Worldspace mapping. You need Tangentspace for fredborgs example. (or have I got it the wrong way round) ;)


AntonyWells(Posted 2004) [#5]
You can transform the light into the local space of each entity when doing entitycolor so that the mapping stays correct no matter how you position/rotate the entity.

Function entityLight(entity,light,inten#=0.5,hull=False)
	ox#=EntityX(light)
	oy#=EntityY(light)
	oz#=EntityZ(light)
	If Not hull inten=1.-inten
	tp=CreatePivot()
	PositionEntity tp,EntityX(light),EntityY(light),EntityZ(light)
	TFormPoint ox,oy,oz,tp,entity
	light=tp
	PositionEntity light,TFormedX(),TFormedY(),TFormedZ() ;Transpose light into 
	dx# =(EntityX(light)-EntityX( entity));*inten
	dy# =(EntityY(light)-EntityY( entity));*inten
	dz# =(EntityZ(light)-EntityZ( entity));*inten
	nl#=Sqr(dx*dx+dy*dy+dz*dz)
	nx#=dx/nl
	ny#=dy/nl
	nz#=dz/nl
		
	nx=nx*inten
	ny=ny*inten
	nz=nz*inten

	FreeEntity tp
	EntityColor entity,128.+(128.*nx),128.+(128.*nz),128.+(128.*ny)
End Function


Here's one that does per vert

Function vectorLight(entity,light,inten#=0.5,hull)
	ox#=EntityX(light)
	oy#=EntityY(light)
	
	oz#=EntityZ(light)
	If Not hull inten=-inten
	tp=CreatePivot()
	PositionEntity tp,EntityX(light),EntityY(light),EntityZ(light)
	TFormPoint ox,oy,oz,tp,entity
	
	light=tp
	
	PositionEntity light,TFormedX(),TFormedY(),TFormedZ() ;Transpose light into 
	srf=CountSurfaces(Entity)
	lx#=EntityX(light)
	ly#=EntityY(light)
	lz#=EntityZ(light)

	cs=CountSurfaces(entity)
	For s=1 To cs
		srf=GetSurface(entity,s)
		For v=0 To CountVertices(srf)-1
			tformpoint vertexX(srf,v),vertexY(srf,v),vertexZ(srf,v),entity,0
                  vx#=tformedX()
                  vy#=tformedY()
                  vz#=tformedZ()
			dx# =(lx-vx)
			dy# =(ly-vy)
			dz# =(lz-vz)
			tdx#=vx-lx
			tdy#=vy-ly
			tdz#=vz-lz
		;	tl#=Sqr(tdx*tdx+tdy*tdy*+tdz*tdz)
		;	dx=(dx/tl)*inten
		;	dy=(dy/tl)*inten
			;dz=(dz/tl)*inten
			nl#=Sqr(tdx*tdx+tdy*tdy+tdz*tdz)
			nx#=dx/nl
			ny#=dy/nl
			nz#=dz/nl
			nl#=(nl*10.-255.)/255.
	
			nl=1-nl
	
	If nl>1 nl=1
	If nl<0 nl=0
	nl=in

	nx=nx*inten
	ny=ny*inten
	nz=nz*inten

			
			VertexColor srf,v,128+(128*nx),128+(128*nz),128+(128*ny)
		Next

	Next
	FreeEntity tp
End Function




Murphy(Posted 2004) [#6]
thx for the replys :)

thx Otacon for the snipes... i found a solution witch work with yours and fredborgs function...

on the tformpoint i set the destination to light. that way the normalmaps are comes the right way, depending on where the light-source is.

would you like to see a demo?

<edit>
anybody realised a way to lightmap the level AND use the normalmap-effect?


RetroBooster(Posted 2004) [#7]
anybody realised a way to lightmap the level AND use the normalmap-effect?

Yes, we've been using a technique that does this as well as correct normal mapping ever since normal mapping got put in. It's really not all that hard. What's causing you trouble? Tho normal mapping is really better of used with dynamic level lighting. Which is what we use instead in most cases.


Murphy(Posted 2004) [#8]
Well, hmm.. dynamic lighting.
do you use a costum system, or swift's system?


RetroBooster(Posted 2004) [#9]
Custom, naturaly. I believe swifft didn't even release his intended dynamic lighting system... Just his shadow system.


Murphy(Posted 2004) [#10]
can you summary the rough way, how you managed it?
i'm not so well with all this light stuff ;)
hope u could help me :)