Others How to bake AO maps for a Daz figure?

Zavijava_

Member
Oct 19, 2020
457
7,809
(Daz 4.14, Blender 2.79b)

I've been banging my head against this all day now... I have a Daz G8F figure I'm trying to bake AO maps for, to use in UE4. Daz seems to pretend to have a feature that could bake AO "Surfaces -> Shader Baker -> Bake Illumination?) but I can't get it to do anything at all. So I exported the mesh to Blender as an OBJ and tried to bake AO maps there. Every time, no matter what I do, all maps are completely black except the face:

(This isn't exactly the mesh I'm trying to use, this is a completely basic G8F loaded in Daz and exported immediately, with nothing else done to it)

shitfuck.png

This happens even if I split the mesh up into materials and render only the torso or other parts.

Every so often I try to use Blender for something, and every time I find it has the most convoluted, pointlessly obstructionist interface I have ever had the displeasure to work with. Has anyone done this and gotten it to work? Is there a different program I could pirate that would be easier to use?
 

MissFortune

I Was Once, Possibly, Maybe, Perhaps… A Harem King
Respected User
Game Developer
Aug 17, 2019
4,713
7,758
I don't think Daz or their figures use Ambient Occlusion at all. From what I understand of it, it's a bit like fake lighting in a map for biased renderers like 3DL. Iray works off of a semi-realistic lighting model from the get-go, so an AO map isn't necessary. That said, I don't work with other programs like Unity or UE, so that may change with that. Might want to wait for someone else to answer in that regard.

As for better/other programs to work with, have you maybe looked into Adobe Substance Designer/Painter? Might be worth a look depending on what you need.

is probably the best/easiest route, but I believe ZoneGFX has some of the newer versions.
 

mickydoo

Fudged it again.
Game Developer
Jan 5, 2018
2,446
3,547
Every so often I try to use Blender for something, and every time I find it has the most convoluted, pointlessly obstructionist interface I have ever had the displeasure to work with.
I feel your pain :D

I used to make them in 3ds max but not for a hundred years now so I know blender will do it, fucked if I can help you with that, however -

I use this
(its free)
to make bumps and normals, it bakes AO's but I have no idea if it is the same quality as blender would eventually yield.
 

Zavijava_

Member
Oct 19, 2020
457
7,809
I don't think Daz or their figures use Ambient Occlusion at all. From what I understand of it, it's a bit like fake lighting in a map for biased renderers like 3DL. Iray works off of a semi-realistic lighting model from the get-go, so an AO map isn't necessary. That said, I don't work with other programs like Unity or UE, so that may change with that. Might want to wait for someone else to answer in that regard.

As for better/other programs to work with, have you maybe looked into Adobe Substance Designer/Painter? Might be worth a look depending on what you need.

is probably the best/easiest route, but I believe ZoneGFX has some of the newer versions.
Yes, the UE4 materials I've made can make use of AO maps. I wasn't asking whether I really needed to do the thing, I was asking how to do the thing. :)

I'll try Substance Designer if Blender really doesn't pan out, but I might have solved it.

I feel your pain :D

I used to make them in 3ds max but not for a hundred years now so I know blender will do it, fucked if I can help you with that, however -

I use this
(its free)
to make bumps and normals, it bakes AO's but I have no idea if it is the same quality as blender would eventually yield.
Thanks for the link, but that program (It seems?) doesn't bake AO from the geometry of a mesh - it just fakes it based on a given image. Useful in some contexts, but not anything I can use for what I need.

---

I cracked the OBJ open in my editor of choice (Wings3D - it doesn't do much, but it doesn't try and stop you from doing anything either) And found what I think is the reason it doesn't work. These are the UV maps:

shitfuck.png

Everything that was rendered black in Blender is off the UV square and stashed in adjacent ones for some godforsaken reason (this is, at least, Daz's fault and not Blender's). This will work for most purposes since most renderers wrap UV coordinates, but Blender won't play well with it when drawing to a texture.

Now I just need to find a way to move the UVs over cleanly - keeping them in the same place in the square while moving them to the 0-1 square. I trust Blender to make this horrendously difficult for no reason.
 

shark_inna_hat

