Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by hbey · Feb 15, 2017 at 07:37 AM · shaderupgrade

When upgrade unity to 5.5.0f3, this shader can't work anymore

it works good when I use unity version 5.3.4. But when I upgrade unity to 5.5.0,it's can't work anymore. And also it can't work on iOS platform because of "metal" issue.

 Shader "Image Effects/Fog of War"
 {
     Properties
     {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _FogTex0 ("Fog 0", 2D) = "white" {}
         _FogTex1 ("Fog 1", 2D) = "white" {}
         _Unexplored ("Unexplored Color", Color) = (0.05, 0.05, 0.05, 0.05)
         _Explored ("Explored Color", Color) = (0.35, 0.35, 0.35, 0.35)
     }
     SubShader
     {
         Pass
         {
             ZTest Always
             Cull Off
             ZWrite Off
             Fog { Mode off }
                     
 CGPROGRAM
 #pragma vertex vert_img
 #pragma fragment frag vertex:vert
 #pragma fragmentoption ARB_precision_hint_fastest 
 #include "UnityCG.cginc"
 
 sampler2D _MainTex;
 sampler2D _FogTex0;
 sampler2D _FogTex1;
 sampler2D _CameraDepthTexture;
 
 uniform float4x4 _InverseMVP;
 uniform float4 _Params;
 uniform float4 _CamPos;
 uniform half4 _Unexplored;
 uniform half4 _Explored;
 
 struct Input
 {
     float4 position : POSITION;
     float2 uv : TEXCOORD0;
 };
 
 void vert (inout appdata_full v, out Input o)
 {
     o.position = mul(UNITY_MATRIX_MVP, v.vertex);
     o.uv = v.texcoord.xy;
 }
 
 float3 CamToWorld (in float2 uv, in float depth)
 {
     float4 pos = float4(uv.x, uv.y, depth, 1.0);
     pos.xyz = pos.xyz * 2.0 - 1.0;
     pos = mul(_InverseMVP, pos);
     return pos.xyz / pos.w;
 }
 
 fixed4 frag (Input i) : COLOR
 {
     half4 original = tex2D(_MainTex, i.uv);
 
 #if SHADER_API_D3D9
     float2 depthUV = i.uv;
     depthUV.y = lerp(depthUV.y, 1.0 - depthUV.y, _CamPos.w);
     float depth = UNITY_SAMPLE_DEPTH(tex2D(_CameraDepthTexture, depthUV));
     float3 pos = CamToWorld(depthUV, depth);
 #else
     float depth = UNITY_SAMPLE_DEPTH(tex2D(_CameraDepthTexture, i.uv));
     float3 pos = CamToWorld(i.uv, depth);
 #endif
     
     // Limit the fog of war to sea level
     if (pos.y < 0.0)
     {
         // This is a simplified version of the ray-plane intersection formula: t = -( N.O + d ) / ( N.D )
         float3 dir = normalize(pos - _CamPos.xyz);
         pos = _CamPos.xyz - dir * (_CamPos.y / dir.y);
     }
     
     float2 uv = pos.xz * _Params.z + _Params.xy;
     half4 fog = lerp(tex2D(_FogTex0, uv), tex2D(_FogTex1, uv), _Params.w);
     
     return lerp(lerp(original * _Unexplored, original * _Explored, fog.g), original, fog.r);
 }
 ENDCG
         }
     }
     Fallback off
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Feb 15, 2017 at 09:06 AM 0
Share

And what error does the shader compiler give you?

avatar image hbey tanoshimi · Feb 16, 2017 at 03:40 AM 0
Share

I have located the error code as below, and now still find the way to fix this issue. it's so weird version 5.3.4 is ok, but 5.5.0 can't work.

  #if SHADER_API_D3D9
      float2 depthUV = i.uv;
      depthUV.y = lerp(depthUV.y, 1.0 - depthUV.y, _CamPos.w);
      float depth = UNITY_SA$$anonymous$$PLE_DEPTH(tex2D(_CameraDepthTexture, depthUV));
      float3 pos = CamToWorld(depthUV, depth);
  #else
      float depth = UNITY_SA$$anonymous$$PLE_DEPTH(tex2D(_CameraDepthTexture, i.uv));
      float3 pos = CamToWorld(i.uv, depth);
  #endif
avatar image tanoshimi hbey · Feb 16, 2017 at 09:12 AM 0
Share

Yes, and what's the error? And where do you define _Inverse$$anonymous$$VP?

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me converting this shader to urp? 0 Answers

Unity 5 upgrade broke lightmapped shader 1 Answer

Problem after upgrading from Unity 4.6 to Unity 5 0 Answers

Shader issue after upgrade to 4.5.2 1 Answer

UPDATE FROM HDRP 2020.1.6. to HDRP 2021.1.9 Project Errors 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges