Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Scale and directional light in directx Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
TFreudi1

April 26, 2005, 10:34 AM

If I only use directional light in a scene and I scale a object (loaded from x-file) with for example
matView._11 = 100.0f; matView._22 = 100.0f; matView._33 = 100.0f;

The directional light component is nearly off. Means there are no more colors/shadow on the object. If I scale it back the colors/shadows come again.

I try setting the diffuse-component (r/g/b) of the directional light to 100.0f instead of 1.0f then the color came back, but I have other effects that I did'nt want.
Is there a solution for this problem ?

Thanks Freudi

 
juhnu

April 26, 2005, 11:25 AM

the fixed function pipeline in the d3d uses the same matrix to transform both vertices and normals and as the normals are scaled as well it causes the lighting calculations not working correctly. You can however enable a certain renderstate so the d3d will renormalize the normals before doing any lighting calculations. try

  1.  
  2. device->SetRenderState( D3DRS_NORMALIZENORMALS,TRUE );
  3.  


..maybe this fixes your problem


juhani

 
Reedbeta

April 26, 2005, 11:26 AM

Make sure you turn on normalization of normal vectors. When you scale your object, the normals will get scaled too, so they need to be renormalized in order to be correct for lighting.

 
TFreudi1

April 26, 2005, 02:45 PM

That's it. Thanks a lot !
I guess
device->SetRenderState( D3DRS_NORMALIZENORMALS,TRUE );
is the slow but easy solution ?

Or is it Ok to program like
device->SetRenderState( D3DRS_NORMALIZENORMALS,TRUE );
device->SetTransform( D3DTS_WORLD, &matView )
m_pBox->Render( device );
device->SetRenderState( D3DRS_NORMALIZENORMALS,FALSE );

Thanks a lot again. I know that normals play a role with directional light, but there is nothing about the scaling thing in my books nor SDK Docu.

Freudi



 
Reedbeta

April 26, 2005, 04:50 PM

Yes, you can turn the normalization state back off after you render the world if you want. Just leaving it on doesn't hurt anything, though - unless you are rendering other things, that don't need normalization.

 
This thread contains 5 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.