0

I'm not sure if this is possible (or if I'm asking the right question). I have a vertices/indices and I render in a scene in DirectX 9.0. Now, I'd like to add ambient and diffuse lights, and then get the final resulting calculated Diffuse Shade of each vertex. So basically, have a sun, and then different point lights around. I guess it would be similar to how Blender would do it. Then I want to get the final result of each vertex, and write it off to a file statically (no dynamic lighting). Then it will go into a game which uses static diffuse color per vertex. So it wouldn't depend on camera, the lighting, only on the static point/sun.

I don't think I can use DirectX lighting, because that doesn't appear to let you get the final RGB of the final vertices for export?

Does anyone have algorithms? Or a way to somehow add lights in DirectX and then get final result?

Mary Ellen Bench
  • 589
  • 1
  • 8
  • 28

1 Answers1

0

I'm not sure if I understand the question entirely, but the way I understand it, you're saying that you want to "bake" the lighting from the point lights into the vertex colors?

If that's the case, then you can use the same math that the default directX shader uses to calculate the final vertex color. I think the output color is usually calculated as:

// saturate just clamps the resulting color values between 0 and 1.

out_ambient = saturate(vtx_ambient * ambient_light)
out_diffuse = saturate(vtx_diffuse * light_diffuse * -dot(vtx_normal, light_direction))

out_color = saturate(out_ambient + out_diffuse)

Because you're using point lights, you'd have to calculate the light_direction from the vertex and light positions, but I think using this will get you the resulting color for the individual vertices.

I haven't used shaders extensively myself, so I may have calculated the result wrong - is someone able to verify if this is correct?

Jason Lim
  • 171
  • 6
  • Do you know how they calculate the ambient and diffuse lights as well? (that equation assumes already have those values). – Mary Ellen Bench Jan 13 '13 at 18:59
  • The ambient and diffuse light values are just the color or intensity values of the lights that you want to add to the scene. If you have multiple point lights in the scene, then you're going to use multiple out_diffuse equations using each light's diffuse value. All of your out_diffuse values are then summed together in the final out_color calculation. The same could be applied for multiple ambient lights if you wanted to - but I`m assuming one ambient light value because ambient light is applied uniformly. – Jason Lim Jan 14 '13 at 04:39