Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 musetdima · Jul 02, 2019 at 10:41 AM · shadershader programmingshaderlab

Very bad float precision

Hi, I have a water shader which worked correctly on all devices, but after a Unity update apparently, it is not working correctly anymore on low-budget devices. I see a small water circle around the camera which is drawing correctly, but everything else is wrong. After some debugging, I came up with this simple shader which has the same problem:

 Shader "test"
 {
     SubShader 
     {
         Pass 
         {
             CGPROGRAM
 #pragma vertex vert
 #pragma fragment frag
 #include "UnityCG.cginc"
 
             struct v2f
             {
                 float4 pos : SV_POSITION;
                 float4 wpos : TEXCOORD0;
             };
 
             v2f vert(appdata_base v)
             {
                 v2f o;
                 o.pos = UnityObjectToClipPos(v.vertex);
                 o.wpos = mul(unity_ObjectToWorld, v.vertex);
                 return o; 
             }
  
             float4 frag(v2f i) : COLOR
             {
                 float3 viewDir = normalize(_WorldSpaceCameraPos.xyz - i.wpos.xyz);
                 return float4(viewDir, 1.0f);
             }
             ENDCG
         }
     }
     FallBack "Diffuse"
 }

What I see on PC and Middle/High-end devices with this shader: https://ibb.co/8KYyK0j . And what I see with the same shader on low-end devices: https://ibb.co/cgQZrRS

It seems like there is some big problems with precision.

I tested a lot of workarounds but nothing working. I am clueless now. May be somebody have a clue? My Unity version 2018.4.2 Test device: Galaxy J1 mini

I would say it again to be clear for sure - it worked perfectly before, on the same device, the same shader, nothing changed but Unity version.

Thank you!

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 Namey5 · Jul 04, 2019 at 10:16 AM 0
Share

$$anonymous$$y thinking was that there may have been some form of auto-precision handling on the macros now, but going through the built-in includes that doesn't seem to be the case. Which in turn leads me to think it's the normalization; have you tried doing it manually? i.e.

 float3 viewDir = _WorldSpaceCameraPos.xyz - i.wpos.xyz;
 viewDir = viewDir / length (viewDir);

What is interesting to me is the weird circular value clipping. That makes me think that somehow you're getting a NaN (again, possibly from the normalization). I'm interested to figure out what would be causing this too, although I can't test on said hardware myself.

avatar image musetdima · Jul 04, 2019 at 10:46 AM 0
Share

Of course I tried to normalize it manually and the same thing happens. I even tried to calculate manually the length of the vector and also didn't help.

avatar image Namey5 musetdima · Jul 04, 2019 at 11:55 AM 0
Share

Again, just throwing suggestions around, have you tried compiling for a specific target? From memory, default is OpenGL ES 2.0, which could be messing with precision.

avatar image musetdima Namey5 · Jul 04, 2019 at 11:59 AM 0
Share

I tried for ES 2 - didn't work. Then I tried for ES 3 - didn't work :)

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

176 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Advanced Shader Help 0 Answers

I need help upgrading a shader script to be compatible with URP. 0 Answers

Shader inverts uv map only once, how to fix it? 0 Answers

Vertex Noise Shader Mismatch on Different Computers 0 Answers

How to remove a color from texture using Shader? 0 Answers


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