1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Shaderlab Documentation Requests

Discussion in 'Shaders' started by Tim-C, Sep 1, 2012.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    1,099
    • Inline doc, command+' jumpto and shader autocomplete would go a long way.
    • The frag shader doc is pretty good, especially the example with the balloon cat, it would be nice to see more of that for surface shader and since surface shader need less lines, more examples playing with ref probes, light probes and exotic render stuff
    • A searchable diagram (as opposed to a png) showing how command buffers, cameras, render pass, squirrels, lights, surface, screen etc... interconnect would help decide how to assemble shaders and scripts to get effects (trace the maze until you reach the write normal to the screen)
    • Some ppl say command buffer are dog slow, others say it's faster than multiple post effects. It'd be nice to have a table of performances for instructions (shader/c#)
    • A 2/3 column tables that shows how to transform data
    • Multiple shader variants could use an example
     
    Last edited: Feb 1, 2016
  2. TehWardy

    TehWardy

    Joined:
    Mar 20, 2013
    Posts:
    38
    Does this thread cover compute too?

    Lots of compute documentation is missing, for example, the absolute basics of how to populate different kinds of buffers is not clear / seemingly just not working, it would be good to get some sort of guide or feedback as to how to make the most of compute, maybe a series of examples or something.

    What I mean by "absolute basics" ...
    http://forum.unity3d.com/threads/co...-results-and-general-debugging-advice.385297/

    As you can see from this, I really have 2 concerns ...

    1. This doesn't behave how I would expect and I don't know why and there's nothing out there to tell me why
    2. I can debug a shader that's part of the render process but compute doesn't really have a means to allow us to easily test / debug, more so when the C# side in VS doesn't actually show me what's really in the buffer.
     
    Last edited: Feb 27, 2016
  3. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    230
    Any info on how shader tiers are selected? Docs mention only that it's based on GPU, but nothing else. Can we assume some amount of VRAM or FLOPs?
     
    daxiongmao likes this.
  4. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    230
    Documentation mentions finalgbuffer:ColorFunction, but there's no example of how the signature should look like.

    For the record I've guessed it:
    Code (CSharp):
    1. void ColorFunction (
    2.     Input IN,
    3.     SurfaceOutputStandardSpecular o,
    4.     inout half4 outDiffuse : SV_Target0,            // RT0: diffuse color (rgb), occlusion (a)
    5.     inout half4 outSpecSmoothness : SV_Target1,    // RT1: spec color (rgb), smoothness (a)
    6.     inout half4 outNormal : SV_Target2,            // RT2: normal (rgb), --unused, very low precision-- (a)
    7.     inout half4 outEmission : SV_Target3            // RT3: emission (rgb), --unused-- (a)
    8. ) {
    9.     //  do something useful, like outNormal.a = 0.0;
    10. }
     
    frosted likes this.
  5. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    2,469
    I'm pretty sure this is clipped from the same post I saw it in. There are so few examples or mention of this stuff (or another example is clipping the same signature from elsewhere).

    to be fair, the docs do sort of review this in the layout of the gbuffer: http://docs.unity3d.com/Manual/RenderTech-DeferredShading.html

    But it obviously leaves a lot to be desired.
     
  6. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,826
    Oh wow there's still no documentation for that yet. . . ???!!!
     
  7. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,601

    Final Color Modifier


    Code (csharp):
    1.  
    2. Shader "Example/Tint Final Color"
    3. {
    4.    Properties
    5.    {
    6.      _MainTex ("Texture", 2D) = "white" {}
    7.      _ColorTint ("Tint", Color) = (1.0, 0.6, 0.6, 1.0)
    8.    }
    9.    SubShader
    10.    {
    11.      Tags { "RenderType" = "Opaque" }
    12.      CGPROGRAM
    13.      #pragma surface surf Lambert finalcolor:mycolor
    14.      struct Input {
    15.        float2 uv_MainTex;
    16.      };
    17.      fixed4 _ColorTint;
    18.      void mycolor (Input IN, SurfaceOutput o, inout fixed4 color)
    19.      {
    20.        color *= _ColorTint;
    21.      }
    22.      sampler2D _MainTex;
    23.      void surf (Input IN, inout SurfaceOutput o) {
    24.        o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    25.      }
    26.      ENDCG
    27.    }
    28.   Fallback "Diffuse"
    29. }
    30.  
    31.  
    32.  
    Custom Fog with Final Color Modifier
    Code (csharp):
    1.  
    2. Shader "Example/Fog via Final Color"
    3. {
    4.    Properties
    5.    {
    6.      _MainTex ("Texture", 2D) = "white" {}
    7.      _FogColor ("Fog Color", Color) = (0.3, 0.4, 0.7, 1.0)
    8.    }
    9.    SubShader
    10.    {
    11.      Tags { "RenderType" = "Opaque" }
    12.      CGPROGRAM
    13.      #pragma surface surf Lambert finalcolor:mycolor vertex:myvert
    14.      struct Input {
    15.        float2 uv_MainTex;
    16.        half fog;
    17.      };
    18.      void myvert (inout appdata_full v, out Input data)
    19.      {
    20.        UNITY_INITIALIZE_OUTPUT(Input,data);
    21.        float4 hpos = mul (UNITY_MATRIX_MVP, v.vertex);
    22.        hpos.xy/=hpos.w;
    23.        data.fog = min (1, dot (hpos.xy, hpos.xy)*0.5);
    24.      }
    25.      fixed4 _FogColor;
    26.  
    27.      void mycolor (Input IN, SurfaceOutput o, inout fixed4 color)
    28.      {
    29.        fixed3 fogColor = _FogColor.rgb;
    30.        #ifdef UNITY_PASS_FORWARDADD
    31.        fogColor = 0;
    32.        #endif
    33.        color.rgb = lerp (color.rgb, fogColor, IN.fog);
    34.      }
    35.      sampler2D _MainTex;
    36.  
    37.      void surf (Input IN, inout SurfaceOutput o) {
    38.        o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    39.      }
    40.      ENDCG
    41.    }
    42.    Fallback "Diffuse"
    43. }
    44.  
    45.  
    Source : http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html
     
  8. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,826
    That's final Color not Final GBuffer, it's different stuff
    ie http://forum.unity3d.com/threads/ho...added-unity-5-2-finalgbuffer-modifier.356644/
     
  9. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,601
    Oh, my bad... :oops:
     
  10. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,826
    No worries, at first i thought FinalGbuffer and FinalColor are the same :D
     
  11. hausmaus

    hausmaus

    Joined:
    Dec 9, 2011
    Posts:
    100
    Another vote for finalgbuffer documentation. The existing finalcolor examples do not apply to the Standard shader, and it seems that the approach that works for the default surface shader version of standard do not apply to the vertex/fragment source version. This was a very useful feature in the old pipeline and it would be great to know how to use the new version correctly, especially with the full version of the PBR Standard shader.
     
  12. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,826
    in this link
    http://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html

    On the reflection Per-Pixel sample, why there's nothing mentioned about
    Code (csharp):
    1.  
    2. UNITY_SAMPLE_TEXCUBE_LOD
    3.  
    in this line especially
    Code (csharp):
    1.  
    2. half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, worldRefl);
    3.  
    it can remove the reflection pixelated artifact
     
  13. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    398
    Some mention in the docs of dealing with arrays of shader parameters would be good:

    See http://forum.unity3d.com/threads/passing-arrays-to-shaders.178682/

    In this thead there's a 'workaround' that looks like it should be mentioned in the docs if it's actually a supported thing (I'm struggling to make it work in 5.4) - if an array is declared in a shader (e.g. float4x4 myArray[4]), can you set the elements individually by using "myArray0" to "myArray3"
     
  14. SkullBearer666

    SkullBearer666

    Joined:
    Oct 26, 2015
    Posts:
    3
    More documentation on Compute shaders please.
    Specifically:
    • Binding resources
    • Different types of buffers and their uses
    • Key differences from pixel/surface shader syntax
    • List of predefined functions and Macros
    • And lastly some best practice and beginer guides
    I am very new to it, and having an extremely hard time figuring things out.
     
  15. chayanvinayak

    chayanvinayak

    Joined:
    Jul 11, 2012
    Posts:
    10
    Any Shadow mapping pipeline documentation?
    eg : What is _ShadowMapTexture, is it a texture transformed/ mapped from view space/camera space?
     
    varfare likes this.
  16. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    347
    The code in this link is outdated: https://docs.unity3d.com/Manual/SL-DepthTextures.html

    I was wondering why it'd just render in black for me until I dug into UnityCG.cginc and found this:

    Code (csharp):
    1.  
    2. // Legacy; used to do something on platforms that had to emulate depth textures manually. Now all platforms have native depth textures.
    3. #define UNITY_TRANSFER_DEPTH(oo)
    4. // Legacy; used to do something on platforms that had to emulate depth textures manually. Now all platforms have native depth textures.
    5. #define UNITY_OUTPUT_DEPTH(i) return 0
    6.  
    I've seen other forum posts and blogs linking to this documentation, so it's very misleading and (in my case) a waste of time :(
     
    Last edited: Nov 29, 2016
  17. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    190
    I had a hard time figuring out why a shader of mine didn't write in the depth buffer and another one did. It was because I set a fallback shader, which apparently does things.
    The documentation only points out that this shader will be used if the hardware doesn't support a shader. If I got it right, the fallback shader also handles replacement shaders for the depth buffer.

    Could we get a bit more insight on that: https://docs.unity3d.com/Manual/SL-Fallback.html
     
  18. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    347
    I had the exact same problem with my depth shader. I tried to do some cleaning up, and removed the Fallback line, which broke my shader. Of course it took me a few hours (way too long) to make that connection...

    Even just having Fallback "VertexLit" was enough to fix things. The shader code I linked to above also doesn't have a Fallback line, so I'd be surprised if that worked for anyone now.
     
  19. msklywenn

    msklywenn

    Joined:
    Nov 28, 2014
    Posts:
    64
    It would be nice to have a shader API reference as good as the scripting API. The shader reference in the manual is quite lengthy and not very easy to search. It also fails to define many things that we end up looking for in UnityCG.inc and its friends and trying to find what they mean...
     
    solkar and varfare like this.
  20. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,826
    is this thread still being monitored by documentation team?
     
  21. djoshi

    djoshi

    Joined:
    Mar 28, 2014
    Posts:
    172
    Shader API reference as good as the scripting API, especially for CG.
     
  22. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    334
    The office doc says we can change LightmapSettings.lightProbes to a pre-baked one,but hence we can't bake LightProbes independ ,therefore all GI datas are packed into LightData.asset.
    How can we change the value of LightmapSettings.lightProbes????
    go back to unity 4.x ?

    Maybe some docs about how GI datas are orgnized in this file LightData.asset,and some API to read them from this file
     
    Last edited: Jul 20, 2017 at 12:49 PM