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 temptest123 · May 28, 2013 at 07:20 PM · renderwithshaderreplacement shader

SetReplacementShader to affect only certain objects

Camera.SetReplacementShader seems to allow to render all objects whose original material contains a certain tag using a replacement shader. All objects whose original shader does not contain the specified tag do not get rendered at all.

I would like to render all objects that do not contain this specified tag using their original shader while those that do contain the tag get rendered using the replacement shader. (so, instead of not rendering objects that don't contain the tag, they shall be rendered normally)

How can I achieve this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by psantoki · Apr 11, 2014 at 11:38 PM

Of all the features in Unity that do not work, SetReplacementShader does not work with absolute precision. 100% fail rate. Don't use this function.

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 psantoki · Apr 14, 2014 at 06:55 PM 1
Share

I owe you a more productive answer.

There are a lot of ways to replace materials, during runtime, offline while building streamable assets, in the editor when not running. I'll assume you want runtime replacement of custom materials.

The best way to replace shaders at runtime is to gather all materials that need replacement and manually set your own shader. You can do this by walking through the scene or enumerating all shaders. This is the easiest method and offers the most control, you know exactly what you're replacing and what you're getting.

This doesn't work for terrain and grass, which do not expose their materials to you. (With terrain you can pick a substitute material in the inspector, for grass you must download the Unity grass shaders and add them to your project. This part isn't perfectly clear to me and it's certainly not documented, but you can edit these shaders or create your own with the same internal names ["Hidden/TerrainEngine/Details/WavingDoublePass"] and Unity will secretly, quietly, magically replace the stock grass shader with this one)

The problem with SetReplacementShader is that it cannot just replace one shader, to the confusion of everyone. It's an awful function that wipes out everything in the scene but the shader you want to replace. This is madness. (From the documentation: "any tag types not found in the replacement shader will be not rendered")

avatar image
1

Answer by cmz-neu4590 · Jul 24, 2018 at 05:51 PM

I know this is an old post but for whomever stumbles upon this i would like to try to give another more easy solution than playing with resetting materials through the whole scene and tedious stuff like that. This is not a perfect solution and i have not fully tested it and i will not explain it fully because i'm in a hurry but at least it may give someone and idea on how to do it... Use 2 cameras, set replacement shader in the second one, have cam1's culling mask render everything except one layer and cam2 one render that layer(set the layer of the objects that you want the replacement shader to apply to, to it ), have cam2's clear flag to "depth only" and it depth higher than cam1. This seemed to work for me, hope it helps someone.

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.

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

Depth maps and reconstructing the MVP matrix from a light 0 Answers

setGlobalFloat() doesn't initialise my shader parameters 0 Answers

Shaders and ambient occlusion 1 Answer

Global Shader Question 1 Answer

render order/ multipass shaders (hidden surface shader path) 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