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 kevinspawner · Apr 07, 2015 at 07:56 AM · meshmobile

Mesh Renderer Fade in and fade out.[Mobile Platform]

Is there any way to make the mesh appear with fade in and fade out effect?

Goal: Mesh Fade in slowly and fade out in mobile platform.

Solution I tried: Am pretty sure in normal material I can use the alpha to achieve this effect directly in material by lerping between alpha value in color.

How is it possible to do this in mobile? I want it to be less memory consuming as I need to do achieve this effect in Mobile platform. Is there any efficient way to achieve this effect? In Mobile material there is no separate color value(possibly am i missing something?) also I have a texture[Diffuse] applied in the material

Thanks. Any input would be appreciated.

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 ethestel · Apr 07, 2015 at 08:09 AM

Yes, you can do this by animating a custom material's color or opacity values. And it can be optimized for mobile, depending on the shader you are using.

Comment
Add comment · Show 5 · 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 kevinspawner · Apr 07, 2015 at 08:28 AM 0
Share

So is that mean do I need to write a shader? I want to achieve it through Unity $$anonymous$$obile shader. Is it possible? I don't see any color or opacity properties in mobile shader [Unity Default] Can you provide an example? or do any links possibly? Thanks.

avatar image ethestel · Apr 07, 2015 at 08:44 AM 0
Share

Yes, unfortunately Unity's bundled mobile shaders doesn't have transparency option.

I can share a sample shader if you give more details about the properties of this mesh. How does this mesh looks like? Does it have a texture on it, or just color? Does it affected by lighting? Is it casting shadows?

avatar image kevinspawner · Apr 07, 2015 at 09:27 AM 0
Share

I have a simple diffuse and specular texture. I have lights in the scene (Is it possible to render the lights in mobile? If so I will use it other wise I can remove the light and bake it in the map directly). Can you send the material, that would be very helpful. Am not much in to shader. Thanks.

avatar image ethestel · Apr 07, 2015 at 10:44 AM 0
Share

Hello again,

Here's a shader a quickly put together. It supports 1 directional light which should work without issues on mobile.

 Shader "Diffuse Specular with Opacity w Directional Lights" {
     Properties {
         _DiffuseTex ("Diffuse (RGBA)", 2D) = "white" {}
         _SpecularTex ("Specular (RGB)", 2D) = "white" {}
         _SpecularPower ("Specular Power", float) = 10
         _Opacity ("Opacity", Range(0,1)) = 1
     }
     SubShader {
         Tags { "RenderType"="Transparent" "Queue"="Transparent" "Light$$anonymous$$ode"="ForwardBase" }
         ZWrite Off
         Cull Back
         Blend SrcAlpha One$$anonymous$$inusSrcAlpha
         
         Pass
         {
             CGPROGRA$$anonymous$$
             
             #pragma vertex vert
             #pragma fragment frag
             
             uniform sampler2D _DiffuseTex;
             uniform sampler2D _SpecularTex;
             uniform float4 _DiffuseTex_ST;
             uniform float4 _SpecularTex_ST;
             uniform float4 _LightColor0;
             uniform float _SpecularPower;
             uniform float _Opacity;
             
             
             struct vIn
             {
                 float4 vertex : POSITION;
                 half4 normal : NOR$$anonymous$$AL;
                 half2 coord0 : TEXCOORD0;
                 half2 coord1 : TEXCOORD1;
             };
             struct vOut
             {
                 float4 pos : SV_POSITION;
                 half3 worldPos : COLOR;
                 fixed3 normal : NOR$$anonymous$$AL;
                 half2 diffuseCoord : TEXCOORD0;
                 half2 specularCoord : TEXCOORD1;
             };
             
             vOut vert(vIn v)
             {
                 vOut o;
                 o.pos = mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex);
                 
                 o.worldPos = mul(_Object2World, v.vertex);
                 o.normal = normalize(mul( v.normal, _World2Object).xyz);
                 
                 o.diffuseCoord = v.coord0 * _DiffuseTex_ST.xy + _DiffuseTex_ST.zw;
                 o.specularCoord = v.coord1 * _SpecularTex_ST.xy + _SpecularTex_ST.zw;
                 
                 return o;
             }
             
             float4 frag(vOut i) : COLOR
             {
                 float3 diffuseColor = tex2D(_DiffuseTex, i.diffuseCoord);
                 float3 specularColor = tex2D(_SpecularTex, i.specularCoord);
                 fixed3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
                 fixed3 viewDirection = normalize(_WorldSpaceCameraPos-i.worldPos).xyz;
                 float3 ambientLight = UNITY_LIGHT$$anonymous$$O$$anonymous$$_A$$anonymous$$BIENT.rgb * diffuseColor;
                 float3 diffuseRef = _LightColor0.rgb * diffuseColor * max(dot(i.normal, lightDirection), 0.0);
                 float3 specularRef = _LightColor0.rgb * specularColor * pow(max(dot(viewDirection,reflect(-lightDirection, i.normal)), 0.0),_SpecularPower);
                 
                 
                 return float4(ambientLight+diffuseRef+specularRef,_Opacity);
             }
             
             ENDCG
         }
     } 
     FallBack "Diffuse"
 }
 
avatar image kevinspawner · Apr 07, 2015 at 05:41 PM 0
Share

Wow! Super Awesome. Thanks. Am away from my workstation. Once I get back to work, I will check this one. Thanks.

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

19 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

Related Questions

Materials disappear on Mobile when more then one is set to static batching. 0 Answers

Unity Android project dead. 1 Answer

Number of vertices for android 0 Answers

Mesh changing in realtime 1 Answer

A doubt in QA on performance on a generic mesh info? 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