Marschner shader Per-particle Channel question, etc

Hi! I’ve been experimenting with the Marschner Hair shader applied to a PRT Hair and I think I’ve got a pretty good handle on it, except for one thing. On the left hand side of each parameter there is a corresponding “Per-particle []Channel” button. It says that when it’s checked that particular channel “will be allocated in memory, initialized to the default value, and can be set and modified by a KCM”. I don’t really understand what this means, but I assume that it can be controlled by a MagmaFlow. Is that right? I have been looking for a way to do this, but haven’t been able to figure it out. What would a MagmaFlow that controlled the Marschner Per-particle [SpecularLevel] Channel, for example, look like?

BTW- Did you know that the default Specular Shift and Specular 2 Shift values are exactly opposite according to the Marschner model? The model says that the Specular highlight should be closer to the hair root, and the Specular 2 highlight should be toward the tip. But the default values for where those highlights land, which are controlled by the Specular and Specular2 Shifts, are flipped. Just thought you would like to know.

Also, I would love to be able to use an environment map (HDRI) to light the particle hair and have it take the place of the scene lights. But all I seem to be able to get is a blasted out “tinsel-y” look. Is there a way to use it to light the hair and get a nice, soft look that is natural and preserves the Marschner Hair shader qualities?

Any help is greatly appreciated. Thanks!

This is exactly what it does.
In general, Krakatoa only allocates a channel per particle if the channel is needed at render time. For example, the Position, Color and Density of a particle are always allocated as these values are absolutely necessary to render the particle. But the Velocity channel is only allocated if Motion Blur is enabled, the Normal channel is allocated if Reflections or the phase function (shader) require it, Emission and Absorption are allocated if the user explicitly enabled them in the UI, and so on.
Similarly, the per-particle shader-related channels are only allocated if the user explicitly enabled them. Otherwise, a single global value is used for every particle (as specified in the shader’s UI) without allocating any memory for it. With millions (or billions) of particles, a single additional channel can cost a lot. So you have to decide which properties you really want to control per particle.
Once the checkbox is checked, a channel will be allocated, and its initial value will be set to the same global value that would normally be used if you did not check it. So if you do not specify a unique per-particle value, the render output will be the same with or without the checkbox checked, just the memory usage will be different.
What the MagmaFlow would look like is up to you though - the only thing that is absolutely required is the Output node to be set to the name of the channel you want to affect. If you connect an InputValue to it, it will do exactly the same as changing the value via the UI. But if you plug in some computation that produces a different value for every particle (say, a gradient based on the particle’s distance from the root divided by the length of the hair), the result would be obvious.
This is no different than setting other channels like Color, Density etc. via Magma, it just tweaks the shading parameters per particle…

Thanks for the report!

This is not possible in the current version of Krakatoa since it does not support any lights beyond Omni, Spot and Direct, but it has been on a Wish list for a while. We will see what will happen in the future…

Hi Bobo. Thanks for the speedy reply!

As an experiment, I set all the parameters of the Marschner shader to 0, except for the Diffuse Component, which was set to 50 so that the specular effect would show up better. I then checked the Per-Particle[Specular2Level] Channel to active, added a KCM, and added an Output node. I changed the name of the Output node to Specular2Level, since I didn’t see an option for it in the Standard Channel Names column. I then added an InputValue: Float and set it to 0 to get my first control render. It came out as expected looking like a darker version of the Isotropic shader. Next, I set the InputValue:Float to 1 and re-rendered. Ta-dah!! I’m finally getting a result!

But…

Even though it seems to work,the Float values don’t correspond to the shader values, so it looks like I will have to figure out how the two translate with each other. But more importantly, I’m getting an Arity mismatch error because of the renaming of the Output node. It says “Magma Channel “Specular2Level” Is Not The Expected Type”, and the node turns red. It still seems to work, though.

Is there something I’m missing?

Oops! I think I figured it out, actually…
I just changed the Arity value to 1 in the Output window and the error went away.

As always, Thanks for your help, Bobo! :slight_smile:

Possibly.

When you rename the Specular2Level channel, you have to also change its Arity from 3 to 1.
On my system running Krakatoa MX 2.3.1, I created an Output (defaulted to Color), connected a Float of 1.0, renamed the output channel to Specular2Level (it stayed Arity 3 and caused an error), then I changed it to Arity 1 and the error disappeared.

In some earlier builds of Krakatoa, there were some issues with setting the Arity. Let me know if you are unable to change it.
You could also select a Float channel like Density, then rename. It might stay Arity 1.

SpecularLevel values in the UI are generally multiplied by 100.0 because we wanted to match the values the Max Standard Material uses. A SpecularLevel of 1.0 in Magma should match a SpecularLevel of 100.0 in the Shader settings. It sucks, but it is rather simple to calculate :slight_smile:

Thanks for confirming my fix! It seems to be working error free for now. But if I run into any issues, I’ll let you know.
:slight_smile: :slight_smile:

Well, I did run into a little problem after all…

My goal is to apply zebra stripes to the PRT Hair using a texture map, and apply the Specular Level with a different grayscale map using the Per-Particle[SpecularLevel]Channel switched on in the Marschner shader. I’ve got the color part down, thanks to your previous help :slight_smile:
But the Specular Level doesn’t seem to work. You can see the Flow I’m using here.

