Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Custom Particles-compatible shader?

Discussion in 'Scripting' started by ninthtale, Jul 14, 2023.

  1. ninthtale

    ninthtale

    Joined:
    Jan 23, 2018
    Posts:
    17
    Hey, so the default Particles > Standard Unlit shader has the limitation of not being able to determine Render Queue properties.

    I'm following this tutorial for a portal shader system, but at the particles stage it uses a basic unlit shader, which is not compatible with the color properties in the Particle System settings. So even when I have this set:
    upload_2023-7-13_18-1-17.png
    It still shows as white:
    upload_2023-7-13_18-1-49.png

    I may be barking up the wrong tree, because maybe there's a simple setting I can enable this functionality with in the shader, but I can't seem to find it. The system default Particles Unlit shader has a lot of settings for colors and I have no hope of pinpointing what about it enables it to take on Particle System color influences.

    Can anyone please point me in the right direction to make this work?
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,235
    It looks like we are missing that bit of UI in the standard particle shaders. i will see if we can get it added.
    To work around it, i think you could write a script that does this:
    Code (CSharp):
    1. material.renderQueue = yourNumber;
     
  3. ninthtale

    ninthtale

    Joined:
    Jan 23, 2018
    Posts:
    17
    Hm, that doesn't seem to work. Adding it to a copy of the shader, it throws the error:

    Parse error: syntax error, unexpected TOK_MATERIAL, expecting TVAL_ID or TVAL_VARREF
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,235
    where did you add it exactly? can you share the relevant bit of code?
     
  5. ninthtale

    ninthtale

    Joined:
    Jan 23, 2018
    Posts:
    17
    So for clarity, what I did is I made a copy of Unity's default ParticlesUnlit.shader file, hoping to capture the particle system compatibility and to add the capacity to modify the Render Queue order beyond 50 (The ParticlesUnlit shader has a default range of -50 to 50).

    I tried adding the line of code you suggested to both the Properties and Subshader subheadings in turn:

    Properties:
    Code (CSharp):
    1. Shader "Universal Render Pipeline/Particles/UnlitNew"
    2. {
    3.     Properties
    4.     {
    5.         [MainTexture] _BaseMap("Base Map", 2D) = "white" {}
    6.         [MainColor] _BaseColor("Base Color", Color) = (1,1,1,1)
    7.         _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
    8.         _BumpMap("Normal Map", 2D) = "bump" {}
    9.         [HDR] _EmissionColor("Color", Color) = (0,0,0)
    10.         _EmissionMap("Emission", 2D) = "white" {}
    11.         material.renderQueue = yourNumber;
    This is the one that threw the error I described:
    upload_2023-7-17_11-8-5.png

    Subshader (where queue order seems to be assigned):
    Code (CSharp):
    1.     SubShader
    2.     {
    3.         Tags{"RenderType" = "Opaque" "IgnoreProjector" = "True" "PreviewType" = "Plane" "PerformanceChecks" = "False" "RenderPipeline" = "UniversalPipeline"}
    4.         material.renderQueue = "Geometry-2";
    5.  
    This actually changes/unlocks the render queue options for the shader, but they're broken and the material changes to the broken default Pink:
    upload_2023-7-17_11-12-14.png

    Also it seems changing the Render Queue order doesn't actually affect the render order, but the whole shader is broken in this scenario so I can't speak to what might be causing that.
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,235
    ah - i meant to add it to a c# script - it’s script code not shader code.
     
  7. ninthtale

    ninthtale

    Joined:
    Jan 23, 2018
    Posts:
    17
    Like as an addable component to the material itself?

    Where in a new C# script would I put that?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ColorParticles : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.        
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.        
    17.     }
    18. }
    19.  
     
  8. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,235
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ColorParticles : MonoBehaviour
    6. {
    7.     public int m_RenderQueue = -1;
    8.  
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         GetComponent<ParticleSystemRenderer>().sharedMaterial.renderQueue = m_RenderQueue;
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.    
    19.     }
    20. }
     
  9. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,235
    For anyone coming here, I have added the missing UI to our Standard Particle Shaders for Unity 2023, to make this possible without scripting.

    It's the same UI we use in the Advanced section of the Standard Shader.