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

"Shader wants tangents, but the mesh doesn't have them"

Discussion in 'Shaders' started by egoquat, Aug 9, 2012.

  1. egoquat

    egoquat

    Joined:
    Jul 4, 2012
    Posts:
    93
    Hello all. I've got a error on shader codes which likes next.
    here are error messages "Shader wants tangents, but the mesh doesn't have them" .

    Code (csharp):
    1.  
    2. sampler2D _Control;
    3. sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
    4. sampler2D _ControlBumpMap;
    5.  
    6. //no vert only surf
    7.  
    8. void surf (Input IN, inout SurfaceOutput o) {
    9.     //o.Normal = normalize(tex2D(_ControlBumpMap, IN.uv_Control)); 
    10.     o.Normal = (0.0f, 1.0f, 0.0f, 1.0f);  //<----- This line occur error but don't know why.
    11.        
    12.     fixed4 splat_control = tex2D (_Control, IN.uv_Control);
    13.     fixed3 col;
    14.     col  = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb;
    15.     col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb;
    16.     col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb;
    17.     col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb;
    18.     o.Albedo = col;
    19.     o.Alpha = 0.0;
    20. }
    21.  

    Thanks all your help.
     
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    The unity terrain doesnt have tangents by default, you must calculate tangents manually in order to make bumpmapping work.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    and what kind is of normal is o.Normal = vector4 ?
    i guess it should be vector3

    btw. aubergine is completely right: you have to calculate tagents in the vertex programm.
    just get the terrain bump map shader from sixtimesnothing or anything related to it to get started with that.

    lars
     
  4. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    As the terrain's UVs only go one way, the tangent is always 1,0,0 but you'll have to gram-schmidt orthogonalize it to the normal before calculating the binormal.
     
  5. MagiKube

    MagiKube

    Joined:
    Jan 20, 2014
    Posts:
    1