Jump to content
  • Advertisement
Sign in to follow this  
Ungunbu

Unity CRPG Pre-rendered Bacgrounds - Draw depth to Z-Buffer

This topic is 1331 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 to everyone,

 

 

 

say I have a pre-rendered background image and I want to display 3d characters on top of it. I also have a depth map; to create it the same background is rendered again but this time the resulting texture stores depth values instead of colors. We then have 2 textures ready to use: color and depth.

Now what I ideally need is a way to copy the visible portion of the depth map into the depth buffer prior to rendering 3d objects. I say visible because the backgrounds will most likely be very big. I'll probably need to create sub-images from them like a tile map with very big tiles. The same applies to the depth map of course.

 

I'm a bit new to Unity but I think I could render a quad using a custom shader that samples the depth map (the visible part of it) and outputs the read values to the depth buffer. Sadly, I have no idea how to implement this (in Unity) so I'd be very grateful if you could:

 

- Comment on my approach

- Suggest a way to implement it or point me to relevant info

 

I'm sorry if my post is a bit confusing, please don't hesitate to ask more details.

 

 

Thank you very much,

ung

 

EDIT: there's a typo in the title but I can't edit it, if you know how to do it please tell me. Thank you.

Edited by Ungunbu

Share this post


Link to post
Share on other sites
Advertisement

That sounds like a reasonable approach. I'm not familiar with writing shaders in Unity, but a search for "unity shader output depth" returns some threads about it, with problems and solutions.

 

Keep in mind you may incur some performance penalty with this, since it will likely disable hierarchical depth testing for anything drawn after.

Share this post


Link to post
Share on other sites

If writing a sampled value to the ZBuffer in your fragment shader proves too inefficient, or too difficult, you could try using a mock or imposter for your background; a lower-resolution mesh that has the approximate 3D shape of the background, onto which you project the pre-rendered background image. There was a post about this just recently, albeit using it for building-shaped "sprites" in a 3D scene.

 

http://www.gamedev.net/topic/665988-simple-geometry-uv-mapping/

Share this post


Link to post
Share on other sites

Seems reasonable to me. You can probably even draw all your opaque objects before rendering in your background, which should give you back most of your hierarchical-Z I would think. You'll need to do transparent objects afterwards, though, if you have any.

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.

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!