Created
September 15, 2014 08:35
-
-
Save pixelmager/b259c6165f67d0039ca3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excerpt from Internal-PrePassLighting.shader (available at e.g. http://download.unity3d.com/download_unity/builtin_shaders-4.5.4.zip )