Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by devin8 · Jan 03, 2013 at 08:52 PM · shaderbatchingvertex shader

Dynamic batching and object local vertex position

I am writing a shader that would pulsate an object by moving vertex position in local coordinates.
It works fine if applied to one object only. However, if it is applied to multiple objects and if they are batched, then local coordinates get messed up and objects pulsate around a common center. Normals are also messed up as can be seen by color. Instead of having a object relative direction, they are relative to a collective of all the batched objects.

 Shader "Custom/Pulsar" {
     Properties {
         _GrowFactor ("Grow Factor", Float) = 0.4
     }
     SubShader {
         Pass {
             Tags { "Queue"="Geometry" }
             Cull Off
             
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #include <UnityCG.cginc>
     
             float _GrowFactor;
             
             struct VertexOutput{
                 float4 pos : SV_POSITION;
                 float4 col : COLOR;
             };
             
             VertexOutput vert(appdata_full v){
                 VertexOutput o;
                 float4 vPos = v.vertex + float4(v.normal.xyz, 1.0)*abs(_GrowFactor*_SinTime.w);
                 o.pos = mul(UNITY_MATRIX_MVP, vPos);
                 o.col = float4(v.normal, 1.0);
                 return o;
             }
             
             float4 frag(VertexOutput o): COLOR0 {
                 return o.col;
             }
             
             ENDCG
         }
     } 
     FallBack "Diffuse"
 }


Is there a way that vertices can be processed in their local coordinates even after batching, possibly in a particular transformation space ?

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 hicks · Jun 26, 2015 at 02:04 PM 1
Share

A little late, but I'm having the same issue right now. I don't think it is possible. It depends on how Unity is doing the batching internally. If they would do seperate draw calls and just share the resources among those consecutive draw calls, they would have to provide different UNITY_$$anonymous$$ATRIX_$$anonymous$$VP matrices for each. That would be nice but I think they are using a different approach.

I ended up just using one material instance for each object. I had many objects dynamically instantiated, so I used just this line after instantiation: renderer.material = renderer.material;, which automatically creates a material instance.

Edit: Just found the new DisableBatching tag to disable batching for this shader completely. http://docs.unity3d.com/500/Documentation/$$anonymous$$anual/SL-SubshaderTags.html

avatar image Pawl hicks · Aug 19, 2016 at 06:47 PM 0
Share

This was a tricky bug to diagnose, but the DisableBatching tag worked great! Thanks!! (verified on Unity 5.4)

 Tags { "DisableBatching"="True" }

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

10 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

Related Questions

How do I set up custom shader options without killing batching? 0 Answers

Dissable Batching in Shader 0 Answers

Dynamic Batching and vertex shader animation 2 Answers

Does dynamic batching and vertex shader work together? 1 Answer

Add new vertex attributes for a shader,Create vertex attributes 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