#Chromatic aberration

1 messages · Page 1 of 1 (latest)

tribal terrace
#

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

analog elk
#
    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;
        }
    }
tribal terrace
#

yes, that is what I was responding to

analog elk
#

so how do I make it go from 1 to 0

analog elk
#

so why doesn't it work?

tribal terrace
#

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

analog elk
#

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?
tribal terrace
#

I don't know, try it

honest sorrel
#

if you're directly using Time you dont need the lerp stuff at all

analog elk
#

but it doesn't work then???

honest sorrel
#

Look at what yiu're passing into Override

analog elk
#

duration

honest sorrel
#

Yes

#

the lerp is not needed.

#

if you're just passing duration

analog elk
#

so should I remove it?

honest sorrel
#

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.

analog elk
#
    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?
tribal terrace
#

when is that while loop going to end?

analog elk
#

after 1 second

tribal terrace
#

why do you say that?

analog elk
#

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
honest sorrel
#

Man

analog elk
#

..wat

honest sorrel
#

if you needed to do this. You needed the lerp.

#

Make it scalable

analog elk
#

what does that mean

honest sorrel
#

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

analog elk
#

alright let me see

#

what value should maxDuration be?

#

1f?

honest sorrel
#

How long do you want this instensity to rise for

#

in seconds

analog elk
#

abound 1 or 2 seconds depending on the force, if possible, if not just 1 second

#

I presume to just put 1 there then

honest sorrel
#

try it and see™️

analog elk
#

bet, let me see if it works

#

works but only sometimes, why?

honest sorrel
#

I do not know

analog elk
#

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

honest sorrel
#

Understanding what its actually doing is valuable and you should od that before trying to fix it

analog elk
#

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
honest sorrel
#

I'm really not sure, I've never messed with PP like this before

analog elk
#

ah I see

analog elk
honest sorrel
#

That makes zero sense. 0 intensity is 0

#

you cannot have negative intensity

analog elk
#

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

honest sorrel
#

Yes its possible

#

just pass in the values you want

analog elk
#

that would work?

honest sorrel
#

Yes

#

this is what i meant about scalability

analog elk
#

would I have to create 2 separate Ienums for that though?

honest sorrel
#

No

analog elk
#

then how do I avoid the first one being conficted with the second?

honest sorrel
#

i dont think it will

#

But you can try it and see™️

analog elk
#

in my head it will execute as both

analog elk
# honest sorrel i dont think it will
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

honest sorrel
#

Unsure

analog elk
#

let me test it real quick then

analog elk
#

it's weird