{"id":1175,"date":"2012-10-06T17:49:18","date_gmt":"2012-10-06T14:49:18","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=1175"},"modified":"2012-10-14T10:47:09","modified_gmt":"2012-10-14T07:47:09","slug":"360-panorama-reflection-shader","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2012\/10\/06\/360-panorama-reflection-shader\/","title":{"rendered":"360 Panorama Reflection Shader"},"content":{"rendered":"<p><a title=\"start webplayer demo\" href=\"http:\/\/unitycoder.com\/upload\/demos\/360ReflectionShader_unity\/\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1176\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/10\/06\/360-panorama-reflection-shader\/360_panorama_reflection_unity\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection_unity.jpg?fit=680%2C442&amp;ssl=1\" data-orig-size=\"680,442\" 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=\"360_panorama_reflection_unity\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection_unity.jpg?fit=300%2C195&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection_unity.jpg?fit=680%2C442&amp;ssl=1\" class=\"alignnone size-full wp-image-1176\" title=\"360_panorama_reflection_unity\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection_unity.jpg?resize=680%2C442\" alt=\"\" width=\"680\" height=\"442\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection_unity.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection_unity.jpg?resize=300%2C195&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<p>Tried to convert this <a title=\"http:\/\/www.clicktorelease.com\/code\/streetViewReflectionMapping\/\" href=\"http:\/\/www.clicktorelease.com\/code\/streetViewReflectionMapping\/\" target=\"_blank\">webgl shader<\/a> to unity.. but its not working yet.<\/p>\n<p><strong>Webplayer:<\/strong><br \/>\n<a title=\"start webplayer demo\" href=\"http:\/\/unitycoder.com\/upload\/demos\/360ReflectionShader_unity\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/360ReflectionShader_unity\/<\/a> (v2.0)<\/p>\n<p><strong>Download Source: <\/strong>(webplayer scene)<br \/>\n<a title=\"Download (with UnityCoder toolbar)\" href=\"http:\/\/unitycoder.com\/download\/index.php?link=257&amp;uid=un1t3c0d5r\" target=\"_blank\">360panoramaFakeReflection.unityPackage<\/a><\/p>\n<p><strong>Source v1.0\u00a0 (broken):<\/strong><\/p>\n<p>&#8211; Can anyone spot what could be the problem..or are the textures just wrong? I have no idea about those matrix stuffs either, just picked something that sounded similar in unity \ud83d\ude42<br \/>\n&#8211; Update: was missing &#8220;IN.&#8221; at pitch line.. also updated some calculations to unity built-in variables.. now it almost works..<br \/>\n&#8211; Added webplayer with torus and new screenshot below.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ original source: http:\/\/www.clicktorelease.com\/code\/streetViewReflectionMapping\r\nShader &quot;Custom\/360reflection2&quot; {\r\nProperties {\r\n_texture (&quot;texture (RGB)&quot;, 2D) = &quot;white&quot; {}\r\n_scaledTexture (&quot;scaledTexture (RGB)&quot;, 2D) = &quot;white&quot; {}\r\n}\r\nSubShader {\r\nTags { &quot;RenderType&quot;=&quot;Opaque&quot; }\r\nLOD 200\r\n\r\nCGPROGRAM\r\n#pragma target 3.0\r\n#pragma surface surf Lambert vertex:vert\r\n\r\nfloat3 vReflect;\r\nfloat3 vRefract;\r\n\r\nstruct Input {\r\nfloat2 uv_MainTex;\r\nfloat4 pos : SV_POSITION;\r\nfloat3 vReflect;\r\nfloat3 vRefract;\r\n};\r\n\r\nvoid vert (inout appdata_full v, out Input o)\r\n{\r\nfloat4 mPosition = mul(_Object2World,float4(v.vertex.xyz, 1.0 ));\r\nfloat3 nWorld = normalize( mul(\u00a0 float3x3(_Object2World&#x5B;0].xyz, _Object2World&#x5B;1].xyz, _Object2World&#x5B;2].xyz) ,v.normal ));\r\no.vReflect = normalize( reflect( normalize( mPosition.xyz - _WorldSpaceCameraPos ), nWorld ) );\r\no.vRefract = normalize( refract( normalize( mPosition.xyz - _WorldSpaceCameraPos ), nWorld, 0.9 ) );\r\no.pos = mul(UNITY_MATRIX_P * UNITY_MATRIX_MV,float4(v.vertex.xyz, 1.0));\r\n}\r\n\r\nuniform float rAmount;\r\nuniform sampler2D _texture;\r\nuniform sampler2D _scaledTexture;\r\n\r\nvoid surf (Input IN, inout SurfaceOutput o)\r\n{\r\nfloat PI = 3.14159265358979323846264;\r\nfloat yaw = .5 - atan2(IN.vReflect.z, - IN.vReflect.x ) \/ ( 2.0 * PI );\r\nfloat pitch = .5 - asin( vReflect.y ) \/ PI;\r\nfloat3 color = tex2D(_scaledTexture, float2( yaw, pitch ) ).rgb * ( 1.0 - rAmount );\r\nyaw = .5 - atan2(IN.vRefract.z, - vRefract.x ) \/ ( 2.0 * PI );\r\npitch = .5 - asin(IN.vRefract.y ) \/ PI;\r\ncolor += tex2D(_texture, float2( yaw, pitch ) ).rgb * rAmount;\r\nhalf4 c =\u00a0 float4( color, 1.0 );\r\no.Albedo = c.rgb;\r\no.Alpha = c.a;\r\n}\r\n\r\nENDCG\r\n}\r\nFallBack &quot;Diffuse&quot;\r\n}\r\n\r\n<\/pre>\n<p>&#8212;<br \/>\n<strong>Image #2:<\/strong> Almost.. reflection image is upside down. Added webplayer for this version.<br \/>\n<a title=\"start webplayer demo\" href=\"http:\/\/unitycoder.com\/upload\/demos\/360ReflectionShader_unity\/\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1184\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/10\/06\/360-panorama-reflection-shader\/360_panorama_reflection2_unity\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection2_unity.jpg?fit=680%2C498&amp;ssl=1\" data-orig-size=\"680,498\" 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=\"360_panorama_reflection2_unity\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection2_unity.jpg?fit=300%2C219&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection2_unity.jpg?fit=680%2C498&amp;ssl=1\" class=\"alignnone size-full wp-image-1184\" title=\"360_panorama_reflection2_unity\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection2_unity.jpg?resize=680%2C498\" alt=\"\" width=\"680\" height=\"498\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection2_unity.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection2_unity.jpg?resize=300%2C219&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Tried to convert this webgl shader to unity.. but its not working yet. Webplayer: http:\/\/unitycoder.com\/upload\/demos\/360ReflectionShader_unity\/ (v2.0) Download Source: (webplayer scene) 360panoramaFakeReflection.unityPackage Source v1.0\u00a0 (broken): &#8211; Can anyone spot what could be the problem..or are the textures just wrong? I have no idea about those matrix [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1184,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_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}},"categories":[4,3],"tags":[321,322,165,14,323,320],"class_list":["post-1175","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-unity3d","tag-321","tag-panorama","tag-reflection","tag-shader","tag-sphere","tag-webgl"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/10\/360_panorama_reflection2_unity.jpg?fit=680%2C498&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-iX","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1175","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=1175"}],"version-history":[{"count":11,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1175\/revisions"}],"predecessor-version":[{"id":2198,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1175\/revisions\/2198"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/1184"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=1175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=1175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=1175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}