Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to make "Enable GPU Instancing" checkbox appear on the shader?

Discussion in 'General Graphics' started by 5argon, Nov 18, 2017.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,554
    I have written a very basic shader as follows. What I have to add to enable GPU instancing?

    Code (CSharp):
    1. Shader "Unlit/NoteColor"
    2. {
    3.     Properties
    4.     {
    5.         _Color ("Main Color", Color) = (1,1,1,1)
    6.         _MainTex ("Texture", 2D) = "white"
    7.     }
    8.     SubShader
    9.     {
    10.         Tags { "RenderType"="Opaque" }
    11.  
    12.         Pass
    13.         {
    14.             ZWrite Off
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.             #pragma target 2.0
    19.            
    20.             #include "UnityCG.cginc"
    21.  
    22.             struct appdata
    23.             {
    24.                 float4 vertex : POSITION;
    25.                 float2 uv : TEXCOORD0;
    26.             };
    27.  
    28.             struct v2f
    29.             {
    30.                 float2 uv : TEXCOORD0;
    31.                 float4 vertex : SV_POSITION;
    32.             };
    33.  
    34.             sampler2D _MainTex;
    35.             float4 _MainTex_ST;
    36.             fixed4 _Color;
    37.            
    38.             v2f vert (appdata v)
    39.             {
    40.                 v2f o;
    41.                 o.vertex = UnityObjectToClipPos(v.vertex);
    42.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    43.                 return o;
    44.             }
    45.            
    46.             fixed4 frag (v2f i) : SV_Target
    47.             {
    48.                 fixed4 col = tex2D(_MainTex, i.uv);
    49.                 return col;
    50.             }
    51.             ENDCG
    52.         }
    53.     }
    54. }
    55.  
    For example, this checkbox is available in Mobile/Diffuse.

    Screenshot 2017-11-18 16.05.37.png
     
    AntofEVA likes this.
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,554
    Thanks. I have been there before but how did I miss that...
     
  4. maggie03230

    maggie03230

    Joined:
    May 23, 2017
    Posts:
    2
    #pragma multi_compile_instancing
     
  5. KarlKarl2000

    KarlKarl2000

    Joined:
    Jan 25, 2016
    Posts:
    592