Newbie: How would I do this??

Started by
17 comments, last by Coleco 19 years, 11 months ago
3D newbie here. I am using 3D textured quads for a 2D engine (tile based) Tile are drawing fine but I want to experiment with lighting. What I want to do is say have my player walk into a cave with torches and everything is completely black until it comes near a torch... I have no idea how to start somthing like this... Suggestions appreciated. Thanks! -cbmeeks

~ c o l ec o ~

Rock the cradle of love! You stupid WANKER! S i g n a l D E V .com Metroid Classic
Rock the cradle of love! You stupid WANKER!
Advertisement
There is hardware lighting in DirectX, but I haven't tried using it myself, yet.

If you want to do it in software, then make sure that your vertex structure includes a D3DCOLOR diffuse value (and adjust your FVF accordingly, of course). Then you can use SetTextureStageState to blend the texture with the vertex color. You'd probably use MODULATE as the operation, use TEXTURE as ARG1, and DIFFUSE as ARG2. Then, before you draw your quad, just make sure that the color values for the vertices are set. White would make the textures show up normally. Black would make them completely black. Blue would filter out all red and green, etc. There are other operations besides MODULATE that you can use too, if you want to brighten a texture beyond its typical brightness, or to maybe even get odd effects.

So the only thing left would be to calculate which tiles need to have a darker color applied to them.

[Edit - I was missing the word "FVF". Dunno how.]

[edited by - Agony on May 25, 2004 11:43:47 AM]
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
dx8: you''ll want to do a m_pD3DDevice->SetMaterial(&mtrl), along with m_pD3DDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(ar, ag, ab). After that, m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE).

then for each light:
m_pD3DDevice->SetLight(0through7, &d3dLight);
m_pD3DDevice->LightEnable(0through7, TRUE);

once you''re out of the caves all yuo need is to set the ambient light back to 255,255,255.
oh, and be aware that lights are very expensive. Especially for a 2d game I''d suggest no more than 1-2 lights. The light you''ll most likely want is a point light.
quote:Original post by kVandaele
oh, and be aware that lights are very expensive. Especially for a 2d game I''d suggest no more than 1-2 lights. The light you''ll most likely want is a point light.

Hm.. 1 - 2 lights? Are you sure that lights are THAT expensive?

I don''t think so.

--
You''re Welcome,
Rick Wong
- Google | Google for GameDev.net | GameDev.net''s DirectX FAQ. (not as cool as the Graphics and Theory FAQ)
Most documents or books I''ve read on lighting say that the first 8 to 10 lights come pretty much free on today''s video cards. Spotlights are expensive, point lights are less, and directional lights are the least. I would think in your case though, you only need 1 light, the one in the player''s (his character''s) hand...unless you put torches on the walls. You might as well use a light map if you''re going to do that though, since the torch won''t be moving (unless you animate the flame).

Chris
Chris ByersMicrosoft DirectX MVP - 2005
Yeah, I just can''t seem to get the spotlight to work. Every variation of lighting I do just acts as ambient light. No matter what direction, type, etc it affects everything.

I am thinking because my quads obviously just have two triangles so you can''t do detailed vertex lighting...

Ok, I''ve been hearing light maps...how would I go about doing that? Any good sites? Remember, I am doing 2D with quads...thanks!

-cbmeeks

~ c o l ec o ~



Rock the cradle of love!
You stupid WANKER!
S i g n a l D E V .com
Metroid Classic

Rock the cradle of love! You stupid WANKER!
quote:Original post by Pipo DeClown
Hm.. 1 - 2 lights? Are you sure that lights are THAT expensive?

I don''t think so.


while true, I don''t think a 2d game is aimed at today''s video cards, nor is it good for a 2d game to have a recent video card as minimum requirements...

Coleco: have you tried reducing the range and/or brightness of the point light? Also, try and make it blue and see if the screen turns blue. If not you forgot to set something (the material, some states, ...)
Yeah, I''ve played with the range and every thing else.

I can change it to blue or any color...it acts just like ambient light.

~ c o l ec o ~



Rock the cradle of love!
You stupid WANKER!
S i g n a l D E V .com
Metroid Classic

Rock the cradle of love! You stupid WANKER!
we''ll you''ll want to set the light right above the quad, and have the range be small. The further away, the less the change across the screen will be...

maybe you could post the code you used to create your lights/quad

This topic is closed to new replies.

Advertisement