• 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 /
This question was closed Jan 12, 2016 at 12:27 AM by DrShikura for the following reason:

Problem fixed; I had a separate camera rendering the stars. Once I removed it, it worked properly.

avatar image
0
Question by DrShikura · Jan 11, 2016 at 11:55 PM · shadermeshparticle systemskyboxstars

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.

alt text

alt text

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 
         }
     }    
 }
 }
ss2016-01-11at064116.jpg (58.0 kB)
ss2016-01-11at064053.jpg (88.1 kB)
Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0

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.

alt text

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. alt text


ss2016-01-11at065246.jpg (597.1 kB)
ss2016-01-11at070701.png (33.8 kB)
Comment
Add comment · 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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

43 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 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 avatar image avatar image avatar image

Related Questions

Transparency / depth problem 0 Answers

Mask a 3D Object using a 3D Volume 0 Answers

Will Semi Transparent mesh with several folds of geometry sort correctly? 1 Answer

How to light back side of quad mesh same way as front side? 1 Answer

Shader for mesh to project onto sprite? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges