PDA

View Full Version : New Script: Material Baker v1 (Lighting, Shading, Wireframe baker)



custom_junk_mail
09-12-04, 06:52 PM
Hi, I had need for a script that would let me bake in the shading and material of my model into a texture, so I created this script. It bakes in the shading of your model in a way similar to projection master with drop/pick shading, but it doesn't burn overlapping areas. It also rotates the lights with the model so that the lighting remains consistent across the baked texture.

Special thanks to Sven and Pixolator for helping me get started with ZScript.

The script and a tutorial on how to use it can be found at my website at http://www.davidikeda.com/materialbaker.html.

pnoland
09-12-04, 07:09 PM
Sweet! Thanks for sharing this script!!

custom_junk_mail
09-12-04, 07:39 PM
NP. If you create any textures with it, I'd love to see them! By the way, load material_baker.txt from the ZScript panel to start the script. The other files are included from that script and shouldn't be loaded up directly.

custom_junk_mail
09-12-04, 09:04 PM
I added a little tip to the site. You can also use the script to bake in your model's wireframe. Here's the result after a minute of baking:

wireframe_bake.jpg

Svengali
09-12-04, 09:18 PM
Hi CJM,

Wow, that was quick. Results look great!

I'm curious about your strategy for light positioning. Must have a look at that. I'll give you any feedback on that I can.

Well done.

Again, welcome to the hunt and thanks for sharing!

Sven

custom_junk_mail
09-12-04, 09:31 PM
Hey Sven, the source is included with the zip if you want to check it out. The light positioning is done using simple transformation functions in ikeda_math.txt.

The only ones I use are RotateX and RotateY:



