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
16
Question by Master_Davicous · May 18, 2017 at 05:10 PM · c#settingspost processingpost-process-effect

Modifying the new Post-Processing Stack through code?

Hello! I've added the new post-processing stack to my game and it looks very good... However, I'd like to have settings in the menu to turn certain post-processing components on and off for those who have lower end graphics cards. How can I access, for example, the on-off toggle buttons on the PP Stack through code to accomplish 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

6 Replies

· Add your reply
  • Sort: 
avatar image
53
Best Answer

Answer by JPhilipp · Mar 21, 2018 at 03:16 PM

And for anyone ending up here looking to do this for the newer versions of the PostProcessing stack, here's what works for me, with thanks to Harinezumi:

 using UnityEngine.Rendering.PostProcessing;
 
 // properties of class
 public float bloom = 10f;
 public float saturation = 5f;
 
 Bloom            bloomLayer            = null;
 AmbientOcclusion ambientOcclusionLayer = null;
 ColorGrading     colorGradingLayer     = null;
 
 // somewhere during initializing
 PostProcessVolume volume = gameObject.GetComponent<PostProcessVolume>();
 volume.profile.TryGetSettings(out bloomLayer);
 volume.profile.TryGetSettings(out ambientOcclusionLayer);
 volume.profile.TryGetSettings(out colorGradingLayer);
 
 // later in this class during handling and changing
 ambientOcclusionLayer.enabled.value = true;
 
 bloomLayer.enabled.value = true;
 bloomLayer.intensity.value = bloom;
 
 colorGradingLayer.enabled.value = true;
 colorGradingLayer.saturation.value = saturation;
 
 // ... with some more checks to disable it fully where
 // needed/ if 0
Comment
Add comment · Show 11 · 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 AviKohl3D · Oct 24, 2017 at 04:49 AM 1
Share

I don't think this works with the current version of the PP stack.

avatar image lodendsg AviKohl3D · Mar 19, 2018 at 04:05 PM 1
Share

I think its simply that some names have changed a bit

PostProcessProfile not PostProcessingProfile

also bloom, etc. isn't called out by name as far as I can see, insted we have a List of PostProcessEffectSettings and various funcitons to help find stuff in that list or if you know what index its at I suppose PostProcessProfile.settings[index] would work just fine.

avatar image elixir-bash lodendsg · Jul 25, 2018 at 08:31 AM 0
Share

is there an alternative for postprocessingbehavior? i tried postprocessbehavior. it dint work ;)

Show more comments
avatar image Harinezumi AviKohl3D · Mar 19, 2018 at 05:07 PM 2
Share

Indeed this won't work with PostProcessingStack v2... but now it is actually a lot more logical how it works. Now you get self-encapsulated settings objects from the profile asset assigned to the PostProcessVolume by calling postProcessVolume.profile.TryGetSettings(out variableOfTypeOfSettingsYouWant). Then you can access its parameters by name of parameter and .value.
Example:

 PostProcessVolume activeVolume = ...;
 if (activeVolume != null) {
     Vignette vignette;
     activeVolume.profile.TryGetSettings(out vignette);
     if (vignette != null) { vignette.intensity.value = 0.675f; }
 }
avatar image Vicarian AviKohl3D · May 08, 2019 at 07:04 PM 0
Share

This isn't an answer. Saying something doesn't work now isn't constructive. Converting to comment.

avatar image Harinezumi · Mar 21, 2018 at 03:32 PM 2
Share

Well, this is one way to do it, but this will create a run-time PostProcessVolume, one that you cannot edit when not in play mode. Ins$$anonymous$$d of instantating the Vignette scriptable object, you could have a PostProcessVolume asset in your project (with Vignette effect enabled on it), and use it in the script (as a reference or getting it from your PostProcess$$anonymous$$anager).

avatar image JPhilipp Harinezumi · Mar 21, 2018 at 03:50 PM 0
Share

Ah, thanks... now it finally works for me! I might remove this answer and post my code in another answer, or maybe actually you wanna answer OPs question.

