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 da_st · Jan 23, 2015 at 07:03 AM · camerashaderreplacement shader

Replace shader at runtime

I have looked around in the docs on how to change all shaders in the scene during runtime and i wrote this and attached to my main camera:

 using UnityEngine;
 using System.Collections;
 
 public class ReplaceShader : MonoBehaviour {
 
     public Shader grayScale;
 
     void Update() 
     {
         Camera.main.SetReplacementShader(grayScale, "Grayscale");
     }
 }

When i try and run the game all that shows up is the default "blue background", the game is still running in the background but you can't see it through the camera, how could i fix this?

(Note I am beginner to coding and to unity)

-------------------------------------EDIT-------------------------------------------------

I found a solutions that kind of works, i changed this line:

 Camera.main.SetReplacementShader(grayScale, "Grayscale");

to this:

 Camera.main.SetReplacementShader ( grayScale, "RenderType" );

Now the camera shows the grayscale, but for some reason the shader is really dark? :/

Comment
Add comment · Show 4
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 PorkMuncher · Jan 23, 2015 at 10:01 AM 0
Share

I am not sure, but arent you supposed to assign shaders to the materials, not cameras?

I think you pretty much have to change the shader for each material.

You can access an objects material with gameObject.GetComponent[$$anonymous$$eshRenderer]().material.shader and assign it there.

replace [] with the pointy parentheses, the comment section deletes them x.x

avatar image da_st · Jan 23, 2015 at 10:49 AM 0
Share

Hm i was hoping there would be a way to change all materials / shaders in the entire scene using the camera, but i will test this method first, thanks ! :)

avatar image sniper43 · Jan 23, 2015 at 11:45 AM 0
Share

I assume you've read through this http://docs.unity3d.com/$$anonymous$$anual/SL-ShaderReplacement.html ?

avatar image da_st · Jan 23, 2015 at 12:00 PM 0
Share

@sniper43 Ah thanks, In the shader i had to add this: Tags {"RenderType" = "Opaque" } and now it works :D

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to combine a camera rendering an edge detection image effect with another camera 1 Answer

Using a camera replacement shader but keeping the underlying (original) colors? -4 Answers

Global Shader Question 1 Answer

Help with multi-purpose replacement shader for camera 1 Answer

Shader Replacement not working with a very simple shader. 0 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