x


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 '10 at 06:15 AM

Jaap Kreijkamp gravatar image

Jaap Kreijkamp
6.9k 21 30 74

Jan 10 '10 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 '10 at 12:55 PM Jaap Kreijkamp
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

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 '10 at 01:11 PM

ReJ gravatar image

ReJ
346 2 6

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 '10 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 '12 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

By RSS:

Answers

Answers and Comments

Topics:

x2153
x955
x541
x169

asked: Jan 10 '10 at 06:15 AM

Seen: 4969 times

Last Updated: Aug 21 '12 at 10:53 AM