Jump to content

Shader with masking


jim c

Recommended Posts

I'm trying to make a shader that will allow the user to specify a texture with multiple colors (say 2), that acts as a mask to determine which "layer" to use to shade the output color.

Lets say layer 1 has a color called lc1, and layer 2 has a color called lc2.

Each layer is itself a VOP network with a complete set of settings. So if you have 2 layers, and if the color from the mask texture is equal to lc1, then you execute layer 1's VOP network, if it's equal to lc2, then you execute layer 2's VOP network.

I got this to sort of work, but to my surprise when it renders it looks spotty...

Adjusting the pixel samples in the Mantra samples tab makes no difference, so I assume the problem is elsewhere.

post-4235-0-02667000-1351097423_thumb.jp

Link to comment
Share on other sites

You would have to attach your scene for investigation, but generally speaking setup you described should be performed with blending different layers (Mix VOP for example), not selecting them inside "if-then" statements. Is it the case of your shader?

hth,

skk.

ps if (value == 1) is very uncertain statement in computer science and specially in rendering context it behaves badly. Renderer constantly computes the integrals of different values, for which it needs to operate on continuous functions. For shaders it means that to make a proper computation mantra for some cases performs both branches of your shaders, what will be disallowed by if-then statement.

Edited by SYmek
Link to comment
Share on other sites

My thought was that you have an image that represents the various sections on your model. So you have a sphere with you material mask. The mask looks like this:

post-4235-0-51634900-1351109064_thumb.jp

It's made of two prefined colors, blue (0,0,1) and green(0,1,0).

If you use a texture() vop, for any diven uv coord, is it not the case that you will get either one of these colors? Then you can say, for that given point, if you match to color1, go do this, if you match to color 2, then do the other?

Attached is the hip file with the mask image and the shader in /shop/MultiMaterialUberShader

The thought process was this - I always want to at least process layer1. If layer 2 is enabled, then process that using the layer mask image to determine what goes where, if not, then use the color from layer 1. This would be repeated for up to 4 layers.

While I suppose this could be done in post, it's more complicated to set up, and I almost certain it would take longer. I can't see any reason why this wouldn't work.

test.zip

Link to comment
Share on other sites

A black and white mask (zero to one) would be easier to work with and plug that into a mix VOP to switch between the two shaders. Though this is generally not a good way to handle multiple shaders. In production this is typically handled using groups in SOP and then applying materials to different groups with the material SOP. Using the material SOP is much more scalable and flexible than trying to use maps or other methods.

http://www.sidefx.com/docs/houdini12.1/nodes/sop/material

Link to comment
Share on other sites

Thanks! I thought the problem might be in the comparison stuff but I wasn't sure, forgot to try the epsilon trick.

@lukeiamyourfather

The B&W mask is a good idea to, thanks! I'm aware of using the material and group SOP for this. However, in my experience, this doesn't work if you have a complex model that doesn't break down into convenient edge loops that follow the material changes. Say for example a complex organic/character model, where the material changes don't follow the geometry. You could retopo it, but that might take a lot of time, make the mesh a lot more complex, and possibly alter the way it deforms if it's animated. It seems to me that this is much easier to deal with. You can generate precise polygroups in a tool like ZBrush, export the colors from there, and boom, Bob's your uncle, you're all set to go. Keep in mind, I can generate the polygroups in ZB at a mesh resolution in the 10s of millions (and with HD geo, potentially in the billions).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...