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
1
Question by Glurth · May 19, 2016 at 01:11 AM · shadershadersgeometryprimitivesprimitive

Call different geometry shader functions, for different primitive type: How?

Hello,

I have a geometry shader that needs to work a bit differently depending on if the primitives are provided via GL.Begin(GL.lines) or GL.Begin(GL.quads).

I tried defining two version of the function in my shader, with the same name, but different parameters. Alas, this does not seem to be working properly. Perhaps I’m using the wrong primate type for GL.quads? I’ve tried both “triangle” and “lineadj”, but neither version ever gets called (unless I rename the "line" version as a sanity check).

My shader currently has both of the following function definitions, but only the second one is ever called, regardless of whether unity is drawing GL.lines or GL.quads

 #pragma geometry GS_Main
 
 …(vertex shader, struct definition, tags, etc)…
 [maxvertexcount(4)] 
 void GS_Main(lineadj v2g p[4], inout TriangleStream<g2f> pStream) //note the "lineadj" in first param.  Tried "triangle v2g p[3]" to, same result, never called.
 {…}
 
 [maxvertexcount(28)]
 void GS_Main(line v2g p[2], inout TriangleStream<g2f> pStream)  //note the "line" in first param
 {…}

I don’t even know if I’m allowed to override the geometry shader, GS_Main, function like that, but it’s not giving my any compile errors.

Primary Question: How can I get the correct version of the geometry shader functions to run depending on weather Unity is using GL.lines vs Gl.quads? Or is it REQUIRED that each shader handle only one type of primitive (in which case I'm open to suggestions).

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

1 Reply

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

Answer by tanoshimi · May 19, 2016 at 03:21 PM

I don't know for sure but, based on the comments in http://gamedev.stackexchange.com/questions/38874/geometry-shader-for-multiple-primitives , I don't think it's possible to overload a geometry shader to handle multiple primitive types (not in GLSL, anyway, but I suspect the same is true for Cg/HLSL)

Comment
Add comment · Show 3 · 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 Glurth · May 19, 2016 at 03:29 PM 0
Share

Yeah, I had come to the same conclusion, but didn't want to believe it. So it sounds like I'll have to swap out materials, in unity, depending on what type of primitive I'm drawing.

OH! Talking about swapping out the material made me realize I DO call this function, just before I draw GL.lines line$$anonymous$$aterial.SetPass(0); Hmm, perhaps I can specify a different SetPass paramater for quads, and get it to use the other geometry shader function, in that way? (I've only done single pass shaders so far...)

avatar image tanoshimi Glurth · May 19, 2016 at 04:47 PM 0
Share

Yes - that could work. Another idea might be to create explicit subshaders for each geometry type with different LODs, and then use shader.maximumLOD to "switch" between them?

avatar image Glurth tanoshimi · May 19, 2016 at 06:03 PM 0
Share

Interesting..I've not worked with LODs before. How/where would I specify that lines use LOD x, and quads use LOD y? The disadvantage to using SetPass() is that, the functionality difference, between quads and lines, is no longer transparent. It also limits the ability to swap the same drawing code to a material that uses a different shader, one with only ONE pass available. Would using LOD ins$$anonymous$$d, help with those issues?

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

57 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

Related Questions

Shader issue with a 170 upper angle 0 Answers

UnityObjectToClipPos is inverted? 0 Answers

How to create a hole using a shader? 0 Answers

Why does AngryBots `QualityManager` alter shader LOD twice? 0 Answers

Why is shader generated from shader graph so large? 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