Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
1
Question by JarJarThomas · Jun 26, 2011 at 07:50 PM · backgroundrenderorder

How to Render an Background on Top

hi

For filtrate issues I want to render the background AFTER all other objects. My idea is to render the bg texture only to places where no other pixel was drawn already. The idea is ok, but the shader is not working for me. I have a simple shader with zwrite off. But how to make a ztest like only if z is unlimited ?

Also how can I enforce to render the background after all other objects?

Greetings

Comment
Add comment · Show 8
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 Marnix · Jun 26, 2011 at 08:11 PM 0
Share

@JarJar$$anonymous$$ Please give me a good reason why I answered your question, because most of the times you can easily get around these kind of issues and rendering it first is still possible most of the times.

avatar image JarJarThomas · Jun 26, 2011 at 09:10 PM 0
Share

I have two reasons for you.

First fillrate. Drawing the background is relatively costly on the iPhone because of limited filtrate. For test reasons I only draw halt of the screen as background. I got instantly 3fps more. Because more than half of my screen is overdrawn it looks for me that the 3-4fps would be possible.

Second, using two cameras lead to a problem with image effects on the iPhone. I do not why but the image effect only was quadratic and the image rotated by 90 degrees (ios only).

$$anonymous$$y current way is now draw the bg plane in the same camera. But here it hides some of my objects.

avatar image Marnix · Jun 26, 2011 at 09:16 PM 0
Share

So, drawing a simple quad with a texture is costly on iOS? How would you ever draw your 3D $$anonymous$$odels then?

Have you thought of using the skybox holder as your background drawer as well?

avatar image JarJarThomas · Jun 26, 2011 at 09:22 PM 0
Share

Fillrate is always important, drawing bg on top is eg also used in mass effect. On mobiles it is just more important and a racing game with 60fps is just better than 30

avatar image Marnix · Jun 26, 2011 at 09:58 PM 0
Share

I can come into that. The pixel shader has way more to accomplish when the complete background has to be drawn. Still, 3 FPS doesn't mean much if your framerate is already 600 or so. Better look at the ms/frame.

How do 2D games fill the complete screen then? Does it really ask that much from your device?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Marnix · Jun 26, 2011 at 08:10 PM

Nice issue,

I will present an alternative option before answering your question. The first thing you do need for both, is layers. You can use a layer and set different object in a layer. For your background, you could create a background layer.

Option 1 (Pro only)

Use a post-effect with RenderTexture to check in your texture if alpha is still 0 on that pixel. If so, it is certain that there was no object there. You can draw a pixel from your background there.

Option 2

Create 2 cameras. One main camera, one second camera that only renders your object (by using the layers). Make sure that the second camera doesn't clear ANYTHING. Also, the depth-buffer needs to stay full.

The background-camera needs a different `depth`. This will control the rendering order. Now, we can adjust the ZTest in the shader for the background object.

I haven't tested this, but in theory it looks fine to me.


I was thinking of more options, but I lost them while writing. Option 2 is probably implementable in the easiest way, because you don't have to write a post-effect. Camera depth is very important to control your render path. If I can think of more, I'll update this answer.

[3]: http://unity3d.com/support/documentation/Components/SL-CullAndDepth.html

Comment
Add comment · Show 2 · 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
avatar image JarJarThomas · Jun 26, 2011 at 09:11 PM 0
Share

Thank you, alpha is something I didn't thought Of

avatar image Marnix · Jun 26, 2011 at 10:19 PM 0
Share

Just thought, you don't even have to change the ZWrite to Greater.

avatar image
0

Answer by Waz · Jun 26, 2011 at 10:17 PM

Are you sure Unity doesn't already draw Opaque geometry objects front-to-back (the transparent ones in the reverse order)? Seems a pretty obvious optimisation.

Comment
Add comment · Show 3 · 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
avatar image Marnix · Jun 26, 2011 at 10:18 PM 0
Share

Good point, but there is no certainty to say that this is true, unless you can give us a reference.

avatar image Waz · Jun 27, 2011 at 02:21 AM 0
Share

I mention it since if using two cameras makes no difference, then this may be the reason, or an equivalent reason, that the GPU is reordering already (they normally do this at least in single draw call).

avatar image Marnix · Jun 27, 2011 at 08:11 AM 0
Share

@Warwick Allison: Opaque objects don't have to be ordered, because it costs CPU time, while z-buffering solves everything in the GPU. It is less efficient to sort everything before drawing. For transparent object, this is indeed true.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Large background image, should I cut it? 1 Answer

background GUI texture 2 Answers

Really easy question, How to set a background image? 1 Answer

Transformation(Movement) of background with increasing Speed 0 Answers

How do I get objects to render against the skybox? 2 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