avatar image Harinezumi JPhilipp · Mar 21, 2018 at 04:08 PM 1
Share

Editing your answer is better than deleting it.
The OPs answer is actually answered and there is an accepted answer, but it is about V1 of the PostProcessingStack. It is better to have an updated answer. If you write it, I will upvote it so that it gains visibility.

Show more comments
avatar image
14

Answer by AurimasBlazulionis · May 19, 2017 at 05:51 AM

First import UnityEngine.PostProcessing

You need to have the PostProcessingProfile as a variable. If we call it profile, then you can access it's settings. If you want to enable bloom, then use profile.bloom.enabled = true. If you need to change the settings of each effect then use this workflow:

1) Save a temporary effect like this: EffectModel.Settings effectSettings = profile.effect.settings. Change the effect to the actual type.

2) Edit the settings.

3) Apply them back: profile.effect.settings = effectSettings.

Keep in mind that it will permanently edit the settings of the profile.

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 monotoan · Oct 10, 2017 at 09:45 PM 3
Share

Yep, this works! Here's a quick example of a specific setting change (Bloom intensity) through script:

 using UnityEngine.PostProcessing;
 
 public class BloomControl : $$anonymous$$onoBehaviour {
 
    //remember to drag and drop your scriptable object into this field in the inspector...
    public PostProcessingProfile ppProfile;
 
    void Start() {
       ChangeBloomAtRuntime();
    }
 
 void ChangeBloomAtRuntime()
     {
         //copy current bloom settings from the profile into a temporary variable
         Bloom$$anonymous$$odel.Settings bloomSettings = ppProfile.bloom.settings;
 
         //change the intensity in the temporary settings variable
         bloomSettings.bloom.intensity = 2;
 
         //set the bloom settings in the actual profile to the temp settings with the changed value
         ppProfile.bloom.settings = bloomSettings;
     }
 }



avatar image Stiffy89 · Nov 23, 2017 at 11:34 PM 0
Share

can confirm the above example script does work. Currently using the most recent version of PP stack from unity.

Share an example of your script so we can help diagnose the issue?

avatar image Wolfram · Dec 21, 2017 at 06:49 PM 1
Share

NOTE: It is also possible to do runtime-only changes, i.e. prevent messing with the Asset itself. Just instantiate your profile at runtime, and re-assign it. See here: https://github.com/Unity-Technologies/PostProcessing/wiki/(v1)-Runtime-post-processing-modification

avatar image
7

Answer by warpfx · Apr 08, 2020 at 07:41 AM

For the new Universal Rendering Pipeline, I was able to animate post-processing values via custom script added to the object containg Volume component (which contains all the effects). Here's working code, ready to be animated:

 using UnityEngine.Rendering;
 using UnityEngine.Rendering.Universal;
 using UnityEngine;
 
 public class PostProcessingData : MonoBehaviour
 {
     private Bloom bloom = null;
     private ChromaticAberration chromaticAberration = null;
 
     public float chromaticAberrationIntensity;
 
     // Start is called before the first frame update
     void Start()
     {
         Volume volume = GetComponent<Volume>();
 
         volume.sharedProfile.TryGet<Bloom>(out bloom);
         volume.sharedProfile.TryGet<ChromaticAberration>(out chromaticAberration);
     }
 
     // Update is called once per frame
     void Update()
     {
         if (chromaticAberration != null)
         {
             chromaticAberration.intensity.SetValue(new NoInterpMinFloatParameter(chromaticAberrationIntensity, 0, true));
         }
     }
 }

Changing intensity by property accessor didn't work and SetValue() was needed.

Hope it will be helpful for someone!

Comment
Add comment · Show 4 · 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 irenya · May 30, 2020 at 06:24 AM 0
Share

Thank you so much for this answer!! There's been so many changes to the Post Processing system that I've spent quite some time stumbling between different options. This works perfectly for those using URP. Thanks!!!

avatar image Jassucks · Jul 07, 2020 at 02:21 PM 0
Share

Thank you so much for that! it's the only thing I found to be working when trying to access PP via script with URP.

