• Advertisement
Sign in to follow this  

DirectX 3D Engine - Adding Materials to a Mesh

This topic is 4029 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, 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 = new HMMesh(2, new Vector3(x, y, z), new Vector3(), new Vector3(1, 1, 1), MySystem.MyDevice); mesh.ObjectID = i; mesh.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.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.SetShader(shader2); obj = new HMObjectNode(mesh); obj.SetLabel(i.ToString()); MySystem.MyScene.Root.Nodes.Add(obj); 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
Advertisement
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
You are right :) I found a good article on how to use a shader so it can accept color input.

http://www.riemers.net/eng/Tutorials...d_Triangle.php

Share this post


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

  • Advertisement