Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by DeadMeat · May 04, 2015 at 11:16 AM · static-batching

PostProcessing specific GameObjects

Hi.

In my project i want to make some custom postprocessing for specific game objects. For example, i have 10 cubes in the scene, but need to re-render (for a postprocess step) only specific 5 of them. Currently, the postprocess consists of rendering to a texture with a simple shader, which outputs white color. While searching for ways to do this in Unity (i'm new to Unity) i found 2 methods:

  1. add a second camera, set it up same as main camera, set it's render target and set specific layers to render. At the same time set these layers for objects, which i need to render.

  2. draw objects with Graphics.DrawMeshNow.

Method (1) looks a kind of hacky to me. The "problem" is that objects that i need to re-render are changing constantly. It's just something like a selected list of objects in RTS. A user is able to pick some of them and not the others. And i need to re-render those, which are picked and not the others. For this i will need to:

  1. before redering, save previous object's layer (used for physics raycastings and stuff)

  2. set the one which is needed for second camera rendering

  3. render objects

  4. set the layer back

Looks a bit messy.

So i took method (2). It needs only one main camera and all the steps are kind of straightforward (during OnRenderImage()):

  1. set my shader pass as current

  2. set render target

  3. iterate through needed objects and through their renderers

  4. draw each of them with Graphics.DrawMeshNow(mesh, renderer.transform.localToWorldMatrix)

  5. put everything back

This looks much better and cleaner, but has one little-bit problem. DrawMeshNow() doesn't render statically batched meshes. Don't know why, but seems that when i simply remove the appropriate flag, they begin to render as they should. But when flag is set, all i get is a blank screen. No matter what has been drawn previously.

So my question is, what should i do with this? Take the "hacky" method (1) with the camera, or there is something that could be done for method (2) to work with statically batched meshes?

Btw, this was tested in Unity 5.0.1f1 Personal.

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
3

Answer by hydrix · Jan 30, 2017 at 07:39 AM

A little late but here's how I did this: alt text

on the camera that doesn't have post processing:

in inspector set "clear flags" to "depth only", "culling mask" to be a layer which you want to ignore post processing, named "PrePostProcess" or something, and finally on "depth" change that to a value higher than all other camera's "depth"

on the camera that has post processing:

set "cull mask" to all the layers you want to apply the post processing to, and again the "depth" should be lower than the other camera

finally:

set all objects that you want to ignore post processing on to have the layer "PrePostProcess" or whatever you named it


selection-001.jpg (8.1 kB)
Comment
Add comment · Show 1 · 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 onic2999 · Nov 08, 2018 at 02:51 PM 0
Share

Dude,you just saved my day :D

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

Can I use static batching in Unity Free? 2 Answers

Static batching - Getting submesh 1 Answer

Transparent shader breaks static batching? 0 Answers

What's the diference with these 2 functions, StaticBatchingUtility.Combine() and Mesh Combining? 0 Answers

How exactly does static batching work in Unity? 1 Answer


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