loading effect shows nothing

Started by
28 comments, last by Comboy 15 years, 11 months ago
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.
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.
Sirob Yes.» - status: Work-O-Rama.
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
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

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

L
-

Visit http://www.mugsgames.com

Stroids, a retro style mini-game for Windows PC. http://barryskellern.itch.io/stroids

Mugs Games on Twitter: [twitter]MugsGames[/twitter] and Facebook: www.facebook.com/mugsgames

Me on Twitter [twitter]BarrySkellern[/twitter]

if i do so it says

Begin cannot be called again until End has been successfully called.
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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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
 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();            }        }
As I see it, you only set the effect, you do not actually draw the parts...

This topic is closed to new replies.

Advertisement