• 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
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

People who like this

0 Show 0
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

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

People who like this

0 Show 0 · 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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

42 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

Related Questions

Have part of mesh change color 0 Answers

Skybox blending 2 Answers

3D textures for Constructive Solid Geometry 0 Answers

Texture stretching on one axis. Skybox Shader help. 1 Answer

Can a shader render darkness inside a mesh? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges