jim c Posted October 24, 2012 Share Posted October 24, 2012 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. Quote Link to comment Share on other sites More sharing options...
lukeiamyourfather Posted October 24, 2012 Share Posted October 24, 2012 This seems like something that should happening in compositing using multiple image planes when rendering. Or using an attribute from the geometry and one shader that looks for that attribute. Not sure exactly how you're doing things now... Quote Link to comment Share on other sites More sharing options...
symek Posted October 24, 2012 Share Posted October 24, 2012 (edited) 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 October 24, 2012 by SYmek Quote Link to comment Share on other sites More sharing options...
jim c Posted October 24, 2012 Author Share Posted October 24, 2012 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: 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 Quote Link to comment Share on other sites More sharing options...
lukeiamyourfather Posted October 24, 2012 Share Posted October 24, 2012 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 Quote Link to comment Share on other sites More sharing options...
symek Posted October 24, 2012 Share Posted October 24, 2012 (edited) As I said, if (value == 1) is an uncertain statement . Round errors caused your subtraction to yield non-zeros which you compared later. Epsilon fixes this issue. hth, skk. test_skk.hipnc Edited October 24, 2012 by SYmek Quote Link to comment Share on other sites More sharing options...
jim c Posted October 24, 2012 Author Share Posted October 24, 2012 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). Quote Link to comment Share on other sites More sharing options...
jim c Posted October 25, 2012 Author Share Posted October 25, 2012 OK so added layering for layers 3 and 4, Close to completing the stuff for the first layer. Feel free to take a peek, have a laugh, etc The layer masking works with either Cd or a texture map. test.zip Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.