i want to write a shader, wich uses the current depth buffer values as tranparency values.
i would also like to use a threshold value, to be able to clamp certain values.
Is something like that already out there, or do you have any idea how to do this? it doesn’t sound really fancy but i have not much experience with the shader language in unity…
Generally reading the depth buffer is not possible in shaders (it’s only possible in DirectX10, which requires Vista plus a DX10 hardware plus a DX10-enabled application).
actually what i want to do is to render a cube partially transparent.
the parts near the viewpoint should be more transparent then parts far away from the viewpoint.
such that it creates an illusion of looking inside the cube, no matter from wich side you look at it.
i thought the way to realize this is to use the depth values as alpha values, so you get always a smooth transition.
is it really only possible with DX10?
What you want to do is get the depth in the vertex shader by measuring the distance from the vertex to the camera (make sure you are in the correct vector space first). Then you can adjust those values so that they equal 0 at the front of a cube and 1 at the back, and feed that into the alpha somehow. The simplest way to do this will probably be with a helper script that passes some constants to the shader every frame.
But you still have the ever present alpha-depth problem (transparent objects can’t write to the depth buffer) and thus you will need to perhaps make each cube face a different object so that sorting can handle the depth for you.
I am looking to do a soft-particles like effect (ie. rendering transparent geometry on top of an opaque scene, fading out clipping) - but I can’t figure out how to access the scene depth-values.
I am aware of the dx10-problem (which apparently extends to opengl for unity), but solutions to circumvent this exists - e.g. rendering depth to the alpha-channel of opaque objects (and making that available as a texture in the transparency pass), or using MRTs, or doing an entirely different render-pass to output depth.
Anyway, I would love to know if this is now possible It seems I could use the same solution as shown to do soft-particles using shader replacement, which essentially is the separate depth-pass approach.