#Chromatic aberration
1 messages · Page 1 of 1 (latest)
your function is only getting called once
so any line that is not inside the coroutine is only going to get called once
the only lines getting called more than once are the ones inside the while loop inside the coroutine
so if you want a value to get set to different things over time
it has to be inside that while loop
here is the full script
public void AnimateCollisionEffect(float _collisionRelativeForce) {
//float collisionRelativeForce = _collisionRelativeForce;
//float postProcessingApplied = Mathf.Lerp(collisionRelativeForce, 0f, /*0.0f*/ 0.0f);
StartCoroutine(LerpMyShit(1f, 0f, 1f, _collisionRelativeForce));
ChromaticAberrationEffects = ScriptableObject.CreateInstance<ChromaticAberration>();
ChromaticAberrationEffects.enabled.Override(true);
ChromaticAberrationEffects.intensity.Override(duration);
PostProcessingEffects = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, ChromaticAberrationEffects);
}
private IEnumerator LerpMyShit(float start, float end, float startTime, float someValue) {
float endTime = 3f;
duration = 0f;
while (startTime < 1) {
var lerpedValue = Mathf.Lerp(start, end, duration);
someValue = lerpedValue;
duration += Time.deltaTime / endTime;
yield return null;
}
}
yes, that is what I was responding to
so how do I make it go from 1 to 0
so why doesn't it work?
okay, let's think about what your code is doing frame by frame
frame 1:
- AnimateCollisionEffect gets called
- LerpMyShit starts running
- LerpMyShit arrives at yield return null and stops for the frame
- CromaticAbberationEffects gets created, enabled, and its intensity gets set
- Something happens with Post Processing Effects
frame 2:
- LerpMyShit continues from where it was last frame.
- LerpMyShit goes through the while loop one time, arrives at yield return null, and stops for the frame
frame 3:
- LerpMyShit continues from where it was last frame.
- LerpMyShit goes through the while loop one time, arrives at yield return null, and stops for the frame
etc
notice how in frames 2, 3, 4, 5, etc
nothing involving Chromatic Aberration gets called
it only happens one time
in the first frame
okay give me a second
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Rendering.PostProcessing;
public class AnimateCollision : MonoBehaviour
{
//Private Variables
private ChromaticAberration ChromaticAberrationEffects;
private float duration;
//Settings Variables
[Header("Animate-on-Collision")]
[SerializeField] private PostProcessVolume PostProcessingEffects;
public void AnimateCollisionEffect(float _collisionRelativeForce) {
//float collisionRelativeForce = _collisionRelativeForce;
//float postProcessingApplied = Mathf.Lerp(collisionRelativeForce, 0f, /*0.0f*/ 0.0f);
StartCoroutine(LerpMyShit(1f, 0f, 0f, _collisionRelativeForce));
ChromaticAberrationEffects = ScriptableObject.CreateInstance<ChromaticAberration>();
ChromaticAberrationEffects.enabled.Override(true);
PostProcessingEffects = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, ChromaticAberrationEffects);
}
private IEnumerator LerpMyShit(float start, float end, float startTime, float someValue) {
float endTime = 3f;
duration = 0f;
while (startTime < 1) {
var lerpedValue = Mathf.Lerp(start, end, duration);
someValue = lerpedValue;
duration += Time.deltaTime / endTime;
ChromaticAberrationEffects.intensity.Override(duration);
yield return null;
}
}
}
``` how about this?
I don't know, try it
if you're directly using Time you dont need the lerp stuff at all
but it doesn't work then???
Look at what yiu're passing into Override
duration
so should I remove it?
I don't know. Should you? What is it you're wanting to happen
duration goes from 0-1
if you want it scalable. don't pass duration.
So you can configure the start and end values as you see fit.
public void AnimateCollisionEffect(float _collisionRelativeForce) {
//float collisionRelativeForce = _collisionRelativeForce;
//float postProcessingApplied = Mathf.Lerp(collisionRelativeForce, 0f, /*0.0f*/ 0.0f);
StartCoroutine(LerpMyShit(_collisionRelativeForce));
ChromaticAberrationEffects = ScriptableObject.CreateInstance<ChromaticAberration>();
ChromaticAberrationEffects.enabled.Override(true);
PostProcessingEffects = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, ChromaticAberrationEffects);
}
private IEnumerator LerpMyShit(float startTime) {
float endTime = 3f;
duration = startTime;
while (0 > endTime) {
duration -= Time.deltaTime / endTime;
ChromaticAberrationEffects.intensity.Override(duration);
yield return null;
}
}
}
``` @honest sorrel I do not know if I'm doing this right?
when is that while loop going to end?
after 1 second
why do you say that?
my bad I see the error
public void AnimateCollisionEffect(float _collisionRelativeForce) {
ChromaticAberrationEffects = ScriptableObject.CreateInstance<ChromaticAberration>();
ChromaticAberrationEffects.enabled.Override(true);
StartCoroutine(LerpMyShit(_collisionRelativeForce));
PostProcessingEffects = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, ChromaticAberrationEffects);
}
private IEnumerator LerpMyShit(float endTime) {
float duration = 0;
while (endTime < duration) {
duration += Time.deltaTime / endTime;
ChromaticAberrationEffects.intensity.Override(duration);
yield return null;
}
}
``` is this better
Man
..wat
what does that mean
I will write it for you again
private IEnumerator LerpMyShit(float startValue, float endValue, float reletiveForce, float maxDuration)
{
float duration = 0;
while (duration < 1)
{
reletiveForce = Mathf.Lerp(startValue, endValue, duration);
ChromaticAberrationEffects.intensity.Override(reletiveForce );
duration += Time.deltaTime / maxDuration;
yield return null;
}
}```
Something like that
abound 1 or 2 seconds depending on the force, if possible, if not just 1 second
I presume to just put 1 there then
try it and see™️
I do not know
hmm, thanks though you saved me from miserably trying it by myself for hours and ultimately failing
Imma try to tweak it a bit to try and see why it only works sometimes
and maybe fix it
Understanding what its actually doing is valuable and you should od that before trying to fix it
yeah I usually do that, it's just that I'm about to go sleep and I didn't have time to spend time reading the entire docs
@honest sorrel may I ask you one more thing? it feels as if the effect being put on is a bit late, should I put the thing before starting the coroutine?
public void AnimateCollisionEffect(float _collisionRelativeForce) {
ChromaticAberrationEffects = ScriptableObject.CreateInstance<ChromaticAberration>();
ChromaticAberrationEffects.enabled.Override(true);
StartCoroutine(LerpMyShit(1f, 0f, _collisionRelativeForce, 1f));
PostProcessingEffects = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, ChromaticAberrationEffects); //<-- this
}
private IEnumerator LerpMyShit(float startValue, float endValue, float reletiveForce, float maxDuration) {
float duration = 0;
while (duration < 1)
{
reletiveForce = Mathf.Lerp(startValue, endValue, duration);
ChromaticAberrationEffects.intensity.Override(reletiveForce);
duration += Time.deltaTime / maxDuration;
yield return null;
}
}
``` because I feel that the post processing effect comes on about 1 second after collision
I'm really not sure, I've never messed with PP like this before
ah I see
would it be possible for it to go from 0 to -100?
nono I want to do a different effect
Color Grading -> Saturation
I want the screen to slowly fade to black and white and go back on collision
I have that part done thanks to you, just unsure how to make it go from 0 to -100 and back
that would work?
that's really cool
would I have to create 2 separate Ienums for that though?
No
then how do I avoid the first one being conficted with the second?
in my head it will execute as both
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Rendering.PostProcessing;
public class AnimateCollision : MonoBehaviour
{
//Private Variables
private ChromaticAberration ChromaticAberrationEffects;
//Settings Variables
[Header("Animate-on-Collision")]
[SerializeField] private PostProcessVolume PostProcessingEffects;
public void AnimateCollisionEffect(float _collisionRelativeForce) {
ChromaticAberrationEffects = ScriptableObject.CreateInstance<ChromaticAberration>();
ChromaticAberrationEffects.enabled.Override(true);
ColorGradingEffects = ScriptableObject.CreateInstance<ColorGrading>();
ColorGradingEffects.enabled.Override(true);
PostProcessingEffects = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, ChromaticAberrationEffects);
PostProcessingEffects = PostProcessManager.instance.QuickVolume(gameObject.layer, 100f, ColorGradingEffects);
StartCoroutine(LerpMyShit(1f, 0f, 1f, _collisionRelativeForce, true));
StartCoroutine(LerpMyShit(1f, 0f, 1f, _collisionRelativeForce, false));
}
private IEnumerator LerpMyShit(float startValue, float endValue, float maxDuration, float reletiveForce, bool isAberration) {
float duration = 0;
while (duration < 1)
{
reletiveForce = Mathf.Lerp(startValue, endValue, duration);
if (isAberration) {
ChromaticAberrationEffects.intensity.Override(reletiveForce);
} else {
ColorGradingEffects.intensity.Override(reletiveForce);
}
duration += Time.deltaTime / maxDuration;
yield return null;
}
}
}
``` is this okay to do?
whoops didn't mean to copy the entire thing
Unsure
let me test it real quick then
it's weird