   [.net] How to uses shaders properly in meshwrapper and larger projects
  Hello everyone. Does anyone have a good suggestion for how to handle artist-programmer interaction in a managed directX project? Or to be more specific, how are you guys handling meshes recieved from your artists?The artists in our project are using 3ds exporting to X format but to make anything good looking out of those I need to apply shaders. This works fine when i have a wrapper class around an object that i know before hand how it looks, what materials it have and I can specify per material in the mesh which shader It should have and what input that shader takes. Sort of "hard coding" shader-material combination.Is there anyway to leave this to the artist to make it more generic? An idea I have was to make a script they could run that generated a small xml file where they could input what shaders used for what material and what inputs they take and then use that xml file in the application. I find it confusing since if an artist makes a shader there is no way for me to know what data I need to feed it with. I would like to have a very generic wrapper class for any mesh that handles the rendering and everything and that does not need to be hand made for each new mesh type we throw in the project. How are you guys doing this?Any answers would be most appreciated.RegardsMe   
  HiEDIT:Instead of using shaders and wrapper classes, you should use effect files. In these your artist can write their shaders and link them together into techniques, allowing you to use multiple passes easily. Also in the effect file you can declare variables like vectors and textures, and give all these semantics and annotations so that your app can automatically load them with meaningfull data. For example, loading textures into the effect parameters means that none of that information has to be hardcoded! Fantastic.If you use effect files, then you can query them for the shader input semantics - then you can create all the tangents and normals that your shader needs from one generic class.I hope that helped.   ;  Hi and thanks for your answer.Im playing around with fx files atm and nvidias fx composer which seems to be a tool for artists to create them. (well artists who knows  how to write fx files). Lets just say for fun that the artists in my team would be able to create an fxfile. How is this shader mapped to materials in an x file? Since i have a world mesh that contains many different type of objects that requires different type of shaders i guess i need a way to apply a an fx file per material or something like this? Perhaps I could go with my old xml file and say if material name is abc apply fx file abc?Damn i feel stuck :(further help appreciated/bronzon   ;  HiThis reply has to be a quicky now, but here's my material loading:for (int i = 0; i < materials.Length; i++){    //Use any effect filename in the effect instances, else use the texture file name    string effectName;    if (effectInstances.EffectFilename != null)   effectName = effectInstances.EffectFilename;    else   effectName = materials.TextureFilename;   //Make the effect name from the effect or texture file name    effectName = MakeEffectName(effectName, meshContainer);    //Create the render methods using the effect name and provided material    MeshSkinned mesh = m_AnimationInstance.Mesh;    renderMethods = m_RenderMethodsCreator.CreateRenderMethods(effectName, materials, mesh);}Note:The function MakeEffectName takes the mesh container as a parameter because I use different effects for static and skinned meshes - so if the mesh is skinned with HLSL I append '_SkinnedIHLSL' to the effect name and a different effect is loaded.Alternatively you could use your XML to determine the effect names.I made clever use of macros to eliminate redundancy between skinned and unskinned effects, so the only thing to do is write a #define, so I highly recommend that.See, I've encapsulated the creation of the render methods there - using aggregation to encapsulate variance and promote weak coupling. [grin]Ooo I can make myself sound cleverer than I really am now I've learnt design patterns and theory [grin]Feel free to ask for clarification since this is a bit rushed. 'Cos you're special :p   ;  Thanks alot!Only a few questions arises :DHow do you get the effectInstances array? Is that retrieved from the x files with the Mesh.FromFile static method somehow? I read in another thread that the X format could carry Effect information per material and when i tried exporting an object from 3d studio using the "panda" plugin i noticed that indeed there was a possability to add shader info and have that stored in the mesh file.Hwever loading that mesh into dx meshviewer it failed horridly with errors reffering to the shader parameters but perhaps that was to be expected.So the follow up questions would be. 1) how do you get the information about which shader to use on what material in the x file. and 2) How did you get that array of effects? oh i forgot 3. How do you know what parameter to send to the shader at runtime? I mean seeing how different shaders requires different inputs like eye location, different map names etc etc. (perhaps those are better left hardcoded in the shader?)My idea for that last question was to send the same set of information to all shaders and hardcode the rest. Like provide world,view,proj matrices for transformation and diffuse light direction for specular and per pixel lighting and then if anything would need to be bumpmapped or something then i'd hardcode that into the shader. What do you think?ps. Is it possible to mix programmable and the regular pipeline? Or is this more often solved by using a defualt shader for items you dont want to look fancy? like a default shader with only diffuse and texturing or something.ds.Thanks againbroNzon   