Search Unity

Using tessellation shader on linux

Discussion in 'Linux' started by karthikkaranth, Feb 6, 2019.

  1. karthikkaranth

    karthikkaranth

    Joined:
    Feb 6, 2019
    Posts:
    6
    Hello,

    I'm trying to use a tessellation shader on Unity in Linux, but it seems to have no effect. I used the fixed amount of tessellation example:

    Code (CSharp):
    1. Shader "Tessellation Sample" {
    2.     Properties {
    3.         _Tess ("Tessellation", Range(1,32)) = 4
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         _DispTex ("Disp Texture", 2D) = "gray" {}
    6.         _NormalMap ("Normalmap", 2D) = "bump" {}
    7.         _Displacement ("Displacement", Range(0, 1.0)) = 0.3
    8.         _Color ("Color", color) = (1,1,1,0)
    9.         _SpecColor ("Spec color", color) = (0.5,0.5,0.5,0.5)
    10.     }
    11.     SubShader {
    12.         Tags { "RenderType"="Opaque" }
    13.         LOD 300
    14.      
    15.         CGPROGRAM
    16.         #pragma surface surf BlinnPhong addshadow fullforwardshadows vertex:disp tessellate:tessFixed nolightmap
    17.         #pragma target 4.6
    18.  
    19.         struct appdata {
    20.             float4 vertex : POSITION;
    21.             float4 tangent : TANGENT;
    22.             float3 normal : NORMAL;
    23.             float2 texcoord : TEXCOORD0;
    24.         };
    25.  
    26.         float _Tess;
    27.  
    28.         float4 tessFixed()
    29.         {
    30.             return _Tess;
    31.         }
    32.  
    33.         sampler2D _DispTex;
    34.         float _Displacement;
    35.  
    36.         void disp (inout appdata v)
    37.         {
    38.             float d = tex2Dlod(_DispTex, float4(v.texcoord.xy,0,0)).r * _Displacement;
    39.             v.vertex.xyz += v.normal * d;
    40.         }
    41.  
    42.         struct Input {
    43.             float2 uv_MainTex;
    44.         };
    45.  
    46.         sampler2D _MainTex;
    47.         sampler2D _NormalMap;
    48.         fixed4 _Color;
    49.  
    50.         void surf (Input IN, inout SurfaceOutput o) {
    51.             half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    52.             o.Albedo = c.rgb;
    53.             o.Specular = 0.2;
    54.             o.Gloss = 1.0;
    55.             o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
    56.         }
    57.         ENDCG
    58.     }
    59.     FallBack "Diffuse"
    60. }
    I've attached an image.

    Here are the details of my setup:
    Unity 2018.2.0
    OpenGL 4.5
    Ubuntu 18.04
    NVIDIA GTX1050Ti + 2080Ti
     

    Attached Files:

  2. Advis91

    Advis91

    Joined:
    Jun 20, 2017
    Posts:
    33
    Did you add textures? Got it to move the surface of cube, which distance them from their original position.

    Then I deleted the texture I added from shader using del key and now I get errors and pink texture ;)
    FIX: Oh, dont use alpha channel texture On normal map.
     
  3. karthikkaranth

    karthikkaranth

    Joined:
    Feb 6, 2019
    Posts:
    6
    Sorry, I was unclear. That's the displacement part. That is working correctly.

    The tessellation is not happening. Switch to wireframe mode, and see if the number of triangles on your mesh has increased. For me there is no effect. Changing the tessellation value on the material should increase the number of subdivided triangles formed.
     
  4. Advis91

    Advis91

    Joined:
    Jun 20, 2017
    Posts:
    33
    For me it is working, I have following textures in use:
    - Knob (Base) (just color...)
    - Default - Particle Texture 2D (Disp)
    - Default - Particle Texture 2D (Normal)
    Using Unity 2018.3.3f1
    Edit: The tesselation value on low has many corners, but when on max, it goes very smooth.
    Edit2: Oh, you wanted to transform the mesh? I think there's someone better to talk about it, but the new form isn't saved to mesh from draw currently. Shader currently only alters how it is drawn in GPU.
     
    Last edited: Feb 6, 2019
  5. karthikkaranth

    karthikkaranth

    Joined:
    Feb 6, 2019
    Posts:
    6
    Are you using OpenGL 4.5? What distro do you use?
     
  6. Advis91

    Advis91

    Joined:
    Jun 20, 2017
    Posts:
    33
  7. karthikkaranth

    karthikkaranth

    Joined:
    Feb 6, 2019
    Posts:
    6
    I am using Shaded+Wireframe mode. On a Windows setup, the tessellated triangles are visible in this mode.

    Is Unity using OpenGL 4.6 for you? While my version string is "OpenGL version string: 4.6.0 NVIDIA 410.48", Unity uses OpenGL 4.5(mentioned in the title bar of the editor)
     
  8. Advis91

    Advis91

    Joined:
    Jun 20, 2017
    Posts:
    33
    Ok, Unity title does say OpenGL 4.5
    Edit: Confirmed that windows does give new wireframe with this shader. Possibly linux version hasn't implemented this or it was forgotten to draw it. However this still doesn't change the mesh and it's just an additional draw call.
     
    Last edited: Feb 6, 2019
  9. karthikkaranth

    karthikkaranth

    Joined:
    Feb 6, 2019
    Posts:
    6
    Yes, I can observe some change in the mesh, but nothing in the wireframe.This is with the Phong tessellation shader

    What do you mean by "However this still doesn't change the mesh and it's just an additional draw call." ?
     
  10. Advis91

    Advis91

    Joined:
    Jun 20, 2017
    Posts:
    33
    My own bad assumption that you can forget. :oops:
    I'm learning shaders now as I don't really use them a lot (Thanks :D ).

    So unity doesn't update geometry to wireframe that was changed in tesselation shader in linux editor.
    It just stays in the same form as it was first given. (Read more about phong and tesselation in https://stackoverflow.com/a/16660645/6148331)

    Edit: Kinda looking forward to the fix. You should see how the geometry changes with the shader.
     
    Last edited: Feb 6, 2019
  11. karthikkaranth

    karthikkaranth

    Joined:
    Feb 6, 2019
    Posts:
    6
    Ah okay! A Unity bug then.

    While phong shading is entirely different, there does exist a phong tessellation. It smooths out the mesh during the tessellation pipeline.

    Unity has an example towards the bottom of this page.
     
  12. Advis91

    Advis91

    Joined:
    Jun 20, 2017
    Posts:
    33
    Thanks :D Might try making some shaders soon. There's no changes on 2019.1.0b2 either.