Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 kkrg001 · Jun 02, 2020 at 02:32 AM · particlesparticlesystem

Is there a way to give a random UV to a particle trail shader?

Is there a way to give a random UV to a particle trail shader? Even if you make a random value with a custom vertex stream, trail does not inherit it. So far all the trail smoke has been collected, It doesn't help at all. Here is a similar question, but world position is meaningless. https://realtimevfx.com/t/random-value-for-particle-system-trails-material-in-unity/11183 I believe there is a simple solution. alt text

trail-problem.png (268.4 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ifurkend · Jun 02, 2020 at 03:16 AM

I am not quite sure what "WP" stands for in that RealTimeFX thread. But if you are willing to sacrifice one channel in vertex color for sending the initial randomized range to your particle trail material, the shader can be very straightforward like this.

Still you will need to create a separate uv for the alpha, otherwise the transparency of the trail texture will offset as well, undesirably. In this example shader I just do tex2D twice with different sets of uv, but you may also use the un-offset uv (xy) to calculate your texture transparency along the trail with functions like smoothstep, either in the vertex shader (faster) or fragment shader (slower), depending on how you weigh between performance and rendering fidelity.

 Shader "Particles/Trail Random UV Offset by Vertex Color"
 {
     Properties
     {
         _MainTex ("Texture", 2D) = "white" {}
     }
     SubShader
     {
         Tags { "RenderType"="Transparent" "Queue"="Transparent" "PreviewType"="Plane"}
         LOD 100
         Lighting Off
         ZWrite Off
         ZTest LEqual
         Blend SrcAlpha OneMinusSrcAlpha
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
                 float4 color : COLOR;
             };
 
             struct v2f
             {
                 float4 uv : TEXCOORD0;
                 float4 vertex : SV_POSITION;
                 float color : COLOR;
             };
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
 
             v2f vert (appdata v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
                 o.uv.zw = o.uv.xy + v.color.rg; //Assuming you offset final uv with vertex color red and green.
                 return o;
                 o.color.r = v.color.a;
             }
 
             float4 frag (v2f i) : SV_Target
             {
                 float4 col = tex2D(_MainTex, i.uv.xy);
                 float4 colOffset = tex2D(_MainTex, i.uv.zw);
                 return float4(colOffset.rgb, col.a * i.color.r);
             }
             ENDCG
         }
     }
 }

alt text


capture.png (285.6 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
avatar image
0

Answer by kkrg001 · Jun 02, 2020 at 04:20 AM

Thank you for your polite sample. As you said, I think randomization is possible by discarding one vertex color. But in most cases it seems difficult. I think this problem existed 10 years ago when I first touched unity. It hasn't been resolved yet...

WP is probably the world position.

Comment
Add comment · Show 1 · 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
avatar image ifurkend · Jun 02, 2020 at 04:48 AM 0
Share

I won't call the lack of UV randomization for particle trails an "issue", the randomization itself would cause more unexpected issues. As for a bunch of plain smoke trails as shown in your screenshot, you hardly need an array of rainbow colors for all trails, so the lack of ability to change trail colors from the particle system with this shader does not have that much of impact. At least this is how I see in many commerical games with lot of gun smoke trails flying in the same scene.

If you want to change the color of the trails in the engine, you can do it with an additional material property of _TintColor (and even use the randomized vertex color to randomize the final color, not just the UV). Indeed you will need a new material for each color of trail material.

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

132 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

Related Questions

Emit Random Particles? 2 Answers

Unity 2D Particle System Interaction. 0 Answers

Glowing Particle 3 Answers

Finding Particle Information Upon Collision 2 Answers

Particle System not working. 1 Answer


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