Jump to content
  • Advertisement
Sign in to follow this  
Programmer101

Depth Test

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

Hi everyone! I have a sword that is being carried by the player character in a first person view. How can I make it so this sword appears in front of everything but still appears behind the water? I can clear the depth buffer and render the sword last but then the sword will not blend with the water. I can also clear the depth buffer and render the sword then the water but then the water appears in front of everything. I want the sword in front of everything except the water. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
As hard as I try, I can't envision what you want. Why would a sword be in front of everything except water?

Render everything, except water. Disable Z (D3DRS_ZENABLE, false). Render sword, Enable Z, render water. The sword's Z won't get written, but I have no idea if that matters to you. I really can't envision what you're doing.

Share this post


Link to post
Share on other sites
If depth testing does matter when rendering the sword you can use the stencilbuffer:

- Render sword to backbuffer using depthtesting (and writing) and set stencilbuffer to 1 for every rendered pixel
- Render water using only depthtesting
- Render the rest of the world to your backbuffer using depthtesting, but only where the stencilbuffer != 1.

Hope it helps

//Emil

Share this post


Link to post
Share on other sites
I want the sword to be in front of everything so that when you walk up to a wall or slash at a wall it won't go through the wall and make the collision look bad. I don't want it in front of the water because I want the water to blend with the sword when it gets submerged.

I still don't know if this makes sense but I got the technique from oblivion if you have ever played that.

Share this post


Link to post
Share on other sites
Render everything but the water and sword,
Disable Z-Testing (ZFUNC to ALWAYS) but don't disable ZWRITEENABLE,
Draw the sword,
Re-enable Z-Testing (ZFUNC to what it was, probably LESSEQUALS),
Draw water.

If I understand correctly, you only want the parts of the sword that are underwater to have the water rendered over them. If so, this should work.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!