Sign in to follow this  
TruthReveller

DirectX 3D Engine - Adding Materials to a Mesh

Recommended Posts

Hi, I was wondering how to color generic DirectX Mesh shapes (Mesh.Sphere), without having to create textures. Is it possible to create a new Material and assign it to a Mesh? Here is some partial code that I have been working on: mesh[i] = new HMMesh(2, new Vector3(x, y, z), new Vector3(), new Vector3(1, 1, 1), MySystem.MyDevice); mesh[i].ObjectID = i; mesh[i].SetScaling(new Vector3(1, 1, 1)); Material[] myMaterial = new Material[1]; myMaterial[0].Ambient = Color.FromArgb(255, 0, 0); myMaterial[0].Diffuse = myMaterial[0].Ambient; mesh[i].myMaterials[0] = myMaterial[0]; HMShader shader1 = new HMShader("TransformPhong", @"../../../Shaders/TransformPhong.fx", MySystem.MyDevice); HMShader shader2 = new HMShader("TransformTexturePhong", @"../../../Shaders/TransformTexturePhong.fx", MySystem.MyDevice); mesh[i].SetShader(shader2); obj[i] = new HMObjectNode(mesh[i]); obj[i].SetLabel(i.ToString()); MySystem.MyScene.Root.Nodes.Add(obj[i]); The result is either black or white shapes, which means it is not texturing the shapes. -_- The closest result I have had is by changing the device material, example "Device.Material = myMaterials[0];". This results in all the shapes being the same color though. Thanks for any help.

Share this post


Link to post
Share on other sites
Perhaps it would have been better to place this thread in the DirectX forum.

I'm not familiar with managed DirectX, but I assume it works somewhat the same as native. Usually when using shaders, you send the colour values of the material to the vertex shader (using ID3DXEffect::SetValue() or its equivalent), then use those colour values in your lighting calculations.

In fixed function, I think all you have to do is enable lighting and send the material using IDirect3DDevice9::SetMaterial().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this