Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 gyb_bobo · Nov 07, 2013 at 12:57 PM · shaderiosassetbundle

It will not show correctly using custom shader while loading assetbundle built in iPhone

Just like title. this is the code pack the prefab

Packcode

 private static void PackSelect()
 {
     string path = Application.streamingAssetsPath + "/bundle.pack";
     
     BuildPipeline.PushAssetDependencies();
     
     BuildPipeline.BuildAssetBundle(Selection.activeObject, null, path,
                                     BuildAssetBundleOptions.CollectDependencies |
                                     BuildAssetBundleOptions.CompleteAssets
                                     , BuildTarget.iPhone);
     BuildPipeline.PopAssetDependencies();
 }
 

the prefab can be shown on iPhone correctly, but it turned black(may be execute "Fallback" in shader) while loading assetbundle in UNITY_EDITOR and other platforms.

 Shader code    
 
 Shader "Mobile/Cutoff2Side"
     {
         
         Properties 
         {
             _Color("_Color", Color) = (0.4980392,0.4980392,0.4980392,1)
             _Colorpower("_Colorpower", Float) = 2
             _Diffusemap("_Diffusemap", 2D) = "gray" {}
             _Clipbias("_Clipbias", Range(0,1) ) = 0.466
             _Alphabias("_Alphabias", Range(0,1) ) = 0
         }
         
         SubShader
         {    
             
             LOD 200
     
             Tags
             {
                 "Queue" = "Transparent"
                 "IgnoreProjector" = "True"
                 "RenderType" = "Transparent"
             }
             
     
             Cull Back
             Lighting Off
             ZWrite Off
             AlphaTest Off
             Fog { Mode Off }
             Offset -1, -1
             ColorMask RGB
             Blend One OneMinusSrcAlpha 
             ColorMaterial AmbientAndDiffuse
             
             CGPROGRAM
             #pragma surface surf Lambert
             #pragma target 2.0
             
             float4 _Color;
             float _Colorpower;
             sampler2D _Diffusemap;
             float _Clipbias;
             float _Alphabias;
             
             struct Input
             {
                 float2 uv_Diffusemap;
             };
             
             void surf(Input IN, inout SurfaceOutput o)
             {
                 float4 color = tex2D(_Diffusemap, IN.uv_Diffusemap);
                 o.Emission =  (color * _Colorpower.xxxx * _Color).xyz;
                 o.Alpha = (color.a - _Alphabias).x;
                 float c = (color.a - _Clipbias).x;
                 clip(c);
             }
             ENDCG
         }
         Fallback "Diffuse"
     }


The left is the prefab loaded from assetbundle, the right is the same asset from hierarchy, it could be shown the same on the mobile, whose material is the same one.

alt text

qq截图20131108122802.jpg (50.7 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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by foobuggy · Dec 09, 2013 at 08:03 PM

This is a bit of an older post, but I thought I'd add an alternate approach. A semi-hacky fix I used is to basically place a script along these lines on the root object of your assetbundle/prefab.

 private void Awake()
 {
     #if UNITY_EDITOR
     foreach(Transform t in gameObject.GetComponentsInChildren<Transform>())
     {
         if(t.gameObject.renderer != null)
         {
             t.gameObject.renderer.material.shader = Shader.Find(t.gameObject.renderer.material.shader.name);
         }
     }
     #endif
 }

It isn't the most efficient approach, but it worked for me. Plus it is better than not being able to see your assets while trying to test the app in editor. Using compiler arguments to restrict this so it only runs in-editor will also avoid any performance hits in final builds.

Comment
Add comment · Show 2 · 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 kaushik-d · Jun 02, 2014 at 06:10 PM 0
Share

This worked for me in the Editor, as well as on Android. Not the cleanest solution of course, but it works. Strangely, shaders don't get loaded with the AssetBundle only if they are one of the transparent ones.

avatar image ferretnt · Mar 01, 2015 at 08:25 AM 0
Share

Genius. Thank you. $$anonymous$$uch easier than messing around building a separate desktop bundle.

avatar image
0

Answer by whydoidoit · Nov 08, 2013 at 04:36 AM

Yeah shaders are compiled for a platform when they are packed into the bundle, just the one platform (iPhone not the editor). I suggest you stick you shaders in a resources folder while you are developing so that they load correctly and switch to packing them in the bundle at the last minute.

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 gyb_bobo · Nov 11, 2013 at 04:04 AM 0
Share

i'm wordering how to configurate shaders before it is compiled.

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

18 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

Related Questions

Streamed textures appearing as default white only on iOS 0 Answers

It will not show correctly using custom shader while loading assetbundle built in iPhone 0 Answers

Multiple tex2D commands in fragment shader needed, is there a workaround? 0 Answers

MovieTexture on iOS 0 Answers

Automatically load asset bundles on start from cache 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