Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How Unity uses SurfaceOutput

Discussion in 'Shaders' started by allenwp, Apr 15, 2014.

  1. allenwp

    allenwp

    Joined:
    Sep 4, 2013
    Posts:
    46
    Hey,

    I am having a hard time finding exactly how Unity uses each field of the SurfaceOutput struct. Because I am making slightly non-photorealistic rendering, I feel that it's even more important that I deeply understand them so I know how I can use them in non-standard ways.

    Currently, this is my understanding of the struct:

    struct SurfaceOutput {
    half3 Albedo;
    ○ Ignored by Unity, up to the lighting function to make use of this
    half3 Normal;
    ○ ??? Used by Unity for some stuff maybe?
    half3 Emission;
    ○ Added once to final color value automatically by Unity
    half Specular;
    ○ Ignored by Unity, up to the lighting function to make use of this
    half Gloss;
    ○ Ignored by Unity, up to the lighting function to make use of this
    half Alpha;
    ○ Ignored by Unity, up to the lighting function to make use of this
    };

    Thoughts? Maybe there's a document somewhere that's evading my detection which describes this...

    Maybe this is more complex than I let it on to be? If so, I'd love to know those fine details...
     
  2. IronMathbook

    IronMathbook

    Joined:
    Apr 12, 2014
    Posts:
    60
    I believe that albedo is the name for color output even that that name means something else to most people
    Emission is making out an area so that it is seen even if there is no lights on the object. It uses a separate texture map.
    I would think that albedo could be used outside of the lighting function. I know that normal can be used else were atleast in vert/frag shaders.
     
  3. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    It's pretty self-explanatory.

    Albedo is the albedo colour (standard diffuse).
    Normal is the normal map - Surface Shaders assume it to be in tangent space.
    Emission is the emissive texture.
    Specular controls the specular highlight brightness.
    Gloss controls the glossiness of the specular highlight.
    Alpha is the alpha value, generally used for transparency.

    These default ones are simply there because Unity uses them in it's built-in shaders, but you can write your own (although I think it requires there be an Emission and an Albedo and if you don't have a Normal that gets written to, it won't give you tangent space values for view and light direction in the lighting function).
     
  4. allenwp

    allenwp

    Joined:
    Sep 4, 2013
    Posts:
    46
    I agree, the names of these fields are pretty self-explanatory. And thanks for the explanation on how the normal interpreted for the lighting model -- I hadn't thought of that.

    ...But I am also interested in how unity uses these fields outside of the built-in lighting models. It's obvious that the emission field is used by unity, regardless of whether you use any built-in lighting models... Are the other fields used in similar ways for different parts of the rendering engine?
     
  5. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I think your best resource would be looking at the output generated from the surface shader. From the manual:

     
    kiiri2 likes this.