Baked shadows and entity lighting

Posted By: eleroux

Baked shadows and entity lighting - 05/15/08 21:58


Hi! These are my first experiences with shadow and texture baking in Blender. I'm doing fine so far.

Shadow baking is great because you can get a more sophisticated shading than with A7 compiler, but I can find some problems right away.

For instance, 3dgs does an excellent job by lighting the entities after the shadowmap/lightmap on the floor it stands ((in A7 this has noble name of PRV - Precomputed radiance Volumes. Every entity gets its radiance color value from the nearest radiance plane below its origin) as in this picture:


Question is, how can I have something like PRV with generated shadows in meshes? as to avoid this:




I know there are people with years of experience baking shadows. Any solution you care to share? Or... maybe the engine supports some kind of separated lightmap for imported geometry?

Thanks!

Emilio
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 05/16/08 00:15

the trick is to trace from the player to the object beneath him/her, get the ambient value and apply it to your model, I think if you look up c_trace it tells you what the trace returns.
BTW: I have not forgotten about my baking tutorial....just busy ATM..

-Justin
Posted By: MaxF

Re: Baked shadows and entity lighting - 05/16/08 00:26

Hi

Is not c_trace slow?

Conitec should help with this! don't you think?
Posted By: eleroux

Re: Baked shadows and entity lighting - 05/16/08 01:11

I was hoping a better solution that wasn't overcoming the whole lighting process manually, using c_trace and doing my own entity lighting. Well, it's a solution, but I hope there's something more engine-wise.

..maybe a second set of coordinates that could be replace the 'radiance maps' in arbitrary geometry. Or maybe a lightmap that is generated but not displayed on the geometry. I was hoping something like that existed already. Maybe people at Conitec already have a solution for this...

Emilio
Posted By: Pappenheimer

Re: Baked shadows and entity lighting - 05/16/08 13:18

What's wrong with using the c_trace?
You are tracing to handle the gravity anyway!

If your entity is above an entity the trace returns "you" for the entity.

Maybe I'm wrong, but I would write something like this after the trace instruction:
if(you != 0)
{
my.ambient = you.ambient;
}

From the manual:
"
you If the obstacle was an entity, the you pointer is set to that entity; otherwise it's set to NULL
"
online manual
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 05/17/08 00:18

fade it into the you's.ambient value(makes the transition smooth) using some testing, and c_trace is only slow if many ents. are doing it, and at what length the trace is.
Posted By: Joey

Re: Baked shadows and entity lighting - 05/18/08 08:52

the ambient value is the same for the whole entity. you have to get the texture's pixel colour. if c_trace with SCAN_TEXTURE can't do the job for entities (i'm not sure here) you should try a view with size 1x1 pointing downwards and reading the texture information via bitmap instructions.
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 05/18/08 23:09

correct, but you can read the lighting on bsp levels I think.
Posted By: Pappenheimer

Re: Baked shadows and entity lighting - 05/18/08 23:25

Sorry, I missinterpreted what I saw on the last screenshot. I thought the bright model stood _on_ a dark entity. Now, I see it is standing in the shadow of a block or something! Sorry, for the confusion!
Posted By: eleroux

Re: Baked shadows and entity lighting - 05/18/08 23:37

Yeah, the character is standing on a dark BAKED shadow.
I don't think it should be correct to read the texture color in this case. A dark or light floor doesn't necessarily mean a light or a shadow.

Unless I take the next c_trace, making sure it's a block and not arbitrary geometry (can this be done?). But even if it's possible, I'd have to reproduce the lights using blocks in WED.

I have heard of a second set of uv coordinates in MED, and soon in the engine. I wonder what can be done with them.

EDIT: I should have read the beta log more carefully:

Quote:

(X) MEDB now supports a second UV set on skins, for special purposes such as shadow mapping. The second UV set is also stored in the MDL7 file, but not yet used by the engine.


I assume a solution is underway.


Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 05/19/08 01:41

maybe you could project a light map upon the entire level, much like a bmap for entity above the level??? At that point you may as well use a shadow mapping shader though...
Posted By: eleroux

Re: Baked shadows and entity lighting - 05/19/08 03:05

I just found The trick! *dances*

Easy like heck. It's exactly the opposite of a Shadow Mapping Shader. You just let the Map Compiler shade the geometry as usual, and then remove the shading in realtime with a simple material!

If someone is interested, this is the workflow:

-Model geometry in your favorite 3d app, then bake the shadows and textures at will (in a single skin, usually).
-Import in WED. Add lights (*SEE BELOW) and set the mesh as SHADED (not FLAT).
-Let WED create the lightmaps as usual. WED will generate a second entSkin to store the shadows of the mesh.

-Assign a little material to the meshes so it doesn't render the shadows!

This is the most simple material. The only thing it does is to 'paint' the mesh with its own skin, ignoring the shadowmap skin. So, basically your mesh will look exactly as FLAT shaded (showing only the beautiful baked shadows), but the lightmaps will be still working, so the entities standing on it will still be lit correctly.

Code:
material mtl_nolightmap
{
effect=
	"
	
	texture entSkin1;

	technique nolightmap
	{
		pass p0
		{
		  Texture[0] = <entSkin1>;
		  			
	  	  ColorArg1[0] = Texture;
		  ColorOp[0] = AddSigned;
		  ColorArg2[0] = Current;
		}
	}
	";
}




Please forgive me because I never coded materials before, so I don't know if this is correct way to code it. I just stole scraps of code from other complex materials I found around. It works so far.

* About adding lights: You may have to manually recreate in WED the light positions you used in your modeling 3d app, so the lightmaps will correspond to the baked shadows. But the good news are that very soon we'll be able to import whole arbitrary 3D levels including lights:

http://www.conitec.net/beta/wed_import.htm
Posted By: eleroux

Re: Baked shadows and entity lighting - 05/19/08 03:19

Again, it's my first time with materials. But this mat is shorter and it works. Is it wrong?

Well, it was about time I started with Materials anyway.. *goes studying*

Code:
material mtl_nolightmap
{
effect=
	"
	technique disable_lightmap
	{
		pass p0
		{
		    ColorOp[2] = Disable;		
		}
	}
	";
}

Posted By: Anonymous

Re: Baked shadows and entity lighting - 05/19/08 09:37

why not use the supertrace plugin from ventlator.
Search for it in the Forum. There is a A6 and a A7 version.
Posted By: eleroux

Re: Baked shadows and entity lighting - 05/20/08 02:04

I seaarched for it and I found it. It's an awesome plugin!

I am sure I will use it - but in this case I think the solution was rather simple, since the lighting of the entities (PVR) will be handled by the engine as usual.
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/21/08 12:34

Hello,

I am extremely interested in this topic and the possibility of making shadows outside Game Studio that can interact with my in-game models.

But I have a little problem- I don’t see how I can import my wed-made models (with textures) in Blender? I only seen option to export them to FBX.

Is there a way to do this with Blender or is there some other program that you would recommend for this? Max and Maya and everything over 100 Euros is out of my budget (if you can call it budget) grin
Posted By: ventilator

Re: Baked shadows and entity lighting - 05/21/08 12:43

blender has no fbx importer at the moment.

you could look for my obj exporter script which i posted in the lite-c contributions forum. with some small changes it would also work with level geometry.



...
there is no need for supertrace anymore. c_trace can do that too now (at least in the beta - i am not sure about the last official release).
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/21/08 13:07

Thanks I will look it up smile

…I’m not much of a programmer frown so I don’t think I will be able to handle it if it needs difficult modifications but I will give it a try.

What about this Milkshape thing? I can see on their page that it supports Alias FBX? Has anyone worked with Milkshape and is it possible maybe to do something with this software?
Posted By: ventilator

Re: Baked shadows and entity lighting - 05/21/08 13:21

you could also try to export as mdl from WED and then use my unmodified obj exporter with the mdl.
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/21/08 16:52

Half of baking work went o.k. grin

I convert my wed-model to fbx, then I convert fbx to obj and I import obj file in Blender.

I adjust default light and I do Render->Render Current Frame just for fun: Everything is there from textures to shadows.

Then I try Render->Bake Render Meshes->Full Render and Blender displayed error: No images found to bake to.
… so I select model and do the same Full Render- Blender goes crazy and all black???

Is there a tutorial about this Blender-baking thing… or maybe if it’s not really difficult someone can just tell me few important steps…? smile

Thanx...
Posted By: eleroux

Re: Baked shadows and entity lighting - 05/22/08 03:57

no, it's not too difficult. First of all, i suggest you use the new blender 2.46 release because they fixed two important bugs about targeting textures for baking.

To bake textures, lights, etc, you need:

- Textures to receive the baking (correctly applied to the meshes via any of the unwrap options)

- Textures or materials IN your meshes, so they will be baked (if you want textures)

- of course, lights.

I suggest to start with simple cubes and objects to understand the process.
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/22/08 16:11

Thanks for tips I am really, really interested in this process.

I have found two nice tutorials:

http://www.vimeo.com/385595

…texture baking video and…

http://www.scifi-meshes.com/forums/dojo/...ure-baking.html

…simple tutorial with cube, but they both use something they call UV Face Select Mode that I don’t have in my Blender modes drop-down menu. frown

I have downloaded new Blender 2.46 Zip Archive and Blender 2.46, Python 2.5 FreeBSD file. Does anyone knows what I must download in order for this mode to appear?
Posted By: Altimeter

Re: Baked shadows and entity lighting - 05/22/08 17:55

for UV Face Select Mode:
it is in the same small window, where you switch between Object Mode and Edit Mode.
It is called UV Face Select
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/22/08 18:15

Yes I know it should be there but I have, unfortunately , everything but UV Mode:

Weight, Texture, Vertex Paint and Sculpt, Edit, Object Mode.

As I see it I should have installed some plugins or maybe some of that Python things frown

Blender really does informs me that I don’t have any Python installed in that first DOS-looking window frown
Posted By: JibbSmart

Re: Baked shadows and entity lighting - 05/22/08 23:50

latest version doesn't have it.

in edit mode you need to open uv's (in another window). while in edit mode press "u" to deal with uv's and stuff. i can't be more specific because my pc doesn't like blender so much, so i have some bugs to sort out.

julz
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/24/08 13:45

It’s a strange thing about Blender unwrapping I must be doing something wrong cry

I’m using CBabe as a test model (transformed in obj format) and everything is o.k. until I unwrap her (btw- her texture seems already unwrapped with every vertex at his own place). When I use Unwrap (smart projections) as indicated in tutorials Blender unwraps CBabe in totally unexpected way- it seems he only makes different vertex positions and leaves texture totally unchanged. So texture is un-touched and vertex position is all different??? frown

Is there something I must do in order for Blender to recalculate texture and not just vertex (as in MED’s Atlas Mapping where there are big changes in texture map)?
Posted By: ventilator

Re: Baked shadows and entity lighting - 05/24/08 14:35

i think smart projections is more meant for architectural geometry. for characters and organic stuff i would mark some seams and use unwrap to get better results.

you have to keep your old uv-set and bake the texture to the new uv-set but i haven't done this before in blender so i don't know how exactly this would have to be set up. you have to experiment a little.
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/24/08 15:14

Success grin grin grin

In UV/Image Editor window (with UV Face Select Mode and CBabe all selected in 3D View window ) I go to Uvs->Scripts->Save Uv Face Layout Then I save CBabe’s Tex-Vertex Map as an TGA image file (that Blender marks as …_mesh.tga) When I open that TGA in UV/Image Editor Blender treats it as a UV Map and all I have to do is click on Bake->Full Render and… MAGIC! My CBabe model has shadows - Baking Done! Hura! grin

I don’t know if this is the best way of doing it (and if it’s really that good because I am posting this moments from doing it in Blender) but I hope when I try more complex model the result will be satisfactory…

smile Thanx to everyone who helped me…
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/24/08 17:34

Nope…

I called it to soon: still not good. Very strange shadows and strange pointer on walls frown

If anyone baked some nice shadows in imported obj files please share process steps… Thanx.
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 05/25/08 12:10

make sure there are NO overlaping UV faces, I use 2 UV sets one UVTex for the materials, and one called baking. set the UVTex as rendering uv set and set baking as active uv..maybe that is backwards...??? anyway try that.
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/25/08 23:14

You are right about overlapping- I used Blender's consolidate in to one image tool to put all model textures in one png and used that image as a baking map. That’s why I had strange shadows- they where overlapping crazy

Once I used MED’s Atlas Mapping to create single texture map it was all o.k. I also took your advice about using the same image twice (for tex and shadow map) and it worked great grin

…but now I have a problem in finding a good mapping tool When I use MED’s Atlas Mapping on files imported directly from WED it’s a disaster- textures are weird and partially washed up.

If after WED I go to Blender, use consolidate in to one image, import model to MED and then do Atlas Mapping everything is fine except it bugs-out if I put specifications bigger then 2048???

It bugs-out in a way that he doesn’t make tex-map but empty map frown So 4096 is out of bounds as far as I can tell and I can’t do nothing with 2048.

Is there some atlas or uv mapping tool that is free or maybe low-costly and works great as the MED’s Atlas Mapping but with bigger image resolutions?

I downloaded Ultimate Unwrap3D Pro demo but haven’t tried it so far...
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 05/27/08 10:31

Blender has far better mapping tools than MED. I think I have a tutorial on my site. it's almost* free. You could search for tutorials though.
Posted By: Pappenheimer

Re: Baked shadows and entity lighting - 05/27/08 20:06

Originally Posted By: Ganderoleg
I’m using CBabe as a test model (transformed in obj format) and everything is o.k. until I unwrap her (btw- her texture seems already unwrapped with every vertex at his own place).


Does this mean that you exported cbabe with uv-map?
How did you achieve that?
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/27/08 21:48

Nowherebrain/
Everything points in that direction and I don’t understand why I can’t create atlas texture map in Blender cry

All I can create is different uv maps that don’t recalculate, change or do anything with texture. Only way I could have done that, is with MED’s Atlas tool and now- with Microsoft DirectX SDK and their uvatlas tool but in this last case texture in a new object is all weird frown

It’s almost unbelievable that I can’t do nothing to recalculate and rearrange my textures so I can bake them. I will try to find some tutorials but as I see it creating atlas texture should be straight and automatic process?

Pappenheimer/
In CBabe case is simple to bake shadows because her texture is already fine (non-overlapping). All you have to do is convert her to obj format, save her texture with different name in some folder (I like to make that second image TGA), open CBabe.obj in Blender and in UV/Image editor window ( while in UV Face Select mode) open saved picture on top of original map as a texture to be baked to. That’s it.

Has anyone worked with Microsoft DirectX SDK and uvatlas.exe tool? My new texture map comes up all weird and misplaced frown
Posted By: Pappenheimer

Re: Baked shadows and entity lighting - 05/27/08 22:53

"All you have to do is convert her to obj format"
My interest is how I can convert her from mdl to obj. How did you convert it?
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 05/28/08 00:04

I downloaded FBX Converter from:

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=6839916

I first saved CBabe as FBX and then converted her to OBJ.
Posted By: Pappenheimer

Re: Baked shadows and entity lighting - 05/28/08 09:18

Thank you! smile
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 05/28/08 10:50

You don't really want atlas mapping(well you might). You want the model to be as island free as possible...in blender enter edit mode(tab)>change your selections to edges(ctrl+tab),edges>select the edges you want to use for a seam(like slicing)>mark seam(ctrl+e)mark seam>select all(a key)>then unwrap(u),unwrap.
You will need a minimum of two views for this one 3d view and one uv image edit view. If you are unfamiliar with what I am talking about, check out my free video "meshing around in blender". It is located on my tutorials page. It should give you a basic understanding of blender(very basic).
Posted By: Ganderoleg

Re: Baked shadows and entity lighting - 06/05/08 20:50

Nowherebrain/

I’m afraid it would be no good for me to try anything manually with my models because I was modeling complete rooms in wed and complexity of the models confuses me- I wouldn’t know where to begin with edges. I could break every room in 5-6 groups of simpler objects (that’s what I’m doing in my method ) and then manually re-map them in Blender but it’s too much time consuming.

Thanx for helping and I really liked your video- it’s very informative and an-eye opener . Blender seems to have every important modeling function and it’s free??? I still don’t get it.

With Blender I guess you can save tons of money and have similar project quality that you would have with Max or Maya.


/////////////////////////////


As for Shadows-On-Textures I have managed to put a method that seems to be doing the trick:

You need 3 programs for this:

GStudio 7
Blender
Fbx Converter


Steps:

Save your WED-Model to FBX.
Convert your WED-FBX-Model to OBJ with FBX Converter.
Import OBJ-Model in Blender, do consolidate into one image thing to put all textures into one and save as FBX.


…now the weird part…


Import Blender-FBX-Model in MED (there should be only one mesh & one skin) and save it as FBX again(overwrite if you want).
Import MED-FBX-Model in WED, save texture in WAD and save everything as MDL.
Open WED-MDL-Model in MED and save as MDL again.
Open MED-MDL-Model in MED, do Create Atlas Mapping, delete old non-atlas texture and save as FBX and MDL.


…this weird part is here because I couldn’t do the atlas mapping any other way. The key thing before creating the atlas is to make sure the texture is on the model. For some reason it’s not enough to see the texture in MED’s 3D View - you have to click Engine Preview to make sure it’s there. In most cases texture was present in 3D View but non-existent in Engine Preview so Atlas didn’t recalculate it but have made an empty texture-map in that strange pink color. I don’t know if this will happen to everyone or it’s just my pc but this is how I must do it. Next…


Convert MED-Atlas-FBX-Model to OBJ with FBX Converter.
Import Atlas-OBJ-Model to Blender, do texture-baking thing, save baked texture.
Open MED-Atlas-MDL-Model (that you saved at the same time as FBX) and just replace old-atlas texture with baked one.
Baking over.

If anyone found a faster (or better) way of doing this please share your steps…
Posted By: Pappenheimer

Re: Baked shadows and entity lighting - 06/05/08 21:12

This was my way:
ingame light mapper contribution thread
Maybe, it is worth a try.
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 06/06/08 01:33

was there not another one...it basically used a loop to trace from each pixel in the second map(of a terrain or model)to the light source(ray trace)and if it hit an obstacle(trace>0)it drew a dark pixel and then blurred the entire skin...???anyone remember that??
Posted By: Pappenheimer

Re: Baked shadows and entity lighting - 06/06/08 02:56

Terrain_Shadowmapping
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 06/07/08 03:02

Yep, I guess that's the one...seems like the right method I was thinking...never used it, but thought it was a decent(even good)idea.
Posted By: Nowherebrain

Re: Baked shadows and entity lighting - 06/09/08 03:30

I tried re-writing this for lite-c, I got through all the warnings to no avail. It just did not work...I don't know if it has something to do with the material..

I basically made the following changes:

*where there was an array...
e.g. changed pixelcolor.x > pixelcolor[0].

* created a VECTOR named temp.// could've used a struct I guess.

*fixed some minor case sensitive items...
IGNORE_ME|IGNORE_SPRITES etc..

*used MATERIAL* name =//instead of material name...

*changed bmap > BMAP*...
....you get the idea

-anyway... The level runs, with skin1 visible and the old shadowmap(skin2)with no change to skin2. I don't know what I have done wrong.
© 2024 lite-C Forums