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.

more ▼

asked Jan 26, 2014 at 04:57 AM

avatar image

100 7 903 21

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

Jan 26, 2014 at 06:11 AM nesis
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Jan 27, 2014 at 03:06 AM

avatar image

100 7 903 21

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)
         _MainTex ("Particle Texture", 2D) = "white" {}
         _FadeDistance ("Fade Start Distance", float) = 0.5
     SubShader {
         Tags { "Queue" = "Transparent" }
         Blend SrcAlpha One
         AlphaTest Greater .01
         ColorMask RGB
         Lighting Off
         ZWrite Off
         Fog { Color (0,0,0,0) }
         Pass {
                 #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    _MainTex_ST,
                 uniform float _FadeDistance;
                 struct appdata_vert {
                     float4 vertex : POSITION;
                     float4 texcoord : TEXCOORD0;
                     float4 color : COLOR;
                 uniform sampler2D _MainTex;
                 struct v2f {
                     float2    uv;
                     float4 color;
                 v2f vert (appdata_vert v) {
                     v2f o;
                     PositionFog( v.vertex, o.pos, o.fog );
                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
                     float4 viewPos = mul(glstate.matrix.modelview[0], v.vertex);
                     float alpha = (-viewPos.z - _ProjectionParams.y)/_FadeDistance;
                     alpha = min(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( _MainTex, i.uv );
                     return texcol*i.color;
     Fallback "Particles/Additive"

Apr 14 at 11:52 PM S37H
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 26, 2014 at 04:57 AM

Seen: 604 times

Last Updated: Apr 14 at 11:53 PM