Fake Lighting Techniques For Blitz3d

Blitz3D Forums/Blitz3D Programming/Fake Lighting Techniques For Blitz3d

Rogue Vector(Posted 2005) [#1]
Hi,

I've run into a problem that I'm sure others have had in the past.

I need to simulate a rotating hazard warning light.

Normally, I'd just use a Blitz 3D Spotlight, but my level is lit using a gile[s] lightmap, so it won't work. I think it has something to do with Blitz only supporting 2 sets of UV coords.

Anyway, I seem to remember a while back that someone came up with a technique that used something like an EntityBlend on a textured sphere to simulate a moving light spot.

The texture was a radial gradiant and when combine with the level mesh it created a fairly convincing fake light effect.

Does anyone have the code, or know how to acheive somehing like this?

Thanks in advance,

Rogue Vector.


Ross C(Posted 2005) [#2]

Normally, I'd just use a Blitz 3D Spotlight, but my level is lit using a gile[s] lightmap, so it won't work. I think it has something to do with Blitz only supporting 2 sets of UV coords.



The blitz lights works by lighting the vertices of the mesh, so it can't be the textures, unless there very dark areas of the lightmap. If the area around the light is flat, you could fake the lighting using a white mesh and using an entityblend mode.


Rogue Vector(Posted 2005) [#3]
I don't really understand why the Blitz3D lighting won't work with my level, but trust me, it simply refuses to illuminate the geometry.

The level mesh has a base texture layer, a masking texture layer - that essentially illuminates certain specific regions of a wall via and additive blend, and finally the light map created in gile[s].

God! It's frustrating. It's a simple scene element and it won't do it.

Rogue Vector


Stevie G(Posted 2005) [#4]
Putting a blitz light in with a premade lightmap may look wrong. Have you tried making sure that the level does not have the entityfx fullbright flag set?


Stevie G(Posted 2005) [#5]
Putting a blitz light in with a premade lightmap may look quite unrealistic. Have you tried making sure that the level does not have the entityfx or brushfx set to fullbright?


Hujiklo(Posted 2005) [#6]
It's not the number of UV co-ords. Light mapping in Giles automatically sets your base mesh to 'full bright' and then adds the lightmaps. I don't remember exactly right now but I think you can have upto 8 sets of UV co-ords in Blitz.

As for the faked spot light effect. I think Fredborg did a nice piece of code for that effect. I don't know if it's in the code archives though but he definitely had it on these forums somewhere.


MadJack(Posted 2005) [#7]
'I don't remember exactly right now but I think you can have upto 8 sets of UV co-ords in Blitz.'

No, Blitz supports 2 UV co-ords but up to 8 texture layers.


Shifty Geezer(Posted 2005) [#8]
I don't really understand why the Blitz3D lighting won't work with my level, but trust me, it simply refuses to illuminate the geometry.

Lights work on vertices. This measures the amount of light hitting each vertex and interpolates it across the triangle between vertices. So a triangle lit with white light in one corner and no light in the other two will show a gradient of illumination from one point to the opposite edge.

Now imagine you've got a wall, a plain rectangle made of two triangles. If you shine a spotlight into the middle of that wall, the vertices are receiving no light so the light won't show. If instead you use a rectangular mesh of say 20x20 smaller rectangles, the central vertices will be illuminated by the spotlight. However this typs of lighting shows the triangles of the mesh, and you won't get a smooth circular spot. Basically small spotlights are very hard to manage in a vertex lit system. You would need to find another solution like a texturing solution. There's a few examples I've seen including one that projects a bat-signal as though it were a torch light.


Naughty Alien(Posted 2005) [#9]
I use to work with this to solve exactly problem you mention about...you can add also nice sprites over light surface and make them changing transparency according to angle against camera..anyway, this will light your geometry, and change intensity of light applied on to level geometry according to distance from light source..

Graphics3D 1280,1024,32,1
SetBuffer BackBuffer()

HidePointer
AmbientLight 12,24,50
SeedRnd MilliSecs()

light = CreateLight()
RotateEntity light,70,40,0
LightColor light,50,50,50


camera = CreateCamera()
scene = CreateMesh()

For i = 0 To 100

cube = CreateCube()
ScaleMesh cube,Rnd(1,10),Rnd(1,10),Rnd(1,10)
RotateMesh cube,Rnd(-90,90),Rnd(-180,180),Rnd(-180,180)
PositionMesh cube,Rnd(-100,100),Rnd(-100,100),Rnd(-100,100)

AddMesh cube,scene

FreeEntity cube

Next

cube = CreateCube()
ScaleMesh cube,150,150,150
FlipMesh cube
AddMesh cube,scene
FreeEntity cube

DL_Init()
DL_SetReceiver(scene)

DL_SetLight(camera)

spd# = 2.0

Repeat

MoveEntity camera,(KeyDown(205)-KeyDown(203))*spd,0,(KeyDown(200)-KeyDown(208))*spd
TurnEntity camera,MouseYSpeed()*0.25,-MouseXSpeed()*0.25,0
RotateEntity camera,EntityPitch(camera,True),EntityYaw(camera,True),0

MoveMouse 320,240

DL_Update()

RenderWorld
Flip

Until KeyHit(1)

DL_Free()









Type dl_receiver
Field mesh
End Type

Type dl_light
Field entity
Field range#
Field scale#
Field intensity#
Field flicker#
Field flickerrange#
Field r#,g#,b#
End Type

Global dl_brush
Global dl_tex

Function DL_Init()

ClearTextureFilters
dl_tex = LoadTexture("your_light_source_texture.png",1+16+32)

dl_brush = CreateBrush()
BrushBlend dl_brush,3
BrushFX dl_brush,1+2
BrushTexture dl_brush,dl_tex

End Function

Function DL_Free()

For dlr.dl_receiver = Each dl_receiver
FreeEntity dlr\mesh
Delete dlr
Next

For dll.dl_light = Each dl_light
Delete dll
Next

If dl_tex Then FreeTexture dl_tex
If dl_brush Then FreeBrush dl_brush

dl_tex = 0
dl_brush = 0

End Function

Function DL_SetReceiver(mesh)

dlr.dl_receiver = New dl_receiver
dlr\mesh = CopyMesh(mesh)
PaintMesh dlr\mesh,dl_brush

End Function

Function DL_SetLight(entity,range#=500.0,scale#=0.75,intensity#=2.0,flicker#=0.05,flickerrange#=0.5,r#=200,g#=220,b#=255)

dll.dl_light = First dl_light

If dll = Null
dll.dl_light = New dl_light
End If

dll\entity = entity
dll\range = range
dll\scale = scale
dll\intensity = intensity
dll\flicker = flicker
dll\flickerrange = flickerrange

dll\r = r
dll\g = g
dll\b = b

End Function

Function DL_Update()

dll.dl_light = First dl_light
If dll = Null Then Return

If Rnd(0.0,9.0)<dll\flicker
intensity# = dll\intensity*Rnd(dll\flickerrange,1.0)
Else
intensity# = dll\intensity
End If

For dlr.dl_receiver = Each dl_receiver
mesh = dlr\mesh
n_surfs = CountSurfaces(mesh)
For s = 1 To n_surfs
surf = GetSurface(mesh,s)
n_verts = CountVertices(surf)-1
For v = 0 To n_verts
TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,dll\entity
x# = TFormedX()
y# = TFormedY()
z# = TFormedZ()

dist# = Sqr(x*x + y*y + z*z)*dll\scale
tu# = (x/dist)+0.5
tv# = 1.0-((y/dist)+0.5)

VertexTexCoords surf,v,tu,tv

If z>dll\range Then z = dll\range
falloff# = 1.0-(z/dll\range)
If falloff<0.0 Then falloff = 0.0
If falloff>1.0 Then falloff = 1.0

TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,dll\entity
dot# = -TFormedZ()*falloff*intensity
If dot>0.0
VertexColor surf,v,dot*dll\r,dot*dll\g,dot*dll\b
Else
VertexColor surf,v,0,0,0
End If
Next
Next
Next

End Function


John Blackledge(Posted 2005) [#10]
Wow, Naughty Alien!
I've tucked that away for when I need 'direct' lighting.
Thanks for sharing.


Rogue Vector(Posted 2005) [#11]
Fredborg's code, which is here by the way, http://www.blitzbasic.com/codearcs/codearcs.php?code=1000

- doesn't work in this instance because it requires another set of UV coords.

I posted the problem in the gile[s] forum and here's the response:
http://www.frecle.net/forum/viewtopic.php?t=424


In gile[s] forum:
Dreamora wrote:
You can't do anything like that with B3D + Lightmaps as B3D only supports 2 UV Coord sets which you both need (1 for base texture, 1 for lightmap) so you can't project another texture over it using a 3rd UV which would be needed for it.



This is why I was thinking in terms of an EntityBlend of a mesh.

But how?

Man! I hope the 3D module for BlitzMax makes doing stuff like this far more straight forward.

Regards,

Rogue Vector


Naughty Alien(Posted 2005) [#12]
but why you wanna project another texture instead of changing vertex colors to simulate light on specific areas?? For example, 3DS file cant support even 2 UV sets, but with vertex color management, yoy can easy apply lightmap information over difuse textures without problems...same things is here...


John Blackledge(Posted 2005) [#13]
Sorry... "3DS file cant support even 2 UV sets" ???

Does this mean that a 3DS files can never be lightmapped ?

This is pretty important as a potential client wants to use 3DS (directly, not B3D), and wants lightmapping.


Naughty Alien(Posted 2005) [#14]
3DS files cant support 2UV sets, so cant be lightmapped on the way like B3D file..but as I'm mention above, you can make them lightmapped on the way I mention early...you can apply lightmap on to 3DS file, or X file on this way..

Graphics3D 800,600,32,2



camera=CreateCamera()

Textured_Mesh=LoadAnimMesh("level.3ds")
litemap_mesh=LoadAnimMesh("lightmap.3ds")
t=LoadTexture("lightmap.bmp")

MapVertices(Textured_Mesh,litemap_mesh,t)
FreeEntity litemap_mesh
FreeTexture t

MoveEntity camera,0,200,-500
PointEntity camera,Textured_Mesh

While Not KeyHit(1)
TurnEntity Textured_Mesh,0,0.1,0
UpdateWorld
RenderWorld
Flip
Wend
End

;=====================
Function MapVertices(model,copy,texture)


For n=1 To CountSurfaces(model)
surf=GetSurface(model,n)

Next

For n=1 To CountSurfaces(model)

surf=GetSurface(model,n)
lsurf=GetSurface(copy,n)
For v=0 To CountVertices(surf)-1

tu#=VertexU#(lsurf,v)
tv#=VertexV#(lsurf,v)
tw#=VertexW#(lsurf,v)
VertexTexCoords surf,v,tu,tv,tw,1
Next
Next



TextureCoords texture,1
EntityTexture model,texture,0,1

For e=1 To CountChildren(Model)
limb=GetChild(model,e)
limb2=GetChild(copy,e)
MapVertices(limb,limb2,texture)
Next

End Function


where is Textured_Mesh your 3DS level textured with difuse textures on to it, LITEMAP_MESH is same mesh as Textured_Mesh, except lightmap texture is applied on to it without any other texture...and T is lightmap texture...what is important here is that lightmapped level (LITEMAP_MESH) MUST BE same geometry as Textured_Mesh...thats all..this things working properly if you exporet geometry on proper way..enjoy


John Blackledge(Posted 2005) [#15]
I've no way of immediately testing your code, but I'll assume it works - and thanks for that.

This at least means I can reopen negotiations over 3DS lightmapping.

Thanks very much for that.

Just out of interest, why did you create this?
And is anyone else finding a need for this, and why?