Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

metal tessellation not show correct for wireframe mode

Discussion in '2018.1 Beta' started by dreamerflyer, Jan 13, 2018.

  1. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    What about this?the wireframe not change when add tessellation. bugT.jpg
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Unity staff is probably going to ask you do submit a bug-report, following the advice given in this document.

    If you want to speed things up, it's probably a good idea to submit that bug-report already and post its case number here for UT to pick up.
     
  3. Image3d

    Image3d

    Joined:
    Jun 20, 2008
    Posts:
    155
    Is tessellation already available...where can i get a tessellation shader ?
     
  4. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
  5. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Last edited: Jan 15, 2018
  6. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
  7. aet

    aet

    Unity Technologies

    Joined:
    Jun 5, 2014
    Posts:
    44
    I can't tell much from this picture alone. But I think at the moment if you're using iOS target in the editor, the Tessellation shader feature is not enabled for Metal Graphics emulation. The workaround is to use iOS target in the editor with emulation disabled (Edit -> Graphics Emulation -> No Emulation) or use standalone for experimenting.
     
    RoughSpaghetti3211 likes this.
  8. aet

    aet

    Unity Technologies

    Joined:
    Jun 5, 2014
    Posts:
    44
    I tried the shader in question myself in 2018.1.0b2 and didn't see any errors.

    I'd go with checking out existing Asset Store content and using shaders with tessellation that are actually built for specific purpose, along with test scene :)

    Other than several Asset Store packages, this one was also tested http://diary.conewars.com/tessellation-melt-shader-part-3/ during development
     
  9. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Did you just not see errors, or did you actually see tessellation happening?

    The melt shader works
     
  10. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    And what asset store package did you test and worked well?
    Interested to try some out
     
  11. comomomo

    comomomo

    Joined:
    Feb 16, 2014
    Posts:
    12
    I’ve only been able to get UnityDistanceBasedTess to work and it doesn’t seem to be generating triangles very smoothly. Below screenshot should be one continuous surface using a height map.
     

    Attached Files:

  12. Enrico-Monese

    Enrico-Monese

    Joined:
    Dec 18, 2015
    Posts:
    77
    Lars-Steenhoff likes this.
  13. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    anything to share?
     
  14. andrii-shpak

    andrii-shpak

    Joined:
    Nov 27, 2014
    Posts:
    315
    Maybe someone know what is wrong with this shader. It works on DX11 but doesn't on Metal, and there are no errors and warnings. I was trying to copy constructions from compiled surface shader. For example have changed [domain("tri")] with [UNITY_domain("tri")] etc. But no success. Unfortunatelly I can't use surface shader. I'm trying to port this asset to IOS/OSX: https://assetstore.unity.com/packages/tools/physics/hair-tool-66094

    Code (CSharp):
    1. Shader "Unlit/TestTess"
    2. {
    3.     Properties
    4.     {
    5.         _Tess ("Tessellation", Range(1,32)) = 4
    6.         _DiffuseColor ("Diffuse Color", color) = (0.5,0.5,0.5,0.5)
    7.  
    8.     }
    9.     SubShader
    10.     {
    11.         Tags { "RenderType"="Opaque"  }
    12.         LOD 200
    13.        
    14.         Pass
    15.         {
    16.             Name "FORWARD"
    17.             Tags { "LightMode" = "ForwardBase" }
    18.  
    19.             CGPROGRAM
    20.             #pragma vertex VS
    21.             #pragma fragment FS
    22. #ifdef UNITY_CAN_COMPILE_TESSELLATION
    23.             #pragma hull HS
    24.             #pragma domain DS
    25. #endif          
    26.  
    27.             #pragma target 5.0
    28.             #pragma multi_compile_fwdbase
    29.  
    30.             #include "UnityCG.cginc"
    31.             #include "Tessellation.cginc"          
    32.            
    33.             float _Tess;
    34.             float4 _DiffuseColor;
    35.            
    36.             struct APP_OUTPUT
    37.             {
    38.                 float4 vertex : POSITION;
    39.                 float3 normal : NORMAL;
    40.             };
    41.  
    42.             struct VS_OUTPUT
    43.             {
    44.                 float4 vertex : POSITION;
    45.                 float3 normal : NORMAL;
    46.             };
    47.                        
    48.             struct HS_OUTPUT
    49.             {
    50.                 float4 vertex : POSITION;
    51.                 float3 normal : NORMAL;
    52.             };
    53.            
    54.             struct DS_OUTPUT
    55.             {
    56.                 float4 vertex : POSITION;
    57.                 float3 normal : NORMAL;
    58.             };
    59.            
    60. #ifdef UNITY_CAN_COMPILE_TESSELLATION
    61.             struct HS_CONSTANT_OUTPUT
    62.             {
    63.                 float edges[3] : SV_TessFactor;
    64.                 float inside : SV_InsideTessFactor;
    65.             };
    66.            
    67.             HS_CONSTANT_OUTPUT HSConst()
    68.             {
    69.                 HS_CONSTANT_OUTPUT o;
    70.                
    71.                 o.edges[0] = _Tess;
    72.                 o.edges[1] = _Tess;
    73.                 o.edges[2] = _Tess;
    74.                 o.inside = _Tess;
    75.                
    76.                 return o;
    77.             }
    78. #endif
    79.             VS_OUTPUT VS (APP_OUTPUT v)
    80.             {
    81.                 VS_OUTPUT o;
    82.                 o.vertex = v.vertex;
    83.                 o.normal = v.normal;
    84.                 o.vertex = UnityObjectToClipPos(o.vertex);
    85.                 return o;
    86.             }
    87.            
    88. #ifdef UNITY_CAN_COMPILE_TESSELLATION
    89.            
    90.             [UNITY_domain("tri")]
    91.             [UNITY_partitioning("fractional_odd")]
    92.             [UNITY_outputtopology("triangle_cw")]
    93.             [UNITY_outputcontrolpoints(3)]
    94.             [UNITY_patchconstantfunc("HSConst")]
    95.             HS_OUTPUT HS(InputPatch<VS_OUTPUT, 3> ip, uint id : SV_OutputControlPointID)
    96.             {
    97.                 HS_OUTPUT o;
    98.                 o.vertex = ip[id].vertex;
    99.                 o.normal = ip[id].normal;
    100.                 return o;
    101.             }
    102.            
    103.  
    104.            
    105.             [UNITY_domain("tri")]
    106.             DS_OUTPUT DS(HS_CONSTANT_OUTPUT input, OutputPatch<HS_OUTPUT, 3> ip, float3 b : SV_DomainLocation)
    107.             {
    108.                 DS_OUTPUT o;
    109.                 o.vertex = ip[0].vertex*b.x + ip[1].vertex*b.y + ip[2].vertex*b.z;
    110.                 o.normal = ip[0].normal*b.x + ip[1].normal*b.y + ip[2].normal*b.z;
    111.                 o.vertex = UnityObjectToClipPos(o.vertex);
    112.  
    113.                 return o;
    114.             }
    115.            
    116. #endif
    117.             fixed4 FS (DS_OUTPUT i) : SV_Target
    118.             {
    119.                 float4 col  = float4(1,1,1,1);  
    120.  
    121.                 return col;
    122.             }
    123.             ENDCG
    124.         }
    125.     }
    126. }
    127.  
    128.  
     
  15. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Does the shader work on Metal with earlier versions of Unity? If that's the case, then you probably found a regression and it's helpful to submit a bug-report, following the advice from this document.
     
  16. andrii-shpak

    andrii-shpak

    Joined:
    Nov 27, 2014
    Posts:
    315
    It doesn't, Tesselation on metal has been promiced from Unity 2018.
     
  17. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    So with a few tweaks to the shader it works as expected, for the shaders that are dealing with tessellation you need to use "INTERNALTESSPOS" when sharing positional data between the shaders, also you shouldn't be transforming to clip pos before the tessellation does it's thing, unless you wanted that behaviour. Here's the tweaked code for the above shader:
    Code (CSharp):
    1. Shader "Unlit/TestTess"
    2. {
    3.     Properties
    4.     {
    5.         _Tess ("Tessellation", Range(1,32)) = 4
    6.         _DiffuseColor ("Diffuse Color", color) = (0.5,0.5,0.5,0.5)
    7.     }
    8.     SubShader
    9.     {
    10.         Tags { "RenderType"="Opaque"  }
    11.         LOD 200
    12.      
    13.         Pass
    14.         {
    15.             Name "FORWARD"
    16.             Tags { "LightMode" = "ForwardBase" }
    17.             CGPROGRAM
    18.             #pragma vertex VS
    19.             #pragma fragment FS
    20. #ifdef UNITY_CAN_COMPILE_TESSELLATION
    21.             #pragma hull HS
    22.             #pragma domain DS
    23. #endif        
    24.             //#pragma multi_compile_fwdbase
    25.             #include "UnityCG.cginc"
    26.             #include "Tessellation.cginc"        
    27.          
    28.             float _Tess;
    29.             float4 _DiffuseColor;
    30.          
    31.             struct APP_OUTPUT
    32.             {
    33.                 float4 vertex : POSITION;
    34.                 float3 normal : NORMAL;
    35.             };
    36.             struct VS_OUTPUT
    37.             {
    38.                 float4 vertex : INTERNALTESSPOS;
    39.                 float3 normal : NORMAL;
    40.             };
    41.                      
    42.             struct HS_OUTPUT
    43.             {
    44.                 float4 vertex : INTERNALTESSPOS;
    45.                 float3 normal : NORMAL;
    46.             };
    47.          
    48.             struct DS_OUTPUT
    49.             {
    50.                 float4 vertex : POSITION;
    51.                 float3 normal : NORMAL;
    52.             };
    53.          
    54. #ifdef UNITY_CAN_COMPILE_TESSELLATION
    55.             struct HS_CONSTANT_OUTPUT
    56.             {
    57.                 float edges[3] : SV_TessFactor;
    58.                 float inside : SV_InsideTessFactor;
    59.             };
    60.          
    61.             HS_CONSTANT_OUTPUT HSConst()
    62.             {
    63.                 HS_CONSTANT_OUTPUT o;
    64.              
    65.                 o.edges[0] = _Tess;
    66.                 o.edges[1] = _Tess;
    67.                 o.edges[2] = _Tess;
    68.                 o.inside = _Tess;
    69.              
    70.                 return o;
    71.             }
    72. #endif
    73.             VS_OUTPUT VS (APP_OUTPUT v)
    74.             {
    75.                 VS_OUTPUT o;
    76.                 o.vertex = v.vertex;
    77.                 o.normal = v.normal;
    78.                 //o.vertex = UnityObjectToClipPos(o.vertex);
    79.                 return o;
    80.             }
    81.          
    82. #ifdef UNITY_CAN_COMPILE_TESSELLATION
    83.          
    84.             [UNITY_domain("tri")]
    85.             [UNITY_partitioning("fractional_odd")]
    86.             [UNITY_outputtopology("triangle_cw")]
    87.             [UNITY_outputcontrolpoints(3)]
    88.             [UNITY_patchconstantfunc("HSConst")]
    89.             HS_OUTPUT HS(InputPatch<VS_OUTPUT, 3> ip, uint id : SV_OutputControlPointID)
    90.             {
    91.                 HS_OUTPUT o;
    92.                 o.vertex = ip[id].vertex;
    93.                 o.normal = ip[id].normal;
    94.                 return o;
    95.             }
    96.          
    97.          
    98.             [UNITY_domain("tri")]
    99.             DS_OUTPUT DS(HS_CONSTANT_OUTPUT input, OutputPatch<HS_OUTPUT, 3> ip, float3 b : SV_DomainLocation)
    100.             {
    101.                 DS_OUTPUT o;
    102.                 o.vertex = ip[0].vertex*b.x + ip[1].vertex*b.y + ip[2].vertex*b.z;
    103.                 o.normal = ip[0].normal*b.x + ip[1].normal*b.y + ip[2].normal*b.z;
    104.                 o.vertex = UnityObjectToClipPos(o.vertex);
    105.                 return o;
    106.             }
    107.          
    108. #endif
    109.             fixed4 FS (DS_OUTPUT i) : SV_Target
    110.             {
    111.                 float4 col  = float4(1,1,1,1);
    112.                 return col;
    113.             }
    114.             ENDCG
    115.         }
    116.     }
    117. }
    As for wireframe not working, we know this is an issue and are trying to find the best way to fix it as there are dragons there ;)
     
  18. andrii-shpak

    andrii-shpak

    Joined:
    Nov 27, 2014
    Posts:
    315
    Thanks alot, already find that by investigating compiled surface shader. But actually I need isoline tesselation. Do you plan to support it? Unity just crashes when I use:

    [domain("isoline")]
    [partitioning("integer")]
    [outputtopology("line")]
    [outputcontrolpoints(3)]
    [patchconstantfunc("HSConst")]
    before HullShader

    and
    [domain("isoline")]
    before domain
     
  19. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    We do support isoline in Unity so if this is crashing it sounds like a bug and probably is a bug with only Metal as it's implementation is very new. Do you mind opening a bug report, this will help us track the issue and get it actioned.
     
  20. andrii-shpak

    andrii-shpak

    Joined:
    Nov 27, 2014
    Posts:
    315
    Ok
    Ok, I'll report a bug. This is a shader:

    Code (CSharp):
    1. Shader "Unlit/TestTess"
    2. {
    3.     Properties
    4.     {
    5.         _Tess ("Tessellation", Range(1,32)) = 4
    6.  
    7.     }
    8.     SubShader
    9.     {
    10.         Tags { "RenderType"="Opaque"  }
    11.         LOD 200
    12.        
    13.         Pass
    14.         {
    15.             Name "FORWARD"
    16.             Tags { "LightMode" = "ForwardBase" }
    17.  
    18.             CGPROGRAM
    19.             #pragma vertex VS
    20.             #pragma fragment FS
    21.             #pragma hull HS
    22.             #pragma domain DS
    23.  
    24.             #pragma target 5.0
    25.             #pragma multi_compile_fwdbase
    26.  
    27.             #include "UnityCG.cginc"
    28.             #include "Tessellation.cginc"          
    29.            
    30.             float _Tess;
    31.            
    32.             struct APP_OUTPUT
    33.             {
    34.                 float4 vertex : POSITION;
    35.             };
    36.  
    37.             struct VS_OUTPUT
    38.             {
    39.                 float4 vertex : INTERNALTESSPOS;
    40.             };
    41.                        
    42.             struct HS_OUTPUT
    43.             {
    44.                 float4 vertex : INTERNALTESSPOS;
    45.             };
    46.            
    47.             struct DS_OUTPUT
    48.             {
    49.                 float4 pos : POSITION;
    50.             };
    51.            
    52.             struct HS_CONSTANT_OUTPUT
    53.             {
    54.                 float edges[2] : SV_TessFactor;
    55.             };
    56.            
    57.                        
    58.             VS_OUTPUT VS (APP_OUTPUT v)
    59.             {
    60.                 VS_OUTPUT o;
    61.                 o.vertex = v.vertex;
    62.                 return o;
    63.             }
    64.            
    65.             HS_CONSTANT_OUTPUT HSConst()
    66.             {
    67.                 HS_CONSTANT_OUTPUT o;
    68.                
    69.                 o.edges[0] = _Tess;
    70.                 o.edges[1] = _Tess;
    71.                
    72.                 return o;
    73.             }
    74.  
    75.             [domain("isoline")]
    76.             [partitioning("integer")]
    77.             [outputtopology("line")]
    78.             [outputcontrolpoints(3)]
    79.             [patchconstantfunc("HSConst")]
    80.             HS_OUTPUT HS(InputPatch<VS_OUTPUT, 3> v, uint id : SV_OutputControlPointID)
    81.             {
    82.                 HS_OUTPUT o;
    83.                 o.vertex = v[id].vertex;
    84.                 return o;
    85.             }
    86.  
    87.             [domain("isoline")]
    88.             DS_OUTPUT DS(HS_CONSTANT_OUTPUT tessFactors, OutputPatch<HS_OUTPUT, 3> vi, float2 uv : SV_DomainLocation)
    89.             {
    90.                 float4 start = lerp(vi[0].vertex, vi[1].vertex, uv.x);
    91.  
    92.                 float4 vertex = lerp(start, vi[2].vertex, uv.y);
    93.  
    94.                 DS_OUTPUT o;
    95.                 o.pos = UnityObjectToClipPos(vertex);
    96.  
    97.                 return o;
    98.             }      
    99.  
    100.             fixed4 FS (DS_OUTPUT i) : SV_Target
    101.             {
    102.                 return fixed4(1,1,1,1);
    103.             }
    104.             ENDCG
    105.         }
    106.     }
    107. }
    108.  
    109.  
     
  21. aet

    aet

    Unity Technologies

    Joined:
    Jun 5, 2014
    Posts:
    44
    Apple's Metal Tessellation comes with some limitations, so currently domain("isoline") or outputtopology("line") / outputtopology("point") are not supported. Future update on the 2018.1 shader compiler will give a user visible error in the editor about this, thanks!