[RoutineDef, "RotateY",
[VarDef, tX][VarSet, tX, ( (sin(#angle) * #z) + (cos(#angle) * #x) )]
[VarDef, tZ][VarSet, tZ, ( (cos(#angle) * #z) - (sin(#angle) * #x) )]
[VarSet, x, tX]
[VarSet, z, tZ]
, x, y, z, angle]


This rotates a vector/point about the Y axis. The light positions are recorded into an array when the user hits Start and absolute rotations are performed based on the yaw setting. Front, Back, Left, and Right just affect yaw.

For top and bottom views, I just hardcoded the light positions to RotateX with 90 degrees and -90 degrees.



[RoutineDef, "RotateX",
[VarDef, tY][VarSet, tY, ( (cos(#angle) * #y) - (sin(#angle) * #z) )]
[VarDef, tZ][VarSet, tZ, ( (sin(#angle) * #y) + (cos(#angle) * #z) )]
[VarSet, y, tY]
[VarSet, z, tZ]
, x, y, z, angle]


I have yet to find a solution where the user can orient the model any way he/she likes and have the lights synchronize when baking. It has to do with the complex rotational angles that ZBrush provides. I can't figure them out.

marcus_civis
09-13-04, 12:59 AM
This is a great script! Many thanks!:tu:

chadtheartist
09-13-04, 02:16 AM
Wow! Awesome script! I've been wanting something like this for a long time! You've just made me a super happy man! Thank you so much for sharing this... Awesome.

I'm going to use it right now!

Fouad B.
09-13-04, 04:16 AM
CJM ... very nice and usefull script. Thx a lot.

Mentat7
09-13-04, 06:04 AM
Very intriguing. I am anxious to give it a try. Thank you for your commitment and hard work! :tu: :tu: :tu: :tu: :tu:

cameyo
09-13-04, 06:13 AM
Wow!!!
Great idea and good script.
Thanks for share.

cameyo

chadtheartist
09-13-04, 06:46 AM
I tested this this morning, and I must say it's a neat concept. I'm not sure if it would replace painting textures exclusively, but I do think it is a great way to start your textures.

Again, thanks for sharing this!

custom_junk_mail
09-13-04, 10:49 AM
Thanks all, I'm glad you guys fnd it worthwhile. The script still produces some 'soft seams' (dark light areas on the baking silhouette) in the areas that overlap (this is why you should bake in order from least important angles to most important), but it's the best solution I've come up with so far. Before this, I spent hours and hours painting in missing areas and combining image maps (I made two or more because projection master was overbaking and composited them in 2D in photoshop). I also tried painting out areas and masking so that projection master would pick up only the areas I liked, but that was equally tedious to pick out areas that were unbaked perfectly (otherwise they the baked areas would get overbaked).

I wish that ZBrush would come up with a surface baker feature that bakes in the entire surface in one click without being limited to viewport resolutions and so forth.

Another feature that could really make this script work much better for the time being is if there's a curve we could edit for 3DCopy's A.I. feature or a simple threshold slider so that you can control how much to occlude polygons that are facing away from you. If 3DCopy could be configured to just copy polygons that are facing almost directly at you, you should be able to do multiple overlapping bakes without any problems at all. I think people would find this useful for all sorts of other reasons too, including texture master. Right now I think it picks up too many side-facing polygons, and that's the main reason this script currently produces those soft, dark/light regions on the edges of the baking.

Reactor
09-13-04, 09:04 PM
Now this looks great! Thanks for your hard work, custom_junk_mail.

aminuts
09-14-04, 10:27 PM
Wow this looks pretty damn cool....with some great possibilities....the idea machine is rolling already!!:D

Thanks for sharing this...I've been looking for or to do something very similar but couldn't quite figure out how to get rid of those overlap shadows!

Can't wait to test it out shortly!

Thanks again!!

TVeyes
09-15-04, 11:39 AM
Very nice results. Thanks for sharing. Glad to see you aboard the zscript ship:)

Arizona
09-22-04, 08:10 AM
David, the download link needs updated on your main page.

It's missing a folder.

It's http://www.davidikeda.com/zscripts/materialbakerv1.zip

rubyscooby
09-28-04, 10:13 PM
Great idea for a script but I used your script exactly as it said and got a bunch of textures but no one texture where all views are baked into one. I used GUVtiles for the UV mapping and the images just seem to be snapshots of each view. Is there a step I am missing? What do I need to do after the baking to get 1 image to use in an external renderer?
Thanks ruby

Arizona
09-30-04, 09:33 AM
It sometimes does that. Just redo it.

rubyscooby
09-30-04, 10:25 AM
Does it everytime.... I have tried and tried....sniff...

aminuts
09-30-04, 10:15 PM
At the end of the script it tells you to do something...hahaha I just forgot what it is....something about going to texture and using grabfill or something like that.....if you don't do that you won't see your newly created baked texture.

I'm sorry I forget what it tells ya...but if you pay attention to that last little window when its done.....you will get your texture.

osamu
10-09-04, 04:16 PM
hi, but it seems this link doesen't work for me , I'm in china, anyone got another link?:) Thanks

lovecrafty
10-18-04, 08:55 PM
CJM,

I've tried your script with good success except I can't get it to make a texture other that 512x512. Whatever I make the document size, set the new texture creation parameters to, have as a selected texture, or set as image size in your script, when I start the script it says a new texture has been created and it's always this size. I would like to use your texture baking script to make a texture of 1024x1024 or 2048x2048 and then resize/manipulate it outside Zbrush. Anyway the 512x512 texture is something I can resize larger and start fixing, but what detail am I missing to make a larger texture in Material Baker?

Svengali
10-19-04, 04:05 AM
Lovecrafty,

I'll answer for Dave since I'm not sure how often he looks in here...



You can set the texture size by editing the Material_Baker.txt file.

Just look for the line at the beginning of the script that says:

[VarDef, textureSize][VarSet, textureSize, 512], and change the 512 value to whatever you want it to be.

(I haven't actually tried this, but it only makes sense that this is the controlling variable :) )

Sven

lovecrafty
10-19-04, 10:54 PM
Hey thanks Svengali!

I'd tried changing just about every "512" to a "2048" in both that and the user interface text file to no avail, but going back to the original files and chaging just that ?default variable? I get what I want. I guess the texture size selector is broken in the script? Oh well, a working solution is now documented!

:)

Jason Belec
10-25-04, 09:10 AM
I had this problem when trying it...

aminuts
10-25-04, 11:21 PM
Jason, do you remember what you had set when you got that....I had gotten it myself a while back when I first tried it and somehow fixed it or figured it out but I can't remember now what I did....maybe if ya posted.....what ya did leading up to it....and if best render or preview etc.......will jog my memory and maybe I could get lucky and actually help someone hahaa.

Jason Belec
10-26-04, 06:38 AM
Will run specific tests - but I believe I was following the instructions step-by-step!

Later Amigo!


TTTAAADDAAAA!!!!

OK

1) run this script - material_baker_interface.txt, when you hit start I get that error.

2) run this script - material_baker.txt, this seems to work.

Doesn't matter the model, material, etc., even if it's the first and only script.

Ideas??

aminuts
10-26-04, 10:02 AM
I never ran the interface one cuz I assumed it was a script called by the first one to perform certain routines. Looking at the files in a text editor seems to confirm that but..

I will try to play with it today and see if I get the same results.

custom_junk_mail
11-17-04, 06:41 AM
Hi all,

I'm sorry, I became very busy with school lately and I've been having to move to other sections of my project. I'll try to take a better look into some of these issues as soon as I can.

Oh and yes, the zscript to run is material_baker.txt. material_baker_interface.txt is just a file inserted from material_baker.txt. I'm sorry if I failed to make that clear earlier (I probably should have placed material_baker_interface.txt into a sub-directory or named it with a different extension).

Jason Belec
11-17-04, 04:39 PM
Don't worry we figured it out! Everyone is always so helpful here. :D

ZaBenkei
01-16-05, 08:57 AM
Hi!
First off, thank you for the cool script! It was exactly what I was waiting for!

I was wondering though if there's any way to smooth out UV coordinates (as in render displacement/normal map)?
If you use the script to bake a detailed, subdivisoned high poly model to use as a texutre for the lowest detail level mesh, the texture generated will of course correspond to the low-poly UV layout, e.g. look very angular.

Any ideas for a workaround?

frenzyfol
04-17-05, 12:06 AM
This script is great, but sometimes it refuses to render best
even though I've set it to best render..

Anyone have this problem?



more specifically I just got this error

Interface item cannot be found

Material : FlatColor
in...
[IPress, Material:Flatcolor]

I dont have Material flat colour applied, Ive tried a bunch of differnet materials..
This is weird because I had it working last night.


its as if my flat colour material has been corrupted...
reinstalling


Ok reinstalling did nothing.. I dont get the error anymore but it still wont render best...
4 hours of this now..



Finally fixed it...
I ended up editing both the script files so that anywhere there was a chance that best render was set to 0 i forced it to be set to 1.
To do this search for best and replace almost every 0 with a 1..


I also forced it to render at 2048 because the slider bar did nothing , it would always fall back to 512..
To do this just replace 512 with 2048...


Now it works beautifully. Thanks

aminuts
04-28-05, 10:42 PM
oops I missed this one....


yes, sometimes a little editing of the script is necessary to achieve desired. I think gamemaster thru it together pretty quick for his needs and shared it so for all you future folks....if it's not accomplishing what you need it to....

take a look at the script and change what ya need to.

Frenzyfol, since Gamemaster posted the source so to speak and you altered it, I am thinking it might be a good idea to upload your altered state, with info on what you changed...such as the canvas size....etc.

just that particulart .txt file......not all the others as folks would already have the other stuff....

this way maybe we can help each other make this a better script.

One of these days when I have some time, I plan on doing an improved version myself as I really do like this little utility.

Anyways, Thanks heaps for posting your findings....it will help future downloaders! Not many folks come back and offer their solutions for others so ya did a great thing!!!!

el-d
05-07-05, 09:03 AM
I've been trying the material baker and also don't get a single texture at the end.
Aminuts : I've looked for the message you mention but just get, baking complete.

I have also noticed that in the individual textures grabbed holes appear. Has anyone else seen this?

Any suggestions on baking the complete material/rgb to a single texture?

Cheers
El-d

aminuts
05-07-05, 09:46 AM
hi el-d,

it's been a while since I have had time to play with it. I will try to grab a minute this afternoon and see what happens and will alter the script for file size and best render too and try to upload it later today.

aminuts
05-07-05, 09:51 AM
hi,

I believe another message pops up right after you click for the baking complete....if I remember right it sometimes goes by quick...almost as if you double clicked.

I'll run it later and note what it tells ya do to because I can't remember anymore:rolleyes: .

el-d
05-08-05, 05:19 AM
Was going to watch REALLLY carefully to spot this message.......and now a day later for some reason , everytime I run the script it fails. It alters the render settings to fast , pausing until something is pressed and then the following pops up.

error.jpg

So, whats different? I rebooted my PC but other than that no changes have been made. Yetsreday it ran through creating the images from all angles but not the final image and now total failure.

Any ideas?

El-d

Aztec...soljA
05-08-05, 02:10 PM
My guess is that you changed something to the original Zscript, or that you misplaced an important part of the Zscript, maybe they're in different folders...
What I would recommend is to download the file again, hope it helps:D
good luck

el-d
05-09-05, 01:21 AM
I'll try that but nothing changed, no file moves , no edits etc .That's what really confused me.

Will redownload later and try again.

EL-d

el-d
05-09-05, 01:45 PM
Eureka!!

Well a fresh download fixed the error message but I still had the issue at the end whereby it wasn't baking the texture......until I hit the quit button which I hadn't done before. This then brings up the crop and fill message.

Might have to look at the script to see if it can be shifted to happen automatically. .... hopefully those years of bad coding will come in handy ;)

Thanks again for the help.


El-d

custom_junk_mail
05-17-05, 05:36 PM
Hi all,

I'm sorry I haven't been able to respond, but I'm glad everyone here is so helpful around here. I've been pretty detached from ZBrush at work lately and haven't had the chance to use it in a long time.

I've received a number of e-mails about the script not working for certain people. I'm afraid I have no idea what's up. This was my first attempt at ZScript and I just sort of hacked together a solution that worked for me with a bare minimal interface and open source so that other people might get some use out of it as well. The only good advice I can give is to try going through the source code and changing some things to suit your needs.

I think the script is more important in showing the need for an all-in-one surface baking solution in ZBrush, as its technique of dropping the model onto the canvas and baking itself is far from ideal. Most of the materials in ZBrush are at least slightly affected by the incidence angle of the camera, and this leads to inconsistencies when you bake piece by piece like this with the pieces rotated to face the camera. The inability to control the falloff rate of auto-intensity for 3d copy (referred to as 'fade' by project master) also makes it much harder to smooth and blend out these inconsistencies.

I just really want to see this feature in ZBrush, and judging by all the responses I've received from this little hack of a script, I imagine that quite a number of other people would like to see this as well. ZBrush already has a magnificent renderer to render unoccluded polygons facing you onto the screen, so it seems like it should naturally follow that it should be able use this type of output for all polygons in the scene and simply output the transformed pixels into a texture image with the associated uv coordinates. It would be ideal for exporting realtime environments and models where sophisticated shaders and indirect lighting are just too expensive to calculate on a frame-by-frame basis.

el-d
05-18-05, 01:44 AM
All those in favour say aye......Aye!


Totally agree with you customJM. As usefull as your script is, it does have the problems you pointed out. Maybe in Z3?

Roll on SigGraph.....surely that must be the launch..... oh for some more teasers to wet our appetites before the big (hopefully soon) launch ;)


EL-D

frenzyfol
05-22-05, 07:21 PM
Definately something that's needed natively in Zbrush. If they want to target game asset creation then baking is a must.

kilik
06-30-05, 05:33 AM
it's verry hard to use but i love it

greeze
09-03-05, 08:17 PM
I think I've been saving my first post for this utility. This is seriously amazing and should be a part of the Zbrush default toolset. It's invaluable for low-poly realtime game asset creation. I just did a quick run-through to test it out and I almost couldn't distinguish the low-poly model from the high-poly. A godsend, and I hope you consider maintaining it.

Thank you!

edonkey
09-04-05, 02:12 PM
Was going to watch REALLLY carefully to spot this message.......and now a day later for some reason , everytime I run the script it fails. It alters the render settings to fast , pausing until something is pressed and then the following pops up.

error.jpg

So, whats different? I rebooted my PC but other than that no changes have been made. Yetsreday it ran through creating the images from all angles but not the final image and now total failure.

Any ideas?

El-d you have to make that a polymesh 3d for that to work.

greeze
09-08-05, 04:59 AM
I noticed that this script wasn't doing a Best Render when I had it selected, and it also wasn't retaining the texture size that I chose (kept doing 512 size, despite the slider value). The following change to the script fixed it for me:

Open material_baker.txt in a text editor.
Change lines 11 and 12 to the following:
[VarDef, textureSize, 512]
[VarDef, bestRender, 0]

(Remove the VarSet blocks).

Now Best Render should work, and the texture size should be correct when you change the slider.

Custom Junk Mail, I pray that you or someone else is maintaining this script, because it's a life-saver. For low-poly real-time game modelling, nothing tops it. Thanks once again.

frenzyfol
10-13-05, 01:08 AM
good job posting ur changes greeze.

Ill try those out next time I make a model..because I was getting exactly the same problems that you were


Thanks,
Adam

TC_Chang
11-15-05, 11:45 AM
truely awesome script! Just what I was looking for! Thanks so much!

:tu: :tu: :D

frenzyfol
06-14-07, 12:57 AM
Although I haven't got ZB3 yet it looks like this feature was unfortunately left out. At least that's what I can tell from the ZB3 documentation. That's a real pity, zb3 painting and materials + lighting captured to 2d texture would be extremely useful.

If someone has news to the contrary please post it here!

nicholasmarks
06-15-07, 10:09 PM
i agree...having this script updated would be awesome

frenzyfol
09-16-07, 09:18 PM
Someone has gone to the trouble of updating the script for zb3
Excellent work!

http://www.zbrushcentral.com/zbc/showthread.php?t=49966