Jump to content
  • Advertisement
Sign in to follow this  
Albert001

Lighting + 3D model + point cloud

This topic is 3530 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 All, I have a problem with setting lighting and material in my code. I would like to visualize a 3D model (which I parse it in myself) and the structure of a vertex is defined as follows: struct a_customvertex { float x, y, z; float nx,ny,nz; }; Also I have a point cloud which for a vertex in the cloud is defined as follows: typedef struct PositionColor { public: PositionColor() : X(0), Y(0), Z(0), Color(0) {} PositionColor( float x, float y, float z, DWORD color ) : X(x), Y(y), Z(z), Color(color) {} float X, Y, Z; DWORD Color; } PositionColor; I have set the FVF for the a_customvertex based model as D3DFVF_XYZ | D3DFVF_NORMAL and for PositionColor used for point cloud as D3DFVF_XYZ | D3DFVF_DIFFUSE. Here is how I use lighting on my OnRenderFrame class: pDevice->BeginScene(); SetUpLights( pDevice ); ... pDevice->SetStreamSource(0, m_aplannedB, 0, sizeof(a_customvertex)); //Render the 3d model STRUCT_INSTANCES * instance = first_instance; while (instance) { pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, instance->startIndex, instance->primitiveCount); } instance = instance->next; } D3DMATERIAL9 mtrl; mtrl.Diffuse.r = mtrl.Ambient.r = mtrl.Specular.r = 1.0f; mtrl.Diffuse.g = mtrl.Ambient.g = mtrl.Specular.g = 1.0f; mtrl.Diffuse.b = mtrl.Ambient.b = mtrl.Specular.b = 1.0f; mtrl.Diffuse.a = mtrl.Ambient.a = mtrl.Specular.a = 0.5f; mtrl.Emissive.r = 0.1f; mtrl.Emissive.g = 0.1f; mtrl.Emissive.b = 0.1f; mtrl.Emissive.a = 0.5f; pDevice->SetMaterial(&mtrl); ... pDevice->EndScene(); pDevice->Present( 0, 0, 0, 0 ); Here is my light class: void CApp::SetUpLights( LPDIRECT3DDEVICE9 pDevice ) { float max = 1; D3DXVECTOR3 vecDir; D3DLIGHT9 light; ZeroMemory(&light, sizeof(D3DLIGHT9)); light.Type = D3DLIGHT_DIRECTIONAL; light.Diffuse.r = 0.5f; light.Diffuse.g = 0.5f; light.Diffuse.b = 0.5f; light.Diffuse.a = 1.0f; light.Specular.r = 0.0f; light.Specular.g = 0.0f; light.Specular.b = 0.0f; light.Specular.a = 0.0f; light.Ambient.r = 0.0f; light.Ambient.g = 0.0f; light.Ambient.b = 0.0f; light.Ambient.a = 0.0f; light.Position.x = (float) -2.0f; light.Position.y = (float) -2.0f; light.Position.z = (float) -2.0f; vecDir.x = -2.0f; vecDir.y = -6.0f; vecDir.z = -1.0f; D3DXVec3Normalize((D3DXVECTOR3*)&light.Direction, &vecDir); light.Range = 5.0f; pDevice->SetLight( 0, &light ); pDevice->LightEnable ( 0, true ) ; D3DLIGHT9 light1; ZeroMemory(&light1, sizeof(D3DLIGHT9)); light1.Type = D3DLIGHT_DIRECTIONAL; light1.Diffuse.r = 0.5f; light1.Diffuse.g = 0.5f; light1.Diffuse.b = 0.5f; light1.Diffuse.a = 1.0f; light1.Specular.r = 0.0f; light1.Specular.g = 0.0f; light1.Specular.b = 0.0f; light1.Specular.a = 0.0f; light1.Ambient.r = 0.0f; light1.Ambient.g = 0.0f; light1.Ambient.b = 0.0f; light1.Ambient.a = 0.0f; light1.Position.x = (float) 2.0f; light1.Position.y = (float) 2.0f; light1.Position.z = (float) 2.0f; vecDir.x = 2.0f; vecDir.y = 6.0f; vecDir.z = 1.0f; D3DXVec3Normalize((D3DXVECTOR3*)&light1.Direction, &vecDir); light1.Range = 5.0f; pDevice->SetLight( 1, &light1 ); pDevice->LightEnable ( 1, true ) ; // Finally, turn on some ambient light. pDevice->SetRenderState(D3DRS_AMBIENT, 0x00707070 ); } Unfortunately the 3d model appears in black (as if the normals are not parsed in). I have traced the parsing and I am for sure the normals are in, however the model still appears in black and the pointcloud gets colored!!! Is there anyway that I can figure out what's going wrong with the material and/or lighting setup for the 3D model and why instead of lighting the model, it lights the point cloud? Thanks, Albert

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!