Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question (Post Processing) How to make the Lens Distortion go up and down all the time?

Discussion in 'General Graphics' started by angiemon, Sep 14, 2023.

  1. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    32
    Hello! :)

    As the title states, I want the Lens Distortion PP value to go up and down all the time (think of like someone moving the slider from the left to the right and back all the time :D)

    What we currently have is kinda weird, looks good with not a lot of distortion but if I increase the numbers it behaves weirdly? (when it comes close to zero it gets super slow and sometimes it's stuck to a value)

    This code is used:

    distortion.intensity.value += Mathf.Abs(distortion.intensity.value) > 1.0f ? Time.deltaTime * 60.0f : 10 + Time.deltaTime * 60.0f;
    } else {
    distortion.intensity.value -= Mathf.Abs(distortion.intensity.value) > 1.0f ? Time.deltaTime * 60.0f : 10 + Time.deltaTime * 60.0f;

    Is there another way to do this?
    Further info: Programmer is currently annoyed with the project so I wanna research for him :)
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    624
    Haha, can I hire you? ;)

    You could try something like this:
    Code (CSharp):
    1. const float speed = 1.0f;
    2. const float minDistortion = 0.0f;
    3. const float maxDistortion = 1.0f;
    4. float t = (Mathf.Sin(Time.time * speed) + 1.0f) * 0.5f;
    5. distortion.intensity.value = Mathf.Lerp(minDistortion, maxDistortion, t);
     
    angiemon likes this.
  3. angiemon

    angiemon

    Joined:
    Mar 26, 2018
    Posts:
    32
    Sure! Please note that I'll have you appreciate that I charge $0.20 whenever the solution I found for your is used in your code! :D



    Aww thanks!! "I" will try that and let you know how it works out :D (probably a bunch of compliation errors until I can kick him to his PC to make a pull request, but fingers crossed, hehe:))
     
    c0d3_m0nk3y likes this.
  4. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    624
    Just realized that you are making a joke about the new license terms LOL (this took me much longer than it should have). Yeah, I think they are ridiculous too. Professionally, I've already moved on to UE but I love the Unity community and will probably continue posting here.
     
    angiemon likes this.