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

avatar image babaqalex Teravisor · Jan 29, 2016 at 02:55 AM 0
Share

I have thought about the if() solution, since I'll probably do branching in the shader anyway, I'll try to put all staff in the shader for now.

I found some articles saying in most recent harderwares, dynamic branching is achieved in $$anonymous$$I$$anonymous$$D(multi-instruction-multi-data) way, so branching in shader wouldn't be a serious performance problems anymore. I don't know if it's true. I guess whenever performance become degraded, I could switch to static branching, or separate functions in different shaders.

Still, feel disappointed that I could do in XNA which is kind of outdated for several years, but can't do the same thing in the newest unity5!!

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Vertex shader breaks render to texture - camera preview and render texture not the same 1 Answer

Can you specify both Surface and Vertex/Fragment shaders? 3 Answers

How to convert surface shader to Vertex/Fragment code? 0 Answers

How to add normal map to "color" shader? 0 Answers

[Shader, sprite] frag shade entire sprite image? 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