Active Member
Game Developer
Dec 25, 2018
697
2,666
Back in the day I used xNormal ( ) to bake AO maps (and normal, height, etc), it's ancient by now, but still good.

I'm guessing you will probably need to split your mesh from daz into individual pieces by texture or make new uvs. For baking textures you usually need to have each point of the surface of the mesh mapped into a unique coordinates on the uv - I think daz uses a separate texture for the face, one for the body, maybe another one for eyes, hair and each piece of clothing, and all of them map pretty much to the whole 0.0-1.0 range of the uvs (or get shifted by a integer). When the renderer cast a ray from a point on the uv it hits multiple points on the mesh - the body, the face, the hair, the shirt, the pants... in a best case scenario it will pick one (nearest, furthest, or random) in the worst case scenario it will do nothing. Both a bad and not what you want.

For a offline renderer multiple textures/materials is not a problem, it's much easier to work with, but for realtime - that's a big performance nope (modern GPU can quickly draw millions of polygons without any issue, but are still limited to a few hundred objects/batches) ... but it's okay if you only have like 5 characters in a scene and are willing to burn half of your frametime rendering just them.

Here's a different idea - for a mesh as dense as that coming from daz, you could just bake the AO into vertex color - but that might be more hassle than it's worth, depending on how you get your mesh into UE.

P.S. Why would one shift the uvs by a integer? It might not be as stupid as it seams - you can merge all the objects into one and assign all the textures to that merged object, then in a vertex shader check the uv offset and use that later in the fragment shader as a bitmask to draw the individual pieces using the right textures. Or if the textures are small enough to fit into a FBO, you can make a offscreen texture buffer that you'd render all the textures into and scale the uv's accordingly - you'd probably waste a bit of vram, but it might still be faster because you don't need to switch context for each individual object/texture.
 
  • Like
Reactions: Zavijava_

Zavijava_

Member
Oct 19, 2020
457
7,809
The AO bake itself worked fine, and I now have AO maps I can use for the foreseeable future.

You're right about the performance issues: having 6 waifus on screen in full outfits slows my FPS to about 30ish. Need to think about what to do about that. Unfortunately, the UVs in separate squares don't survive the transition to UE4 through the Daz plugin - they're all in the 0-1 square according to UE4. So I need to edit the UVs somehow in Daz, not sure if Daz can do that, or learn Diffeomorphic and go to UE4 properly through Blender (ew).

Just thinking out loud... I have 12 surfaces on her mesh at the moment, which I can cut down to 8 easily by being smarter about what I combine using Daz's geometry editor. The eyelashes either must be a separate material, or be converted to masked opacity rather than translucency which might look like crap. The rest are already material instances of a single master material.

Those 8 could be packed cleanly - torso kinda needs to be 4096x4096, arms/legs/face at 2048, eyes/gens/lashes/mouth at 1024 - into an 8192x4096 map. I usually shy away from using 8192 maps, but maybe that's an outdated instinct. Can most mid-range hardware these days handle textures of that size?

