{"id":1146,"date":"2012-10-02T19:16:33","date_gmt":"2012-10-02T16:16:33","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=1146"},"modified":"2014-06-20T15:25:35","modified_gmt":"2014-06-20T12:25:35","slug":"fake-godrays-shader","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2012\/10\/02\/fake-godrays-shader\/","title":{"rendered":"Fake Godrays Shader"},"content":{"rendered":"<p><a title=\"start webplayer demo\" href=\"http:\/\/unitycoder.com\/upload\/demos\/fake_godrays_shader_unity\/\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1147\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/10\/02\/fake-godrays-shader\/fake_godrays_on_texture_plane\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/fake_godrays_on_texture_plane.jpg?fit=680%2C414&amp;ssl=1\" data-orig-size=\"680,414\" 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=\"fake_godrays_on_texture_plane\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/fake_godrays_on_texture_plane.jpg?fit=680%2C414&amp;ssl=1\" class=\"alignnone size-full wp-image-1147\" title=\"fake_godrays_on_texture_plane\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/fake_godrays_on_texture_plane.jpg?resize=680%2C414\" alt=\"\" width=\"680\" height=\"414\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/fake_godrays_on_texture_plane.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/fake_godrays_on_texture_plane.jpg?resize=300%2C182&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<p>Godrays shader on a plane texture.. since no RenderToTexturein indie. ( Converted to unity from this <a title=\"http:\/\/demo.bkcore.com\/threejs\/webgl_tron_godrays.html\" href=\"http:\/\/demo.bkcore.com\/threejs\/webgl_tron_godrays.html\" target=\"_blank\">webgl shader<\/a>)<br \/>\nShould try it as a camera shader also..<\/p>\n<p><strong>Features:<\/strong><br \/>\n&#8211; Adjustable values: effect xy position, exposure, decay, density, weight, clamp,\u00a0 samples (screenshot is using 100 samples)<\/p>\n<p><strong>Webplayer:<\/strong><br \/>\n<a title=\"start webplayer demo\" href=\"http:\/\/unitycoder.com\/upload\/demos\/fake_godrays_shader_unity\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/fake_godrays_shader_unity\/<\/a><\/p>\n<p>Source (shader):<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nShader &quot;UnityCoder\/Rays2&quot; \r\n{\r\n\tProperties \r\n\t{\r\n\t\ttDiffuse (&quot;Base (RGB)&quot;, 2D) = &quot;white&quot; {}\r\n\t\tfX (&quot;fX&quot;, Float) = 0.5 \/\/ you can feed mouse xpos here with script: var mpos:Vector3 = Camera.main.ScreenToViewportPoint(Input.mousePosition); renderer.material.SetFloat( &quot;fX&quot;, mpos.x);\r\n\t\tfY (&quot;fY&quot;, Float) = 0.5 \/\/  mouse ypos\r\n\t\tfExposure (&quot;fExposure&quot;, Float) = 0.6\r\n\t\tfDecay (&quot;fDecay&quot;, Float) = 0.93\r\n\t\tfDensity (&quot;fDensity&quot;, Float) = 0.96\r\n\t\tfWeight (&quot;fWeight&quot;, Float) = 0.4\r\n\t\tfClamp (&quot;fClamp&quot;, Float) = 1.0\r\n\t\t\/\/iSamples (&quot;iSamples&quot;, Int) = 20\r\n\t}\r\n\tSubShader {\r\n\t\tTags { &quot;RenderType&quot;=&quot;Opaque&quot; }\r\n\t\tLOD 200\r\n\t\tCull Off\r\n\t\t\r\n\t\tCGPROGRAM\r\n\t\t#pragma target 3.0\r\n\t\t#pragma surface surf Lambert\r\n\r\n\t\tsampler2D tDiffuse;\r\n\t\tfloat fX,fY,fExposure,fDecay,fDensity,fWeight,fClamp,iSamples;\r\n\r\n\t\tstruct Input {\r\n\t\t\tfloat2 uvtDiffuse;\r\n\t\t\tfloat4 screenPos;\r\n\t\t};\r\n\r\n\t\tvoid surf (Input IN, inout SurfaceOutput o) \r\n\t\t{\r\n\t\t\tint iSamples=100;\r\n\t\t\tfloat2 vUv = IN.uvtDiffuse;\r\n\t\t\t\/\/vUv *= float2(1,1); \/\/ repeat?\r\n\t\t\tfloat2 deltaTextCoord = float2(vUv - float2(fX,fY));\r\n\t\t\tdeltaTextCoord *= 1.0 \/  float(iSamples) * fDensity;\r\n\t\t\tfloat2 coord = vUv;\r\n\t\t\tfloat illuminationDecay = 1.0;\r\n\t\t\tfloat4 FragColor = float4(0.0);\r\n\t\t\tfor(int i=0; i &lt; iSamples ; i++)\r\n\t\t\t{\r\n\t\t\t\tcoord -= deltaTextCoord;\r\n\t\t\t\tfloat4 texel = tex2D(tDiffuse, coord);\r\n\t\t\t\ttexel *= illuminationDecay * fWeight;\r\n\t\t\t\tFragColor += texel;\r\n\t\t\t\tilluminationDecay *= fDecay;\r\n\t\t\t}\r\n\t\t\tFragColor *= fExposure;\r\n\t\t\tFragColor = clamp(FragColor, 0.0, fClamp);\r\n\t\t\tfloat4 c = FragColor;\r\n\t\t\to.Albedo = c.rgb;\r\n\t\t\to.Alpha = c.a;\r\n\t\t\t\r\n\t\t}\r\n\t\tENDCG\r\n\t} \r\n\tFallBack &quot;Diffuse&quot;\r\n}\r\n<\/pre>\n<p>&#8212;<\/p>\n<p>Image#2: Texture used for the plane, you can use any texture..<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1152\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/10\/02\/fake-godrays-shader\/unitytext2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/unitytext2.jpg?fit=512%2C512&amp;ssl=1\" data-orig-size=\"512,512\" 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=\"unitytext2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/unitytext2.jpg?fit=512%2C512&amp;ssl=1\" class=\"alignnone size-thumbnail wp-image-1152\" title=\"unitytext2\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/unitytext2-150x150.jpg?resize=150%2C150\" alt=\"\" width=\"150\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/unitytext2.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/unitytext2.jpg?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/unitytext2.jpg?w=512&amp;ssl=1 512w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Godrays shader on a plane texture.. since no RenderToTexturein indie. ( Converted to unity from this webgl shader) Should try it as a camera shader also.. Features: &#8211; Adjustable values: effect xy position, exposure, decay, density, weight, clamp,\u00a0 samples (screenshot is using 100 samples) Webplayer: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1147,"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":[316,318,52,317,14,319],"class_list":["post-1146","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-unity3d","tag-god-rays","tag-godrays","tag-light","tag-ray","tag-shader","tag-shining"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/fake_godrays_on_texture_plane.jpg?fit=680%2C414&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-iu","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1146","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=1146"}],"version-history":[{"count":9,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1146\/revisions"}],"predecessor-version":[{"id":3016,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1146\/revisions\/3016"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/1147"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=1146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=1146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=1146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}