Custom Shader - More Than 2 Textures

Jan 14, 2010 at 12:23 PM


I've got a custom multiple render shader that requires more than two textures, in fact its alot more. Its from the RandomChaos sample found here

Now I've got the shader working fine, but the issue it with how I am having to pass these textures through. As a material shader only supports 2 textures loaded from the model I am having to manually set the other textures. I notice you manually set a texture in this way for the Shadow mapping custom shader in your examples.

As I wish to render different planets using that shader I will be wanting to switch the extra textures dependant on the object. Is there a preferred method of doing this in the XEN API? I don't want to try and mess with the rendering systems or have a custom importer as I can't and wouldn't want to play with MaterialShader anyway.

I currently can't see a way of doing this without creating some sort of XML file for my objects that states its model, custom shader and the associated extra textures that are required to go with it and loading that up. Am I missing anything obvious or is this the best route to take?


Jan 15, 2010 at 12:33 AM

Yes, ModelInstance / MaterialShader only exposes the two textures. It would be possible to mess with the importer, to import extra textures (that is, assuming they are exposed by the rest of the XNA pipeline) - but this would be fairly tricky and require quite a bit of reworking. It's often a lot of trouble just getting normal maps to work.

I would imagine it will be best to have an XML file, or similar, listing model, textures, shader etc. This way you can more easily reuse resources as well.
If you change the texture on a shader, the API should pick this up and make sure it gets properly bound when next using the shader. So at least on that side of things, it should be OK.

This is very much a general XNA content pipeline issue. Unfortunately.

Also note: (you may already be aware) but Xen does not support changing render state in a technique. (Loads of reasons for this :-)

Sorry I don't have a definitive answer

Jan 15, 2010 at 11:38 AM

Thanks for the quick response.

I assumed the XML route would end up being the easiest way to integrate slightly more complex shaders with the API and just wanted to make sure I wasn't missing anything obvious and needlessly reinventing the wheel. A simple XML drawable object file should be easily resuable for any other custom shaders, infact it might be so generic I can post it here for others to use.


Jan 15, 2010 at 2:39 PM

Hi Feckinotter,

I'm currently starting to work on a similar shader for my space game (using some GPU noise to render planet textures and GPU fractal flames for Nebulae effects) and I didn't get yet on the Xen implementation side of things therefore not fronting the issue you raised. Would be cool if you could share with us the end result of your implementation and potentially we could push that inside the API directly as a feature StatusUnknown? :)