Search Unity

Question Cannot create struct expecting float3 with float3(0.,0.,0.)

Discussion in 'Shaders' started by nosarious, Aug 13, 2022.

  1. nosarious

    nosarious

    Joined:
    May 14, 2014
    Posts:
    16
    I am porting a cloud shader with horizon to Unity for use in an AR app.

    I am stuck trying to get the declaration of a struct to work properly.

    Shader is here: https://www.shadertoy.com/view/XtBXDw

    In the preliminary declarations there are these:
    Code (CSharp):
    1.  
    2. struct sphere_t {
    3.     float3 origin;
    4.     float radius;
    5.     int material;
    6. };
    7.  
    8. struct plane_t {
    9.     float3 direction;
    10.     float distance;
    11.     int material;
    12. };
    13.  
    14. struct hit_t {
    15.     float t;
    16.     int material_id;
    17.     float3 normal;
    18.     float3 origin;
    19. };
    But when the final calculations that use these are declared:

    Code (CSharp):
    1.  
    2.             sphere_t atmosphere
    3.             { float3(0., -450, 0.), 500., 0}
    4.  
    5.             sphere_t atmosphere_2
    6.             {
    7.                atmosphere.origin, atmosphere.radius + 50., 0
    8.             }
    9.             plane_t ground
    10.             {
    11.                 float3(0., -1., 0.), 0., 1
    12.             }
    I get an error for the first instance of an open bracket after the first float3.

    Shader error in 'Unlit/horizon-clouds': syntax error: unexpected token '(' at line 547 (on metal)


    I can't even test this shader until this is resolved. Am I wrong to assume this is really the only way to initialize the struct values?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    struct_type variable_name = { val0, val1, etc };