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 mgc90403 · Jan 26, 2014 at 04:57 AM · iosparticleopacity

Fade particle opacity according to distance from camera?

Hi All I'm working on iOS (base pro, though not iOS pro for the time being) - I want to ramp the opacity of particles down to zero as they approach camera. Is there a simple way to do this? It appears that soft particles don't work on iOS - - so this would be a pretty good workaround for my needs.

Comment
Add comment · Show 1
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 nesis · Jan 26, 2014 at 06:11 AM 1
Share

You could go about appropriating this shader to your needs, since it fades transparent materials out as they get closer to the camera.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mgc90403 · Jan 27, 2014 at 03:06 AM

Thank you for posting the link.
This appears to work great (after ferreting out a phantom typo on my part. ;)

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 S37H · Apr 14, 2015 at 11:52 PM 0
Share

This is a long shot but what was the typo? I can't get past the errors it's giving me : /

'vert': function return value missing semantics at line 50 (on d3d11_9x) 'frag': input parameter 'i' missing semantics at line 62 (on d3d11_9x)

 Shader "Particles/Additive Clipsafe" {
     Properties {
         _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
         _$$anonymous$$ainTex ("Particle Texture", 2D) = "white" {}
         _FadeDistance ("Fade Start Distance", float) = 0.5
     }
 
     SubShader {
         Tags { "Queue" = "Transparent" }
         Blend SrcAlpha One
         AlphaTest Greater .01
         Color$$anonymous$$ask RGB
         Lighting Off
         ZWrite Off
         Fog { Color (0,0,0,0) }
         Pass {
             CGPROGRA$$anonymous$$
                 #pragma vertex vert
                 #pragma fragment frag
                 #pragma multi_compile_builtin
                 #pragma fragmentoption ARB_fog_exp2
                 #pragma fragmentoption ARB_precision_hint_fastest
                 #include "UnityCG.cginc"
                 
                 uniform float4    _$$anonymous$$ainTex_ST,
                                 _TintColor;
                 uniform float _FadeDistance;
                 
                 struct appdata_vert {
                     float4 vertex : POSITION;
                     float4 texcoord : TEXCOORD0;
                     float4 color : COLOR;
                 };
                 
                 uniform sampler2D _$$anonymous$$ainTex;
                 
                 struct v2f {
                     V2F_POS_FOG;
                     float2    uv;
                     float4 color;
                 };
                 
                 v2f vert (appdata_vert v) {
                     v2f o;
                     PositionFog( v.vertex, o.pos, o.fog );
                     o.uv = TRANSFOR$$anonymous$$_TEX(v.texcoord, _$$anonymous$$ainTex);
                     float4 viewPos = mul(glstate.matrix.modelview[0], v.vertex);
                     float alpha = (-viewPos.z - _ProjectionParams.y)/_FadeDistance;
                     alpha = $$anonymous$$(alpha, 1);
                     o.color = float4(v.color.rgb, v.color.a*alpha);
                     o.color *= _TintColor*2;
                     return o;
                 }
                 
                 float4 frag (v2f i) : COLOR {
                     half4 texcol = tex2D( _$$anonymous$$ainTex, i.uv );
                     
                     return texcol*i.color;
                 }
             ENDCG
         }
     }
     
     Fallback "Particles/Additive"
 }

avatar image TheCapGuy S37H · Apr 12, 2016 at 09:07 PM 0
Share

Hi o/ I just found this post and thought.. because I was in need for this kind of shader myself, of course i'll revive this two year old post to comment on your problem. The shader on the wiki is not compatible with Unity 5 (which I assume you used), so i've made the changes required to make it work.

Enjoy.

 Shader "Particles/Additive Clipsafe" {
     Properties {
         _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
         _$$anonymous$$ainTex ("Particle Texture", 2D) = "white" {}
         _FadeDistance ("Fade Start Distance", float) = 0.5
     }
 
     SubShader {
         Tags { "Queue" = "Transparent" }
         Blend SrcAlpha One
         AlphaTest Greater .01
         Color$$anonymous$$ask RGB
         Lighting Off
         ZWrite Off
         Fog { Color (0,0,0,0) }
         Pass {
             CGPROGRA$$anonymous$$
                 #pragma vertex vert
                 #pragma fragment frag
                 #pragma multi_compile_builtin
                 #pragma fragmentoption ARB_fog_exp2
                 #pragma fragmentoption ARB_precision_hint_fastest
                 #include "UnityCG.cginc"
                 
                 uniform float4    _$$anonymous$$ainTex_ST,
                                 _TintColor;
                 uniform float _FadeDistance;
                 
                 struct appdata_vert {
                     float4 vertex : POSITION;
                     float4 texcoord : TEXCOORD0;
                     float4 color : COLOR;
                 };
                 
                 uniform sampler2D _$$anonymous$$ainTex;
                 
                 struct v2f {
                     float4 pos : SV_POSITION;
                     float2 uv : TEXCOORD0;
                     float4 color : COLOR;
                 };
                 
                 v2f vert (appdata_vert v) {
                     v2f o;
                     o.pos = mul (UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex);
                     o.uv = TRANSFOR$$anonymous$$_TEX(v.texcoord, _$$anonymous$$ainTex);
                     float4 viewPos = mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$V, v.vertex);
                     float alpha = (-viewPos.z - _ProjectionParams.y)/_FadeDistance;
                     alpha = $$anonymous$$(alpha, 1);
                     o.color = float4(v.color.rgb, v.color.a*alpha);
                     o.color *= _TintColor*2;
                     return o;
                 }
                 
                 float4 frag (v2f i) : COLOR {
                     half4 texcol = tex2D( _$$anonymous$$ainTex, i.uv );
                     
                     return texcol*i.color;
                 }
             ENDCG
         }
     }
     
     Fallback "Particles/Additive"
 }

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

20 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

Related Questions

Character with hair (mobile) 0 Answers

Particle Animator Opacity 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Problem rendering particles in ios 1 Answer

iOS Game freeze, when particles emitted for first time. 2 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