Search Unity

Displacement + Transform Scale + Static Batching breaks?

Discussion in 'General Graphics' started by Chaiker, Dec 18, 2017.

  1. Chaiker

    Chaiker

    Joined:
    Apr 14, 2014
    Posts:
    63
    Hi there. I use this shader (from unity docs, but with vertex color) for displcament. And if i change scale of mesh (transform) to another from Vector3.one, and check static batching, so displacement will work differently on batched and not batched instancies with same scale. Why?

    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 5.0
    18.  
    19.             struct appdata {
    20.                 float4 vertex : POSITION;
    21.                 float4 tangent : TANGENT;
    22.                 float3 normal : NORMAL;
    23.                 float2 texcoord : TEXCOORD0;
    24.                 float4 color: COLOR;
    25.             };
    26.  
    27.             float _Tess;
    28.  
    29.             float4 tessFixed()
    30.             {
    31.                 return _Tess;
    32.             }
    33.  
    34.             sampler2D _DispTex;
    35.             float _Displacement;
    36.  
    37.             void disp (inout appdata v)
    38.             {
    39.                 float d = tex2Dlod(_DispTex, float4(v.texcoord.xy,0,0)).r * _Displacement;
    40.                 v.vertex.xyz += normalize(v.normal) * v.color * d;
    41.             }
    42.  
    43.             struct Input {
    44.                 float2 uv_MainTex;
    45.             };
    46.  
    47.             sampler2D _MainTex;
    48.             sampler2D _NormalMap;
    49.             fixed4 _Color;
    50.  
    51.             void surf (Input IN, inout SurfaceOutput o) {
    52.                 half4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    53.                 o.Albedo = c.rgb;
    54.                 o.Specular = 0.2;
    55.                 o.Gloss = 1.0;
    56.                 o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
    57.             }
    58.             ENDCG
    59.         }
    60.         FallBack "Diffuse"
    61.     }
    With batching and plane scale lower than Vector3.one:

    Without batching and plane scale lower than Vector3.one:
     
  2. Chaiker

    Chaiker

    Joined:
    Apr 14, 2014
    Posts:
    63
    Upd:
    It happens if i batch (static batching) instantiated meshes (clones).
    Right now i have next problem. I have vertex colored instantiated mesh (clone of plane). And when it's alone, it work okay. But, if they are more than one, it behave strange with batching (dynamic or static). Of course, if i disable dynamic batching, it will be work okay. You can see on video: