Reading lightmap at location.

Blitz3D Forums/Blitz3D Programming/Reading lightmap at location.

Sledge(Posted 2004) [#1]
Is there any way to cross reference a picked part of a b3d with the portion of the lightmap it uses, returning the rgb of the particular spot on the lightmap?

I've looked through the command set and there seem to be a couple of commands related to setting the lighting on part of a mesh but nothing for reading a value back. As you can probably guess I'm trying to alter an entity's colour dynamically so that it continually matches the lightmap hue as it travels about a level -- but I'm a bit stumped as to a "BASIC" solution. Anybody achieved something similar that they fancy going over?


Tom(Posted 2004) [#2]
Fredborgs PickedU() and PickedV()

http://www.blitzbasic.com/codearcs/codearcs.php?code=515


Sledge(Posted 2004) [#3]
Crikey! Thanks for the link. I've no idea what U's, V's or W's are of course, but I'm sure if I employ my time honoured develoment methodology (changing things at random until they happen to work) to the task I'll soon have it doing... something.


ZombieWoof(Posted 2004) [#4]
think of u/v as x/y on the texture map -- range is 0-1, so you have to multiply by the w/h of the texture.


Sledge(Posted 2004) [#5]
Ahh, I see... what's W for though? :/

I've run into a bit of a problem anyway in that you need to supply Fredborg's functions with the handle of the texture you're interrogating. How are you supposed to know that with an automatically loaded lightmap? I'm kind of amazed there isn't a straightforward command for this... it's not as if its use would be unanticipated (what else are you going to want a lightmap for?)


ZombieWoof(Posted 2004) [#6]
Dunno -- blitz docs that I have say it doesnt get used, and I dont know of any app that does use w. Maybe there are shaders/procedural textures that use all 3 ??


Mustang(Posted 2004) [#7]
W is/was meant for future expansion... it's unused. IMO bit like XYZ (note that UVW comes before XYZ alpabetically), so W would be "depth" but it has no use in (UV) texturemaps.


Rottbott(Posted 2004) [#8]
Sledge, use:

GetEntityBrush()
GetBrushTexture()

Don't forget to free them once you're done!


Sledge(Posted 2004) [#9]
Thanks for the suggestions -- I will plug away at this and, if successful, wang a method in the code archive. Don't hold your breath though!


Caff(Posted 2004) [#10]
Sledge also look at: http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=kusonagi09182003234308&comments=no


Sledge(Posted 2004) [#11]

GetEntityBrush()
GetBrushTexture()

Don't forget to free them once you're done!



So let's say I do something like this...
map=LoadMesh("mymap.b3d")
lmaptex=GetBrushTexture(GetEntityBrush(map))

How would I go about tweaking it so I'm getting information about the lightmap layer only... and how do I know what the brush I have to subsequently free is called? This is all very alien.
++:D <-- smiley with alien forehead a la TV's famous Start Wreck.

EDIT: I'll have a look at that Caff... I was typing while you were posting.

EDIT: Looks perfect (and scarily complex) Caff. Thanks for that -- totally missed it.


ZombieWoof(Posted 2004) [#12]
its called lmaptex -- what you named it :)

Can blitz automatically load a lightmap ?? every example I've seen loads it in code and applies it to the mesh.


Sledge(Posted 2004) [#13]
lmaptex is the texture, not the brush, isn't it? In answer to your question yes... if a lightmap is present it is loaded automatically. In fact, whenever I've tried to load a lightmap separately I've just ended up with the entire map texture applied to every wall like a regular texture -- no idea how you'd load one manually.


ZombieWoof(Posted 2004) [#14]
ok -- my bad -- you didnt store the result of GetEntityBrush(map) into its own variable.

This is how I load terrain with lightmap that I create with ALE: (dont expect it to be much different for any lightmapped mesh)

;Load Level
level = LoadMesh("default/default.b3d")
ScaleEntity level, 2, 2, 2
PositionEntity level, 0,-5,0

;Lightmap
EntityFX level, 1
Global lightmap = LoadTexture("default/default_lm.png")
TextureCoords lightmap, 1
TextureBlend lightmap, 2
EntityTexture level, lightmap, 0, 1

Note the EntityTexture command.. the lightmap is loaded into texture slot 1 (of 0-7 possible). One may presume that the mesh textures are in slot 0 -- if you replace slot 0, you get lightmap all over your models :)


Sledge(Posted 2004) [#15]

you didnt store the result of GetEntityBrush(map) into its own variable.


Heh - now does that mean there is anything to free or not?! :/

re Loading lightmaps manually -- it was TextureCoords I was missing previously, thanks for the example.


Sledge(Posted 2004) [#16]
Bitter-sweet: kusonagi's routine (linked to by Caff) is great, but all the line-picking and associated number-crunching slow things right down. Looks like pre-calcing a three dimensional shadowmap using kusonagi's function then referencing THAT instead is the order of the day. A bit more work, then, but there shouldn't be any reason why lots of shadow-sensitive entities can't be maintained this way.

(Or alternatively, use a low-res lightmap that is blurry enough to hide the lag in an entity's hue then only linepick every few frames)

EDIT: Quick update, kusonagi's code is plenty fast on smaller lightmaps. I can easily do a pick per frame out of it under such circumstances.