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

Started by
3 comments, last by Ravyne 9 years, 1 month ago

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.

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.

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/

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

Maybe I could render a simplified version of the level mesh but only outputting its depth.

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.

throw table_exception("(? ???)? ? ???");

This topic is closed to new replies.

Advertisement