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. Dismiss Notice

Question what is the parameter "render target" in the ShaderLab command "ColorMask" ?

Discussion in 'Shaders' started by FariAnderson, Aug 4, 2023.

  1. FariAnderson

    FariAnderson

    Joined:
    Jan 20, 2020
    Posts:
    29
    Last edited: Aug 4, 2023
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    625
    Hi, I think it's for assigning different ColorMask when using Multiple Render Targets (MRT) feature.

    One usage of MRT is the deferred rendering path, which usually uses MRT in fragment shader to fill all GBuffer textures in one pass.

    Code (CSharp):
    1. // Example from URP's Lit GBuffer shader pass
    2.  
    3. struct FragmentOutput
    4. {
    5.     half4 GBuffer0 : SV_Target0;
    6.     half4 GBuffer1 : SV_Target1;
    7.     half4 GBuffer2 : SV_Target2;
    8.     half4 GBuffer3 : SV_Target3; // Camera color attachment
    9.  
    10.     #ifdef GBUFFER_OPTIONAL_SLOT_1
    11.     GBUFFER_OPTIONAL_SLOT_1_TYPE GBuffer4 : SV_Target4;
    12.     #endif
    13.     #ifdef GBUFFER_OPTIONAL_SLOT_2
    14.     half4 GBuffer5 : SV_Target5;
    15.     #endif
    16.     #ifdef GBUFFER_OPTIONAL_SLOT_3
    17.     half4 GBuffer6 : SV_Target6;
    18.     #endif
    19. };
    20.  
    21. // fragment stage
    22. FragmentOutput fragment(Varyings input)
    23. {
    24.     //...
    25. }
     
    lilacsky824 and FariAnderson like this.
  3. FariAnderson

    FariAnderson

    Joined:
    Jan 20, 2020
    Posts:
    29
    Thanks for the clue <3
     
    wwWwwwW1 likes this.