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
3
Question by Paulius-Liekis · Apr 08, 2010 at 07:40 PM · shadertagsrenderorder

Is it possible to pass SubShader tag as a parameter?

Hi,

I'm trying to control rendering order explicitly. One of the ways to do that is to control "Queue" Tag in my shader. Unfortunately that means I have to create a shader for each rendering "layer".

I would like to create a shader which takes "Queue" Tag as a parameter - that would allow me to create a single shader and then just to pass an parameter value to control rendering order.

Is it possible to do that (and how)? Or is there a better technique?

Thanks, Paulius

Comment
Add comment · Show 1
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 yoyo · Apr 10, 2010 at 02:56 PM 0
Share

Exactly the question I was about to ask!

2 Replies

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

Answer by cncguy · Aug 04, 2010 at 12:29 PM

I have this same issue and put it in the too hard basket for a while. Now after looking through the documentation for the Material class I noticed that a material uses the shader renderqueue position by default, however you can override that via Material.renderQueue (i.e. NOT shader.renderQueue). Once you do this the Material maintains its new position in the renderQueue. So you can control this in code and it only requires ONE version of your shader.

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
2
Best Answer

Answer by yoyo · Apr 10, 2010 at 03:02 PM

[EDIT] Changing my answer to YES. Shader.renderQueue is readonly, but Material.renderQueue is writable. (Everything else here is still correct, just not complete.)


Unfortunately I think the answer is no. The Tag syntax only supports strings. Also, Shader.renderQueue is read-only:

http://unity3d.com/support/documentation/ScriptReference/Shader-renderQueue.html

Which implies you can't change it dynamically.

Also, since renderQueue is a property of the shader, not the material, you couldn't use the same shader on different materials with different queue settings.


But I did find a way to manage static render order from the Unity scene editor.

Create the shader for the effect you want, with a named pass that you will reuse below. Note that pass name should be uppercase.

Shader "MyShader"
{
    Properties { ... }
    SubShader
    {
        Tags {"Queue"="Transparent"}
        Pass
        {
            Name "MAIN"
            ... (implement your effect)
        }
    } 
}

Now create a shader per desired layer, named and tagged by layer number (here's layer 1):

Shader "MyShader/1"
{
    Properties { ... (need to duplicate from main shader) }
    SubShader
    {
        Tags {"Queue"="Transparent+1"}
        UsePass "MyShader/MAIN"
    } 
}

Create your material(s) per layer, selecting shader MyShader > 1, 2, 3, etc. You can change the shader selection from the scene editor to change the layer order. Since your implementation is all in one shader ("MyShader") and reused in the layer shaders, you only have to modify one shader in order to change the implementation.

Unfortunately if you add or remove passes or change the properties you need to update all the layer shaders as well, so this isn't perfect, but it helps.

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

No one has followed this question yet.

Related Questions

Player Silhouette Shader ignore certain objects 0 Answers

Different behavious of shader in unity's build in simulator and ios device 0 Answers

Render group of objects in front? 0 Answers

How to force the compilation of a shader in Unity? 5 Answers

ShaderLab - What is "RenderType" subshader tag used for? 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