This project is read-only.

How to apply shaders for some material in .x model?

May 10, 2010 at 10:06 PM

Hello! And sorry for my bad English - i'm from Russia =)

I want to use glass reflection shader for some materials in .x model of car. But I can't understand how do this =(

In opensource RacingGame for XNA these shaders applying directly in .x model.. Where can I find example how do this? I learned tutorial 14 about material and lights and 25 about shadowmap, but can't understand.

How can I find simple way to do simple reflection on car and simple reflection-transparancy for glass in one model? Maybe use .fbx model?

May 13, 2010 at 11:37 AM
Edited May 13, 2010 at 11:38 AM

Hi. Unfortunately, due to the way shaders work in Xen, they cannot be compiled through the Content Pipeline. (There are limits in XNA that prevent this). They have to be part of the project, so they can generate the C# binding class.

Also, ModelInstance is a bit tricky to override the shader - because in a lot of cases you want to provide an animation shader as well. You have to use the ShaderOverride class to specify the shader that is used.

I'm aware this isn't a very nice situation. In Xen 2.0 I am certainly going to fix the shader override problem, and I will look at supporting content pipeline generated Effects (with some restrictions).

Sorry about that

May 14, 2010 at 4:12 PM

That's ok =) So, what I supposed to do? Override shader for a MaterialShader property in GeometryData? Or?

Like you wrote in another discussion?

//This is an example!

	//create a shader
var myShader = new FillSolidColour();
//setup the shader, etc.
myShader.FillColour = new Vector4(1,2,3,4);

//create the model
ModelInstance myModel;
myModel = new ModelInstance();
//add to content, etc.

//create a 'shader provider' that uses 'myShader'
var shaderProvider = new ModelInstanceShaderProvider(myShader);

//set the model to use the shader provider
//The model will now use the shader instead of it's own MaterialShader!

But how override shader only for glass meshes - windows in my car model ( meshes with material named "glass" in .x model)? Can you help me again, please?



May 18, 2010 at 11:13 PM

The ModelInstanceShaderProvider class comes in two flavours, one is a generic class that takes a single shader and applies it to everything. The other is the base class that has virtual methods you can override that are called before each model, mesh and geometry is drawn. So, if you are willing to do it, you can set a specific shader per geometry by overriding the BeginGeometry method within your shader provider class.

I fully understand that this is a *really bad* design. I'm totally rewriting it for 2.0.

Sorry! :-(