Niosop Posted January 2, 2010 Author Share Posted January 2, 2010 Yup, it is a really good solution for multiple textures. I'd still like to see a model:Uninstance() type command someday that would recursively split it out if we needed to, say to modify the mesh dynamically. But it's not a big priority for me, multiple textures is enough for my current needs. Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Josh Posted January 2, 2010 Share Posted January 2, 2010 You can add a property for the skin number (with options 1-4) and override the color property with this one. I think the Source engine does something like this. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Niosop Posted January 2, 2010 Author Share Posted January 2, 2010 K, got it working Quick question before I post it though. Is there any advantage to using a 4096x4096 texture instead of a 1024 x 16384 texture? Does the card limit texture size by individual dimensions or just total texture area? Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Scott Richmond Posted January 2, 2010 Share Posted January 2, 2010 Originally I was tending to agree to Tyler on this, but I'll freely admit that I don't fully understand how the shader solution works. So I'll have to assume Josh in correct in saying it is more efficient and faster. Could someone, anyone, maybe write up a bit of a tutorial on how this is supposed to work? I'm sure many people here would benefit from it. Programmer, Modeller Intel Core i7 930 @ 3.5GHz | GeForce 480 GTX | 6GB DDR3 RAM | Windows 7 Premium x64 Visual Studio 2008 | Photoshop CS3 | Maya 2009 Website: http://srichnet.info Link to comment Share on other sites More sharing options...
Niosop Posted January 2, 2010 Author Share Posted January 2, 2010 Yes, I'll post the shader code and a tutorial on how to use it shortly. Just waiting on a reply to my texture size question above and thinking about the best way to handle UV wrapping and sharing normals to conserve texture space. Code is REALLY simple, but a lot of other little things to consider. Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Josh Posted January 3, 2010 Share Posted January 3, 2010 Just divide the texcoord by 2.0, then add a value depending on which skin you want to use: 0.0,0.0 = skin 1 0.5,0.0 = skin 2 0.0,0.5 = skin 3 0.5,0.5 = skin 4 You might use different normal maps for each skin, or you might just use the same one. Fortunately the shader lets you decide. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted January 3, 2010 Share Posted January 3, 2010 What if we want more than 4 textures? Are we limited to just 4 to choose from? RPG games would have a ton more textures than 4. Link to comment Share on other sites More sharing options...
Josh Posted January 3, 2010 Share Posted January 3, 2010 You can divide the texture up any way you choose, for any number of skins. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted January 3, 2010 Share Posted January 3, 2010 I still can't imagine 1 texture being able to hold all the skins in a complete rpg game. I mean we would be talking hundreds. Link to comment Share on other sites More sharing options...
Niosop Posted January 3, 2010 Author Share Posted January 3, 2010 It all depends how big of a texture your video card will allow you to use. I was doing 4096x4096 divided up into 16 1024x1024 and it worked fine. If you're using diffuse+normal then you could write a shader/material that takes 5 diffuse and 5 normal textures with 16 variations on each and get 80 textures you could use on a single model. Or if they all use the same normal, then you could use 9 of the textures for diffuse giving you 144 different textures you could choose from based just on the alpha value you assign to that instance. Sorry, I fell asleep for a bit (think I'm coming down with something) but will finish up the example here shortly. Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Rick Posted January 3, 2010 Share Posted January 3, 2010 It all depends how big of a texture your video card will allow you to use. I was doing 4096x4096 divided up into 16 1024x1024 and it worked fine. If you're using diffuse+normal then you could write a shader/material that takes 5 diffuse and 5 normal textures with 16 variations on each and get 80 textures you could use on a single model. Or if they all use the same normal, then you could use 9 of the textures for diffuse giving you 144 different textures you could choose from based just on the alpha value you assign to that instance. Sorry, I fell asleep for a bit (think I'm coming down with something) but will finish up the example here shortly. Cool. Thanks for explaining that because I get it better now. I'm still not a fan of that limitation but I won't hit 80 on 1 model but in an online RPG I could see that being an issue. Even 144 would most likely not be enough for some MMO's. Not that anyone is creating an MMO but it's still nice not to have limitations if they aren't needed. So the size we decide to make the textures would have an impact of the cards our players have with this. Again, kind of a limitation that wouldn't be there if the models weren't instanced but I guess it's livable. Link to comment Share on other sites More sharing options...
wailingmonkey Posted January 3, 2010 Share Posted January 3, 2010 ...If you're using diffuse+normal then you could write a shader/material that takes 5 diffuse and 5 normal textures with 16 variations on each and get 80 textures you could use on a single model. ... hmmm...normal-mapped facial wrinkles to go along with morph shapes (eventually)...<rubs hands together> Vista Ultimate SP1 64bit | Q6600 2.40 GHZ | 8GB RAM | 320MB Nvidia 8800GTS Link to comment Share on other sites More sharing options...
Niosop Posted January 3, 2010 Author Share Posted January 3, 2010 Ok, here's my implementation of a shader that will allow you to switch between different textures based on the value of the alpha channel of the instance. You could easily make a choice property in Lua for the model that would set the alpha to the correct value for you so it would be more intuitive to use. EDIT: See two posts below for mesh.frag file. Ok, now an explanation of how to use it. Say you have a model that you want to have 4 different textures depending on some factor. Maybe based on damage taken. You'll create 1 big texture that contains the 4 textures you want to use. You have a couple options on how to lay this out (textures numbered from 0 to 3): 0 1 2 3 --OR-- 0 1 2 3 --OR-- 0 1 2 3 Which one you use depends on if you use any type of UV tiling. The first is good if you use Y tiling, the second good if you use X tiling. For this example I'll use the third one. After laying out the textures in a 2x2 grid you need to write your shader. I'm going to use 4 different diffuse texture and and a single normal texture that is used by all of them. mesh_diffuse_bumpmap_2x2.frag: #define LW_DIFFUSE texture0 #define LW_BUMPMAP texture1 #define LW_TEXTURESTRIP_DIFFUSE_X 2 #define LW_TEXTURESTRIP_DIFFUSE_Y 2 Include "mesh.frag" If I wanted to use a 2x2 grid of normal textures as well I would use this: #define LW_DIFFUSE texture0 #define LW_BUMPMAP texture1 #define LW_TEXTURESTRIP_DIFFUSE_X 2 #define LW_TEXTURESTRIP_DIFFUSE_Y 2 #define LW_TEXTURESTRIP_NORMAL_X 2 #define LW_TEXTURESTRIP_NORMAL_Y 2 Include "mesh.frag" Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Niosop Posted January 3, 2010 Author Share Posted January 3, 2010 Ok, found the problem. Going to split out the non-texture strip diffuse code and I'll post a working version. Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Niosop Posted January 3, 2010 Author Share Posted January 3, 2010 Here's the updated mesh.frag file. It wouldn't let me upload a .frag, so just rename to mesh.frag. A quick video on how to use it is at: http://www.screentoaster.com/watch/stVENWQURIR19dRV1YX1ldX1ZV/leadwerks_multi_texture_shader_tutorial Let me know if anyone has any problems or ideas. mesh.txt Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
TylerH Posted January 3, 2010 Share Posted January 3, 2010 I never said a shader-based solution wouldn't work, I am just saying that all the responses to people who post feature requests are always a different way to implement the feature request by someone else in the community as opposed to making the change in the engine as the request would most efficiently be handled. nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Rick Posted January 3, 2010 Share Posted January 3, 2010 Here's the updated mesh.frag file. It wouldn't let me upload a .frag, so just rename to mesh.frag. A quick video on how to use it is at: http://www.screentoaster.com/watch/stVENWQURIR19dRV1YX1ldX1ZV/leadwerks_multi_texture_shader_tutorial Let me know if anyone has any problems or ideas. Very cool. Thanks! How would we handle a model that has multiple textures? For example I have a character that has different textures for different parts of the body. It seems with this the 1 alpha setting would determine all these textures? I would need a way to specify the alpha on all parts of the model. So for example the shirt area texture would use alpha 1 while the pants area texture would be alpha 5. This would be ideal in an rpg game where all the different clothes characters can wear. You'd basically have a huge pants texture with all different kinds of pants on it and be able to just specify the alpha number to change pants. Also, with all of this, is there anything you do that actually needs the alpha channel for alpha stuff? Link to comment Share on other sites More sharing options...
Niosop Posted January 3, 2010 Author Share Posted January 3, 2010 Yeah, there's lots of situations where this won't work as is. Wanna send me an example of the multi texture model/textures you have and I'll experiment around to see if I can find an efficient way of doing what you want? Depending what you want to do you could probably still use the alpha channel for other things as well, you'd just loose resolution. Say I have an 8 texture texture sheet. Setting the alpha to 0 would be the same as setting it to 8, 16, 24, 32, etc. Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Rick Posted January 3, 2010 Share Posted January 3, 2010 Sent you an IM. Thanks for taking a look at this. Link to comment Share on other sites More sharing options...
panoramix Posted January 3, 2010 Share Posted January 3, 2010 This time I actually like Josh's solution, should work as long as you want every instance to have the same material properties. Desktop: Intel 2600K - Gigabyte Z68X-UD3H-B3 - 16GB G.Skill Sniper - EVGA 580 gtx - Raid0 OCZ Vertex 3 SSD - Win7 64bit. Link to comment Share on other sites More sharing options...
Rick Posted January 3, 2010 Share Posted January 3, 2010 It still seems limiting compared to each model instance being able to have it's own texture. Link to comment Share on other sites More sharing options...
Niosop Posted January 3, 2010 Author Share Posted January 3, 2010 It is limiting compared to not using instancing, but it's faster. At some point I'm sure Josh will add a command to split out an instance, we'll just have to be careful not to overuse it or it will kill performance. Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Josh Posted January 4, 2010 Share Posted January 4, 2010 If I were making a game that had different skins on the same model, the shader technique described here is exactly what I would use, even if a unique copy command was already implemented. It's so much faster when you render in batches. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted January 4, 2010 Share Posted January 4, 2010 So if you were making an RPG that allowed the model to be able to have 200+ some different textures for different parts of the body how would you go about using this shader model to do that? It seems with this way the texture size could start to be an issue as the graphics card would need to allow for very large texture size. I just have a hard time believing this is how games like WoW handle this seeing as it can run on some pretty low end cards. Link to comment Share on other sites More sharing options...
Scott Richmond Posted January 4, 2010 Share Posted January 4, 2010 I don't know how most MMOs do it, but I would not have entire character models just with different texture sets. I would cut the models up into body parts (arms, legs, torso, head, etc) and then put the model together with LUA scripting at runtime. That way you can have all the combinations you want and are interchangable at will. Programmer, Modeller Intel Core i7 930 @ 3.5GHz | GeForce 480 GTX | 6GB DDR3 RAM | Windows 7 Premium x64 Visual Studio 2008 | Photoshop CS3 | Maya 2009 Website: http://srichnet.info Link to comment Share on other sites More sharing options...
Recommended Posts