But I think an even bigger issue is the outfits. I have two outfits I've imported so far, each consisting of several meshes attached to the body mesh so they can be turned on/off (which I'd like to be able to do). Each piece has its own material, naturally (one corset piece has 6 materials, and I'll probably just end up replacing it), and all the materials are instances of a single clothing master material. Without the outfits, but with the same 6 ladies on screen, I get about 55-60 FPS - so this cost is even worse than the performance hit from the body mesh, and it didn't improve after I made LODs and disabled the boob physics.

There must be a solution here, since many games have exactly this kind of modularity and they don't start chugging along as soon as 6 NPCs are on screen. ¯\_(ツ)_/¯
 

Synx

Member
Jul 30, 2018
488
468
You're right about the performance issues: having 6 waifus on screen in full outfits slows my FPS to about 30ish. Need to think about what to do about that. Unfortunately, the UVs in separate squares don't survive the transition to UE4 through the Daz plugin - they're all in the 0-1 square according to UE4. So I need to edit the UVs somehow in Daz, not sure if Daz can do that, or learn Diffeomorphic and go to UE4 properly through Blender (ew).

Just thinking out loud... I have 12 surfaces on her mesh at the moment, which I can cut down to 8 easily by being smarter about what I combine using Daz's geometry editor. The eyelashes either must be a separate material, or be converted to masked opacity rather than translucency which might look like crap. The rest are already material instances of a single master material.

Those 8 could be packed cleanly - torso kinda needs to be 4096x4096, arms/legs/face at 2048, eyes/gens/lashes/mouth at 1024 - into an 8192x4096 map. I usually shy away from using 8192 maps, but maybe that's an outdated instinct. Can most mid-range hardware these days handle textures of that size?

But I think an even bigger issue is the outfits. I have two outfits I've imported so far, each consisting of several meshes attached to the body mesh so they can be turned on/off (which I'd like to be able to do). Each piece has its own material, naturally (one corset piece has 6 materials, and I'll probably just end up replacing it), and all the materials are instances of a single clothing master material. Without the outfits, but with the same 6 ladies on screen, I get about 55-60 FPS - so this cost is even worse than the performance hit from the body mesh, and it didn't improve after I made LODs and disabled the boob physics.

There must be a solution here, since many games have exactly this kind of modularity and they don't start chugging along as soon as 6 NPCs are on screen. ¯\_(ツ)_/¯
Well 3D games don't use 8+ textures for each model. Most of them use two max: 1 for the head if close ups is required, and 1 for everything ells. Body under clothing is often removed as well to make it more light weight. DAZ assets aren't really suited for 3D games because of this reason. For 3D games they are unnecessary detailed.

Anyway for maybe the future the UVs spaced out over multiple rows is called UDIM texturing. It allow you to use 1 material with multiple textures. So instead of a separate material for face,body,arms,legs,etc. You just have 1 material, that automatically assigns the right texture to the right UV.

I don't know if UE supports UDIM texturing, but if it does you don't need to change the UVs. You properly only need to rename your textures so they are all called the same (like base color instead of base color-face), and end them with 1001, 1002, etc. I think. (Don't know if all 4 numbers are needed, I only know if you export UDIM textures from substance painting it names them like that).

Blender supports UDIM texturing as well. I think if you change the baking texture from single to UDIM tiles you should be able to bake it without the need to move your UVs.
 

Zavijava_

Member
Oct 19, 2020
457
7,809
I enabled virtual textures in my UE4 project and can see the UVs - unfortunately, the eyelashes and genitalia UVs are overlapping the face in the UDIM 1001 square. So I do need to change the UVs, unless I just leave those in their own material slot. But as bad as the base model is, the outfits are far worse:

Nothing in the scene (only the MC and environment): 130ish FPS, 8 ms per frame
50 naked ladies: 21ish FPS, 46 ms per frame
50 ladies with outfit 1: <5 FPS, 211 ms per frame (+165, >4x as costly as the base model)
50 ladies with outfit 2: 4 FPS, 256 ms per frame (+210, >5x as costly as the base model)

I've read about merging skeletal meshes into one, which I'll have to crack open the engine and write code to do (Ugh, setting up VS to compile UE4 again) but can be done at runtime for any combination of clothing. That would (ideally) also mean unifying clothes materials into another set of virtual textures for each one, which again means editing their UVs from Daz somehow. I also read that it loses morphs, which... I'm not actually sure would be a problem for me. I don't really have a goal here, I'm just kinda seeing what I can get done with UE4.
 

shark_inna_hat

Active Member
Game Developer
Dec 25, 2018
697
2,666
With a performance drop like that - I don't think batching is the bottleneck (unless outfit 2 is made out of 100 pieces), it might be animations - that's a lot of matrix multiplication (vertex x weight x matrix per joint/bone). Check if you get the same performance drop using static meshes and if it's an order of magnitude faster - see if there's any built-in hardware skinning in UE, cause implementing that yourself is a pain (tricky part is sending all the matrices to the vertex shader in an efficient way).
 

Zavijava_

Member
Oct 19, 2020
457
7,809
Quick test shows that with 50 static meshes of the nude model, I get ~36ms per frame, so the animations are costing about 10, the model itself costing about 30ish... definitely not an order of magnitude faster. Will combine the materials I can, excluding gens and eyelashes, so the mesh is 3 materials instead of 12 and benchmark again (in a bit, gtg for the moment).

Then I'll see if tweaking the material helps, but I don't think it will. For one, it's not overly complicated (I've only started making it) and seems pretty green in the shader complexity view. And secondly, the problem doesn't get any worse the closer I am to them (meaning the skin takes up more pixels on the screen) - it seems directly related to how many models are being drawn.

Part of the issue is that I'm devving on a 1070 that was a budget buy a few years ago, and an I5 2500K that's over a decade old. (But tbh I kind of like it that way - I don't want to dev on some uber Bitcoin rig, only to realize too late that nobody else could run what I make)
 

Domiek

In a Scent
Donor
Game Developer
Jun 19, 2018
1,915
9,805
(Daz 4.14, Blender 2.79b)

I've been banging my head against this all day now... I have a Daz G8F figure I'm trying to bake AO maps for, to use in UE4. Daz seems to pretend to have a feature that could bake AO "Surfaces -> Shader Baker -> Bake Illumination?) but I can't get it to do anything at all. So I exported the mesh to Blender as an OBJ and tried to bake AO maps there. Every time, no matter what I do, all maps are completely black except the face:

(This isn't exactly the mesh I'm trying to use, this is a completely basic G8F loaded in Daz and exported immediately, with nothing else done to it)

View attachment 1910228

This happens even if I split the mesh up into materials and render only the torso or other parts.

Every so often I try to use Blender for something, and every time I find it has the most convoluted, pointlessly obstructionist interface I have ever had the displeasure to work with. Has anyone done this and gotten it to work? Is there a different program I could pirate that would be easier to use?

Any specific reason why you're using blender 2.79? Any version before 2.8 has an interface straight from Satan's asshole.

You should be able to quickly bake a map using an AO node + color ramp in the newer versions.

If you're going the pirate route, substance painter can easily achieve the results you're looking for as well.
 

Zavijava_

Member
Oct 19, 2020
457
7,809
Just momentum really, I've baked AO for stuff using 2.79 before. And honestly the new stuff is probably still bad, but differently bad so I'd have to learn it all again.

Case in point, I have no clue what "nodes" you're talking about - in 2.79 as long as I have materials with textures on them (which I do after import) I just pick AO in the "bake" settings in the render tab, enable AO and fiddle with the samples in the world tab, click "bake" and we're done. It's esoteric as all fuck but given that I already know how to do it, it's pretty simple.

[EDIT] Taking the base mesh from 12 surfaces down to 3 (a UDIM material for most of the skin, and the genitals and eyelashes material since they share the 0-1 square) only saves a small bit of time - rendering 50 meshes with animations goes from 46 ms per frame down to 40. (Reducing it further to 1 material has no noticeable impact.) I'm less confident now that it's worth the hassle of figuring out how to fix the UVs so I can UDIM everything on every mesh.

[EDIT] lol I'm stupiiiid! ALL the stress testing I've done has happened with a few stationary lights in the scene with shadow casting enabled, which wrecked the performance. I noticed this when I booted up a fresh project, put 50 of the default UE4 mannequin in it, and it was way faster than 50 of the default mannequin in my project. So.

Nothing except the MC: 6.5 ms
50 default mannequins: 17 ms (the same as with the empty project)
50 nude waifus (12 materials): 25 ms
50 mostly-merged waifus (3 materials): 19.5 ms
50 fully-merged waifus (1 material): 20.5 ms (more? huh?)
50 mostly-merged with outfit 1: 83 ms
50 mostly-merged with outfit 2: 96 ms (oof)

Definitely think the next thing is to fire up VS again and get mesh merging working, because that seems to be the big bottleneck now. Also good info to know for picking DAZ outfits in terms of how well they'll work in UE4.

[EDIT] For posterity: Here's how you edit the UVs: Hide everything but the mesh you want to edit (in my case, the figure, including eyelashes and Dicktator merged with "merge fitted figure(s) geometry" in Daz 4.10). Make sure the mesh is in base resolution. Export to OBJ. Import to Blender with "Keep vert order". Fiddle with the UVs, export to another OBJ, again making sure "Keep vertex order" is selected. In Daz, on the original merged mesh, Edit -> Figure -> Geometry -> Load UV Set and pick the new OBJ exported from Blender. If all goes well, you can now pick the new UVs in the surfaces tab. Having an attached mesh (like the eyelashes normally are) or trying to change the UV seams in Blender can muck this up!
 
Last edited: