- Home /
Post Processing Stack Bloom Intensity C#
Increasing and Decreasing Bloom Intensity
I'm trying to increase and decrease the bloom from 1-10 and back over time. The bloom intensity starts at 1 and I want it to increase up to 10 and then lower back to 1 but it increases over time but carries on past 10.
Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PostProcessing;
public class CamMovement : MonoBehaviour {
public PostProcessingProfile profile;
void Start(){
BloomModel.Settings bloomSettings = profile.bloom.settings;
bloomSettings.bloom.intensity = 1;
}
void Update(){
BloomModel.Settings bloomSettings = profile.bloom.settings;
if (bloomSettings.bloom.intensity >= 10) {
bloomSettings.bloom.intensity = (bloomSettings.bloom.intensity - 0.5f) * Time.time;
}
if (bloomSettings.bloom.intensity <= 1) {
bloomSettings.bloom.intensity = (bloomSettings.bloom.intensity + 0.5f) * Time.time;
}
Debug.Log ("Bloom Intensity: " + bloomSettings.bloom.intensity);
profile.bloom.settings = bloomSettings;
}
}
Answer by Iarus · Nov 23, 2017 at 07:33 PM
Time.time is the time since you started the game, so if your script execute for the first time 10 minutes after the game starts (ie: you spend lots of time in the main menu), the bloom strength will go from 1 to (1 + 0.5) 600 => 900 This is outside of your desired range of [1 - 10]. On your next frame (900 - 0.5) 600.1 => 539789.95. You'll probably break max float after less than a second.
Try this:
public class CamMovement : MonoBehaviour {
public PostProcessingProfile profile;
public float bloomSpeed = 0.5f;
private float direction = 1;
void Start(){
BloomModel.Settings bloomSettings = profile.bloom.settings;
bloomSettings.bloom.intensity = 1;
}
void Update(){
BloomModel.Settings bloomSettings = profile.bloom.settings;
bloomSettings.bloom.intensity += direction * bloomSpeed * Time.deltaTime;
if (bloomSettings.bloom.intensity >= 10) {
direction = -1;
}
else if (bloomSettings.bloom.intensity <= 1) {
direction = 1;
}
Debug.Log ("Bloom Intensity: " + bloomSettings.bloom.intensity);
profile.bloom.settings = bloomSettings;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How can I change URP Bloom via code? 0 Answers
Distribute terrain in zones 3 Answers
How to increase the Call Stack Size in Unity? 0 Answers
How to make emissive material which responds to Sprite Renderer color? -1 Answers