Before updating to Windows 10 you may need to return your Pro license. More information here

Force elements in same batch

In our game iphone game we're drawing fake shadows under about every object. Although most are defined static (can't move only destroyed) they aren't batched all together. This is probably done to prevent drawing order issues. But as with many shadows this results in easily 10 draw calls for the shadows alone it would be useful to be able to force them in one batch (and live with possible ordering issues). Is there a way to do this?

alt text

more ▼

asked Jan 10, 2010 at 06:15 AM

avatar image

Jaap Kreijkamp
7.3k 46 71 114

Jan 10, 2010 at 06:58 AM Jessy

Possibly it's more about which lights affect the objects then distance from camera, but it's black magic. Added an answer to your q with my findings.

Jan 10, 2010 at 12:55 PM Jaap Kreijkamp
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

First, make sure all your fake shadows use the same material. Next, 'move' all your fake shadows into the separate rendering layer (Render Queue) by specifying:

Tags {"Queue" = "Transparent-1" } in the shader

Explanation: Unity have to sort all transparent objects by distance instead of sorting them by material. If you have different materials on transparent objects in your frame, then chance of them being batched decreases. By putting them into the separate rendering layer you tell Unity to sort them independently of other transparent objects - maximizing batching.

more ▼

answered May 24, 2010 at 01:11 PM

avatar image

361 1 3 8

I already did that (sorry, haven't been in Answers for quite a while) but still get more batches than I would expect when using lighting, even though the shader doesn't use lighting. We fixed it with making shadow part of of the objects using vertex colors to make them transparant.

Jun 11, 2010 at 12:31 AM Jaap Kreijkamp

You can avoid editing the shader by using a script to change the queue. This script will do it if it is attached to 1 of the objects using the material. http://wiki.unity3d.com/index.php/SetRenderQueue

Aug 21, 2012 at 10:53 AM The Scripter
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 10, 2010 at 06:15 AM

Seen: 5855 times

Last Updated: Aug 21, 2012 at 10:53 AM