• 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 babaqalex · Jan 28, 2016 at 01:27 PM · vertex shaderfragmentcustom shader

is it possible to define multiple vertex/fragment shader in one pass?

hi all,

I am translating a old XNA *.fx shader effect to Unity5. previously I defined multiple vertex and pixel shaders, and compiled them in arrays, and use some parameter to tell the rendering pipeline which vertex/fragment shader combinations to use in one pass:

VertexShader VSArray[3] = { compile vs_2_0 VSSin(), compile vs_2_0 VSSquare(), compile vs_2_0 VSLinear(), };

PixelShader PSArray[2] = { compile ps_2_0 PSNone(), compile ps_2_0 PSGaussian(), };

technique Technique1 { pass Pass1 { VertexShader = (VSArray[VSIndex]); PixelShader = (PSArray[PSIndex]); } }


but in unity5 shaderlab, I don't have a clue how to achieve this. I tried to define more than one vertex/fragment shaders:

Shader "myshader" { Properties {

     sigma("Sigma", Float) = 0.05
     sf("SF", Float) = 0.2
     time("Time", Float)=0
 }
     SubShader
 {
     Tags { "RenderType" = "Opaque" "Queue" = "Transparent" }
     Blend SrcAlpha OneMinusSrcAlpha
     LOD 100

     Pass
     {
         CGPROGRAM
         #pragma vertex vert
         #pragma vertex vert1
         #pragma fragment frag
         # include "UnityCG.cginc"
           
              //.....
         ENDCG
      }
 }

}


and unity5 editor showed "Duplicated #pragma...."

I am wondering is it possible to do something similar to my old .fx effect. or I have to separate each vertex/fragment shader in each shader file, and use some other parameter to combine them in one pass?

thanks,

Comment
Add comment · Show 2
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 Teravisor · Jan 28, 2016 at 05:37 PM 0
Share

Defining more than one vertex/fragment shader in shader obviously won't work as there can only be one vertex and only one fragment shader in single shader. A slow-working solution is using if(...)else... statements in shader to choose which function to call, but if statement is generally slowest thing you can do in shader code. So the only thing I can advise you (not pleasant solution either so not posting as answer) is to compile all vertex/fragment shader combinations into separate shaders and change them when you need.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tanoshimi · Jan 28, 2016 at 09:05 PM

Sounds like you're looking for #pragma multi_compile

http://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html

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.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Fragment/Vertex shader complex issue 0 Answers

From within the frag function of a shader, can you access the uv values of vertices? 0 Answers

How to access array elements in Surface Vertex shaders? 0 Answers

Combine Vertex / Fragment and Surface Shader 0 Answers

How to achieve shadows in custom Vertex/Frag shaders? 0 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