- Home /
Problem fixed; I had a separate camera rendering the stars. Once I removed it, it worked properly.
Mesh (custom shader) appears in front of particles (default shader)?
So, I have a couple screenshots here that i'd like to display, followed by a couple snippets of code.
The top image is the appearance that I want. The lower image is the appearance I am trying to eradicate.
I scripted a custom shader for the stars, which is nothing more than a copy of the Particles/Additive shader that ignores fog. The fog turns the white sky particles black, which emulates the appearance of clouds blocking the stars. However, after 30-60 seconds of gameplay, the stars suddenly appear on top of the clouds. The only way to fix this is by restarting the particle emitter and forcing it to rebuild the clouds.
What exactly could be happening to cause this? I've looked through my particle emitter settings and am completely stumped.
Here's a copy of my shader. It seems to work properly.
Shader "Particles/Additive (No Fog)" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Particle Texture", 2D) = "white" {}
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
}
Category {
Tags { "Queue"="Transparent-100" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha One
ColorMask RGB
Cull Off Lighting Off ZWrite Off
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_particles
//#pragma multi_compile_fog
#include "UnityCG.cginc"
sampler2D _MainTex;
fixed4 _TintColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
//UNITY_FOG_COORDS(1)
#ifdef SOFTPARTICLES_ON
float4 projPos : TEXCOORD2;
#endif
};
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
#ifdef SOFTPARTICLES_ON
o.projPos = ComputeScreenPos (o.vertex);
COMPUTE_EYEDEPTH(o.projPos.z);
#endif
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
//UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
sampler2D_float _CameraDepthTexture;
float _InvFade;
fixed4 frag (v2f i) : SV_Target
{
#ifdef SOFTPARTICLES_ON
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
float partZ = i.projPos.z;
float fade = saturate (_InvFade * (sceneZ-partZ));
i.color.a *= fade;
#endif
fixed4 col = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
//UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
return col;
}
ENDCG
}
}
}
}
Answer by DrShikura · Jan 12, 2016 at 12:07 AM
Here's a preview of what my scene looks like, maybe it can help shine some light on the issue.
The wireframe is the stars mesh. It's an isosphere with 2 subdivisions and uses ProCore Basic to build the UV mapping for the texture.
Inside the mesh, you can clearly see the black smudges that are the clouds rendering dark because of the fog, which I have enabled in this screenshot. The clouds are nothing too special. They're a particle emitter that renders roughly 250 large particles around the shell of a hemisphere shape. The particle system lasts 60 seconds and each particle has a life span of 60 seconds. The material for these clouds uses the Particles/Alpha Blended shader.
Here's a screenshot of the inspector view.
Follow this Question
Related Questions
Transparency / depth problem 0 Answers
Shader mesh not being effected by directional lights? 1 Answer
How to use mesh data in shader 0 Answers
How does appdata_base work? 0 Answers