ZBrushCentral

How to calculate alpha gain and alpha offset in maya when using disp.maps from Zbrush

Here’s a way to calculate alpha gain and alpha offset at least for mental ray for Maya… It should work with most packages though at least the way to calc alpha offset

Alpha gain = (Alpha Depth Factor from zbrush * 10) * 2

Alpha offset= the negative (the inverse?) of half the alpha gain.

Example:
Zbrush Alpha Depth Factor = 0.834
Maya alpha gain = 16.68
Maya alpha offset = -8.34

An alternative to using this method is using the set range node and the multiply divide node:

Don’t change anything on the file node.
Connect the out alpha from the file node to the value.x in the set range node
Use these settings for the set range node
Min: -1
Max: 1
Old min: 0
Old max: 1

Connect the outvalue.x from the set range to input1.x on the multiply divide node
Connect the outvalue.x from the multiply divide node to your displacement.

Now instead of changing the alpha gain when we want to scale the displacement, change input2.x value on the multiply divide node.

These methods will give you the exact same result but the one using set range is a bit less math.

for more info go here

seems that that link only works when it wants to :slight_smile:
heres the original post in full:

Ok no more guessing… Here’s a way to calculate alpha gain and alpha offset at least for mental ray for Maya… It should work with most packages though :slight_smile: at least the way to calc alpha offset

Quick fix:
If you don’t need to understand what the problem is and how the solution works here’s the values in short

Alpha gain: (Alpha Depth Factor from zbrush * 10) * 2

Alpha offset: the negative (the inverse?) of half the alpha gain.

Example:
Zbrush Alpha Depth Factor = 0.834
Maya alpha gain = 16.68
Maya alpha offset = -8.34

An alternative to using this method is using the set range node and the multiply divide node.

Don’t change anything on the file node.
Connect the out alpha from the file node to the value x in the set range node
Use these settings for the set range node

Min: -1
Max: 1
Old min: 0
Old max: 1

Connect the outvalue.X from the set range to input1.x on the multiply divide node
Connect the outvalue.x from the multiply divide node to your displacement.

Now instead of changing the alpha gain when we want to scale the displacement, change input2.x value on the multiply divide node.

These methods will give you the exact same result but the one using set range is a bit less math.

Now for the ppl who just need to know (like me) :slight_smile:

The reason ppl have been getting “bloated” result is because the midpoint or the “no displacement” color of maps made by zbrush is 0,5 or gray instead of 0 or black

THIS HOWEVER IS NOT A BAD THING

Why? Because when modeling in zbrush you are quite likely to push your model inwards, creating negative displacement. If we wanted to get these negative displacements into a map while at the same time having the no displacement color at 0 (black) we would have to have negative color values. This is not supported by any image format I know of. This is why the makers of zbrush have decided to set the zero displacement color to 0.5 or gray.

So what to do? Well you could split the map in one negative and one positive displacement map by using Photoshop to save out al the values above 0.5 to one map and the ones below 0.5 to another.

How ever this poses a new problem and that’s how to get to displacement maps onto a single object. I didn’t find any way to do this in Maya so another way had to be found.

Something that is less that obvious in Maya (and mental ray) is that the displacement node actually can displace negatively. If you want to see for your self add a displacement material without any texture and set the displacement to a negative value. The whole object will shrink.

So what we need to do is subtract half of the values that we got from the map, simple enough just set the alpha offset to -0.5 and you’re done right? Well kinda.

The way alpha gain and alpha offset works is the value from the map is multiplied by the alpha gain and then added to the alpha offset.

Example:
If the value from the map is 0.5,
The AG is 1
And AO is -0.5
The out value would be 0.

This is what we want. Gray in the map is now zero displacement. But what happens if we change the alpha gain?

0.5 from the map
AG is 2
AO is -0.5

(0.5 * 2) - 0.5 = 0.5

Woops… Now gray in the map means a displacement of 0.5. When using AG of 2 we must subtract another 0.5 using the Alpha offset. So for gray to be zero displacement we have to set the alpha offset to -1

This means that the relationship between AO and AG should be
Alpha offset = -(alpha gain/2)

Now we have one more problem. Let’s say we have these settings
Value from map: 1
AG: 1
AO: -0.5

The out value will be 0.5 not 1. To fix this we double the AG and change the AO accordingly.
So:

AG: 2
AO: -1

Now we’ll get an out value of 1 when the value from the map is 1, we’ll get an out value of 0 when the map says 0.5 and we’ll get an out value of -1 when the map says 0.

And that’s all folks :wink:

Do you always have to manually write down what the Alpha Gain value is? Is there some way to clamp that value in Zbrush first, or include that data with the file? Kinda not fun when pulling many textures into Maya, each one is a different value.

I name my displacement map files like this:

Head_disp_3p111_1.tif
Arm_disp_p845_2.tif

Which means to me <which part_what for_displacement amount(3 point 111)_version.file extension

Kind of contrived, but it makes sense to me…the point is - put it in the file name!

Sounds great. However, I’m doing this stuff for a next-gen game system, and here’s my real problem.

