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 AlicanHasirci · Dec 22, 2015 at 09:07 AM · shaderscgunlitvertex colordrawcall

Using Vertex Color increases Draw Call

I am working on a card game right now and to keep draw calls at minimum i am using single texture atlas for all cards where i set UV values of vertices programmatically to change each card.

Each card has face and back mesh also with a text mesh in front. By changing each card as i said earlier for any number of cards i can keep the draw calls at 2 thanks to dynamic batching but i also want to add highlight to cards. To do this i wanted to use vertex colours, thou this totally screwed up the dynamic batching, causing draw calls to increase linearly related to card count. Every article i've read remotely related to this topic says that usage of vertex colours does not increase draw calls and here is the interesting part, this is unlit shader i use :

 Shader "Custom/Unlit Cutoff Vertex" {
 Properties {
     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
 SubShader {
     Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
     LOD 100
 
     Lighting Off
 
     Pass {  
         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc"
 
             struct appdata_t {
                 float4 vertex : POSITION;
                 float2 texcoord : TEXCOORD0;
                 float4 color : COLOR;
             };
 
             struct v2f {
                 float4 vertex : SV_POSITION;
                 half2 texcoord : TEXCOORD0;
                 float4 color : COLOR;
             };
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
             fixed _Cutoff;
 
             v2f vert (appdata_t v) {
                 v2f o;
                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                 o.color = v.color;
                 return o;
             }
             
             fixed4 frag (v2f i) : SV_Target {
                 fixed4 col = tex2D(_MainTex, i.texcoord);
                 clip(col.a - _Cutoff);
                 return col * i.color;
             }
         ENDCG
     }
 }
 
 }

..the built-in unlit cutoff shader slightly modified to support vertex color. Whenever i add

o.color = v.color;

to vertex shader it screws up the batching. Anyone has an idea why?

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 tanoshimi · Dec 22, 2015 at 09:12 AM 0
Share

How many vertices does each card have? Does including vertex colour cause the mesh to exceed 900 vertex attributes total? That would break dynamic batching.

avatar image AlicanHasirci tanoshimi · Dec 22, 2015 at 09:22 AM 0
Share

Each card has 16 vertices, but interestingly when i use vertex color it increases to 20 still far off from the limit. I am guessing the reason for the increase in vertex count is to provide better interpolation between vertex colors.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

GrabPass twirl shader not centering correctly 0 Answers

How to make shader that uses vertex colors to colorize mesh but accepts shadows? 0 Answers

Can this shader run in unity? 1 Answer

_WorldSpaceLightPos0.xyz always 0 2 Answers

[Shader] Usage #ifdef DIRECTIONAL 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