ofer Posted November 24, 2007 Share Posted November 24, 2007 Hi, What is the best way to emulate texture arrays in a shader? I mean, I have a lot of textures, and I want to sample one of them based on an index to this array. I though about several options: 1. Create a big 3D texture, and use the index as a third coordinate. But I might have sampling problems between layers. 2. Use a texture atlas, but then I will have mip-mapping issues. 3. Create the index as an integer point attribute, and then use this attribute inside and embedded expression in the texture's name parameter, eg. $HIP/textures/V_`ch("./index")`.png This is the easiest method, but I don't know how to use a point attribute inside a shader. What I'm trying to do is to implement the rain streak rendering algo from siggraph 06, which uses a database of rain textures. Thanks. Quote Link to comment Share on other sites More sharing options...
symek Posted November 24, 2007 Share Posted November 24, 2007 (edited) Not really sure if I got your point. You want to vary textures per frame on one surface? Then you can prepare expression in SOP to do it. You don't need any arrays. Similarly you can save attribute on face or point to vary texture on per point bases. Shaders are time independent. Mantra ifd describes your scene in discreet point in time - once per frame. There is no sense to build in" texture sequencer" (your arrays) ability in shader since creating a proper set of *.ifd files with varying texture's strings brings to you similar results with no big effort. Unless I missed the point . cheers, sy. EDIT: 3. Create the index as an integer point attribute, and then use this attribute inside and embedded expression in the texture's name parameter, eg.$HIP/textures/V_`ch("./index")`.png Sorry, I didn't notice that. This is usual way to do such things. All you need is to create in shader body a parameter of the same name as primitive attribute in geometry. Shader will use those instead of a values specified initially. Mantra overrides shader parameter with attributes found on geometry. Edited November 24, 2007 by SYmek Quote Link to comment Share on other sites More sharing options...
ofer Posted November 25, 2007 Author Share Posted November 25, 2007 Ok, and I need to add this parameter as invisibile, right? But how do I reference this attribute/parameter from the expression? Something like ch("../parameter/value") ? And what are ifd files? They sound interesting. Thanks. Quote Link to comment Share on other sites More sharing options...
jhiggins Posted November 25, 2007 Share Posted November 25, 2007 you don't need to make it invisible ifd - instantaneous frame description which is what mantra needs to render, which is equivalent rib for prman or mi for mentalray cheers Quote Link to comment Share on other sites More sharing options...
diula Posted November 25, 2007 Share Posted November 25, 2007 The easiest way I can think of is to (like Symek said) to create an integer attribute on your geometry and vary it with any method you want -random, etc (just limit it's value to the max number of textures you have there). Then in your shader create an instance variable of the same type and name, and Mantra will pick up it's values. The actual texture name you should create with a sprintf() format call and pass it to the texture() call. Cheers Quote Link to comment Share on other sites More sharing options...
ofer Posted November 25, 2007 Author Share Posted November 25, 2007 OK, I added a parameter, and used its value in an expression inside the texture's name. But even though I created an attribute with the same name, the shader always takes the parameter's default value. I referenced the parameter in the expression like that: $HIP/textures/tex`ch("../param_name")`.png the attribute and the parameter's name is param_name. Are there any example files with this trick? Thanks. Quote Link to comment Share on other sites More sharing options...
symek Posted November 25, 2007 Share Posted November 25, 2007 (edited) http://www.sidefx.com/index.php?option=com...ghlight=texture Hope this help! cheers, sy. PS Can't prepare new scene now. Some ugly troubles with Ati&Houdini. Edited November 25, 2007 by SYmek Quote Link to comment Share on other sites More sharing options...
edward Posted November 26, 2007 Share Posted November 26, 2007 I'm not entirely sure you can pass integer attributes into shaders. You might need to pass it as a float and then cast it to an integer. Quote Link to comment Share on other sites More sharing options...
symek Posted November 26, 2007 Share Posted November 26, 2007 Brief example. Static and animated version with chops' indexing. There are endless possibilities here. Also with point clouds, generating textures on the fly in COPs etc. All depends on what you need. cheers, sy. texures_expression.hipnc.gz Quote Link to comment Share on other sites More sharing options...
ofer Posted November 26, 2007 Author Share Posted November 26, 2007 Ok, thank you all. With string attributes I can only use primitive attributes, but floats works with point attributes, and this is what I want. Thanks again. 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.