I have to give the model to the programmers and they need to know how much to displace each mesh. It sounds really cumbersome to have to give them a NEW displacement intensity number each time for each texture. And, since I want to blend between these (simulating animating folds, for example, by pointing to two shirt textures that cross-face) then I’d be animating between different disp values as well. Grr.

Is there a way to clamp the displacement values so that I’d always be using a consistent value? I mean, any time I go in to repaint/sculpt some of the folds on the ZBrush model and spit out an updated disp map, the Alpha Depth value would change, so I’d constantly be having to write that info down and passing it along to the programmers.

I don’t want to do normal maps. I am doing a layered shader with a high frequency bump applied over the displacement, and the programmers would prefer to have all these images as greyscale.

Do you know if it would be possible to save the displacement map texture as a floating point texture rather than a 16 bit texture, so that I wouldn’t need to scale the displacement values. Otherwise it’s very awkward to write down the scale every time you save a 16 bit texture to bring it back into MAYA. It would also help the programmers I work with, since the floating point info would be included in the file, and I wouldn’t have to keep track of it in the filename as you suggest.

Is there an SDK that we could have access to?

this was also a question someone asked at a sony demo of zbrush. i would love to know the answer to this too.

is there a way to clamp the distance zbrush looks out to for the displacement map so that black is always say 3 units in? the obivious issue is defining what 3 units is and how that relates to different models that are brought into zbrush at different times and then what happens when you are scalling your creatures and such. How would zbrush figure out the world scale matrix (using fancy words i dont totally understand here) from model to model?

in fact, how does zbrush define the alpha depth factor?

r

<in fact, how does zbrush define the alpha depth factor?>

That’s what my programmer was asking me. Obviously ZBRUSH knows what that alpha depth value is. He was stating that if we could save off not just a TIF but a floating point tif, we could encode that value in the file. Then our game engine would know to reproduce the displaced art, and we wouldn’t need to put those values in by hand.

So, just to ask again in case anyone knows, is there an SDK available for programmers if they wanted to write plugins to do just this kind of stuff?

there still hiring someone to help with the sdk development so i would assume its not done yet.

r

Saving displacement maps in the TIFF floating-point format is planned for the next free-update.

very cool. thanks aurick! so as ArtisanCG mentioned does this mean we do away with alpha depth factor in say mental ray as well?

r

It’s nice that it will be updated in the upcoming releases of Zbrush.

Currently you can probably script Zbrush to put it in the file name, then have a script put it in another app say maya which can then run a plugin or MEL script - sounds a lot but it is pretty easy and quick after the first run.

I use the automated interface of OSX for stuff like this. I can grab files, put in a particular place, open on a certain machine under a certain app with user preferred settings, etc…

I can’t help the Winows users, but I don’t see why a few gifted code monkies couldn’t figure something out.

osx does that? cool. whats getting me is how these things can fit into a sony or dreamworks pipeline? no doubt they can write their own scripts for these things but then they operate in linux and there is no linux version of zbrush yet.

r

Yeah OSX is cool. Most people just haven’t bothered to really look at it for the production pluses, well except for Post houses. But even then, they still use them as dumb terminals. OSX also interfaces with Windows and Linux very well. Guaranteed. :smiley: My renderfarm is Linux using the G5 processors and I like having final rendered scenes come back to my desktop in near real-time, with lights and shadows and pretty colours without having to do anything once I decide the file is ready. And it fits into very small, quiet cool footprint.

Linux is ok for propeller heads, I use Bash all the time under UNIX as well, not much different on Linux. It’s just that Linux never really delivered all it promised, I prefer UNIX anyway - a lot more stuff available.

You really do have to have some knowledge how to get from point A to point B, but it is getting easier. If you want to stray from the ‘one package does it all’ model, that is.

The real unglorious joys of the business.

Man …this is so simple and yet so smart not to forget the values…u just write the numbers on the name…gosh…thanks friend…

Hi , I’m a beginner with this program ( I 'm a Maya’s user) . I’m learning to use
displacement map from Z brush to Maya and I wanted to say thank you for this post. But where can I find the: Zbrush Alpha Depth Factor ?
Aloha,Stefano.

Hi Stefano -

After you create a displacement map, you can find the map that it created in the Alpha palette. When you select the alpha , the depth factor is written in the “Alpha Depth Factor” near the bottom (of the alpha palette).

Hope it helps

Many thanks , Meier and I’m very glad for your reply. I’m waiting for your dvd "ZBrush Production Pipeline " . I have just bought it . I 'm looking forward to seeing it .
Aloha,Stefano.

A big thank to all :slight_smile:
It works perfecly :wink:

Can someone do me a favor and post a description of how floating point maps will allow you to not have to rescale values? This concept confuses me and I realy want to grasp it. I thought we rescaled the values in mental ray to adjust for the 50% gray as no displacement… Am I thinking of two different “scaling” operations here, the value offset as opposed to the scaling by alpha gain (in mental ray) to adjust for displacement “height”

As I understand if you use a floating point map you dont need to adjust the gain the render will always know how much to displace… is this correct? How does this work.

Thanks : )