Jump to content
Niosop

Non-instancing copy command

Recommended Posts

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.

Share this post


Link to post

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.

Share this post


Link to post

K, got it working :D 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?

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

You can divide the texture up any way you choose, for any number of skins.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post
...

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>

Share this post


Link to post

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"

Share this post


Link to post

Ok, found the problem. Going to split out the non-texture strip diffuse code and I'll post a working version.

Share this post


Link to post

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.

Share this post


Link to post

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?

Share this post


Link to post

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.

Share this post


Link to post

Sent you an IM. Thanks for taking a look at this.

Share this post


Link to post

This time I actually like Josh's solution, should work as long as you want every instance to have the same material properties.

Share this post


Link to post

It still seems limiting compared to each model instance being able to have it's own texture.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post
Guest
This topic is now closed to further replies.
×
×
  • Create New...