Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Trying to access time in an HLSL post-processing shader. Am I doing anything wrong?

Discussion in 'Shaders' started by cs5947, Sep 4, 2023.

  1. cs5947

    cs5947

    Joined:
    Feb 6, 2021
    Posts:
    6
    Here's the code:

    I'm getting this error:
    If you need any extra information you can use to help, I'm working Unity 2023.2.0 <DX11> with an HDRP project. What I'm trying to do is to create a simple static effect that creates a psuedo-random value for each pixel, and refreshes the pixels based on time each frame. I'm new to HLSL but I dont think this should be way too hard of a shader to make. I'm using this shader from Shadertoy to copy into HLSL so I at least have an understanding of how the values are generated and refreshed.
     
    Last edited: Sep 4, 2023
  2. cs5947

    cs5947

    Joined:
    Feb 6, 2021
    Posts:
    6
    I am aware that there may be errors aside from this one inside of the code, you’re welcome to fix them and tell me how you fixed them so that I may know later. Thanks, cs5947
     
  3. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,141
    Unlike in C#, you can't declare properties with an initial value, linking to yet another property. The error hints at this, but it's really asking you to make the value a constant.

    You can:
    • Declare it as a local property in the CustomPostProcess function
    • Change it to a macro (#define time _Time.x) (no semicolumn at the end!)
    • Replace the usage of the 'time' variable with '_Time.x'.
    Have you noticed the "Hash" function is also nested in the CustomPostProcess function? That needs to be moved up outside of the function's scope.

    Side note: best to replace '_Time' with '_TimeParameters'. The former is legacy code, whilst the latter is the SRP standard.
     
    cs5947 likes this.