Page 1 of 2

Integrating shaders into a pipeline

Posted: Wed Jun 11, 2008 3:56 pm
by impulse3d
I've done a lot of searching on the forums and Google, and I haven't found an answer.

DirectX .x files have the ability to save shader information into them, but from a bunch of tests and browsing the source code, it doesn't look like Irrlicht loads them. How can you integrate shaders in such a way that you don't need to explicitly specify them for specific objects in code?

It would be ideal to be able to model everything in Max/Maya and export the model as a .x (which they already can), and have Irrlicht load up the shader information so that the shaders can be specified via Max & Maya (which I don't think it can).

Is there any best way to handle attaching shaders to models without having to specify them myself in code? (so that artists can model and attach the shaders themselves)

Any help is greatly appreciated! :D

Edit: If there are any other formats that save shader information (the only one I know of is .x) it would be useful to know also. However, the .x format would be ideal.

Posted: Wed Jun 11, 2008 6:25 pm
by impulse3d
It looks like the best bet to make it easiest for artists, so that they can use the shader materials in max/maya, is just to add .x shader support myself. I'll post a patch when I'm done.

Posted: Wed Jun 11, 2008 7:42 pm
by dlangdev
That would be a cool pipeline.

Maya-->Irrlicht.

Max-->Irrlicht.

I have the impression that it can be in Maya using Mel Scripting. Not sure about Max, though as I'm not a Max user.

Posted: Thu Jun 12, 2008 2:15 pm
by Slaine
I've asked this similar question in the past, I think what you are thinking of is a shader parser, where Irrlicht reads the materials on an object and if say Fur shader was applied to material index 0 then Irrlicht would setup a shader for that materal and faces only and perhaps you'd applied glow to another set of faces/materal, so you end up with a multi-shader object. This is what next gen engines do and something noone has done on here, I tried but simply couldn't wrap my head around it.

Posted: Thu Jun 12, 2008 2:18 pm
by Slaine
Added to say that this technique is the only thing amongst a few other smaller features that makes a render engine next gen really, I mean, what's the use in applying parrallax mapping to an entire ship, or boat, it's not efficient, you want to be able to apply it to only the areas required.

Posted: Thu Jun 12, 2008 3:25 pm
by impulse3d
Irrlicht's per-face texturing from .x files is borked.

As a result, since THAT'S something that I don't want to fix, I'll only be adding the ability to add one shader per mesh. I don't think that's so bad though--I hear from artists that it's bad practice to use materials on a per-face basis on a mesh anyway. The preferred way is to have a single material that completely UV maps onto a model.

Posted: Thu Jun 12, 2008 3:33 pm
by hybrid
You can apply materials - even shader based ones - to only parts of a mesh. Even if the examples don't show it, it's still possible.

Posted: Thu Jun 12, 2008 3:37 pm
by JP
yeah it's ideal to have one texture for as much of a model as possible, but as slaine says it's useful to be able to have different parts of a model with different materials.

take the fur shader example, you may have a bear model and you might want a fur shader to cover its body, but you wouldnt want that fur to cover, say, its teeth and eyes etc so you'd need different shaders/materials for those.

as hybrid says though, it's possible, you just have multiple mesh buffers. each mesh buffer has one material so if you want more than one material you seperate each face into the required mesh buffer with that material, the .x loader does all this for you.

Posted: Thu Jun 12, 2008 4:05 pm
by impulse3d
I haven't yet gotten Irrlicht to load up a .x file with textures applied to specific faces of the mesh using 3ds max and Panda exporter. Some vertices are out of wack and go to either 0 or infinity.

Maybe I'm missing something big, but I'm looking at the source for the x. loader, and it doesn't parse "EffectInstance" blocks at all from .x files, meaning that you can't parse .fx files that have been linked to parts of the mesh.

@ hybrid: I know you can do this through the code, but I'm trying to get this done with the pipeline
max/maya => .x exporter => Irrlicht
instead of specifying materials, even shader materials, explicitly through code. Specifying non-.fx materials works for some formats in Irrlicht, like .3ds, but NOT for .x files judging from the 10 or so quick tests that I did.

@ JP: The .x loader doesn't do anything with EffectInstance blocks, which is responsible for specifying .fx shaders.

Posted: Fri Jun 13, 2008 8:44 am
by Slaine
Yeah the multi shader system is imperative, I've worked in the games industry for years and the engines they use do this. The bear example is a classic :lol: You simply can't do cutting edge effects with Irrlicht yet, until someome writes what JP said, a system which reads the seperate objects into a buffer, reads it's information on what shader it uses, then creates it in Irrlicht, this is something which IrrEdit is crying out for! Just applying lightmapping to a level just isn't enough, this has been done for years.

Another example, and really quite serious is level creation! How do you apply the correct shaders for seperate areas of your level, you can't, hense it looks naff compared to modern games! If someone writes this system for Irrlicht it will make a MASSIVE jump.

Posted: Fri Jun 13, 2008 9:14 am
by dlangdev
I think it can be done...if they can be broken down into code-able pieces, though.

The Shader model I know is basically a rip-off from Maya. But I'm guessing there are others out there that have better shader models. For example, ATI's RenderMonkey or Nvidia's (can't remember it at the moment). I'm using a 3850 at home and an 8500 at work.

I know in Irrlicht a material type can be set to a shader, the default is basically setting a shader to all materials of a node.

I remember playing around with materials in Blender 2.45, I was able to define material names like head, left_arm, right_arm, torso, left_leg, etc. Then I was able to set attributes to it later. Exported it to obj, loaded it in Irrlicht and set the material type to them.

Posted: Fri Jun 13, 2008 9:30 am
by dlangdev
hybrid wrote:You can apply materials - even shader based ones - to only parts of a mesh. Even if the examples don't show it, it's still possible.
Maybe the shader demo can be modified to show two sides of a cube having a blinn shader and the other side a lambert.

Posted: Fri Jun 13, 2008 9:33 am
by Slaine
Oh yeah it can be done alright, just not by me, it's too advanced. I'm researching Ogre at the moment, see if anyone has written anything for that. The Unity engine does it, but that's ££, so does Quest3D but that's £££££££££ lol.

Posted: Fri Jun 13, 2008 9:35 am
by Slaine
dlangdev wrote:
hybrid wrote:You can apply materials - even shader based ones - to only parts of a mesh. Even if the examples don't show it, it's still possible.
Maybe the shader demo can be modified to show two sides of a cube having a blinn shader and the other side a lambert.
Yeah definatly, but this needs to be done within a 3D app, like Milkshape, 3dsmax, Maya, not with code. Elseways you'd have to hard code your characters and levels to have multi suface effects :wink:

Posted: Fri Jun 13, 2008 7:43 pm
by dlangdev
Hi Slaine,

Good luck on Ogre, hope you get what you're looking for. I wish I had the time to play with Ogre.

I'm still doing research about shader-material binding on Irrlicht. I think a visor (that's what they call it in Maya) is needed so that I can pull-up the shader and attach it to an attribute. The thing is, the Irrlicht object model has no attributes. Big problem right there.

Once I get a good view of how it fits nicely it will eventually come together. I need more time to know the finer details.