Jump to content
  • Advertisement

Archived

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

AndyGeers

Bump Mapping

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

I''m trying to make a game using bump mapping to create the effect of 3D sprites. I can do directional light sources easily enough using the dot product texture blending mode (i.e. do a dot product between the bump map texture value and a vector specifying the direction of the light source, then blend the result of that with the original sprite''s texture value) but I haven''t, as yet, found out how to create positional light sources, where the vector from the light source will vary from pixel to pixel. Is it necessary to start using programmable pixel shaders to do this, or is there a more portable means of creating the effect?

Share this post


Link to post
Share on other sites
Advertisement
A positional light is not really that much different: you just need to calculate the light vector per vertex rather than being able to use a constant vector for all objects. You can calculate it in a vertex shader if you want to, but for a 2d game you probably won''t notice any speed difference by calculating it by hand before drawing. The colour interpolation between vertices will create the inbetween vectors for you.

The only snag is that the interpolation will de-normalise your light direction vector. For some situations you won''t really notice a difference (especially if the two vectors are pretty similar anyway) but it can have some nasty side effects. The solution to this is a normalisation cube map - you specify the light vector using texture coords, which look up to a normalised vector (stored as an RGB colour). Google should be able to give you a more complete description.

Share this post


Link to post
Share on other sites
Thanks for your reply, but how would you actually go about setting the light vector per vertex? At the moment I use SetTextureStageState to use the D3DTOP_DOTPRODUCT3 texture operation with D3DTA_TFACTOR as one of the arguments to store the direction of the light source, but the TFACTOR is a constant rather than something per-vertex.

Share this post


Link to post
Share on other sites
quote:
Original post by AndyGeers
Thanks for your reply, but how would you actually go about setting the light vector per vertex? At the moment I use SetTextureStageState to use the D3DTOP_DOTPRODUCT3 texture operation with D3DTA_TFACTOR as one of the arguments to store the direction of the light source, but the TFACTOR is a constant rather than something per-vertex.


You need to use something that:
a) is capable of being a vector (e.g. an RGB value)
b) is interpolated across the face
c) is available as an input to a texture stage

For DOT3 using the fixed function pipeline,usually one of the vertex colours (COLOR1 or COLOR2, aka DIFFUSE or SPECULAR) is used whereby the vector is stored per vertex in the colour (the same way as you convert the vector ro RGB to go into TFACTOR).

You''ll need to do the same when you get into texture/tangent space bump mapping where you''ll also need to transform the light vector into the coordinate system of the texture map on each individual polygon.

Obviously if the model changes with respect to the light source, you''ll need to recompute the per vertex light vectors and change the contents of the vertex buffer.


Personally, unless I was working at something very specifically targetted at first generation hardware T&L cards (e.g. GeForce1 & 2), I''d use a vertex shader for the vertex processing side of things, even if I had to use software vertex processing. Shaders make DOT3 a *lot* cleaner to use.


Simon O''Connor
Game Programmer &
Microsoft DirectX MVP

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!