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

Lost on shader for linux.

Discussion in 'Shaders' started by grobonom, May 30, 2022.

  1. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    Hi all.

    I spent the day on this shader:
    Code (CSharp):
    1. Shader "My_shaders/Unlit/amb_nite_transition"
    2. {
    3.     Properties
    4.     {
    5.       _MainTex ("Diffuse", 2D) = "white" {}
    6.       _NiteColor ("Night lights Color", Color) = (1, 1, 1, 1)
    7.      
    8.          _Ambient_factor("Ambient dif. fact.", Float) = 1
    9.      
    10.         _TransitionDist("Transition dist", Float) = 100
    11.     }
    12.     SubShader
    13.     {
    14.  
    15.         Pass
    16.         {
    17.         //        Tags {"Queue"="Geometry" "RenderType"="Opaque" }
    18.         //Tags {"Queue"="Geometry" "RenderType"="Transparent" "IgnoreProjector"="True" }
    19.         //LOD 100
    20.        
    21.         //Cull off
    22.  
    23.             CGPROGRAM
    24.            
    25.             #pragma require geometry
    26.  
    27.             #pragma multi_compile_local ___ WITH_WORLD_NIGHTLIGHTS
    28.            
    29.             #pragma vertex vertex_program
    30.             #pragma geometry geometry_program
    31.             #pragma fragment fragment_program
    32.             #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
    33.  
    34.             // make fog work
    35.          //   #pragma multi_compile_fog
    36.  
    37.             #include "UnityCG.cginc"
    38.            
    39.            
    40.             struct APP2V
    41.             {
    42.                float4 vertex : POSITION;
    43.                half3 normal: NORMAL;
    44.                fixed2 UV : TEXCOORD0;
    45.             };
    46.  
    47.             struct V2G
    48.             {
    49.                float4 pos : SV_POSITION;
    50.                fixed2 UV : TEXCOORD0;
    51.                half4 posWorld: TEXCOORD1;
    52.          //      UNITY_FOG_COORDS(2)
    53.             };
    54.            
    55.             struct G2F
    56.             {
    57.                float4 pos : SV_POSITION;
    58.             //   half fade_factor: COLOR0; // transition IN/OUT fade to ambient factor
    59.                fixed2 UV : TEXCOORD0;
    60.         //       UNITY_FOG_COORDS(1)
    61.             };
    62.  
    63.             sampler2D _MainTex;
    64.             fixed4 _MainTex_ST;
    65.                 fixed _Ambient_factor;
    66.             static const half _TransitionColorSpread=4;
    67.             static const float _TransitionMessFactor=20;
    68.             half _TransitionDist;
    69. #if defined(WITH_WORLD_NIGHTLIGHTS)
    70.             fixed4 _NiteColor;
    71. #endif
    72.  
    73.  
    74.  
    75.             V2G vertex_program (APP2V v)
    76.             {
    77.             V2G o;
    78.  
    79.                o.posWorld = mul( unity_ObjectToWorld, v.vertex);
    80.                o.pos = v.vertex;
    81.              
    82. //               o.vertex = UnityObjectToClipPos(v.vertex);
    83.              
    84.                o.UV = v.UV;//TRANSFORM_TEX(v.uv, _MainTex);
    85.              
    86.     //           UNITY_TRANSFER_FOG(o,o.pos);
    87.                return o;
    88.             }
    89.            
    90.          inline float random11(float p)
    91.          {
    92.              p = frac(p * .1031);
    93.              p *= p + 33.33;
    94.              p *= p + p;
    95.           //   return((frac(p)-0.5)*2);  //-1 to +1
    96.              return frac(p);  //0 to +1
    97.            
    98.          }
    99.          //========================================================================
    100.  
    101.  
    102.          // geometry program
    103.        
    104.          [maxvertexcount(3)]
    105.          void geometry_program(triangle V2G IN[3], inout TriangleStream<G2F> triStream)
    106.          {
    107.             G2F o;
    108.       //      half4 displace_effect;
    109.  
    110.     //        half3 a= half3(random11(IN[0].posWorld),random11(IN[1].posWorld),random11(IN[2].posWorld));
    111.  
    112.            
    113.   //          float3 tri_in_cam = _WorldSpaceCameraPos.xyz - (IN[0].posWorld.xyz+IN[1].posWorld.xyz+IN[2].posWorld.xyz)/3;
    114. //            half tri_dist = length(tri_in_cam);
    115.  
    116.            
    117.             // quand TransitionDist < 0 on inverse le mess far/near
    118.             // idem plus bas pour le fade au blanc....
    119.             //if(_TransitionDist >= 0.0)
    120.           //     displace_effect = half4(a.xyz*_TransitionMessFactor*clamp(sqrt(tri_dist)-_TransitionDist,0,60),0);
    121.         //    else
    122.       //         displace_effect = half4(a.xyz*_TransitionMessFactor*clamp(-_TransitionDist-sqrt(tri_dist),0,60),0);
    123.  
    124.             for(int i = 0; i < 3; i++)
    125.             {
    126.                o.pos = UnityObjectToClipPos(IN[i].pos);//+displace_effect);
    127.  
    128.             //   UNITY_TRANSFER_FOG(o,o.pos);
    129.              
    130.                o.UV = IN[i].UV;
    131.              
    132.                //if(_TransitionDist >= 0.0)
    133.                  // o.fade_factor = saturate(length(_TransitionMessFactor*sqrt(tri_dist)-_TransitionDist)/50-(_TransitionDist/_TransitionColorSpread));
    134.                //else
    135.                 //  o.fade_factor = saturate(length(-_TransitionMessFactor*_TransitionDist-sqrt(tri_dist))/50-(_TransitionDist/_TransitionColorSpread));
    136.               // o.fade_factor=1;
    137.                triStream.Append(o);
    138.             }
    139.  
    140.             triStream.RestartStrip();
    141.          }        
    142.            
    143.  
    144.            
    145.            
    146.             fixed4 fragment_program (G2F i) : SV_Target
    147.             {
    148.                // sample the texture
    149.           //     fixed4 c = tex2D(_MainTex, i.UV);
    150.                
    151.             //        fixed3 outputColor = c.rgb*UNITY_LIGHTMODEL_AMBIENT.rgb*_Ambient_factor;
    152.              
    153. #if defined(WITH_WORLD_NIGHTLIGHTS)
    154.           //     fixed3 nite_lights = _NiteColor*c.a;
    155.                
    156.             //        outputColor += c.rgb*nite_lights;//*_LightStrength;              
    157. #endif              
    158.              
    159.                // coming IN and OUT color setting
    160.            //    outputColor = lerp(outputColor,UNITY_LIGHTMODEL_AMBIENT.rgb,i.fade_factor);
    161.            
    162.              
    163.                // apply fog
    164.             //   UNITY_APPLY_FOG(i.fogCoord, outputColor);
    165.              
    166. //               return fixed4(outputColor,1);
    167.                return fixed4(1,1,1,1);
    168.             }
    169.             ENDCG
    170.         }
    171.     }
    172. }
    173.  
    I commented out everything !
    When i compile it to target, on windows it draws a simple white object but on debian10 it ALWAYS draws a pink thing.

    This makes me crazy as i stripped almost everything and it just don't work at all !

    Please could anyone with an new eye tell me what i'm missing ?

    Thanks a lot !

    Happy unitying !
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Hi!
    Check the Editor.log - it should say why it's rendering pink. Likely the shader is not supported by your GPU driver.
     
  3. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    hi @aleksandrk and thanks for your answer :)

    The problem i have is that the pink appears on the compiled app running on linux debian10.
    In editor ( under windows 7 ) all works fine.

    The app log on linux ( .config/Unity3D......./Player.log ) it says that this shader is not compatible with this GPU.

    I also got other shaders with geometry program that do not throw this error. ( thought they do not work properly but it is another topic^^ )
    My conclusion is that i do something wrong in this shader but i'm totally unable to se what's wrong :/

    I think i will rewrite all and go on digging....

    Happy unitying !
     
  4. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    hm. This is quite strange and looks like some malfunction in unity compilation of shaders for OpenGL^^
    The editor i use ( where all works fine under windows ) is a 2020.3.20f1
    I don't know wether it has known bugs on linux target shaders ?

    Though i use Debian10 under VMWARE, it runs OpenGL3.3 and works fine on any other SM5 shaders....
    Someone also ran the app on a native ( non VirtualMachined ) Debian and it works the same: shader incompatible with GPU.

    Moreover, none of may shaders having a geometry program, work. Strangely, they are not marked as incompatible, they seem to load properly with no error but they simply do nothing at all^^
    When i copy a shader with geometry program, that raises no error, to my amb_nite shader, it also raises an error.

    There's some mishandling somewhere i believe....

    If anyone can help it would really be appreciated :)

    Happy unitying !
     
  5. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    bumpies :)