Layered Shader [Update]


This post is in addition to my Layering Shaders with Mental Ray post and the focus of that was the mib_color_mix node. A thread on SimplyMaya reminded me that I needed to update this thing.

I found that plugging bare textures into mib_color_mix slots results in weirdo alpha channels in the rendered image, like a strange masking effect on the shader.

This confused me for a while, it seems that Mental Ray uses the top most layer on the mib_color_mix to generate the alpha channel, which in this case is a simple fractal texture. It ignored the fact that there are solid SSS and mia_material shaders beneath it.

I needed to have my fractal spit out a solid alpha, and this is where the "alpha offset" attribute comes into play.



Alpha offset allows me to add black or white value to my texture's alpha in a uniform manner. I set the value to 1. The rendered image will look the same but my little torus will be solid in my alpha mask now because my fractal's alpha is all white.



And of course a value of -1 will have my fractal not even show up in the alpha channel of my render, since since its now black.

Commentor JJJenkins was having problems with alpha offset affecting his color channel and these are the results of my tests.  Forgive my texture, it's the result of 10 seconds in Photoshop lol.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

12 comments:

  1. Dont you get jagged, pixelated edges when setting the alpha offset to 1?

    ReplyDelete
  2. Actually, no I don't, and I have no clue what could be giving you those results. Strange :s

    ReplyDelete
  3. Awesome post. I have run into a problem that I can't seem to figure out, though. What if, instead of a procedural tex, you use a file tex instead. The same problem happens: black hole cut in alpha by top layer. However, if you change the alpha offset in the file tex you are using for your alpha it changes the color channels in addition to the alpha. Have you any idea how to fix this? I've been experimenting and have come up with nothing that works as of yet. Thanks so much!

    ReplyDelete
  4. Actually I tried to recreate that and I couldn't, cranking up the alpha offset to 1 solved the issue even with a file texture and it didn't cause any changes to the color.

    ReplyDelete
  5. Hmmm...maybe I did something wrong. You are talking about the alpha offset on the actual file texture node you are using to mask the top most shader in the mib_color_mix, correct? Which blend mode are you using? That may have something to do with it. I am using the blend mode, 'mix'. Is that the same one you are using?

    ReplyDelete
  6. Yep. I tried "mix", I even used the default color mix instead of the new one I made by following David's MR phenomenon tut on his blog. I'm adding the images of my test to the post, I still can't see any differences in color if I change the alpha offset.

    ReplyDelete
  7. Hello, thanks a lot for trying to help me figure out what's going on here. After you posted the last pics of your workflow that helped me to figure out some discrepancies as to how we are working. I was hoping maybe you could re-create my process and see if the alpha offset still works for you. Our workflows differ slightly, and that may be where the problem lies. Ok, here we go: First, I am attempting to layer two different materials together, not just a texture over top of a material. But for simplicities sake, lets just try and layer one regular maya lambert over another maya lambert. My first lambert has no file textures plugged into it. It's just using color from the maya swatch. My second lambert does have a file texture plugged into the color swatch, BUT I have no transparency information in that color texture. It's just a regular old jpeg file. That's it for the two lamberts to layer. Next thing I do is make a seperate file texture that holds the transparency information for my second material that I want to layer over the first. It's just a black and white jpeg file. I load that into maya and make sure to check 'alpha is luminence' in the file texture node right under 'alpha offset.' I take this file and plug it into the 'Weight 1' slot of the mib_color_mix node. I take the two lamberts we created earlier and plug them into Color 0 and Color 1. Color 0 holds the lambert with no file texture node and Color 1 holds the lambert WITH the file texture node. I set 'Mode 1' to mix. If I render at this point, it looks perfect. The two materials layer one over the next with no problem. The only issue is the alpha channel as we already know. At this point I go into the file texture node I have plugged into 'Weight 1' and set it's alpha offset to 1.0. After I do this things go bonkers in the color channels. Maybe I am using the mib_color_mix in an incorrect way be using a file containing transparency info plugged into 'Weight 1'? I'm not sure. Maybe you could try out this approach and see if you run into any problems? That would be awesome if so because I would love to get this issue ironed out. Thanks for all your help so far. Really appreciate it. :)

    ReplyDelete
  8. I tried that, and I couldn't even get an alpha channel contribution from the object, when I used lamberts. Then I switched out the two lamberts for mia_materials and I didn't even have to change the alpha offset, I got a solid alpha from it right out the gate.

    colorMixAlpha

    ReplyDelete
  9. I wonder if there is anyway to get an alpha contribution layering standard maya materials? I tried the mia_material_x over the mia_material_x and got a solid alpha as well. But then I tried a maya lambert over the mia_material_x and got the same alpha problem. Changing the alpha offset to 1 on the transparency map plugged into the Weight 1 resulted in the funky colors phenomenon I was reffering to earlier. Not only that, but say you have other objects in your scene BEHIND the material using the mib_color_mix. The alpha channel from the topmost layer will punch a hole right through ALL of them...not just your object it's applied to. For instance I have a beer bottle I made sitting inside of a room. I used mib_color_mix to layer the label on top of the transparent, refractive bottle. The label is a blinn, the bottle is mia_material_x. The alpha from the label cut a hole through the room and all other objects. It's impossible to split a scene up into layers for post compositing with behavior like this. Maybe using a mia_material_x instead of the blinn would fix the problem. I'll try that, but it would be cool to have maya shaders work correctly with the node as well.

    ReplyDelete
  10. Actually David did a post on a solution.
    p_color_plus_alpha

    ReplyDelete
  11. Nice! I can't believe I missed that. I've skipped over that post quite a few times looking for other things. Thanks a lot for the heads up. Very cool!

    ReplyDelete
  12. Just wanted to throw out that this didn't work for me but it did put me on the right track. What I ended up doing was adding an extra layer on top (highest number). Making that layer white and setting its blend mode to replace alpha.

    ReplyDelete

Leave a message at the beep...wait for it...:p