And in a script attached to the camera I set " camera.depthTextureMode = DepthTextureMode.Depth;"
However in Unity 3, this returns a gray texture. The shader definitely works, although it seems there are no proper depth values in _CameraDepthTexture, or I’m interpreting them incorrectly.
If I switch the camera to deferred rendering it renders fine. Switching it to forward rendering nothing seems to get written to the depth texture.
If I activate deferred rendering, hit Play, hit Stop, switch to forward rendering and hit Play I notice my depth texture still works, but doesn’t get updated anymore. If I hit Stop, and Play again now the depth texture seems to be cleared and doesn’t update.
It should work in both forward deferred rendering (and it certainly does in our test suites). More details please how to reproduce the problem (best file a bug with complete project that reproduces the issue).
When I try your shader set camera’s depth texture mode from script, it works for me as well. (Unity 3.0.0f1, Mac OS X 10.6.4, GeForce 8600M).
Hi, sorry for the slow response. I added an example project and some screenshots to my bug report. It’s case #374352.
Here’s deferred when not playing
Here’s deferred when playing (only time when its rendered right, and ONLY in scene, and not game view)
Here’s forward. Either playing or not playing it’s the same problem.
If you have deferred on, and switch to forward rendering and hit play, the depth texture will render, but wont get updated. (I assume it remained from the deferred rendering and wasn’t cleared). But if you stop and play once more, now it will not show it anymore until you go back to deferred.
The exact shader code is (different from my first post):