XNA Creators Club Online
Page 1 of 1 (18 items)
Sort Posts: Previous Next

Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

Last post 06-24-2008 5:17 PM by jwatte. 17 replies.
  • 05-21-2008 12:41 PM

    Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    I made a cube in 3DS, assigned a material, set a diffuse map and bump map, adjusted their UV offsets to be different from one another, and exported it as FBX.

    Next, I created a custom processor extending from ModelProcessor, overrode the Process method, added a System.Diagnostics.Debugger.Break() call to it, and then assigned that processor to the FBX model that I exported.

    I opened a second instance of Visual Studio 2005 (with admin elevation in Vista), and used the Attach to Process command in the tools menu to link up with the original instance of Visual Studio (devenv.exe).

    I compiled the application with the first instance of Visual Studio, and the second instance stopped at the debug break command as expected.  I moused over the NodeContent "input" parameter to see what it contained.  It loaded both textures in the MaterialContent instance (diffuse and bump), but it still has only one channel for texture coordinates (TextureCoordinate0).  Of course, the second texture is lost once the MaterialContent instance is cast to BasicMaterialContent.

    If you don't need multiple UV coordinates, then you could just continue on with a custom model processor and be done with it.  However, I'd really like to get the second set of UV coordinates read in as a second texture coordinate in the vertex channels.

    I tried using the kW X-port plugin, but with that, I couldn't even get two textures to come through, let alone the UV coordinates.  kW X-port, apparently, does export multiple sets of UV coordinates, but not in a way that the default importer can read them in as channels.

    So that's the problem: finding an exporter that captures multiple textures for a material and exports them in a format that the default importer can read them in as textures and vertex channels.  Any help with this would be greatly appreciated.


  • 05-21-2008 12:59 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    AFAIK, the default importer does not handle multiple UV coordinates. I believe you will have to write a custom Content Processor.
  • 05-21-2008 1:09 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    I'm not convinced that it's not supported, although that has been suggested.  The disassembly for the channel importing looks like it might handle multiple texture coordinate sets if they're in separate layers.  See  http://forums.xna.com/forums/p/3261/63034.aspx#63034.  That's why I'm wondering if there's an exporter out there that the default importer can read multiple texture coordinates from.  If it really doesn't support them, then I guess I'll have to write a custom importer or just use the COLLADA importers for which full source code is available.

    The default importers should really support multi-texturing by V3.0.  Parallax and bump mapping shaders are nice, but they're kinda useless without a pipeline to import the model data they need to function.


  • 05-21-2008 3:49 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    The FBX format does not currently support multiple texture coordinate channels, so you are out of luck there. Autodesk are adding this functionality in their next version of the format, so we will pick up that support when we upgrade to the latest FBX SDK for our v3 release.

    X files fully support multiple texture coordinate channels, as does our importer, as does our Content Pipeline graphics object model, as does our standard Model class and model processor. You should not need to write any special code to make this work, as long as you are able to export a .X file that contains more than one texture coordinate channel.

    XNA Framework Developer - blog - homepage
  • 05-21-2008 4:57 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    That's what I suspected from looking at the importer code, but the standard importer for .X is not reading a second set of UV coordinates.

    A thread on the kW X-port forum titled "problems exporting second set of UV coords using max8 and max9" http://kwxport.sourceforge.net/?q=node/42 says that "The second texture coordinate (and in later versions, up to 4 sets), plus the tangents/bitangents, are all stored in the DeclData vertex stream. The X format does not support templates for each individual vertex channel, only for some of the more common (position, normal, first texture coordinate, etc).  The documentation for the X file format is on MSDN: http://msdn.microsoft.com/en-us/library/bb172982(VS.85).aspx"

    Looks like either a problem with the exporter or a limitation of the .X format.

    Is there a known .X exporter for 3DS Max, which is known to produce an .X file from which XNA's default model importer is known to read a second texture coordinate channel?

    There's a lot of talk about support for multi-texturing, but I haven't seen anything that actually works yet.

  • 05-21-2008 5:23 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    This is beginning to look like a limitation of the .X format.

    Based on http://kwxport.sourceforge.net/?q=node/32 , "The .X file format does not allow more than one texture per model part, unless you are using the DirectX Material in 3ds Max. I suggest you develop a DirectX shader to use within 3ds Max that supports multiple textures (decals, gloss maps, normal maps, etc) and export that, as that will include all the information you have in the shader".

    Is that the problem, and perhaps why BasicEffect uses only one texture per model part?

     

    UPDATE:

    Yes, that was the problem.  You need to use a DirectX Material in 3DS Max in order for multiple texture coordinates to be exported.  Also, I can confirm that the default content importer loads channels for both TextureCoordinate0 and TextureCoordinate1, using models exported with kW X-port.  A DirectX material will be available in 3DS Max only if you're using the DirectX drivers (otherwise it will categorized as incompatible), which can be set in Customize::Preferences::Viewports::DisplayDriver.  I actually tried loading a DirectX material while the OpenGL drivers were active, and in addition to not loading the FX file, it also crashed 3DS, haha.

    However, now it's not loading any textures!

     

    UPDATE 2:

    Looks like you need to set the textures explicitly as shader texture parameters, so you can't set the texture maps in Max's material editor, you have to do it right there in the shader parameter editor.  Based on http://kwxport.sourceforge.net/?q=node/36, you may also want to ensure the shader is DXSAS compliant (DirectX Standard Annotations and Semantics), so textures will show up in the DirectX Viewer.  That first link in this post has an example shader with all the annotations.

     Textures still don't seem to be exporting though...

     

    UPDATE 3:

    Ok, so far so good.  It's necessary to activate the "export shader" option in the kW X-port exporter... that will cause an EffectMaterialContent instance to be imported rather than a BasicMaterialContent instance.  So, with 3DS Max 9, kW X-port, and a DirectX shader material, it's possible to export an .X file with multiple texture coordinate channels and a compiled effect.  Now... I hope the parameters are baked into the compiled effect, because I don't see them anywhere else.

    Finally, I don't like having to export everything into shader parameters, because this means that instead of being able to read properties from a nice BasicMaterialContent instance, I'll have to know in advance which shader the model uses to extract parameters from the shader or I'll at least have too coordinate all my shaders to use the same parameter names, in order to build a custom model processor.  The information might be useful to categorize materials as they are loaded, since XNA has the render method reversed, "foreach model part, for each effect", when it should be "for each effect, for each model part", which has been discussed on the collada forums as a performance issue.

     

    UPDATE 4:

    I figured out how to deal with these effects once and for all by creating a custom model which loads an AdvancedEffect by default instead of a BasicEffect or a generic MaterialEffect.  See my thread on custom Effect and Model classes here: http://forums.xna.com/forums/t/12065.aspx.  An AdvancedEffect is like the BasicEffect in that it has a lot of built-in properties for advanced effects, but it's built around my own custom shader like the MaterialEffect, so it's the best of both worlds.  No more messing with parameter.SetValue for me!

  • 06-12-2008 3:44 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon


    I've a little problem exporting a model, and this thread, even if quite small, gave me a useful hand! Now I've just two questions to make:

    JSpiel:

    Looks like you need to set the textures explicitly as shader texture parameters, so you can't set the texture maps in Max's material editor, you have to do it right there in the shader parameter editor.

    What do you mean? In 3ds 9 I used a DirectX Shader Material that use "lightmap.fx" (included in the fx folder inside 3ds); I put my two textures (diffuse and lightmap) into the panel called "lightmap.fx Parameters", right under the panel where I can load the .fx file in the Material Editor. It's the right place? Sorry, I'm quite a n00b with 3ds...

    Then:

     

    JSpiel:

    UPDATE 3:

    Ok, so far so good.  It's necessary to activate the "export shader" option in the kW X-port exporter... that will cause an EffectMaterialContent instance to be imported rather than a BasicMaterialContent instance.  So, with 3DS Max 9, kW X-port, and a DirectX shader material, it's possible to export an .X file with multiple texture coordinate channels and a compiled effect.

     Ok, perfect, I did everything you said. But I tried to export the scene with kW and there's only one UV set. I have the diffuse map on channel 1, and the lightmap on channel 3; I set "Num of UV channels" on 2, and export Materials and Shaders. I've tried to change, for example, the number of UV channels, but I can only obtain a single set of UV coords. Where did I wrong?

  • 06-12-2008 4:50 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    I put my two textures (diffuse and lightmap) into the panel called "lightmap.fx Parameters", right under the panel where I can load the .fx file in the Material Editor. It's the right place?

    Yes, that is the right place.

    To export channel 3, I think you need to set the number of UV channels to 3, although it would probably be better to simply use channel set 2 for the second set, instead.

    Finally, make sure you install version 1.3.0, but then install the test version 1.3.1 on top of that, to fix some bugs that were in 1.3.0.

    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
  • 06-12-2008 5:16 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    I'm trying to change the channel directly in 3ds, but the only one that give me the right result is the channel 3. My (partial) model is a lawn (with a squared grass texture repeated multiple times) whith shadows of trees and houses (the lightmap, much bigger); what happens when I try to use channel 2, for example, is that in the Perspective view inside 3ds the lightmap is repeated alongside the diffuse (as if they share the same UV set). In my XNA project, no matter what parameters I set in the kW exporter, I have just this - wrong - effect of tessellation of both diffuse map and lightmap.

    Speaking about the exporter, I've installed the 1.3.0 version; I've just downloaded the .zip of the 1.3.1: I quickly tried to substitute kwxport.dle with the .dll file, but 3ds doesn't recognise it. Did already tell you that I'm not so able with 3ds? ;)

    Many, many thanks for all the help!

    EDIT: Some image to help you to understand me:

    Right effect

    Wrong effect

    Wrong effect in XNA


  • 06-12-2008 5:53 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    The images didn't show up.

    To upgrade to 1.3.1 test, you need to quit Max, remove the kwxport.dle file, and replace it with the file in the test zip file. That should have the same name -- kwxport.dle.

    There were texture channel problems fixed in 1.3.1, including problems with "scrambling" channels, so it's definitely worth an upgrade.


    Jon Watte, Direct3D MVP kW X-port 3ds Max .X exporter kW Animation source code
  • 06-12-2008 6:12 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon

    Images fixed, now they should be visible!

    As for the test file - nope, I downloaded 2 times, and the .zip contains kwxport.dll and README-testversion.html. No kwxport.dle.

  • 06-12-2008 9:48 PM In reply to

    Re: Multi-texturing - multiple textures and multiple texture-coordinate channels on a single polygon