• 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 Hamesh81 · Jun 29, 2013 at 06:25 AM · texturematerialdrawcallsdecaltexture-atlas

How can I lower Decal draw calls at runtime?

I think this is a quite common issue with decals, so I'd appreciate some optimization tips.

Decals are great for things like bullet holes or for adding that sense of variety into textures and models, but the problem is of course if not handled correctly each new decal can mean an extra draw call.

In my case I am using decals for bullet holes. I'm using a texture atlas which has all of the different bullet holes packed together into a single texture. When I fire and the bullet holes appear at runtime, if I only use 1 material all of the bullet holes get batched. This is perfect, but of course it makes all the bullet holes look exactly the same. If I create one material for each bullet hole (still using the one texture atlas) and simply adjust the tiling and offset; then all the bullet holes now look nice and different, but it creates a lot of draw calls (one for each material obviously). So I'm wondering how can I get the best of both worlds, have a variety of different looking bullet holes but be able to batch them all as well.

I've looked at Bootcamp and the free Decal System and both seem to be creating meshes at runtime, which is a bit beyond my programming expertise since I'm simply using a plane which is positioned and rotated to where the bullet hit. I also can't combine the decal planes since they are obviously dynamic objects. Any suggestions?

Comment
Add comment · Show 3
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 Hamesh81 · Jun 29, 2013 at 07:02 AM 0
Share

Interesting, I've never used mesh.uv before so I'll try this. I will need to change the uvs each time a bullet hits a surface though, since there's no way to know what bullet hole in the atlas should render until the surface hit is actually detected. Would I be able to change it this way at runtime many times?

And btw, yes the planes I'm using are two triangle meshes.

avatar image robertbu · Jun 29, 2013 at 07:54 AM 0
Share

Yes, you can easily make the change at runtime.

avatar image Hamesh81 · Jun 29, 2013 at 08:43 AM 0
Share

Thanks a lot, I've done some testing and it seems this will work for what I need. If you'd like to convert your comment to an answer I'll mark it as accepted ;)

1 Reply

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

Answer by robertbu · Jun 29, 2013 at 06:47 AM

I can suggest a direction for you. You'll have to get your hands a bit dirty with meshes, but not to the extent of creating/expanding meshes. What you need to do is to set the UV coordinates for your atlas directly in the mesh, not use the tiling and offset. If you set the UV directly in the mesh of each plane, all the bullets will batch. Note this will be easier if you use two triangle planes. The CreatePlane script can be used to create two triange planes if you don't have access a 3D modeling package.

http://docs.unity3d.com/Documentation/ScriptReference/Mesh-uv.html

Note creating meshes at runtime is the best way to solve this problem. @alucardj did a great answer on how to render footsteps that you might examine to get the basic concepts:

http://answers.unity3d.com/questions/475795/rendering-permanent-trails-such-as-footsteps.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.

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

15 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

Related Questions

lowering draw calls 5 Answers

2 materials/shaders 1 texture? 2 Answers

Can I have multiple/alternate UV textures for one mesh in a single file? 0 Answers

Does same material on different mesh reduce draw calls ? 2 Answers

Can't figure out why 5 objects with the same material/texture are not batching.. 2 Answers

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