{"id":732,"date":"2012-03-06T20:47:14","date_gmt":"2012-03-06T17:47:14","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=732"},"modified":"2014-07-08T16:43:50","modified_gmt":"2014-07-08T13:43:50","slug":"camera-shaders","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2012\/03\/06\/camera-shaders\/","title":{"rendered":"Camera Shaders"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"733\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/03\/06\/camera-shaders\/depthmapshader1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/depthmapshader1.jpg?fit=680%2C383&amp;ssl=1\" data-orig-size=\"680,383\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"depthmapshader1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/depthmapshader1.jpg?fit=680%2C383&amp;ssl=1\" class=\"alignnone size-full wp-image-733\" title=\"depthmapshader1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/depthmapshader1.jpg?resize=680%2C383\" alt=\"\" width=\"680\" height=\"383\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/depthmapshader1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/depthmapshader1.jpg?resize=300%2C168&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>yay..took few hours just to get this working: Render a whole camera view with one shader.<br \/>\nIt should be simple, but the documents wont give any examples: <a title=\"http:\/\/unity3d.com\/support\/documentation\/ScriptReference\/Camera.RenderWithShader.html\" href=\"http:\/\/unity3d.com\/support\/documentation\/ScriptReference\/Camera.RenderWithShader.html\" target=\"_blank\">Camera.RenderWithShader <\/a><\/p>\n<p>Main image is showing vertex-depth-shader seen with camera (its modified version from one of these <a title=\"http:\/\/unity3d.com\/support\/resources\/example-projects\/shader-replacement.html\" href=\"http:\/\/unity3d.com\/support\/resources\/example-projects\/shader-replacement.html\" target=\"_blank\">unity replacement shaders<\/a>)<\/p>\n<p>Next..<br \/>\n&#8211; How to use camera shaders to make some more fake shadows? or ambient occlusion? or this kind of screen <a title=\"http:\/\/unitycoder.com\/blog\/2012\/02\/26\/water-splash-screen-effect-shader\/\" href=\"http:\/\/unitycoder.com\/blog\/2012\/02\/26\/water-splash-screen-effect-shader\/\" target=\"_blank\">water effect<\/a>? (with unity indie..)<br \/>\n(I dont know..going to play around with the camera shader a bit..)<\/p>\n<p>&#8212;<\/p>\n<h3>Update#1<\/h3>\n<p>Well this is interesting, the fake river shader works quite nicely as camera shader.<br \/>\nAnd a problem..fragment shaders wont work with camera??<\/p>\n<p><strong>image#2<\/strong>:\u00a0 without camera shader &amp; with shader<br \/>\n<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"740\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/03\/06\/camera-shaders\/fullscreenshader1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/fullscreenshader1.jpg?fit=680%2C295&amp;ssl=1\" data-orig-size=\"680,295\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"fullscreenshader1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/fullscreenshader1.jpg?fit=680%2C295&amp;ssl=1\" class=\"alignnone size-full wp-image-740\" title=\"fullscreenshader1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/fullscreenshader1.jpg?resize=680%2C295\" alt=\"\" width=\"680\" height=\"295\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/fullscreenshader1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/fullscreenshader1.jpg?resize=300%2C130&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>&#8212;<\/p>\n<p>CameraShader.js:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\n#pragma strict\r\n\r\nprivate var cam:Camera;\r\npublic var repl:Shader;\r\n\r\nfunction Start () {\r\n\/\/repl = Shader.Find( &quot;Custom\/Render Depth&quot; );\r\ncam = Camera.main;\r\ncam.RenderWithShader(repl, &quot;RenderType&quot;);\r\n}\r\n\r\nfunction OnPostRender ()\r\n{\r\ncam.RenderWithShader(repl, &quot;RenderType&quot;);\r\n}\r\n\r\n<\/pre>\n<p>Depth shader test:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\n\/\/ Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP'\r\n\r\nShader &quot;Custom\/DepthCamSurf2&quot;\r\n{\r\n\u00a0\u00a0\u00a0 Properties {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 _Amount (&quot;Extrusion Amount&quot;, Range(-1,1)) = 0.5\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 SubShader {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Tags { &quot;RenderType&quot; = &quot;Opaque&quot; }\r\n\u00a0\u00a0 \u00a0\u00a0 Lighting Off\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 CGPROGRAM\r\n\/\/ Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices\r\n#pragma exclude_renderers gles\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0#pragma surface surf Lambert vertex:vert\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0#include &quot;UnityCG.cginc&quot;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 struct Input {\r\n\/\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 float2 uv_MainTex;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float2 uv_MainTex;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 depth;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float4 pos;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 viewDir;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 color;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 worldPos;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 worldRefl;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 worldNormal;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float4 screenPos;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0INTERNAL_DATA\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 };\r\n\/\/\u00a0\u00a0 \u00a0struct v2f {\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float4 pos : POSITION;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float4 color : COLOR;\r\n\/\/\u00a0\u00a0 \u00a0};\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 float _Amount;\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 void vert (inout appdata_full v, out Input o) {\r\n\/\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 v.vertex.xyz += v.normal * _Amount;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0o.pos = mul(UNITY_MATRIX_MVP, v.vertex);\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 viewNormal = mul((float3x3)glstate.matrix.invtrans.modelview&#x5B;0], v.normal);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float z = (mul((float3x4)UNITY_MATRIX_MV, v.vertex).z+9);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0o.color.rgb = float3(z,z,z); \/\/viewNormal * 0.5 + 0.5;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/o.color.a = 1; \/\/-z \/ _ProjectionParams.z;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 sampler2D _MainTex;\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 void surf (Input IN, inout SurfaceOutput o) {\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0half3 col = IN.color;\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ could use as &quot;scanner effect&quot; (laser line moves across screen)\r\n\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (IN.worldPos.x &gt;= 2 &amp;&amp; IN.worldPos.x &lt;= 2.1)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0col= float3(1,0,0);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 o.Albedo = col; \/\/tex2D (_MainTex, IN.uv_MainTex).rgb;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 ENDCG\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 Fallback &quot;Diffuse&quot;\r\n\u00a0 }\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>One other test shader:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\n\/\/ Upgrade NOTE: replaced 'glstate.matrix.mvp' with 'UNITY_MATRIX_MVP'\r\n\r\nShader &quot;Custom\/DepthCamSurf3&quot;\r\n{\r\n\u00a0\u00a0\u00a0 Properties {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 _Amount (&quot;Extrusion Amount&quot;, Range(-1,1)) = 0.5\r\n\u00a0\u00a0 \u00a0\u00a0 _ObjPos (&quot;ObjPos&quot;, Vector) = (1,1,1,1)\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 SubShader {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 Tags { &quot;RenderType&quot; = &quot;Opaque&quot; }\r\n\u00a0\u00a0 \u00a0\u00a0 Lighting Off\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 CGPROGRAM\r\n\/\/ Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices\r\n#pragma exclude_renderers gles\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0#pragma surface surf Lambert vertex:vert\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0#include &quot;UnityCG.cginc&quot;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 struct Input {\r\n\/\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 float2 uv_MainTex;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float2 uv_MainTex;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 depth;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float4 pos;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 viewDir;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 color;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 worldPos;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 worldRefl;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 worldNormal;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float4 screenPos;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0INTERNAL_DATA\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 };\r\n\/\/\u00a0\u00a0 \u00a0struct v2f {\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float4 pos : POSITION;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float4 color : COLOR;\r\n\/\/\u00a0\u00a0 \u00a0};\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 float _Amount;\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 void vert (inout appdata_full v, out Input o) {\r\n\/\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 v.vertex.xyz += v.normal * _Amount;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0o.pos = mul(UNITY_MATRIX_MVP, v.vertex);\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float3 viewNormal = mul((float3x3)glstate.matrix.invtrans.modelview&#x5B;0], v.normal);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float z = (mul((float3x4)UNITY_MATRIX_MV, v.vertex).z+9);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0o.color.rgb = float3(z,z,z); \/\/viewNormal * 0.5 + 0.5;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/o.color.a = 1; \/\/-z \/ _ProjectionParams.z;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ do scanning here, with screenpos?\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 sampler2D _MainTex;\r\n\u00a0\u00a0 \u00a0\u00a0 uniform float4 _ObjPos;\r\n\/\/\u00a0\u00a0 \u00a0sampler2D input : register(s0); \/\/ ?\r\n\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 void surf (Input IN, inout SurfaceOutput o) {\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0half3 col = IN.color;\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float x1 = IN.worldPos.x;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float y1 = IN.worldPos.y;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float x2 = _ObjPos.x;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float y2 = _ObjPos.y;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0int steps = 15;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float dx = x2-x1;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float dy = y2-y1;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float xs = dx\/steps;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float ys = dy\/steps;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float x = x1;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float y = y1;\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/half3 origcol = tex2D (_MainTex, IN.uv_MainTex).rgb*3;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float pixel=0;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0half c = 0;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0float2 screenUV = IN.screenPos.xy \/ IN.screenPos.w;\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0screenUV *= float2(8,6);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0for (float n= 0; n &lt;= 15; n++)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/pixel = tex2D (_WallTex, float2(x,y)*0.1).r;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0pixel = IN.color.r;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (pixel&gt;0)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0c++;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0x+=xs;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0y+=ys;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (c&gt;0) \/\/ we hit something\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0col = float3(1,0,0);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}else{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0col = float3(0,0,1);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\r\n\/\/\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0col = tex2D (input, IN.uv_MainTex).rgb;\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\/\/ could use as &quot;scanner effect&quot; (laser line moves across screen)\r\n\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0if (IN.worldPos.x &gt;= 2 &amp;&amp; IN.worldPos.x &lt;= 2.1)\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0{\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0col= float3(1,0,0);\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0}\r\n\r\n\u00a0\u00a0 \u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 o.Albedo = col; \/\/tex2D (_MainTex, IN.uv_MainTex).rgb;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 ENDCG\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0 \u00a0\r\n\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 Fallback &quot;Diffuse&quot;\r\n\u00a0 }\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>yay..took few hours just to get this working: Render a whole camera view with one shader. It should be simple, but the documents wont give any examples: Camera.RenderWithShader Main image is showing vertex-depth-shader seen with camera (its modified version from one of these unity replacement [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":733,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4,3],"tags":[185,200,201,128,198,199,14],"class_list":["post-732","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-unity3d","tag-camera","tag-depth","tag-depthmap","tag-render","tag-renderwithshader","tag-replacement","tag-shader"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/03\/depthmapshader1.jpg?fit=680%2C383&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-bO","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=732"}],"version-history":[{"count":10,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/732\/revisions"}],"predecessor-version":[{"id":3081,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/732\/revisions\/3081"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/733"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}