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 Giantbean · Apr 25, 2019 at 12:21 AM · scripting beginnerpost processingpost effects

Changing Post process V2 with C#

There are a lot of tutorials on how to use the new Post Process v2 but very little to no information on how to effect the stack with a script.

I am trying to manipulate a post process with C# and the documentation from unity seems to be for version 1. While the answerer HERE has me confused. but may be of use to more experienced programmers.

Following the Unity documentation I tried:

 using UnityEngine;
 using UnityEngine.Rendering.PostProcessing;
 
 public class SteadyPostHealthDrain : MonoBehaviour
 {
 
     //When done this script should increase post process effects by a steady rate while active
     //It could be cool to make a variable for another script to pass a multiplier so health drains faster without protective gear if the script is active.
     PostProcessVolume m_Volume; //Using Apps Hungarian member m_ just because the documentation does.
     Vignette m_Vignette;
     ChromaticAberration m_ChromaticAberration;
     DepthOfField m_DepthOfFeild;
     Bloom m_Bloom;
     bool passedOut; //Or dead
 
     //All of this could be created with a post process volume that is turned off and on instead of instantiating.
     void Start()
     {
         passedOut = false;
 
         m_Vignette = ScriptableObject.CreateInstance<Vignette>();
         m_Vignette.enabled.Override(true);
         m_Vignette.intensity.Override(1f);
         m_Vignette.smoothness.Override(100f);
 
         m_ChromaticAberration = ScriptableObject.CreateInstance<ChromaticAberration>();
         m_ChromaticAberration.enabled.Override(true);
         m_ChromaticAberration.intensity.Override(1f);
 
 
         m_Bloom = ScriptableObject.CreateInstance<Bloom>();
         m_Bloom.enabled.Override(true);
         m_Bloom.intensity.Override(1f);
         m_Bloom.threshold.Override(1f);
 
         m_DepthOfFeild = ScriptableObject.CreateInstance<DepthOfField>();
         m_DepthOfFeild.enabled.Override(true);
         m_DepthOfFeild.focusDistance.Override(1f);
         //m_DepthOfFeild.kernelSize.GetValue<Small>; //How can I set the "Max Blur Size" to small?
 
         m_Volume = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, m_Vignette);
         m_Volume = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, m_ChromaticAberration);
         m_Volume = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, m_Bloom);
 
     }
 
     //increase effects over time
     void Update()
     {
         if (!passedOut) // post not fully faded in
         {
             //Bloom intensity from 0 to 5 Bloom threshold from 1.5 to .25
 
             //Chromatic Aberration intensity from 0 to 1
 
             //Depth of Field Focus Distance from 3f to .6f
 
             //Vignette Intensity from 0 to 1 color #841717 
             //This effect could have a delay to start fading in a few seconds after the other effects.
 
         }
         if (passedOut) //already faded-in, destroy volume
         {
             //Remove the post process
             Destroy(m_Volume, 0f);
             // Display a failure message
             //...instantiate a canvas?
         }
         // Better yet if a post process volume is used just turn off the effect and reset its values for next use.
     }
 }


However I am unsure of how to turn my pseudo-comments into a working script. and it seems the new v2 post process stack should be written differently. so I wrote this:

 using UnityEngine;
 using UnityEngine.Rendering.PostProcessing;
 
 public class SteadyPostHealthDrain : MonoBehaviour
 {
 
     Vignette vignetteLayer; // why is this set to null in jPhilpp's example? Does that zero out the properties?
     ChromaticAberration chromaticAberrationLayer;
     DepthOfField DOFLayer;
     Bloom bloomLayer;
 
     private bool passedOut; //Or dead
     private bool updateTimer = false;
     private float effectTimer = 0.0f;
 
   
     void Start()
     {
         passedOut = false;
 
         //This seems to be one volume with multiple effects instead of the old mess seen in the last script.
         PostProcessVolume activeVolume = gameObject.GetComponent<PostProcessVolume>();
         activeVolume.profile.TryGetSettings(out vignetteLayer);
         activeVolume.profile.TryGetSettings(out chromaticAberrationLayer);
         activeVolume.profile.TryGetSettings(out DOFLayer);
         activeVolume.profile.TryGetSettings(out bloomLayer);
 
         updateTimer = true;
         effectTimer = 0.0f;
 
     }
 
     //increase effects over time
     void Update()
     {
         if (updateTimer == true)
         {
             effectTimer += Time.deltaTime * 1; // I can slow this down once I know it works
         }
             
         if (!passedOut) // post not fully faded in
         {
             //Bloom intensity from 0 to 5 Bloom threshold from 1.5 to .25
             bloomLayer.enabled.value = true;
             bloomLayer.threshold.value = effectTimer; // can this be clamped?
 
             //Chromatic Aberration intensity from 0 to 1
             chromaticAberrationLayer.enabled.value = true;
             chromaticAberrationLayer.intensity.value = effectTimer; 
 
             //Depth of Field Focus Distance from 3f to .6f
             DOFLayer.enabled.value = true;
             DOFLayer.focusDistance.value = (3.0f - effectTimer);
             //DOFLayer.MaxBlurSize = small ... how is this set by code? Do I even need to if I'm just turning off and on a volume?
 
             //Vignette Intensity from 0 to 1 color #841717 
             //This effect could have a delay to start fading in a few seconds after the other effects.
             if (effectTimer >= 15)
             { 
                 vignetteLayer.enabled.value = true;
                 //vignetteLayer.color.value = #841717; How?
                 vignetteLayer.intensity.value = (effectTimer - 15.0f); 
             }
         }
         if (passedOut) //already faded-in, destroy volume
         {
             //Remove the post process
             bloomLayer.enabled.value = false;
             chromaticAberrationLayer.enabled.value = false;
             DOFLayer.enabled.value = false;
             vignetteLayer.enabled.value = false;
 
             //set the values back to a default ... is this needed?
 
             //Adding a color grading effect to make the screen black may effect a failure message
             // Display a failure message
             //...instantiate a canvas? 
         }
 
     }
 }

I put the script on a post processing layer and tried to use a collision to activate it. Some of it worked its not turning off and on but the vision gets very blurry and colorful very fast. I tried putting the script on a collider that I could touch to activate it but it didn't work at all?

So.... If anyone knows of better documentation or a good tutorial on scripting these effects please let me know.

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

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

108 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

Related Questions

How to switch OFF motion vectors for SkinnedMeshRenderer ? 0 Answers

How to capture screenshot with post process effect? 1 Answer

Disabling / Destroying a camera component cause a black blinking / flickering on Android 0 Answers

Running an OnRenderImage effect before the post processing stack (v2) 1 Answer

Skybox and color correction with steamVR 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