D3DIM Light not displaying

Started by
11 comments, last by LaChoppe 24 years, 6 months ago
Are you sure your using the right vertex format? You need to use D3DVERTEX if you want Direct3d to do lighting. If you use D3DLVERTEX your telling Direct3d that your doing the lighting yourself.

--TheGoop

Advertisement
Yup, the DramPrimitive call is thus:

pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_VERTEX, verts, numverts, NULL);

I only tried the LVERTEX bit to see if the normals were screwed up, but they aren't.

Thanks for the help, though...

-La'Choppe

[This message has been edited by LaChoppe (edited September 19, 1999).]

Maybe you could post some code. It's hard to guess at whats going wrong without seeing the setup code.

-TheGoop

Here you go, everything involved in light and material creation and scene rendering.


LPDIRECT3DLIGHT g_pLight = NULL;
LPDIRECT3DMATERIAL3 g_pmtrlObjectMtrl = NULL;

// LIGHT CREATION

if( FAILED( pD3D->CreateLight( &g_pLight, NULL ) ) )
return E_FAIL;

D3DLIGHT2 light;

ZeroMemory(&light, sizeof(D3DLIGHT2));
light.dwSize = sizeof(D3DLIGHT2);
light.dltType = D3DLIGHT_POINT;

light.dvPosition.x = 0.0f;
light.dvPosition.y = 10.0f;
light.dvPosition.z = -80.0f;

light.dcvColor.r = 1.0f;
light.dcvColor.g = 1.0f;
light.dcvColor.b = 1.0f;
light.dvAttenuation0 = 1.0f;
light.dwFlags = D3DLIGHT_ACTIVE;

if (FAILED(g_pLight->SetLight( (LPD3DLIGHT) &light )))
return E_FAIL;

if (FAILED(pvViewport->AddLight( g_pLight )))
return E_FAIL;

// MATERIAL CREATION

if( FAILED( pD3D->CreateMaterial( &g_pmtrlObjectMtrl, NULL ) ) )
return E_FAIL;

D3DMATERIAL mtrl;
D3DMATERIALHANDLE hmtrl;
ZeroMemory( &mtrl, sizeof(D3DMATERIAL) );
mtrl.dwSize = sizeof(D3DMATERIAL);
mtrl.dcvAmbient.r = 0.4f;
mtrl.dcvAmbient.g = 0.6f;
mtrl.dcvAmbient.b = 0.7f;
mtrl.dvPower = 40.0f;
g_pmtrlObjectMtrl->SetMaterial( &mtrl );

g_pmtrlObjectMtrl->GetHandle( pd3dDevice, &hmtrl );
pd3dDevice->SetLightState( D3DLIGHTSTATE_MATERIAL, hmtrl );

pd3dDevice->SetLightState( D3DLIGHTSTATE_AMBIENT, 0x80808080);
pd3dDevice->SetRenderState( D3DRENDERSTATE_DITHERENABLE, TRUE );
pd3dDevice->SetRenderState( D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD );

// RENDER SCENE

if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{

if (FAILED(pvViewport->Clear2( 1UL, prcViewportRect,
D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L )))
{

pd3dDevice->EndScene();
return S_OK;
}

// Only one oject right now, no state changes
D3DVERTEX *verts = AllObjects.GetStart()->GetVertices();
unsigned int numverts = AllObjects.GetStart()->GetNumVertices();

pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_VERTEX, verts, numverts, NULL);

pd3dDevice->EndScene();
}

[This message has been edited by LaChoppe (edited September 19, 1999).]

point lights are affected by range, and i think you didn't set the range in your code (i hope it's not my eyes' faults). if after that it still doesn't work, i suspect a problem with normals. what you could try doing then is setting all the normals to point in one direction, such as <0,0,-1>, put the object at <0,0,1>, and put light at <0,0,0> and see if it works

Thanks for the help.

I tried setting the range, and it didn't help. I also tried forcing the normals to be <0,0,-1> (facing the camera), and placing the light in front, to no avail. I even tried replacing the point light with a directional light pointing <0,0,1>.

Any more ideas?

-La'Choppe

i'm not sure, but you may need a texture for lighting. you could try using a directional light to see if you're just putting the light in the wrong place. also try setting range to some really huge value

I tried a directional light, and it had no effect, even with the normals overridden to face opposite the light. I set the range to D3DLIGHT_RANGE_MAX, with no effect.

I'll try the texture dealie. Thanks...

### ADDED:

I'm back. No apparent effect having the texture set. Also, it makes no difference whether I'm using the HAL or RGB emulation. ;(

[This message has been edited by LaChoppe (edited September 21, 1999).]

Still nothing. I've tried just about everything I can think of. Anyone else have any ideas? I'm almost ready to reinstall the D3D SDK (I know it won't have any effect, just for peace of mind... )...

Thanks...

-La'Choppe

maybe if you made the source available people could figure it out. i did have a problem like that where my object would always be at full brightness, found out i didn't have normals in my custom vertex format. does ambient light have any effect?

try drawing just a triangle and see if that gets lit properly.

it my be a problem with the attenuation values, although i see nothing wrong with what you did you could mess with that. you could also call GetLight and see if the values you get back are what you put in.


This topic is closed to new replies.

Advertisement