Jump to content

Non-instancing copy command


Niosop
 Share

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.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

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

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?

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

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

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

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

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

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

...

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

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

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

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.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

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

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

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

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

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

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

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

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...