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 nbaja1 · Jul 12, 2017 at 03:43 PM · androidshader

Shader not working correctly on android

I have a shader that works fine in the unity editor on my machine, but it doesn't work correctly when I run it on Android. It's strange that it doesn't give me a broken shader, but it also doesn't do what it's supposed to do, as you will see.

It's a shader that takes in 6 planes, two for each axis, and then uses them to cross section an object. I started with this, and then modified it: https://www.assetstore.unity3d.com/en/#!/content/66300

Here it is working on my machine: alt text The cube with the sliders on it on the bottom left is indicating how to cut the object. The shader is also on the sliders on the cross section UI cube, trimming away the exess, which you can see it not doing below.

Here it is not working correctly on my phone: alt text

 Shader "CrossSection/ThreeAAPlanesBSP" {
     Properties{
         _Color("Color", Color) = (1,1,1,1)
         _CrossColor("Cross Section Color", Color) = (1,1,1,1)
         _Transparent("Transparent", Range(0,1)) = 1                  //NB    
         _MainTex("Albedo (RGB)", 2D) = "white" {}
         _Glossiness("Smoothness", Range(0,1)) = 0.5
         _Metallic("Metallic", Range(0,1)) = 0.0
         _Plane1Position("Plane1Position",Vector) = (0,0,0,1)
         _Plane2Position("Plane2Position",Vector) = (0,0,0,1)
         _Plane3Position("Plane3Position",Vector) = (0,0,0,1)
         _Plane4Position("Plane4Position",Vector) = (0,0,0,1)
         _Plane5Position("Plane5Position",Vector) = (0,0,0,1)
         _Plane6Position("Plane6Position",Vector) = (0,0,0,1)
         _EmissionColor("Emission Color", Color) = (0,0,0,0)
 
         //cross sectioning is off
         _CS_switch("_CS_switch", Float) = 0
 
     }
 
         SubShader{
         Tags{ "Queue" = "Transparent" "RenderType"="Transparent" }
         //LOD 200
         
         Cull off
         CGPROGRAM
         // Physically based Standard lighting model, and enable shadows on all light types
 #pragma surface surf Standard fullforwardshadows 
 
         // Use shader model 3.0 target, to get nicer looking lighting
 #pragma target 3.0
 
         sampler2D _MainTex;
 
     struct Input {
         float2 uv_MainTex;
         float3 worldPos;
     };
 
 
     half _Glossiness;
     half _Metallic;
     fixed4 _Color;
     fixed4 _CrossColor;
     fixed3 _Plane1Position;
     fixed3 _Plane2Position;
     fixed3 _Plane3Position;
     fixed3 _Plane4Position;
     fixed3 _Plane5Position;
     fixed3 _Plane6Position;
     fixed4 _EmissionColor;
 
     fixed _CS_switch;
 
 
     bool checkVisability(fixed3 worldPos)
     {
         if (_CS_switch == 0)
             return 0;
 
         float dotProd1 = dot(worldPos - _Plane1Position, fixed3(1, 0, 0));
         float dotProd2 = dot(worldPos - _Plane2Position, fixed3(0, 1, 0));
         float dotProd3 = dot(worldPos - _Plane3Position, fixed3(0, 0, 1));
 
         float dotProd4 = dot(worldPos - _Plane4Position, fixed3(-1, 0, 0));
         float dotProd5 = dot(worldPos - _Plane5Position, fixed3(0, -1, 0));
         float dotProd6 = dot(worldPos - _Plane6Position, fixed3(0, 0, -1));
 
         return !(dotProd1 > 0 && dotProd2 > 0 && dotProd3 > 0 && dotProd4 > 0 && dotProd5 > 0 && dotProd6 > 0);
     }
 
     void surf(Input IN, inout SurfaceOutputStandard o) {
         if (checkVisability(IN.worldPos))discard;
 
         fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
 
         // Metallic and smoothness come from slider variables
         o.Metallic = _Metallic;
         o.Smoothness = _Glossiness;
         o.Emission = _EmissionColor;
 
         o.Albedo = c.rgb;
         o.Alpha = c.a;    
 
     }
     ENDCG
 
         Cull Front
 
         CGPROGRAM
 #pragma surface surf NoLighting  noambient  alpha
 
     struct Input {
         half2 uv_MainTex;
         float3 worldPos;
     };
 
     sampler2D _MainTex;
     fixed4 _Color;
     fixed4 _CrossColor;
     fixed3 _Plane1Position;
     fixed3 _Plane2Position;
     fixed3 _Plane3Position;
     fixed3 _Plane4Position;
     fixed3 _Plane5Position;
     fixed3 _Plane6Position;
     half _Transparent;
 
 
     fixed _CS_switch;
 
     bool checkVisability(fixed3 worldPos)
     {
         if (_CS_switch == 0)
             return 1;
 
         float dotProd1 = dot(worldPos - _Plane1Position, fixed3(-1, 0, 0));
         float dotProd2 = dot(worldPos - _Plane2Position, fixed3(0, -1, 0));
         float dotProd3 = dot(worldPos - _Plane3Position, fixed3(0, 0, -1));
 
         float dotProd4 = dot(worldPos - _Plane4Position, fixed3(1, 0, 0));
         float dotProd5 = dot(worldPos - _Plane5Position, fixed3(0, 1, 0));
         float dotProd6 = dot(worldPos - _Plane6Position, fixed3(0, 0, 1));
 
         return !(dotProd1 > 0 && dotProd2 > 0 && dotProd3 > 0 && dotProd4 > 0 && dotProd5 > 0 && dotProd6 > 0);
     }
 
     fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
     {
         fixed4 c;
         c.rgb = s.Albedo;
         c.a = _Transparent;
         return c;
     }
 
     void surf(Input IN, inout SurfaceOutput o)
     {
         if (checkVisability(IN.worldPos))discard;
         o.Albedo = _CrossColor;
     }
     ENDCG
 
     }
         //FallBack "Diffuse"
 }
 

I also wanted to point out that I added it to the list of always included shaders.

Any and all input would be appreciated! My shader knowledge is weak and after trying to fix this for a few days, I thought I'd see if anyone would be willing to give me a hand on this.

Thanks!

working.jpg (89.9 kB)
screenshot-20170711-162820.png (270.8 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

Answer by nbaja1 · Jul 13, 2017 at 08:49 AM

@Aerospyke 's solution here solved this.

Thanks!

Comment
Add comment · 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

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

161 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

Related Questions

Water4 Advanced Edge blend Not working with GearVR 0 Answers

GL - Shader not working in Android 1 Answer

Shader From Assetbundle Compiled On PC with Target of Android Platform Turn Pink 0 Answers

need help making this mobile shader more efficient 0 Answers

Custom shader go to black on android devices. 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