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 /
  • Help Room /
avatar image
0
Question by alvaro_perez_omnidrone · Mar 27, 2017 at 08:20 AM · shadershader programmingshader writingsamsung

Custom shader not working on Samsung S6

I am having problems with a custom shader only on Samsung S6 (also possibly some iOS devices, can't check right now for a number of reasons, but on other Android devices everything is fine)

File

Since it's a rather complicated shader (it maps sections of a texture along a given x range of UVs and has a lot of variants - the purpose of the shader is to paint the area of effect of an attack) I've tried to find the "minimal expression" that returns an error, to pinpoint the error (at first I thought it would be the usage of ddx and ddy, but it turns out it's not the case.

So, this small shader already fails on the device (Of course, there's a lot of unused variables and #pragma, but that's beside the point):

 Shader "Custom/Tiled hints"
 {
 
     Properties
     {
         _MainTex ("Texture", 2D) = "white" {}
         _Color ("Color", Color) = (1,1,1,0)
         [HideInInspector] length ("length", Float) = 1
         [HideInInspector] aspectRatio ("aspect ratio", Float) = 1
         [HideInInspector] lMap ("begin", Float) = 0
         [HideInInspector] rMap ("end", Float) = 1
         [HideInInspector] lCut ("slice left", Range(0, 1)) = 0.25
         [HideInInspector] rCut ("slice right", Range(0, 1)) = 0.75
         [HideInInspector] lRemove ("remove left", Range(0, 1)) = 0
         [HideInInspector] rRemove ("remove right", Range(0, 1)) = 1
         [HideInInspector] lHeadTile ("head tile", Range(0, 1)) = 0
         [HideInInspector] lHeadMapTile ("head tile", Float) = 0
     }
     SubShader
     {
         Tags {  "QUEUE"="Transparent-2" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
  
         ZWrite Off
         ZTest On
         Cull Back
         Blend SrcAlpha OneMinusSrcAlpha
         AlphaTest Greater .01
         Fog { Mode Off }
         
         LOD 100
         Offset -1, -1
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile_fog
             
             #pragma multi_compile _ TILED_HEAD 
             #pragma multi_compile TILED_MIDDLE_LEFT TILED_MIDDLE_RIGHT
             #pragma multi_compile _ TILED_HEAD_WITH_CUT
             #pragma multi_compile _ DEBUG_SHADER
             #pragma multi_compile _ UVS_01
             #pragma multi_compile _ PING_PONG_FMOD
 
             #pragma target 3.0
             
             #include "UnityCG.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 UNITY_FOG_COORDS(1)
                 float4 vertex : SV_POSITION;
             };
             
             //Parameters
             float length;
             float aspectRatio;
             float lMap;
             float rMap;
             float lCut;
             float rCut;
             float lRemove;
             float rRemove;
             float lHeadTile;
             float lHeadMapTile;
             float4 _Color;
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
             
             v2f vert (appdata v)
             {
                 v2f o;
                 UNITY_INITIALIZE_OUTPUT(v2f,o);
                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                 UNITY_TRANSFER_FOG(o,o.vertex);
                 return o;
             }
 
             float ilerp(float a, float b, float lerped)
             {
                 return saturate((lerped - a) / (b - a));
             }
 
             fixed4 frag (v2f i) : SV_Target
             {
                 float2 orUV = i.uv;
                 bool mirror = lMap > rMap;
                  float lMapScaled = lMap / length;
                  float rMapScaled = rMap / length;
                 float lMapSide = min(lMapScaled , rMapScaled);
                 float rMapSide = max(lMapScaled , rMapScaled);
                 return ilerp(lMapSide, rMapSide, mirror ? 1 - orUV.x : orUV.x);
             }
             ENDCG
         }
     }
     CustomEditor "TiledHintShaderInspector"
 }

Smaller versions of the fragment shader seem to work just fine. I'm on Unity 5.3.6 (it's a rather big project, updating is a headache)

The variable length is not 0 (I set it from code to nonzero values), and lMap and rMap are also set from code to different values. This is also true before changing the values (i.e. the material already has these values set like this.

Any help? I don't really know what is going on. I've read that the Mali chips the Samsung s6 uses are known to give headaches, but we can't really drop it from the list of supported devices. Thanks!

tiled.txt (7.6 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by alvaro_perez_omnidrone · Mar 27, 2017 at 09:51 AM

I finally found what the problem was! After comparing the compiled code of the shader I posted with one replacing length by a known possible value (which worked), I noticed that length got changed to xlat_varlength for some platforms. I didn't know it was an standard function. It seems that generally it just gets translated and the shader works anyway, but or this device, this doesn't seem to be very compatible with the way Unity handles the shader variables.

So, changing length into some other name solved the problem completely.

Comment
Add comment · Show 1 · Share
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 ThomasAstrom · Aug 24, 2020 at 06:40 AM 0
Share

How do you compare the compiled shader code on different platforms? I'm having a weird Samsung problem too...

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

124 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

Related Questions

How do I get the fragment position in world coordinates? 1 Answer

Shader - SV_Target 1 Answer

Shader object parts discard by Shadow 0 Answers

Reversed UV Light with 2D PointLight (shader graph) 0 Answers

How to write a shader like this? [Screenshots] 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