• 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 destructivArts · May 09, 2016 at 06:52 AM · shadergraphicsproceduralprocedural generationdraw calls

Procedural Shader Cost/Draw Calls

Really quick question (I hope).

I'm challenging myself to try and do all the materials for my game in the shader (ie. no or few textures allowed, and I'm leaning towards only allowing auxiliary textures, like AO or position, nothing so visible as an Albedo or metallic rough map).

My question has to do with using the same shader for multiple objects, and the render cost that incurs. For example, I have a shader which blends between two colors based on a position map, and a custom voronoi function. The voronoi function takes into account object position via a mul(_Object2World, float4(0, 0, 0, 1) ) call. This means that for each object, I get a different return on the voronoi diagram (or any kind of noise function), meaning each looks distinct.

My understanding is that because I created one material from this shader, and applied it to multiple objects in my scene, that this is one draw call. Is this accurate? Or am I going to hit a wall later on by doing this again in multiple other shaders?

Thanks! Peter

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 Bunny83 · May 09, 2016 at 10:50 AM

No, that wouldn't work ^^. Yes, if all objects use the same material they could be batched into a single drawcall. Read the documentation on batching carefully as only certain condition will lead to batching.

Your problems is that batching means all objects that are batched together will behave like a single object. Batching actually transforms the vertices into the same space before it's send to the GPU. So technically it transforms multiple objects into a single one. So you only have one single matrix in the shader which only has a single position.

If you want to support batching you would have to encode the object position into the actual vertex data. So that each vertex has an additional position (stored as color / texcoords / ...) which represents the object position. So all vertices of a single object would have the same position stored in that vertex attribute. So in the shader this position will represent the object position.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

61 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 avatar image avatar image avatar image avatar image

Related Questions

Graphics.DrawProceduralIndirect isnt rendering anything 0 Answers

Shader input position.w, what is it for? 1 Answer

Can I unpack normal / tangent / uv information in the vertex function in a surface shader? 1 Answer

How can I pan a texture to specific location on a sheet? 1 Answer

How can I make my own shader include file (.cginc or .glslinc)? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges