Skip to content

Instantly share code, notes, and snippets.

@pixelmager
Created September 15, 2014 08:35
Show Gist options
  • Save pixelmager/b259c6165f67d0039ca3 to your computer and use it in GitHub Desktop.
Save pixelmager/b259c6165f67d0039ca3 to your computer and use it in GitHub Desktop.
sampler2D _CameraNormalsTexture;
float4x4 _CameraToWorld;
v2f vert (appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = ComputeScreenPos (o.pos);
o.ray = mul (UNITY_MATRIX_MV, v.vertex).xyz * float3(-1,-1,1);
// v.normal contains a ray pointing from the camera to one of near plane's
// corners in camera space when we are drawing a full screen quad.
// Otherwise, when rendering 3D shapes, use the ray calculated here.
o.ray = lerp(o.ray, v.normal, _LightAsQuad);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
depth = Linear01Depth (depth);
float4 vpos = float4(i.ray * depth,1);
float3 wpos = mul (_CameraToWorld, vpos).xyz;
}
@pixelmager
Copy link
Author

Excerpt from Internal-PrePassLighting.shader (available at e.g. http://download.unity3d.com/download_unity/builtin_shaders-4.5.4.zip )

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