Archived

This topic is now archived and is closed to further replies.

Disabling lighting in DX8.1 (newbie question)

This topic is 5676 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

Ok, I have a small problem that''s driving me up the wall. I am trying to make a simple space-dueling-type game. The camera moves and turns with the player through 3D space while fighting. All models are loaded from .X files which were created with either 3DS Max or Lightwave (both made by a friend, not myself). The models are colored, but not textured. For code, I''ve built the game upon the EnhancedMesh sample that comes with the DX81 SDK (minus the EnhanceMesh function itself). I know that lighting is on by default in D3D, and I understand how to move the lights around and change the lights. But what I want is for the player to be able to see all objects within view without the shadows. Normally, the models look fine in light from the front, but black in the back. If I turn off the light, the entire model is black (obviously). If I disable lighting, the entire model turns white. I understand that you can use vertex coloring to make the model appear fine without lighting, but I''m not sure if something has to be changed when the model is exported, or if there''s a DX8 feature that I need to enable. I''ve tried moving the directional light with the camera, but that caused the game''s framerate to drop tremendously, and gave me horrible artifacts. Any suggestions about how to do this?

Share this post


Link to post
Share on other sites
Actually, I wanted to get rid of the light so that all objects were lit equally for this project. I''ve tried using SetRenderState to set D3DRS_AMBIENT to various values, but it doesn''t seem to have any effect on the scene. As I''m reading the DX help files, this only affects the color of the Ambient light. It mentions that ambient light has an intensity too, but it gives absolutely no information about where to change this intensity...

Share this post


Link to post
Share on other sites
You could also create 2 lights, one in front and one in back. One shines light on the front of everything, and there's another in the back of the scene that shines light on the back of everything. This will also give you the option of making the lights different so create a cool shading effect.
I'm not too sure how you can just not use lights because, as you said, if you disable lighting then it all turns white.. I'm sure there's another simple solution somewhere with some flag or state that you can set, but I think creating another simple light in the back would look good without too much more computation power. Maybe a point light or something just to shed a little light on the backs.

Edit: I would think an ambient white light would make everything show. But you can't get that to work. Make sure that both Ambient light is on and lighting is enabled (since you tested disabling the lighting, make sure you turned it back on).

[edited by - okonomiyaki on June 4, 2002 5:52:03 PM]

Share this post


Link to post
Share on other sites
That''s the first thing I tried after I couldn''t solve my problem directly. Having two directional lights opposite of each other just looks very bad as you approach from the side, and planes that are perpendicular to the light rays are still shadow black. Adding a third for fourth light and arranging the lights in a pyramid fashion didn''t look much better.

Yeah, I''m sure there''s a simple way to do this. Just going insane that I can''t find that way.

I may as well post the exact code that I''ve been using.


  
//-----------------------------------------------------------------------------

// Name: RestoreDeviceObjects()

// Desc: Restore device-memory objects and state after a device is created or

// resized.

//-----------------------------------------------------------------------------

HRESULT CMyD3DApplication::RestoreDeviceObjects()
{

m_bUseHWNPatches = (m_d3dCaps.DevCaps & D3DDEVCAPS_NPATCHES);

// Setup render state

m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); // I''ve been toggling this on and off

m_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_RGBA(128,128,128,128) ); // I''ve been playing with this value a lot.

m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );

// Setup the light

D3DLIGHT8 light;
D3DUtil_InitLight( light, D3DLIGHT_DIRECTIONAL, 0.0f,-1.0f, 1.0f );
m_pd3dDevice->SetLight(0, &light );
m_pd3dDevice->LightEnable(0, TRUE ); // Also tried without enabling the light


// Setup the projection matrix

D3DXMATRIX matProj;
FLOAT fAspect = (FLOAT)m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect,
m_MeshList[0].m_fObjectRadius/64.0f, m_MeshList[0].m_fObjectRadius*200.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

// Restore the font

m_pFont->RestoreDeviceObjects();

return S_OK;
}

//-----------------------------------------------------------------------------

// Name: FrameMove()

// Desc: Called once per frame, the call is the entry point for animating

// the scene.

//-----------------------------------------------------------------------------

HRESULT CMyD3DApplication::FrameMove()
{
// Update user input state

UpdateInput( &m_UserInput );

// Setup world matrix

D3DXMATRIX matWorld;
D3DXMATRIX matViewTemp;

m_pd3dDevice->SetTransform( D3DTS_VIEW, D3DXMatrixInverse( &matViewTemp, NULL, &(m_ViewMat.mat)));

return S_OK;
}

//-----------------------------------------------------------------------------

// Name: Render()

// Desc: Called once per frame, the call is the entry point for 3d

// rendering. This function sets up render states, clears the

// viewport, and renders the scene.

//-----------------------------------------------------------------------------

HRESULT CMyD3DApplication::Render()
{
// Clear the backbuffer

m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0x000000ff, 1.0f, 0L );

// Begin the scene

if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
{
if (m_bUseHWNPatches)
{
float fNumSegs = 1.0f;

m_pd3dDevice->SetRenderState(D3DRS_PATCHSEGMENTS, *((DWORD*)&fNumSegs));
}

m_ObjectMat->Render(m_pd3dDevice);

// Draw UI

DrawUserInterface();

if (m_bUseHWNPatches)
{
m_pd3dDevice->SetRenderState(D3DRS_PATCHSEGMENTS, 0);
}

// Output stats

{
// Output statistics

m_pFont->DrawText( 2, 0, D3DCOLOR_ARGB(255,255,255,0), m_strFrameStats );
m_pFont->DrawText( 2, 20, D3DCOLOR_ARGB(255,255,255,0), m_strDeviceStats );

TCHAR buffer1[80], buffer2[80];
_stprintf( buffer1, "Score: " );
_stprintf( buffer2, "%i ", score );
m_pFont->DrawText( 2, 40, 0xffffff00, buffer1 );
m_pFont->DrawText( 150, 40, 0xffffffff, buffer2 );
_stprintf( buffer1, "Your X: %f ", m_ViewMat.x_pos );
m_pFont->DrawText( 2, 60, 0xffffff00, buffer1 );
_stprintf( buffer1, "Your Y: %f ", m_ViewMat.y_pos );
m_pFont->DrawText( 2, 80, 0xffffff00, buffer1 );
_stprintf( buffer1, "Your Z: %f ", m_ViewMat.z_pos );
m_pFont->DrawText( 2, 100, 0xffffff00, buffer1 );
_stprintf( buffer1, "Target X: %f ", m_ObjectMat->x_pos );
m_pFont->DrawText( 2, 120, 0xffffff00, buffer1 );
_stprintf( buffer1, "Target Y: %f ", m_ObjectMat->y_pos );
m_pFont->DrawText( 2, 140, 0xffffff00, buffer1 );
_stprintf( buffer1, "Target Z: %f ", m_ObjectMat->z_pos );
m_pFont->DrawText( 2, 160, 0xffffff00, buffer1 );
}

// End the scene.

m_pd3dDevice->EndScene();
}

return S_OK;
}

void C3DObject::Render(LPDIRECT3DDEVICE8 m_pd3dDevice)
{
m_pd3dDevice->SetTransform( D3DTS_WORLD, &mat );

meshData->Render(m_pd3dDevice);
}

void C3DMeshData::Render(LPDIRECT3DDEVICE8 m_pd3dDevice)
{
// set and draw each of the materials in the mesh

for( UINT i = 0; i < m_dwNumMaterials; i++ )
{
m_pd3dDevice->SetMaterial( &m_pMaterials[i].MatD3D );
m_pd3dDevice->SetTexture( 0, m_ppTextures[i] );

m_pMeshSysMem->DrawSubset( i );
}

}

Share this post


Link to post
Share on other sites
How about trying one directional light then one point light? It can just shed a little light, although it won''t be the same as the directional. If you really have to have the whole scene in uniform lighting, it will be very hard to position lights in a certain way..
Not too sure why disabling lighting as a whole isn''t working. I would say it was the .x file but it can''t be because you are saying it looks fine in a certain situation, so this means the file has to have the data. I skimmed you code, and nothing seemed terribly wrong.. It should look normal if you just disable the lighting. I''ll be interested in hearing the solution to this.

Share this post


Link to post
Share on other sites