Jump to content
  • Advertisement
Sign in to follow this  
Comboy

loading effect shows nothing

This topic is 3708 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

I want to apply effect to scene (or some meshes individually) I’m doing it in DX10 XNA2 First of all the blinn.fx from fx composer, I load it
Effect blinn;
Texture2D diffuseMap;

blinn = Content.Load<Effect>("blinn");
diffuseMap = Content.Load<Texture2D>("diffuseMap");

and then in draw:
private void DrawModel(Model m)
        {
            Matrix[] transforms = new Matrix[m.Bones.Count];
            float aspectRatio = graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height;
            m.CopyAbsoluteBoneTransformsTo(transforms);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                aspectRatio, 1.0f, 10000.0f);
            Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, Zoom), Vector3.Zero, Vector3.Up);

            foreach (ModelMesh mesh in m.Meshes)
            { 
                blinn.CurrentTechnique = blinn.Techniques[0];
           
                foreach (ModelMeshPart part in mesh.MeshParts)
                    blinn.Begin();
                    foreach (EffectPass pass in this.blinn.CurrentTechnique.Passes)
                    {
                        pass.Begin();
                        blinn.Parameters["ColorTexture"].SetValue(diffuseMap);
                        
                        part.Effect = blinn;
                        pass.End();
                    }
                }
            blinn.End();
            mesh.Draw();
            }
        }


so I first set the technique, then for each mesh part I start the effect then for each pass I set the parameters then end the pass then set the effect for the mesh part, but nothing is on the monitor :( But with basiceffect it works, so mesh position and camera position are suitable.

Share this post


Link to post
Share on other sites
Advertisement
Two things:

1) You need to call Effect::CommitChanges if you modify parameter values after calling Begin.

2) You havn't pasted your effect file. There's a good chance an error in the effect file might cause nothing to show on screen. I would recommend you start off with a very simple shader and attempt to get something on-screen, then gradually add complexity to the shader, while making sure things remain visible.

Hope this helps.

Share this post


Link to post
Share on other sites
I also tried to commit changes but it still remains blank, the shader is default fx composer hlsl blinn shader and i compiled it there,

in basiceffect there is something which blinn doesn't have:


foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();

effect.View = view;
effect.Projection = projection;
effect.World = gameWorldRotation * transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position);
}





that's view and projection and world

Share this post


Link to post
Share on other sites
attempt using other effects simpler failed, Am i doing it in right order?

first tech set
foreach meshpart in mesh {effect.begin}
setvalues and commit them
foreach pass in effect {pass.begin}
end pass
end effect
draw mesh

Share this post


Link to post
Share on other sites
I think you need to put drawing the mesh within the Pass begin/end calls, otherwise you're drawing nothing during each pass.

L
-

Share this post


Link to post
Share on other sites
Quote:
Original post by Comboy
attempt using other effects simpler failed, Am i doing it in right order?

first tech set
foreach meshpart in mesh {effect.begin}
setvalues and commit them
foreach pass in effect {pass.begin}
end pass
end effect
draw mesh


Looks like you need "effect.end" somewhere!

Post your actual code for a bit more help.

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye


Looks like you need "effect.end" somewhere!

Post your actual code for a bit more help.


I do it after ending the pass, you see
end pass
*end effect*
draw mesh

but ok i'll post the code

Share this post


Link to post
Share on other sites


private void DrawModel(Model m)
{
Matrix[] transforms = new Matrix[m.Bones.Count];
float aspectRatio = graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height;
m.CopyAbsoluteBoneTransformsTo(transforms);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, Zoom), Vector3.Zero, Vector3.Up);

foreach (ModelMesh mesh in m.Meshes)
{
blinn.CurrentTechnique = blinn.Techniques[0];

foreach (ModelMeshPart part in mesh.MeshParts)
{
blinn.Begin();
foreach (EffectPass pass in this.blinn.CurrentTechnique.Passes)
{
pass.Begin();
blinn.Parameters["ColorTexture"].SetValue(diffuseMap);
blinn.CommitChanges();
part.Effect = blinn;
pass.End();
}
blinn.End();
}
mesh.Draw();
}
}


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!