I am creating a fog machine type of effect for this project, but I am finding a part of it undesirable. I have created a mesh particle emitter directly under my floor, and have the particles slowly floating upward a short ways before fading out. The undesired part is that when each fog particle sprite goes through the floor there is an obvious line where they intersect. I still want to be able to have them appear in front/behind the characters in the scene, so disabling the depth buffer isn’t exactly what I’m looking for. Is there anyway I can have it somehow ignore the floor plane when being rendered? Any other techniques and ideas would be appreciated.
EDIT: I’m using the Particles\Additive shader for the material, so if there is something more appropriate or a change I could potentially make to prevent the intersection from appearing, I would love to hear about it.
Awesome! This looks exactly like what we want to achieve. We have a Pro license but have been waiting to upgrade to Unity 3 until we’re absolutely sure everything is working the way we want it to and we need to do so in order to utilize some new feature… looks like we’ve reached that point.
After doing a little more digging (now that I know what to call this effect), I found that there is a Soft Particle example in the Shader Replacement example pack. It works fine when I play the demo scene, but when I copy the shader and try to use it in my scene, I get a really funky error (seen in the picture below). Keep in mind this is still 2.6.1.
Here is the shader code that I pulled from that example, if anyone has an idea why it’s not displaying properly:
Shader "Particles/~Additive-Multiply (soft particles)" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Particle Texture", 2D) = "white" {}
_Fadeout ("1/Fadeout distance", Float) = 0.5
}
Category {
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" }
Blend One OneMinusSrcAlpha
ColorMask RGB
Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,1) }
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex;
float4 texcoord;
float4 color;
};
struct v2f {
float4 pos : POSITION;
float4 color : COLOR;
float3 uvz : TEXCOORD0;
float3 screen : TEXCOORD1;
};
uniform float4 _GlobalDepthTextureSize;
v2f vert(appdata v) {
v2f o;
o.pos = mul(glstate.matrix.mvp, v.vertex);
o.color = v.color;
o.uvz.xy = v.texcoord.xy;
COMPUTE_EYEDEPTH(o.uvz.z);
float3x4 mat= float3x4 (
0.5, 0, 0, 0.5,
0, 0.5, 0, 0.5,
0, 0, 0, 1
);
float3 coord = mul(mat, o.pos);
#ifdef SHADER_API_OPENGL
coord.xy *= _GlobalDepthTextureSize.xy;
#endif
o.screen = coord;
return o;
}
sampler2D _MainTex;
samplerRECT _GlobalDepthTexture;
uniform float _Fadeout;
half4 frag(v2f i) : COLOR {
// regular thing that a additive multiply shader would do
half4 texcol = tex2D( _MainTex, i.uvz.xy );
half4 col;
col.rgb = texcol.rgb * i.color.rgb * 2;
col.a = 1 - texcol.a*i.color.a*2;
// Fade out particles where they are close to intersection
// with the scene
float z = texRECTproj( _GlobalDepthTexture, i.screen ).r;
float sceneDepth = DECODE_EYEDEPTH( z );
float myDepth = i.uvz.z;
col *= saturate((sceneDepth-myDepth)*_Fadeout);
return col;
}
ENDCG
}
}
}
Fallback "Particles/~Additive-Multiply"
}
Just realized I left out the script/shader attached to the main camera to create the rendertexture necessary to gauge depth in the scene. It now treats the bottom of the sprite with a linear alpha gradient which prevents the hard edge when intersecting other geometry. However It still displays the crazy black rectangle, when really I just want the white to show through like with the Particles\Additive shader. Is there an obvious multiply effect in this shader that someone can point out so I can attempt to comment it out?
Ok, so by changing the blend mode from “Blend One OneMinusSrcAlpha” to “Blend SrcAlpha One” I get all of the black content to disappear, and it acts additively… however it no longer allows the Particle Animator to influence the alpha value of the fog. Also, my camera is being horizontally mirrored and the viewport is 75% (this is all required for our installation screen)… and this seems to be having a strange effect on it, as though the render texture is acquired before the camera is mirrored.
Either upgrade to Unity 3.0 and use the soft particles included or create a new thread regarding the problems you have with the soft particle shader you found for 2.6.
We tried it with a Unity 3 pro trial and you have to switch the rendering path to deferred lighting, which causes pixel lights to act sort of weird… plus the red emissive stars are no longer emissive. I may have to play around with this script more, as I don’t think the simple toggle on in unity 3 will work for our project…