• Advertisement

Archived

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

Shadows Using Alpha Transparency?

This topic is 5741 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 render a model of earth with the hemisphere opposite the sun dark. I''ve been messing with the d3ddevice->SetRenderState() flags for a bit but I can''t find a way to make this work. I currently have a half-sphere model that is being textured with a black map. The half-sphere is slightly larger than the earth so it covers approximately half the planet. I wan''t it to render with a slight transparency (turning off transparency makes it look totally unrealistic) so that the covered hemisphere looks almost completly shrouded in darkness. Unfortunately, since black is normally the color used for transparency I''m stuck. Thanks for the help, -Ben | particlefield.com |

Share this post


Link to post
Share on other sites
Advertisement
Why are you not just using directional lighting? It would accomplish everything you need (at least as you''re describing it)

Share this post


Link to post
Share on other sites
D3D has the capability to do these basic lighting effects internally. There are several ways to go about doing this, but by far the most simple is to enable vertex lighting.

A complete description is in the documentation, but to give you a quick idea of what's involved:

-- Make sure your sphere mesh has surface "normals", in addition to vertex positions. The D3DX function D3DXComputeNormals can do this if your using the D3DX stuff. If not, there are some tutorials in the "articles" section on how to do this. Depending on how you got your sphere, it might already have surface normals... Anyway, make sure your vertex format reflects this, and then lock the vertex buffer and send the position/normal vertices in. All this can seem rather daunting, but it's not as bad as it sounds.

-- Set the D3DRS_LIGHTINGENABLE to TRUE, to turn lighting on. From now on, unless you put a light somewhere, everything will be black, so don't be shocked!

-- You can then create a directional light to simulate the sun light. This means filling out a small D3D structure, and passing it into a function.

-- You might have to set some other values, and create a material if you want. It;s explained much better in the documentation.

So unless you're doing something that really specifically needs another textured halfsphere, you can just use the original sphere with the internal D3D lighting mechanism, and the dark side will always face away from whatever direction you choose for the directional light.

Good luck!

[edited by - SH on May 31, 2002 1:50:23 PM]

[edited by - SH on May 31, 2002 1:56:23 PM]

Share this post


Link to post
Share on other sites
Hey thanks a lot for the help. I originally stayed away from the lighting stuff because I didn''t know if it was widely supported in hardware, but I guess it is pretty common. Two quick questions about it. Do I have to make (or load from my 3ds files *shudder*) any D3D8MATERIAL (I think that''s the name) stuff? Also, can I just turn lighting off when I render certain parts of the scene (like the heads up display)?

Thanks again.
-Ben

You can see a screenshot here if you''re interested:
http://www.particlefield.com/misc/wge.jpg



| particlefield.com |

Share this post


Link to post
Share on other sites
Just about every graphics card on the market right now supports the standard vertex lighting in hardware. This includes everything from the "lowly" GeForce1 and Radeon upwards. Those that don't do hardware lighting also don't do vertex transformations in hardware either, so D3D does everything in software anyway-- the lighting is just a small additional cost. And the D3D software is HIGHLY optimized, I understand. I don't think you should trouble yourself with this, unless you're specifically trying to render VERY dense meshes on VERY low-end hardware, at the cost of all else...

I don't believe 3ds files support the D3DMATERIAL8 format, but I could be wrong. In anycase, if you just want to modulate the light with your texture (basically "light" the texture), I think a default material should be more than adequate-- you don't have to load a material from 3ds. See the documentation for more info on setting this up-- it should almost work without you doing anything, as it's a common technique. I don't know the 3ds format, but if you're using a texture, you might have to load it from this file. In anycase, you can easily get around this by using the handy D3DX load texture functions to just load the texture manually from a .tga or .bmp or .jpg file.

Yes, certainly, it's a wonderful idea to turn lighting off when you're not using it. Use lighting when you need it for the effect, then toss it when you want to render other stuff that isn't lit/doesn't use lighting.

I know it sounds really complicated, but I'm not really writing this well, and D3D really is sort of setup (finally...) to make doing things like this easy.

Very impressive screenshot-- interested in how you handle the rendering of the text. Are they triangle strips? I always had a great deal of trouble with this...






[edited by - SH on May 31, 2002 10:48:42 PM]

Share this post


Link to post
Share on other sites
Cool, I''ll be spending the next few hours putting lighting in then. I have a few changes to make with the model loading code.

quote:

I don''t believe 3ds files support the D3DMATERIAL8 format, but I could be wrong. In anycase, if you just want to modulate the light with your texture (basically "light" the texture), I think a default material should be more than adequate-- you don''t have to load a material from 3ds.



They don''t support D3DMATERIAL8 directly, but they can store material info which can be thrown into a D3DMATERIAL8. I think you''re right that I don''t need to load anything from the files. If I can just use a default material than that''ll be perfect. Good thing too, If I ever have to look at that God awful file format again *ugh bad memories*...

As for the text rendering, I''ve just been using the ID3DXFont class. You can use D3DXCreateFont() to create a custom font from the HFONT returned by the windows CreateFont() function. It''s been working pretty well so far. I''m not sure if it uses GDI or if it''s related to CD3DFont class, but I don''t see any loss in framerate while I''m using it. Here''s the tutorial I learned it from:
http://www.drunkenhyena.com/dload/D3DLesson13.zip
It''s a lot less work than making a bunch of textured quads for each font.

Cheers,
-Ben


| particlefield.com |

Share this post


Link to post
Share on other sites
Holy crap, lighting is in place and WOW
It was definitely worth it, even if it did cut my framerate clean in half lol. I''ll have to lower the number of tris in those spheres. The whole world right now is about 63,500 vertices and 21,000 tris. I guess that doesn''t seem that high. oh well.

Thanks again for the advice. It was well worth it. Here''s a shot:
http://www.particlefield.com/misc/wge2.jpg

30 FPS on a GF2 lol. I didn''t think I could ever do that much damage

Cheers,
-Ben




| particlefield.com |

Share this post


Link to post
Share on other sites
You can probably increase that speed a good bit if you call Optimize on the mesh. (Assuming your using D3DX)

Jack

Share this post


Link to post
Share on other sites
look into LOD algorithms which are designed to lessen the number of polygons in a mesh the further the mesh is away from the viewer (ie smaller on the screen). since you only need really high polygon counts if you are close to the sphere.

Share this post


Link to post
Share on other sites

  • Advertisement