| Poster | : Apples | | Posts | : 8 | | Country | : usa | | City | : |
| | | | Posted by Apples on 12/02/2009 at 15:06:19
| |
foreach (Effect currentEffect in mesh.Effects)
{
currentEffect.CurrentTechnique = currentEffect.Techniques["Colored"];
currentEffect.Parameters["xWorld"].SetValue(xwingTransforms[mesh.ParentBone.Index] * worldMatrix);
currentEffect.Parameters["xView"].SetValue(viewMatrix);
currentEffect.Parameters["xProjection"].SetValue(projectionMatrix);
currentEffect.Parameters["xEnableLighting"].SetValue(true);
currentEffect.Parameters["xLightDirection"].SetValue(lightDirection);
currentEffect.Parameters["xAmbient"].SetValue(0.5f);
}
|
ive followed every thing to a T.
your xwing.x file works perfectly, color and all.
Problem is, im using autodesk 3ds max 2009, i make a cube, color it red, with the material editor, and then i export it to .3ds, i then use conv3ds and convert it to .x and i rename it xwing replaceing your xwing file in content.
for some odd reason it keeps showing up in black! but when i relaod yours... its back in color. ive tryed everytyhing, ive messed around with the lighting, ive turned off lighthing. ive even tryed chainging it from colored to Textured, but that only turned it white... how did you get your xwing.x file to be color, and why is it i cant seem to get my own model to do the same? it keeps showing in black, and im so frustreated right now. please help me figure how to solv my hair pulling problem. ive spent he last 3 days hours and hours trying to figure a way around, ive read every post regarding this, and have not found an awnser to help me here.
-Apples | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 12/02/2009 at 17:03:04
| | I remember having issues with the same thing (and in fact, many other projects I've used the .X format in). It would seem that some modelling apps output slightly varying versions of the .x model format. For example, I used to export models from Blender for my last project. If I left all textures assigned to the model, it wouldnt display in the engine I was working on. However, if I removed all references to textures from the project (keeping the UV Coords) it would load and texture a-ok in the engine.
I know it's not much help, but you could try another modelling app (such as blender, it is free!) or changing the export method for your model. I also wouldnt recommend pumping it through file convertors as you don't know what data it might miss or add as it feels
gd luk! | |
|
|
| |
| |
| Poster | : TekuConcept | | Posts | : 19 | | Country | : United States | | City | : Alpine |
| | | | Posted by TekuConcept on 13/02/2009 at 00:13:53
| | I imported fbx model formates and most of the time came out with black models too... I belive that it is the .fx file that is the cause.
//------------------------------------------------------------
// Microsoft® XNA Game Studio Creator's Guide
// by Stephen Cawood and Pat McGee
// Copyright (c) McGraw-Hill/Osborne. All rights reserved.
// http://www.mhprofessional.com/product.php?isbn=007149071X
//------------------------------------------------------------
float4x4 fx_WVP : WORLDVIEWPROJ;
struct gtVertex
{
float4 f4Position : POSITION0;
float4 f4Color : COLOR0;
};
struct gtPixelFormat
{
float4 f4Position : POSITION0;
float4 f4Color : COLOR0;
};
struct tScreenOutput
{
float4 f4Color : COLOR0;
};
// alter vertex inputs
void vertex_shader(in gtVertex IN, out gtPixelFormat OUT)
{
// transform vertex
OUT.f4Position = mul(IN.f4Position, fx_WVP);
OUT.f4Color = IN.f4Color;
}
// alter vs output and send to hardware one pixel at a time
void pixel_shader(in gtPixelFormat IN, out tScreenOutput OUT)
{
float4 fColor = IN.f4Color;
// set f4Color range between 0 and 1
OUT.f4Color = clamp(fColor, 0, 1);
}
// the shader starts here
technique simple
{
pass p0
{
vertexshader = compile vs_1_1 vertex_shader(); // declare and initialize vs
pixelshader = compile ps_1_1 pixel_shader(); // declare and initialize ps
}
}
|
this fx file is sure to display in color (at least for fbx models)
Add this to the top of the Game1 class:
// shader object - BasicShader.fx
private Effect mfx; // shader object
private EffectParameter worldViewProjParam; // cumulative matrix w*v*p (use this order)
// sets wvp in shader |
Next create a method after the Update() method:
private void init_XNA_app()
{
// load BasicShader.fx and set global params
mfx = content.Load<Effect>(@"shadersBasicShader");
worldViewProjParam = mfx.Parameters["fx_WVP"];
mfx.CommitChanges();
gfx.GraphicsDevice.RenderState.CullMode = CullMode.None; // see both sides
} |
In the Draw() method add this so is to make sure that the objects to be rendered are for that fx file:
// begin shader - BasicShader.fx
mfx.Begin();
mfx.Techniques[0].Passes[0].Begin();
//draw_objects();
// end shader - BasicShader.fx
mfx.Techniques[0].Passes[0].End();
mfx.End(); |
That is the way I would do it, if that helps.
NOTE:
any effect (unless otherwise) to objects that will be drawn with that fx file, must have the declared 'mfx'
ex: | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 18/05/2009 at 17:41:31
| | Hi,
i also made this tutorial and i also have the problem with fbx models. So i read this thread, added the other shader and the lines of code, but it didn't work.
I just started to learn xna and i don't know much about shaders, so i maybe made a mistake. Does anybody else tried this? | |
|
|
| |
| |
| Poster | : Archenon | | Posts | : 428 | | Country | : Romania | | City | : Oradea |
| | | | Posted by Archenon on 19/05/2009 at 03:16:16
| | | I think your FBX is textured and you forgot to pass the texture to the effect. So it is working with a null texture which is black. | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 19/05/2009 at 11:52:52
| | Sorry for that, but i dont know if there is a texture. I made my first model in 3ds max and only painted it gray. If I render it there, it is gray as it should be and if I use the standard XNA procedure in adding a model it works, too.
could you give me an example?
btw: i call the mfx.Begin() before DrawModel() and stop it after it. The initialization is done when the other shader is initialized. is that correct? What else has to be done?
Thanks! | |
|
|
| |
| |
| Poster | : Archenon | | Posts | : 428 | | Country | : Romania | | City | : Oradea |
| | | | Posted by Archenon on 20/05/2009 at 00:56:51
| | Another common thing that have to be checked when working with models and it renders black is the lighting ... is lighting enabled and should it be enabled.
Try disabling the lighting from the graphics.GraphicsDevice.Renderstate.Light.... | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 20/05/2009 at 07:05:40
| | Hi,
i think there is something wrong when using the shader.
when i initialize the model, i still use the effect.fx shader (see the method in the tutorial) and in my opinion i will redo the effects of the new one, when calling the "colored" techinque.
does something else have to be changed in the draw method? or how do i have to initialize it?
thanks | |
|
|
| |
| |
| Poster | : Quasar | | Posts | : 121 | | Country | : Australia | | City | : Brisbane |
| | | | Posted by Quasar on 21/05/2009 at 21:07:34
| | I had this same problem this morning. In my case it was the texture (or lack thereof). Try adding a texture to the model in your 3d editing software and re-exporting it.
If that doesn't work, assign a texture 2D to the shader in the draw call in Xna (just before you draw the model):
| effect.Parameters["xTexture"].SetValue(myTexture2D); |
| |
|
|
| |
| |
| Poster | : Quasar | | Posts | : 121 | | Country | : Australia | | City | : Brisbane |
| | | | Posted by Quasar on 21/05/2009 at 21:13:44
| | To add a texture in 3ds Max (just in case you don't know :) ):
- Press "m" to bring up the material editor
- Go down and open the "Maps" rollout.
- Click the empty "diffuse" button.
- Select Bitmap.
- Find an image you like the look of, and click Open.
- Drag the new material from the material editor to your object.
- Re-export your object. | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 08/01/2010 at 21:12:45
| | Make sure you export the normals (easier), or recreate them unpon loading the mesh (advanced).
If some models display and one is black, normals are at zero. If you disable lighting, you will see a flat-colored model.
If the model is white (or severely "over-exposed"), it means that the normals were scaled along with some model scaling. The devoec should have a NormalizeNormals function, or you can normalized them as a post-loading process.
Panda Exporter plugin works great from 3DS Max directly to .x mesh
Good luck. | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 24/03/2010 at 08:34:11
| | | Hi, im having big troubles trying to get the texture not black, im using maya and exporting to .fbx if anyone could help me asap, it would be greatly aprciated. | |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 19/06/2011 at 10:32:09
| | Hi,
I've got the same black-model problem, with a .FBX that has 4 textures (layered), using the "Textured" technique from the Series 4 shader. The textures are from a array, which is filled by the | LoadModel(String assetName, out Texture2D[] vehicleTex) | method similar to that of Series 3. Can anyone help me? Here's the code:
vehicleModel = LoadModel("Cessnaa", out vehicleTex);
|
calls..
private Model LoadModel(string assetName, out Texture2D[] vehicleTex)
{
Model newModel = Content.Load<Model>(assetName);
vehicleTex = new Texture2D[newModel.Meshes.Count];
int i = 0;
foreach (ModelMesh mesh in newModel.Meshes)
foreach (BasicEffect currentEffect in mesh.Effects)
vehicleTex[i] = currentEffect.Texture; i++;
foreach (ModelMesh mesh in newModel.Meshes)
foreach (ModelMeshPart meshPart in mesh.MeshParts)
meshPart.Effect = effect.Clone();
return newModel;
}
|
draw:
private void DrawModel(Matrix currentViewMatrix, Texture2D[] vehicleTex)
{
//draw ze tank, rotate so its the right way round (hacky!)
Matrix worldMatrix = Matrix.CreateScale(0.00005f, 0.00005f, 0.00005f)
* (Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateRotationY(MathHelper.Pi/2))
* Matrix.CreateFromQuaternion(vehicleRotation)
* (Matrix.CreateTranslation(vehiclePosition));
Matrix[] vehicleTransforms = new Matrix[vehicleModel.Bones.Count];
int j = 0;
vehicleModel.CopyAbsoluteBoneTransformsTo(vehicleTransforms);
foreach (ModelMesh mesh in vehicleModel.Meshes)
{
foreach (Effect currentEffect in mesh.Effects)
{
currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
currentEffect.Parameters["xTexture0"].SetValue(vehicleTex[j]);
currentEffect.Parameters["xLightDirection"].SetValue(lensFlare.LightDirection);
currentEffect.Parameters["xWorld"].SetValue(vehicleTransforms[mesh.ParentBone.Index] * worldMatrix);
currentEffect.Parameters["xView"].SetValue(cam.viewMatrix);
currentEffect.Parameters["xProjection"].SetValue(cam.projectionMatrix);
currentEffect.Parameters["xEnableLighting"].SetValue(false);
currentEffect.Parameters["xAmbient"].SetValue(0.5f);
} j++;
mesh.Draw();
}
}
|
| |
|
|
| |
| |
| Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 31/07/2012 at 10:29:36
| | Here is the fix:
1. Go to this line:
List<BoundingSphere> targetList = new List<BoundingSphere>(); Texture2D bulletTexture;
and add this to the end:
Texture2D youchooseTexture;
2. Then go here:
bulletTexture = Content.Load<Texture2D>("bullet"); skyboxModel = LoadModel("skybox2", out skyboxTextures);
and add this to the end:
youchooseTexture = Content.Load<Texture2D>("TheNameofYourBMP/JPG");
3. Then go to the 'foreach (Effect currentEffect in mesh.Effects)' section of your model and add this to the list:
currentEffect.Parameters["xTexture"].SetValue(youchooseTexture);
Worked flawlessly. | |
|
|
| |
| |
| Poster | : MadApples | | Posts | : 4 | | Country | : | | City | : |
| | | | Posted by MadApples on 26/10/2012 at 23:07:02
| | wow, lol i made this post in 2009 3 years ago.. hahah i feal old now :P
Now a days i use blender, a good fbx exporter for xna works perfect for me :D
Talk about old times :P | |
|
|