I am trying to create a shader that has translucency, but the amount of light that passes through depends on how "thick" the object is, or how far the light would have to travel. The paper that I read (http://http.developer.nvidia.com/GPUGems/gpugems_ch16.html) had the camera render the depth from the light into a texture, then reference that texture to find the distance the light would travel. However, since I don't know how many lights are in a scene at a given time, I can't very well do that (or can I? I don't know!). My alternative idea was to "trick" it by rendering the depth of the scene into a depth texture, but with culling set to "front." My reasoning was that we could find the differences in depths, and at least "approximate" the distance the light would have traveled through. It's not ideal, but it's all I have. I can't get SetReplacementShader (http://docs.unity3d.com/ScriptReference/Camera.SetReplacementShader.html) to actually replace anything on my camera. I set up a secondary camera as a child of the main, and applied this script to it: http://pastie.org/private/bezkrrcm4b11vbobvrjfqw. I put a renderTexture in the "Target Texture" for the camera, but nothing is being written there. What am I doing wrong? Am I even going about this the right way? Am I crazy?
Actually what that paper is talking about is the BASICS on how we do shadows nowadays! And usually you limit it to the directional light. (note, singular), as it consumes quite a bit of performance. Now however for your case I'd suggest that you simply paint your translucency texture based on how thick the material is there. If you Really want to go towards perfection based on the lights directions you could use Unity shader replacment to render ONLY the translucent objects, as that shouldn't be to heavy on performance. Even for 10+ lights.
What do you mean by "how thick the material is?" Do I need to have a "thickness" variable in the shader? I'm confused.
No thickness in the shader, just another map that would need to be painted/baked to get an idea of how much translucency to use. It's the normal way of doing translucent objects. Your, (Awesome I might add), solution would not require this in exchange for complexity and performance.
Thanks! If I can get it working that would be great. Right now I'm having trouble with getting the depth texture to actually be something other than black. I am using the shader given here: http://docs.unity3d.com/Manual/SL-DepthTextures.html
Check out my SSR article, I'm doing exactly this to calculate geometry depth. http://www.kode80.com/blog/2015/03/11/screen-space-reflections-in-unity-5/index.html
Hi Kopde80 i am also intrested in translucency, i sas wondering if your method can compute depth for non convex objects (eg human ears, that is the most common use for it) Thanks victor
Kode80, I see that you use two depth textures. I'm wondering if I could get by with just one (the front culled one) and use the COMPUTE_EYEDEPTH macro for my shader. I'd like to make my shader as freestanding as possible. I have been unable to get COMPUTE_EYEDEPTH to work right though.