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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How is the correct way of passing constant / uniform variables to a Compute Shader in Unity?

Discussion in 'Shaders' started by andSol, Jun 1, 2016.

  1. andSol

    andSol

    Joined:
    May 8, 2016
    Posts:
    22
    So, my question is pretty much what the title says: in the Compute Shaders in Unity, what is the correct way of having constant/uniform/global variables?

    Compute shader do not accept the definition 'uniform' and in the official documentation (http://docs.unity3d.com/Manual/SL-BuiltinMacros.html), there is only a sparse mention of the format:

    Code (CSharp):
    1. CBUFFER_START(MyRarelyUpdatedVariables)
    2. float4 _SomeGlobalValue;
    3. CBUFFER_END
    However, that gives me the error "unrecognized identifier "CBUFFER_STAR'". What is exactly the correct way of having variables that are passed by C# and behave as global constant variables in the Compute Shader?

    PS: I did find a past question about that in the forum, but it didn't get any answers: http://forum.unity3d.com/threads/cbuffer-and-compute-shader.164968/
     
    Last edited: Jun 1, 2016
  2. a3dline

    a3dline

    Joined:
    Dec 28, 2013
    Posts:
    17
    dx metal
    cbuffer name{
    }