Jump to content
  • Advertisement
Sign in to follow this  
Feadur

Using FX files in XNA

This topic is 4276 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I've been using .FX files with HLSL to render my models in XNA. But always the models and the shaders came togheter. But now I'm trying to use the sample shaders from "NVIDIA FX Composer", doesn't work at all. I'm not shure if I'm using them incorrectly or why aren't working. That's the code for the drawing:

foreach (ModelMesh modmesh in this.model.Meshes)
            {
                foreach (Effect currenteffect in modmesh.Effects)
                {
                    
                    Matrix worldMatrix = Matrix.CreateRotationX((float)Math.PI)
                        * Matrix.CreateScale(new Vector3(1, 1, 1));

                    currenteffect.CurrentTechnique = effect.Techniques["glass"];
                    currenteffect.Parameters["worldIT"].SetValue(Matrix.Transpose(Matrix.Invert(worldMatrix)));
                    currenteffect.Parameters["world"].SetValue(worldMatrix);
                    currenteffect.Parameters["wvp"].SetValue(worldMatrix * matrizVista * matrizProyeccion);
                    currenteffect.Parameters["viewI"].SetValue(Matrix.Invert(matrizVista));
                }

                modmesh.Draw();
            }


And this are the parameter I think I have to pass to the vertex shader

/************* TWEAKABLES **************/

float4x4 worldIT : WorldInverseTranspose;
float4x4 wvp : WorldViewProjection;
float4x4 world : World;
float4x4 viewI : ViewInverse;



It's not drawing anything at all :( Thank's!

Share this post


Link to post
Share on other sites
Advertisement
IIRC Mesh.Draw will still use the shader that's set on the model by default (BasicEffect if no shader is specified by the model). Since you aren't setting the correct parameters on that, pretty much nothing should be getting rendered. You could replace the effect instance on the model with your own, but since that's a bit of a pain I've gotten around this by drawing the mesh 'manually', like this:

[source lang=C#]
...

// set up your effect parameters/constants here

deferredShadingEffect.Begin();

foreach (EffectPass pass in deferredShadingEffect.CurrentTechnique.Passes)
{
pass.Begin();

// There's only one mesh in the model, so we'll just draw that. To
// apply a custom effect, we'll need to draw the mesh manually with
// our DrawMesh method, props to Kris Nye
//
// To draw the whole mesh, you'd need to loop over the model.Meshes
// collection and call DrawMesh for each mesh in the model.

DrawMesh(graphics.GraphicsDevice, model.Meshes[0]);

pass.End();
}

deferredShadingEffect.End();

}

private void DrawMesh(GraphicsDevice device, ModelMesh mesh)
{
// This method basically does what mesh.Draw() does, only without
// using the default BasicEffect set by the framework. Since we
// are using a custom effect with different parameters, we'll need
// this approach. Otherwise we might have just set the effect on the
// appropriate mesh parts.

device.Indices = mesh.IndexBuffer;

for (int i = 0; i < mesh.MeshParts.Count; i++)
{
ModelMeshPart part = mesh.MeshParts;

if (part.NumVertices > 0)
{
device.VertexDeclaration = part.VertexDeclaration;
device.Vertices[0].SetSource(mesh.VertexBuffer, part.StreamOffset, part.VertexStride);
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, part.BaseVertex, 0, part.NumVertices, part.StartIndex, part.PrimitiveCount);
}
}
}




Hope this helps :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!