0

I'm new to DirectX and having trouble getting colors & lighting to work.

I want to be able to load various colored vertices into a single vertex buffer and enable with directional lighting, however every method I try has problems. Imagine I want to render 3 cubes, red green & blue respectively, with white directional lighting from the back.

1) I don't want to set the color via device.Material because then I'd have to make a separate call to DrawPrimitives() for each cube.

2) Working from samples, I seem to be able to get something working by using CustomVertex.PositionNormalColored - problem is I'm not really clever enough to set the Normal vertex programmatically. (Any tips? I don't want anything fancy, just for the lighting to work.)

3) CustomVertex.PositionColored seems ideal but doesn't seem to work with I turn on lighting and add a direction light, it seems to want the Normal vector.

I don't really have a stable code sample to provide but would appreciate any general advice on how to implement this - what CustomVertex to use, what's necessary for directional lighting to work, etc.

-Brendan

Brendan Hill
  • 3,406
  • 4
  • 32
  • 61
  • 1
    Normals are required since most simple lighting models use some form of `dot(pixel.Normal, lightVector)` for calculating the lighting amount at a pixel. Either [calculate the normals](http://gamedev.stackexchange.com/questions/8191/any-reliable-polygon-normal-calculation-code) or export them directly from your 3D modelling application (which usually gives better results). – Lucius Feb 19 '13 at 11:35
  • Thanks Lucius, looks like I'll have to get my head around these surface normals then. – Brendan Hill Feb 20 '13 at 10:51

0 Answers0