Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by WizzardH · May 07, 2021 at 01:35 PM · shadershadersparticlesparticlesystemfadeout

Limit particle shader / discard from certain worldpos

Hi there, new to shader programming and struggeling to recreate a particle shader that does not go through walls. It's a looping visualisation of a circle that fades out reaching the end of its lifetime. If it reaches a wall I want it to discard every fragment that is beyond a certain x or y value, so beyond the wall (will do that with discard). My problem at the moment is that the shader I'm rebuilding on my own (to introduce properties to use discard) isn't looking like the one made with the built in unity shader and a sprite attached to it. Yellow: Built in "Particles Alpha Blended Shader" |Green: own shader based on an unlit shader. alt text

As you can see, the edges of the green one aren't fading out as the one of the yellow one. I think the problem is that I don't get the current "color over lifetime" from the particle system as an input, but I don't know how I could get that.

My Code looks like this:

 Shader "Unlit/TestShader"
 {
     Properties
     {
         _MainTex ("Base (RGB) Transparency (A)", 2D) = "" {}
     }
     SubShader
     {
         Tags { "RenderType"="TransparentCutOut" "Queue"="AlphaTest" }
         Blend SrcAlpha OneMinusDstAlpha     
         AlphaToMask On
         ZWrite Off
         Cull off
         
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #include "UnityCG.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float4 color : COLOR;
                 float2 uv : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 float4 vertex : SV_POSITION;
                 float4 color : COLOR;
             };
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
             float4 _Color;
             
             v2f vert (appdata v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                 o.color = v.color;
                 return o;
             }
 
             fixed4 frag (v2f i) : SV_Target
             {
                 fixed4 col = tex2D(_MainTex, i.uv);
                 return col * i.color;
             }
             ENDCG
         }
     }
 }

Can someone point out to me what I'm doing wrong or how the solution could look like?

Have a nice Friday and take care.

particleshaderrebuild.png (22.0 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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by WizzardH · May 10, 2021 at 01:12 PM

The problem has solved itself now. I've checked the shader code that Unity generated for the original shader and even though it has some confusing parts it one can still get the most basic out of it. So I replaced the subshader properties and now it works as beautifully as I want it to:

 Properties
     {
         _TintColor ("Tint Color", Color) = (0.500000,0.500000,0.500000,0.500000)
         _MainTex ("Particle Texture", 2D) = "white" { }
         _InvFade ("Soft Particles Factor", Range(0.010000,3.000000)) = 1.000000
         _LeftBoarder("Left", Float) = 1
         _RightBoarder("Right", Float) = 1
         _TopBoarder("Top", Float) = 1
         _BottomBoarder("Bottom", Float) = 1
     }
     SubShader
     {
         Tags { "RenderType"="Transparent" "Queue"="Transparent" "PreviewType"="Plane" }
 
         Blend SrcAlpha OneMinusSrcAlpha
         ColorMask RGB
         ZWrite Off
         Cull off
         
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             float4 _TintColor;
             float _LeftBoarder = 0;
             float _RightBoarder = 0;
             float _TopBoarder = 0;
             float _BottomBoarder = 0;
             
             struct appdata
             {
                 float4 vertex : POSITION;
                 float4 color : COLOR;
                 float2 uv : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 float4 vertex : SV_POSITION;
                 float4 color : COLOR;
                 float3 worldPos : TEXCOORD1; 
             };
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
             float4 _Color;
             
             v2f vert (appdata v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.worldPos = mul(UNITY_MATRIX_M, v.vertex.xyz); //object to world
                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                 o.color = v.color;
                 return o;
             }
 
             fixed4 frag (v2f i) : SV_Target
             {
                 fixed4 col = tex2D(_MainTex, i.uv);
 
                 if(i.worldPos.x < _LeftBoarder || i.worldPos.x > _RightBoarder)
                     return col * i.color * _TintColor;
                 
                 return col * i.color;
             }
             ENDCG
         }
     }
 
 
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

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

PS Custom Vertex Streams to Particle Trail 0 Answers

My particles glow at night how can I stop the glowing 0 Answers

Unity inbuilt distorsion shader? 1 Answer

Make Start Color setting in particle system control _EmissionColor 1 Answer

Glowing Particle 3 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