yty
August 1, 2011, 4:19pm
1
c#
function OnEnable () {
camera.depthTextureMode = DepthTextureMode.Depth;
}:face_with_spiral_eyes:
shader
sampler2D _CameraDepthTexture;
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 fragThin (v2f i) : COLOR
{
half4 depth= tex2D (_CameraDepthTexture, i.uv);
return depth;
}
But why the results of a white, can not see anything?
sampler2D _CameraDepthTexture;
v2f vert( appdata_img v )
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 fragThin (v2f i) : COLOR
{
half4 depth = half4(Linear01Depth(tex2D(_CameraDepthTexture, i.uv).r);
return depth;
}
yty
August 1, 2011, 5:03pm
3
Thank you very much to reply my post in the forum
Why only use Linear01Depth, can not LinearEyeDepth?
Only Linear01Depth in play mode to be effective, LinearEyeDepth nothing in game mode.
uniform float4 _ZBufferParams;
// Z buffer to linear 0…1 depth (0 at eye, 1 at far plane)
inline float Linear01Depth( float z )
{
return 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
}
// Z buffer to linear depth
inline float LinearEyeDepth( float z )
{
return 1.0 / (_ZBufferParams.z * z + _ZBufferParams.w);
}
yty
August 2, 2011, 2:45am
4
Also, I want to ask can depthTexture to gui draw on it?
For example rendertexture.
GUI.DrawTexture (new Rect(0, 0, 128, 128), m_ReflectionTexture, ScaleMode.StretchToFill, false);
This will not find _CameraDepthTexture
GUI.DrawTexture (new Rect(0, 0, 128, 128), _CameraDepthTexture, ScaleMode.StretchToFill, false);?
_CameraDepthTexture is a texture to use in shaders, you can’t use it outside no
is the _CameraDepthTexture only usable in vert and frag shaders ? not in surface shaders ?
Cause I can’t get this to work in a surface shader
Marrt
January 8, 2013, 9:57am
7
since this thread has been reanimated:
can i copy the “clearing-texture”(dont know if this even exists) from one viewport to another?
http://forum.unity3d.com/threads/162235-Creating-a-ClearMask-Texture?p=1109426&viewfull=1#post1109426