Skip to content

Instantly share code, notes, and snippets.

@MattRix
Created December 12, 2015 18:29
Show Gist options
  • Select an option

  • Save MattRix/3ecec4325db2712efd7e to your computer and use it in GitHub Desktop.

Select an option

Save MattRix/3ecec4325db2712efd7e to your computer and use it in GitHub Desktop.
Basic depth texture rendering
Shader "----------/Edger"
{
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _CameraDepthNormalsTexture;
struct appdata
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv:TEXCOORD0;
};
//Vertex Shader
v2f vert (appdata v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.pos);
#if defined (UNITY_UV_STARTS_AT_TOP)
o.uv = float2(v.uv.x,1-v.uv.y);
#else
o.uv = v.uv;
#endif
return o;
}
//Fragment Shader
half4 frag (v2f i) : COLOR
{
return tex2D(_CameraDepthNormalsTexture, i.uv);
}
ENDCG
}
}
FallBack "Diffuse"
}
@MattRix
Copy link
Copy Markdown
Author

MattRix commented Dec 12, 2015

ahhh github's indenting drives me nuts

@spk921
Copy link
Copy Markdown

spk921 commented Mar 31, 2017

I found your code from William's site: http://williamchyr.com/2013/11/unity-shaders-depth-and-normal-textures/. I am trying to use depth information. And can't run his example. Do you know how I can code camera component or any related source?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment