0
Under review

Depth Blend Display Bug when in Isometric view.

William Lau 10 years ago updated 10 years ago 8
So today I was working on a SF particle shader with soft particles to plug into Unity's shuriken particle system and I stumbled upon this bug where particles don't display properly.

This bug only happens in Editor scene view and only in Isometric scene camera.
I am using deferred camera and soft particles enabled. 
So far I only seem to notice this happen with Shuriken, 

This is the shader I am testing with:

Image 230

This is the expected and correct result (Currently in Perspective mode):




This is the expected and correct result (Currently in Perspective mode):




This is the result in Isometric Mode:



I removed the Depth Blend:




This is the result in Isometric with out depth blend:





Anyone able to reproduce this problem?
Under review
I suspect this has something to do with the positioning of particle shaders vs normal shaders. Not sure why it happens. Does it write to the Z buffer?
It doesn't write to Z buffer. But I tried it with Z buffer and same situation happens.
This bug only happens when you don't have the particle system selected. When it is in focus, it works fine.
I have found the problem with this issue.
This is caused by not declaring #pragma multi_compile_particles and using #ifdef SOFTPARTICLES_ON in the shader code.
depth blend cannot be used in isometric editor view and hence SOFTPARTICLES_ON is not defined when in isometric view.

After adding the ifdef tags to the depth blend sections of the code it will solve this problem.
Right now I have to manually add them in after compiling the shader.
Hope you can incorporate this into future versions.
The problem though, is that there's no way for me to know if someone is making a particle shader or not, and whether or not they're using the depth blend node as a way of softening particles.
If I'm adding this, it'll be through a checkbox in the blending settings, specifically for soft particles
Heres the working shader code for the earlier shown depth blend shader:

Pass {
Name "ForwardBase"
Tags {
"LightMode"="ForwardBase"
}
Blend One One
Cull Off
ZWrite Off
Lighting Off
Fog {Color (0,0,0,0)}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
//#pragma multi_compile_fwdbase
#pragma multi_compile_particles
#pragma exclude_renderers xbox360 ps3 flash d3d11_9x
#pragma target 3.0
uniform sampler2D _CameraDepthTexture;
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
uniform float4 _TintColor;
uniform float _Softness01;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float4 vertexColor : COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float4 vertexColor : COLOR;
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD1;
#endif
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.uv0 = v.texcoord0;
o.vertexColor = v.vertexColor;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
#ifdef SOFTPARTICLES_ON
o.projPos = ComputeScreenPos (o.pos);
COMPUTE_EYEDEPTH(o.projPos.z);
#endif
return o;
}
fixed4 frag(VertexOutput i) : COLOR {

#ifdef SOFTPARTICLES_ON
float sceneZ = max(0,LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)))) - _ProjectionParams.g);
float partZ = max(0,i.projPos.z - _ProjectionParams.g);
#endif


////// Lighting:
////// Emissive:
float2 node_856 = i.uv0;
float4 node_2 = tex2D(_MainTex,TRANSFORM_TEX(node_856.rg, _MainTex));
float4 node_782 = i.vertexColor;
float3 emissive = (node_2.rgb*node_2.a*(_TintColor.rgb*node_782.rgb*node_782.a*2.0));
#ifdef SOFTPARTICLES_ON
emissive *=saturate((sceneZ-partZ)/_Softness01);
#endif
float3 finalColor = emissive;
/// Final Color:
return fixed4(finalColor,1);
}
ENDCG
}