So it's changing the values correctly but I'm not sure what you meant by "ready to be animated"? I'm wondering how to animate between the values, like a simple lerp. There's not much documentation about that NoInterp$$anonymous$$inFloatParameter so if you could please explain and/or show a working animated example that would be absolutely amazing

avatar image warpfx Jassucks · Jul 07, 2020 at 02:39 PM 0
Share

Hi @Jassucks !

When you add PostProcessingData script into object containing Volume component, you can change chromaticAberrationIntensity value using Animation window:

https://cloud.warp.sh/index.php/apps/files_sharing/publicpreview/Bi8e2jWjGr$$anonymous$$R9CX?x=3820&y=1626&a=true&file=effectsanimation.png≻alingup=0

Update() method is called every frame so the script will pick up current chromaticAberrationIntensity value and update Post Processing's chromatic aberration via chromaticAberration.intensity.SetValue(new NoInterp$$anonymous$$inFloatParameter(chromaticAberrationIntensity, 0, true));

Thus way you can animate Post Processing effects, e.g., make a heartbeat effect, or loose of player's focus.

avatar image Jassucks warpfx · Jul 07, 2020 at 02:45 PM 0
Share

Oh! i'm sorry lol, I completely forgot about animating with the Animation window. That should probably work just as good for me. Thanks again, this is super helpful! :-)

avatar image
3

Answer by Wolfram · Aug 01, 2018 at 10:55 AM

For Post-Processing v2, there is actually a Unity docs page that describes exactly the method to creat Volumes on-the-fly, or to manipulate existing profiles either temporarily during Play mode, or permanently: https://docs.unity3d.com/Packages/com.unity.postprocessing@2.0/manual/Manipulating-the-Stack.html

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
avatar image
0

Answer by idbrii · Mar 22, 2019 at 09:17 PM

As an extension of JPhilipp's great answer, here's a more complete code sample for toggling effects "ApplySettings" function.

There isn't a global method for adjusting effects, but we can force each volume to have its own configuration. Since PostProcessVolume.profile creates a volume-local profile, we can modify that and keep the sharedProfile as a reference for the tuned value.

 public void ApplySettings()
 {
     bool use_ambient_occlusion = PlayerPrefs.GetInt("use_ambient_occlusion") > 0;
     bool use_auto_exposure = PlayerPrefs.GetInt("use_auto_exposure") > 0;
     // ...

     // Get all volumes (even inactive ones). Assuming you're not
     // using QuickVolume, you can cache this list.
     var all_volumes = FindAll<PostProcessVolume>();
     foreach (var volume in all_volumes) {
         var vanilla = volume.sharedProfile;
         if (vanilla == null) {
             continue;
         }
         var active = volume.profile;

         ApplyRestriction<AmbientOcclusion>(vanilla, active, use_ambient_occlusion);
         ApplyRestriction<AutoExposure>(vanilla, active, use_auto_exposure);
         // ...
     }
 }
 
 void ApplyRestriction<T>(PostProcessProfile vanilla, PostProcessProfile active, bool is_allowed)
     where T : PostProcessEffectSettings
 {
     T vanilla_layer = null;
     T active_layer = null;
     vanilla.TryGetSettings(out vanilla_layer);
     active.TryGetSettings(out active_layer);
     if (vanilla_layer != null && active_layer != null)
         active_layer.enabled.value = is_allowed && vanilla_layer.enabled.value;
 }

FindAll<T>() could be something like Resources.FindObjectsOfTypeAll<T>(), but in editor, it finds assets , so you need an editor implementation too.

These effects have additional options to scale quality:

  • AmbientOcclusion

  • Bloom

  • ChromaticAberration

  • MotionBlur

  • ScreenSpaceReflections

You'd need to special case them in the for loop.

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
  • 1
  • 2
  • ›

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

338 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to manipulate PostProcessing effects settings during execution with c#? 1 Answer

Changing URP Volume values in code not working 0 Answers

Creating Chalk-drawing Post Processing 0 Answers

How can I save and load a Coroutine state ? 0 Answers

Script To Update Post Process Profile At Runtime [2018 HDRP] 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