I’ve tried converting the Spec map to grayscale and tried different Arity values in the SpecularLevel Output, but I keep getting an error. I’m using a Standard Max shader with the color plugged into the Diffuse slot and the spec map plugged into the Specular Level slot. I don’t know if that makes much difference. And it’s applied to the geo.

I suspect that there needs to be something between the InputTexmap and the Output node, but I’m just guessing and even if that’s correct, I don’t know what to add.

Thanks for any help you can offer!


In the Texmap node, there is a list that switches between “Color”, “Mono” and “Perturb” (Bump) output. There is also a [C] sign underneath the thumbnail and next to the output socket of the node. That shows me the output is Color. It should read [M] for Mono. Then it should work because the output will be a Float Arity 1 and not a Vector (Float Arity 3).

Thanks, Bobo! That works just fine :slight_smile:

By the way, I’ve been compiling a list of the keyboard shortcuts for the Magma Editor. I’ve been trying to take your suggestion to learn them and they really do make life a lot easier! I’m sure that the list I’m including here is not definitive, but if a more comprehensive list doesn’t exist somewhere else, maybe this could be put somewhere on the board where others can add to it.

Anyway, just a thought.
MagmaFlow_keyboard_shortcuts.rtf (3.6 KB)

I used to have a few definitive lists, but they were compiled around V1.6.
Then we reworked Magma in 2.0 and some things changed, the ActiveType was added, more shortcuts were added.
In Stoke 2.0+Genome, further changes were made inspired by some development for the Krakatoa Maya Magma, and so on.
I should sit down and update those lists…

You will find a few of them here:
thinkboxsoftware.com/krak-pa … shortcuts/
If you want, you can post a list of those that have changed in 2.x, it will help me with the future updates :slight_smile:

Also note that in the newest versions of Magma, as we add new operators, the letters in the menus are assigned automatically according to some rules, so the list can mutate as we develop the tool further. In the very beginning (when those lists were compiled), the keyboard shortcuts were mostly hard-coded.

In Magma 2.x, you can even use multiple strokes to get to channel names, e.g. I>C>P creates Input Channel Position… I don’t know if it is necessary to collect and list those.

Thanks for the link. I will compare what I have with what is in the list you pointed me to and post the differences in a new thread.

I use the multiple key commands quite a lot. And since I’ve been dealing with hair lately, I’m getting pretty good at hitting the / on the Numpad to get a Divide node, I+C+I to make an InputChannel Distance node, and I+C+L to make an InputChannel HairLength node :slight_smile:

What I really wish is that there was a catalog/video series or something that covered all the Magma nodes in detail, explaining what they do, what their acceptable connections are, and maybe an example or two of them in action. I know it would be quite a challenge to put together something like that, but I think it would go a long way toward smoothing out the learning curve.

As always, thanks for all your help, Bobo! :slight_smile:

Right now this is all we have:
thinkboxsoftware.com/krak-magma-2-nodes/

Creating an example for every node would be a challenge though. If you have any questions about any of them, please post here.

Hi Bobo,

I’ve been fooling around with the Per-Particle Channels in the Marschner shader trying to get different effects. And to illustrate the issue I’ve run into, I’m using the same flow as in the pic I attached earlier, the one with the zebra stripes. However, I have since changed the Result Type on the Input Texmap node to Mono, like you suggested.

The grayscale image that I’m using as a mask for the SpecularLevel is very simple. The black areas have a 0 value in the image, and the white is at 255. One thing I’ve noticed is that the Float value being output by the InputTexturemap node seems to have a limited effect on the rendered result. In fact, after carefully scrutinizing various renders, I’ve found that the maximum 255 grayscale value in the texture map only translates to a Float value of 100. However, the range of the SpecularLevel in the Marschner shader goes from 0- 100,000. It seems that using the Float value obtained by the texture map can only get you to a maximum of 100, which is far short of the 100,000 range.

The Marschner shader parameters have various ranges: All the “Level” parameters have a range from 0- 100,000, the SpecularGlossiness and Specular2Glossiness go from 0- 1000, the SpecularShift and Specular2Shift go from -1 - 1, and the GlintSize and GlintGlossiness go from 0-360.

Considering the various ranges of these parameters, is there a way to create a flow that can create input values appropriate to the entirety of those ranges? I’m at my wits end trying to figure it out. If you can help, I would appreciate it very much.

Wait! I think I got it.

I just added a Multiply node between the InputTexmap and the SpecularLevel Output, and plugged an InputValue Float to the Left Value (or Right) of the Multiply node. The Float value 0.25 equals the default Marschner shader SpecularLevel value of 25. So it’s an easy bit of math to work out the corresponding values.

If you have a better way, or one that adds more functionality, I would love to see it!

I am so glad to see you are finding your way through Magma! :slight_smile:
That’s exactly what you are supposed to do!
The Ranges in the UI are somewhat arbitrary to allow the user to enter values that make sense, (e.g. -1 to 1), but in cases like Glossiness and Level, these values can be very high - the shading functions use the Glossiness to control the shape of the highlight which uses the Square of the Cosine of the angle - the higher the value, the sharper / smaller the highlight. The Level is a multiplier to boost the intensity of the sharp parts of the highlight, so it does not have a meaningful limit, but 3ds Max seems to be limiting it to 1000 in its UI which would be equivalent to 10.0 inside the Magma… You can use Magma to define values OUTSIDE of these ranges if you want to.

Thanks for the moral support, Bobo! Yes, I was pretty proud of myself :slight_smile: