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. Dismiss Notice

[RELEASED] GPU Instancer

Discussion in 'Assets and Asset Store' started by LouskRad, May 3, 2018.

  1. dayframe

    dayframe

    Joined:
    Dec 13, 2017
    Posts:
    3
    I tried but still same error.
     
  2. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @Mr-EmiR
    Do you also use the "HDRenderPipeline/Lit" shader? For example, if you are using a shader which is made for Standard pipeline, they won't render in HDRP.
     
  3. torvald-mgt

    torvald-mgt

    Joined:
    Jun 14, 2015
    Posts:
    8
    Thanks, it helped.
     
  4. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Hi @LouskRad and @GurhanHazinedar ,

    Wonderful product! Fantastic work! The GPU occlusion culling practically seems like science fiction to me. Its all extremely impressive, and very usable in a serious production capacity, which I can only imagine how much work it took to get it there.

    We're trying to use AddPrefabInstance() and RemovePrefabInstance() but instead of of using a GPUInstancerPrefab with an attached gameobject, we'd like to use a no gameobject workflow and do it from a packed list of matrixes and a GPUInstancerPrefabPrototype. Perhaps I'm missing something in the API docs, but is this possible?

    In terms of what we're trying to achieve with this: Basically we're extremely GPU bound, and we're trying to unburden the GPU a little by combining it with some less granular prebaked culling that can be handled from C#. We have a _lot_ of objects and we don't want to use deactivated gameobjects because of how heavy they are.
     
  5. dayframe

    dayframe

    Joined:
    Dec 13, 2017
    Posts:
    3
    Of course I use hdrp lit shader.
    Today I'll tried to regenerate GPUI Shaders and create new clean project I got this two errors when i try regenerate shader and creating new project.

    Screenshot_162.png

    Screenshot_161.png
     
  6. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @djweinbaum
    I am happy to hear you like GPUI and thanks for your kind words. We do our best to make these complex operations easily accessible for both beginners and experienced developers. And you are right, it took a lot of work :)

    For an example usage of no-GameObject workflow you can take a look at this wiki documentation. It does not explain currently how to add/remove instances, so we will improve the documentation soon to include different usages. I will explain the basics here shortly:

    There are 2 main API methods that can be used for no-GameObject workflow.

    First one is InitializeWithMatrix4x4Array, which mainly allocates the required memory in the GPU and sets the data from the given Matrix4x4 array. This is enough to start the rendering process for the given objects.

    Second one is UpdateVisibilityBufferWithMatrix4x4Array, which updates the GPU memory with the given Matrix4x4 array. This is used to update the matrix data of the objects, when you want to move, rotate or scale the objects. It can also be also used for add or remove operations if there was enough allocated memory during initialization.

    The first method where the initialization happens, works slower because of setting up the GPU memory for the indirect instancing. The second one works much faster, because it only updates a portion of GPU memory.
    Because of this, the best way to add/remove objects is to start with a big enough array that can hold your maximum number of instances, and only reinitialize when required (e.g. when the allocated memory is not enough anymore or it is too big and you want to free up some GPU memory). For the extra indexes you have on the array, which are not used, can be set to Matrix4x4.zero. These will be discarded by GPUI's compute shaders automatically and will not be processed for rendering.
     
    PutridEx likes this.
  7. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @Mr-EmiR
    Thanks for sending the screenshot. It seems the include paths inside the generated shaders are wrong.
    You can fix it easily by changing the these paths to the correct location. I can't tell the exact location without knowing which HDRP version you are using. But you can easily find it from the Search tool, when you set it to search In Packages.

    upload_2019-3-7_17-11-17.png

    It might also be fixed by selecting Tools->GPU Instancer->Shaders->Clear Shader Bindinds. And choose Yes for both pop-ups. This will remove the generated shaders and recreate them when needed.

    This error might be result of a change in the GPUI folders or if the HDRP version is changed after the shader was created. We test the latest HDRP versions on the Package Manager on every feature update for GPUI (latest we tested on HDRP 4.10.0). It is important to note that HDRP is still in Preview and shaders and paths change for every HDRP version.
     
  8. txarly

    txarly

    Joined:
    Apr 27, 2016
    Posts:
    197
    hi, the tree manager fails with the floating point,I cannot exactly tell you where, because may be works well 3 days, but you change a tree, or add new ones, (in truth don´t know what it is) and some trees doesn´t move.I have noticed that GPUI tree manager proxy usually is present when this fails.Sometimes is duplicated.

    Screenshot_29.png

    I would like to give you more information but is difficult to know why fails.
     
  9. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Hi,
    I'm getting the following error when trying to modify the Standard Image Effect "EdgeDetect" shader:-

    Code (CSharp):
    1. Shader error in 'Hidden/EdgeDetect': failed to open source file: 'GPUInstancer/Resources/Shaders/Include/GPUInstancerInclude.cginc' at line 299 (on metal)
    2.  
    3. Compiling Vertex program
    4. Platform defines: UNITY_NO_DXT5nm UNITY_ENABLE_REFLECTION_BUFFERS UNITY_NO_CUBEMAP_ARRAY UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_DLDR_ENCODING
    5.  
    Using a Mac with the latest Unity 2018.3.

    The GPUInstancerInclude.cginc is at that location, the file isn't missing...

    Here is the EdgeDetect Shader in case I've put anything in the wrong place there..


    Code (CSharp):
    1.  
    2. Shader "Hidden/EdgeDetect" {
    3.     Properties {
    4.         _MainTex ("Base (RGB)", 2D) = "" {}
    5.     }
    6.  
    7.     CGINCLUDE
    8.    
    9.     #include "UnityCG.cginc"
    10.    
    11.     struct v2f {
    12.     UNITY_VERTEX_INPUT_INSTANCE_ID
    13.         float4 pos : SV_POSITION;
    14.         float2 uv[5] : TEXCOORD0;
    15.     };
    16.    
    17.     struct v2fd {
    18.     UNITY_VERTEX_INPUT_INSTANCE_ID
    19.         float4 pos : SV_POSITION;
    20.         float2 uv[2] : TEXCOORD0;
    21.     };
    22.  
    23.     sampler2D _MainTex;
    24.     uniform float4 _MainTex_TexelSize;
    25.     half4 _MainTex_ST;
    26.  
    27.     sampler2D _CameraDepthNormalsTexture;
    28.     half4 _CameraDepthNormalsTexture_ST;
    29.  
    30.     sampler2D_float _CameraDepthTexture;
    31.     half4 _CameraDepthTexture_ST;
    32.  
    33.     uniform half4 _Sensitivity;
    34.     uniform half4 _BgColor;
    35.     uniform half _BgFade;
    36.     uniform half _SampleDistance;
    37.     uniform float _Exponent;
    38.  
    39.     uniform float _Threshold;
    40.  
    41.     struct v2flum {
    42.     UNITY_VERTEX_INPUT_INSTANCE_ID
    43.         float4 pos : SV_POSITION;
    44.         float2 uv[3] : TEXCOORD0;
    45.     };
    46.  
    47.     v2flum vertLum (appdata_img v)
    48.     {
    49.         UNITY_SETUP_INSTANCE_ID(v);
    50.         v2flum o;
    51.  
    52.         o.pos = UnityObjectToClipPos(v.vertex);
    53.         float2 uv = MultiplyUV( UNITY_MATRIX_TEXTURE0, v.texcoord );
    54.         o.uv[0] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    55.         o.uv[1] = UnityStereoScreenSpaceUVAdjust(uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance, _MainTex_ST);
    56.         o.uv[2] = UnityStereoScreenSpaceUVAdjust(uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance, _MainTex_ST);
    57.         return o;
    58.     }
    59.  
    60.  
    61.     fixed4 fragLum (v2flum i) : SV_Target
    62.     {
    63.         fixed4 original = tex2D(_MainTex, i.uv[0]);
    64.  
    65.         // a very simple cross gradient filter
    66.  
    67.         half3 p1 = original.rgb;
    68.         half3 p2 = tex2D(_MainTex, i.uv[1]).rgb;
    69.         half3 p3 = tex2D(_MainTex, i.uv[2]).rgb;
    70.        
    71.         half3 diff = p1 * 2 - p2 - p3;
    72.         half len = dot(diff, diff);
    73.         len = step(len, _Threshold);
    74.         //if(len >= _Threshold)
    75.         //    original.rgb = 0;
    76.  
    77.         return len * lerp(original, _BgColor, _BgFade);          
    78.     }  
    79.    
    80.     inline half CheckSame (half2 centerNormal, float centerDepth, half4 theSample)
    81.     {
    82.         // difference in normals
    83.         // do not bother decoding normals - there's no need here
    84.         half2 diff = abs(centerNormal - theSample.xy) * _Sensitivity.y;
    85.         int isSameNormal = (diff.x + diff.y) * _Sensitivity.y < 0.1;
    86.         // difference in depth
    87.         float sampleDepth = DecodeFloatRG (theSample.zw);
    88.         float zdiff = abs(centerDepth-sampleDepth);
    89.         // scale the required threshold by the distance
    90.         int isSameDepth = zdiff * _Sensitivity.x < 0.09 * centerDepth;
    91.    
    92.         // return:
    93.         // 1 - if normals and depth are similar enough
    94.         // 0 - otherwise
    95.        
    96.         return isSameNormal * isSameDepth ? 1.0 : 0.0;
    97.     }  
    98.        
    99.     v2f vertRobert( appdata_img v )
    100.     {
    101.         UNITY_SETUP_INSTANCE_ID(v);
    102.  
    103.         v2f o;
    104.         o.pos = UnityObjectToClipPos(v.vertex);
    105.        
    106.         float2 uv = v.texcoord.xy;
    107.         o.uv[0] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    108.        
    109.         #if UNITY_UV_STARTS_AT_TOP
    110.         if (_MainTex_TexelSize.y < 0)
    111.             uv.y = 1-uv.y;
    112.         #endif
    113.                
    114.         // calc coord for the X pattern
    115.         // maybe nicer TODO for the future: 'rotated triangles'
    116.        
    117.         o.uv[1] = UnityStereoScreenSpaceUVAdjust(uv + _MainTex_TexelSize.xy * half2(1,1) * _SampleDistance, _MainTex_ST);
    118.         o.uv[2] = UnityStereoScreenSpaceUVAdjust(uv + _MainTex_TexelSize.xy * half2(-1,-1) * _SampleDistance, _MainTex_ST);
    119.         o.uv[3] = UnityStereoScreenSpaceUVAdjust(uv + _MainTex_TexelSize.xy * half2(-1,1) * _SampleDistance, _MainTex_ST);
    120.         o.uv[4] = UnityStereoScreenSpaceUVAdjust(uv + _MainTex_TexelSize.xy * half2(1,-1) * _SampleDistance, _MainTex_ST);
    121.                
    122.         return o;
    123.     }
    124.    
    125.     v2f vertThin( appdata_img v )
    126.     {
    127.         UNITY_SETUP_INSTANCE_ID(v);
    128.  
    129.         v2f o;
    130.         o.pos = UnityObjectToClipPos(v.vertex);
    131.        
    132.         float2 uv = v.texcoord.xy;
    133.         o.uv[0] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    134.        
    135.         #if UNITY_UV_STARTS_AT_TOP
    136.         if (_MainTex_TexelSize.y < 0)
    137.             uv.y = 1-uv.y;
    138.         #endif
    139.        
    140.         o.uv[1] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    141.         o.uv[4] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    142.                
    143.         // offsets for two additional samples
    144.         o.uv[2] = UnityStereoScreenSpaceUVAdjust(uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance, _MainTex_ST);
    145.         o.uv[3] = UnityStereoScreenSpaceUVAdjust(uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance, _MainTex_ST);
    146.        
    147.         return o;
    148.     }    
    149.    
    150.     v2fd vertD( appdata_img v )
    151.     {
    152.         UNITY_SETUP_INSTANCE_ID(v);
    153.  
    154.         v2fd o;
    155.         o.pos = UnityObjectToClipPos(v.vertex);
    156.        
    157.         float2 uv = v.texcoord.xy;
    158.         o.uv[0] = uv;
    159.        
    160.         #if UNITY_UV_STARTS_AT_TOP
    161.         if (_MainTex_TexelSize.y < 0)
    162.             uv.y = 1-uv.y;
    163.         #endif
    164.        
    165.         o.uv[1] = uv;
    166.        
    167.         return o;
    168.     }
    169.  
    170.     float4 fragDCheap(v2fd i) : SV_Target
    171.     {  
    172.         // inspired by borderlands implementation of popular "sobel filter"
    173.  
    174.         float centerDepth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv[1]));
    175.         float4 depthsDiag;
    176.         float4 depthsAxis;
    177.  
    178.         float2 uvDist = _SampleDistance * _MainTex_TexelSize.xy;
    179.  
    180.         depthsDiag.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist, _CameraDepthTexture_ST))); // TR
    181.         depthsDiag.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(-1,1), _CameraDepthTexture_ST))); // TL
    182.         depthsDiag.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(-1,1), _CameraDepthTexture_ST))); // BR
    183.         depthsDiag.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist, _CameraDepthTexture_ST))); // BL
    184.  
    185.         depthsAxis.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(0,1), _CameraDepthTexture_ST))); // T
    186.         depthsAxis.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(1,0), _CameraDepthTexture_ST))); // L
    187.         depthsAxis.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(1,0), _CameraDepthTexture_ST))); // R
    188.         depthsAxis.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(0,1), _CameraDepthTexture_ST))); // B
    189.  
    190.         depthsDiag -= centerDepth;
    191.         depthsAxis /= centerDepth;
    192.  
    193.         const float4 HorizDiagCoeff = float4(1,1,-1,-1);
    194.         const float4 VertDiagCoeff = float4(-1,1,-1,1);
    195.         const float4 HorizAxisCoeff = float4(1,0,0,-1);
    196.         const float4 VertAxisCoeff = float4(0,1,-1,0);
    197.  
    198.         float4 SobelH = depthsDiag * HorizDiagCoeff + depthsAxis * HorizAxisCoeff;
    199.         float4 SobelV = depthsDiag * VertDiagCoeff + depthsAxis * VertAxisCoeff;
    200.  
    201.         float SobelX = dot(SobelH, float4(1,1,1,1));
    202.         float SobelY = dot(SobelV, float4(1,1,1,1));
    203.         float Sobel = sqrt(SobelX * SobelX + SobelY * SobelY);
    204.  
    205.         Sobel = 1.0-pow(saturate(Sobel), _Exponent);
    206.         return Sobel * lerp(tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)), _BgColor, _BgFade);
    207.     }
    208.  
    209.     // pretty much also just a sobel filter, except for that edges "outside" the silhouette get discarded
    210.     //  which makes it compatible with other depth based post fx
    211.  
    212.     float4 fragD(v2fd i) : SV_Target
    213.     {  
    214.         // inspired by borderlands implementation of popular "sobel filter"
    215.  
    216.         float centerDepth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1], _CameraDepthTexture_ST)));
    217.         float4 depthsDiag;
    218.         float4 depthsAxis;
    219.  
    220.         float2 uvDist = _SampleDistance * _MainTex_TexelSize.xy;
    221.  
    222.         depthsDiag.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist, _CameraDepthTexture_ST))); // TR
    223.         depthsDiag.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(-1,1), _CameraDepthTexture_ST))); // TL
    224.         depthsDiag.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(-1,1), _CameraDepthTexture_ST))); // BR
    225.         depthsDiag.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist, _CameraDepthTexture_ST))); // BL
    226.  
    227.         depthsAxis.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(0,1), _CameraDepthTexture_ST))); // T
    228.         depthsAxis.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(1,0), _CameraDepthTexture_ST))); // L
    229.         depthsAxis.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(1,0), _CameraDepthTexture_ST))); // R
    230.         depthsAxis.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(0,1), _CameraDepthTexture_ST))); // B
    231.  
    232.         // make it work nicely with depth based image effects such as depth of field:
    233.         depthsDiag = (depthsDiag > centerDepth.xxxx) ? depthsDiag : centerDepth.xxxx;
    234.         depthsAxis = (depthsAxis > centerDepth.xxxx) ? depthsAxis : centerDepth.xxxx;
    235.  
    236.         depthsDiag -= centerDepth;
    237.         depthsAxis /= centerDepth;
    238.  
    239.         const float4 HorizDiagCoeff = float4(1,1,-1,-1);
    240.         const float4 VertDiagCoeff = float4(-1,1,-1,1);
    241.         const float4 HorizAxisCoeff = float4(1,0,0,-1);
    242.         const float4 VertAxisCoeff = float4(0,1,-1,0);
    243.  
    244.         float4 SobelH = depthsDiag * HorizDiagCoeff + depthsAxis * HorizAxisCoeff;
    245.         float4 SobelV = depthsDiag * VertDiagCoeff + depthsAxis * VertAxisCoeff;
    246.  
    247.         float SobelX = dot(SobelH, float4(1,1,1,1));
    248.         float SobelY = dot(SobelV, float4(1,1,1,1));
    249.         float Sobel = sqrt(SobelX * SobelX + SobelY * SobelY);
    250.  
    251.         Sobel = 1.0-pow(saturate(Sobel), _Exponent);
    252.         return Sobel * lerp(tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)), _BgColor, _BgFade);
    253.     }
    254.  
    255.     half4 fragRobert(v2f i) : SV_Target {              
    256.         half4 sample1 = tex2D(_CameraDepthNormalsTexture, i.uv[1].xy);
    257.         half4 sample2 = tex2D(_CameraDepthNormalsTexture, i.uv[2].xy);
    258.         half4 sample3 = tex2D(_CameraDepthNormalsTexture, i.uv[3].xy);
    259.         half4 sample4 = tex2D(_CameraDepthNormalsTexture, i.uv[4].xy);
    260.  
    261.         half edge = 1.0;
    262.        
    263.         edge *= CheckSame(sample1.xy, DecodeFloatRG(sample1.zw), sample2);
    264.         edge *= CheckSame(sample3.xy, DecodeFloatRG(sample3.zw), sample4);
    265.  
    266.         return edge * lerp(tex2D(_MainTex, i.uv[0]), _BgColor, _BgFade);
    267.     }
    268.    
    269.     half4 fragThin (v2f i) : SV_Target
    270.     {
    271.         half4 original = tex2D(_MainTex, i.uv[0]);
    272.        
    273.         half4 center = tex2D (_CameraDepthNormalsTexture, i.uv[1]);
    274.         half4 sample1 = tex2D (_CameraDepthNormalsTexture, i.uv[2]);
    275.         half4 sample2 = tex2D (_CameraDepthNormalsTexture, i.uv[3]);
    276.        
    277.         // encoded normal
    278.         half2 centerNormal = center.xy;
    279.         // decoded depth
    280.         float centerDepth = DecodeFloatRG (center.zw);
    281.        
    282.         half edge = 1.0;
    283.        
    284.         edge *= CheckSame(centerNormal, centerDepth, sample1);
    285.         edge *= CheckSame(centerNormal, centerDepth, sample2);
    286.            
    287.         return edge * lerp(original, _BgColor, _BgFade);
    288.     }
    289.    
    290.     ENDCG
    291.    
    292. Subshader {
    293. Pass {
    294.       ZTest Always Cull Off ZWrite Off
    295.  
    296.       CGPROGRAM
    297.       #include "UnityCG.cginc"
    298.     #include "GPUInstancer/Resources/Shaders/Include/GPUInstancerInclude.cginc"
    299.       #pragma multi_compile_instancing
    300.     #pragma instancing_options procedural:setupGPUI
    301.       #pragma vertex vertThin
    302.       #pragma fragment fragThin
    303.       ENDCG
    304.   }
    305. Pass {
    306.       ZTest Always Cull Off ZWrite Off
    307.  
    308.       CGPROGRAM
    309.       #include "UnityCG.cginc"
    310.     #include "GPUInstancer/Resources/Shaders/Include/GPUInstancerInclude.cginc"
    311.       #pragma multi_compile_instancing
    312.     #pragma instancing_options procedural:setupGPUI
    313.       #pragma vertex vertRobert
    314.       #pragma fragment fragRobert
    315.       ENDCG
    316.   }
    317. Pass {
    318.       ZTest Always Cull Off ZWrite Off
    319.  
    320.       CGPROGRAM
    321.       #include "UnityCG.cginc"
    322.     #include "GPUInstancer/Resources/Shaders/Include/GPUInstancerInclude.cginc"
    323.       #pragma multi_compile_instancing
    324.     #pragma instancing_options procedural:setupGPUI
    325.       #pragma target 3.0  
    326.       #pragma vertex vertD
    327.       #pragma fragment fragDCheap
    328.       ENDCG
    329.   }
    330. Pass {
    331.       ZTest Always Cull Off ZWrite Off
    332.  
    333.       CGPROGRAM
    334.       #include "UnityCG.cginc"
    335.     #include "GPUInstancer/Resources/Shaders/Include/GPUInstancerInclude.cginc"
    336.       #pragma multi_compile_instancing
    337.     #pragma instancing_options procedural:setupGPUI
    338.       #pragma target 3.0  
    339.       #pragma vertex vertD
    340.       #pragma fragment fragD
    341.       ENDCG
    342.   }
    343. Pass {
    344.       ZTest Always Cull Off ZWrite Off
    345.  
    346.       CGPROGRAM
    347.       #include "UnityCG.cginc"
    348.     #include "GPUInstancer/Resources/Shaders/Include/GPUInstancerInclude.cginc"
    349.       #pragma multi_compile_instancing
    350.     #pragma instancing_options procedural:setupGPUI
    351.       #pragma target 3.0  
    352.       #pragma vertex vertLum
    353.       #pragma fragment fragLum
    354.       ENDCG
    355.   }
    356. }
    357.  
    358. Fallback off
    359.    
    360. } // shader
    361.  
    Apart for this the asset is amazing and has sped up my project a ton!
     
  10. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @txarly
    I sent you a fix for this by e-mail in Feb 27. Did it not work? Or maybe you did not see it? There were some files attached, maybe it fell in your spam folder. If the mail is lost, send us another e-mail at support@gurbu.com and I will send the files again.
     
    Last edited: Mar 8, 2019
  11. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @wxxhrt
    With the 1.0 update, we moved the Shaders out of the Resources folder. Usually the shaders are updated automatically but maybe this shader reference was lost during import. You can fix it by changing include paths from this:
    Code (CSharp):
    1. #include "GPUInstancer/Resources/Shaders/Include/GPUInstancerInclude.cginc"
    to this:
    Code (CSharp):
    1. #include "GPUInstancer/Shaders/Include/GPUInstancerInclude.cginc"
     
  12. txarly

    txarly

    Joined:
    Apr 27, 2016
    Posts:
    197
    we will test again that fix and tell you something, but i think is not working.
     
  13. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    Came across this asset...

    Does the occlusion culling works for all asset in the game, or only "prototypes" added to the manager?

    Does it use the last frame depth buffer or is built from something else?
     
  14. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Hi @GurhanHazinedar I've made the changes you've suggested but I'm still getting the failed to open source file error, clicking on the error in the console gives me this:-
    Code (CSharp):
    1. Shader error in 'Hidden/EdgeDetect': failed to open source file: 'GPUInstancer/Shaders/Include/GPUInstancerInclude.cginc' at line 296 (on metal)
    2.  
    3. Compiling Vertex program
    4. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR
    5.  
    This is with a new project with just GPUInstancer and Standard Image Effects installed for the asset store. Running Mojave 10.14.3.

    EDIT:-

    Following on from this thread-

    https://forum.unity.com/threads/include-custom-cginc-files.94518/

    I moved the Edge Detect Shader I'm trying to get work from its original location to the GPUInstancer/Shaders folder and changed the include to:-

    Code (CSharp):
    1. #include "Include/GPUInstancerInclude.cginc"
    2.  
    And it kind of works, well 3 of the 5 Edge Detection modes work bu the ones I'm wanting Roberts Cross Depth and Triangle Luminance are not working, no errors just not displaying the edges, here is the shader, it would be amazing if you could take a look and see if I need to alter anything :-


    Code (CSharp):
    1.  
    2. Shader "Hidden/EdgeDetect" {
    3.     Properties {
    4.         _MainTex ("Base (RGB)", 2D) = "" {}
    5.     }
    6.  
    7.     CGINCLUDE
    8.    
    9.     #include "UnityCG.cginc"
    10.    
    11.     struct v2f {
    12.         UNITY_VERTEX_INPUT_INSTANCE_ID
    13.         float4 pos : SV_POSITION;
    14.         float2 uv[5] : TEXCOORD0;
    15.     };
    16.    
    17.     struct v2fd {
    18.         UNITY_VERTEX_INPUT_INSTANCE_ID
    19.         float4 pos : SV_POSITION;
    20.         float2 uv[2] : TEXCOORD0;
    21.     };
    22.  
    23.     sampler2D _MainTex;
    24.     uniform float4 _MainTex_TexelSize;
    25.     half4 _MainTex_ST;
    26.  
    27.     sampler2D _CameraDepthNormalsTexture;
    28.     half4 _CameraDepthNormalsTexture_ST;
    29.  
    30.     sampler2D_float _CameraDepthTexture;
    31.     half4 _CameraDepthTexture_ST;
    32.  
    33.     uniform half4 _Sensitivity;
    34.     uniform half4 _BgColor;
    35.     uniform half _BgFade;
    36.     uniform half _SampleDistance;
    37.     uniform float _Exponent;
    38.  
    39.     uniform float _Threshold;
    40.  
    41.     struct v2flum {
    42.         UNITY_VERTEX_INPUT_INSTANCE_ID
    43.         float4 pos : SV_POSITION;
    44.         float2 uv[3] : TEXCOORD0;
    45.     };
    46.  
    47.     v2flum vertLum (appdata_img v)
    48.     {
    49.         v2flum o;
    50.         UNITY_SETUP_INSTANCE_ID(v);
    51.  
    52.         o.pos = UnityObjectToClipPos(v.vertex);
    53.         float2 uv = MultiplyUV( UNITY_MATRIX_TEXTURE0, v.texcoord );
    54.         o.uv[0] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    55.         o.uv[1] = UnityStereoScreenSpaceUVAdjust(uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance, _MainTex_ST);
    56.         o.uv[2] = UnityStereoScreenSpaceUVAdjust(uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance, _MainTex_ST);
    57.         return o;
    58.     }
    59.  
    60.  
    61.     fixed4 fragLum (v2flum i) : SV_Target
    62.     {
    63.         fixed4 original = tex2D(_MainTex, i.uv[0]);
    64.  
    65.         // a very simple cross gradient filter
    66.  
    67.         half3 p1 = original.rgb;
    68.         half3 p2 = tex2D(_MainTex, i.uv[1]).rgb;
    69.         half3 p3 = tex2D(_MainTex, i.uv[2]).rgb;
    70.        
    71.         half3 diff = p1 * 2 - p2 - p3;
    72.         half len = dot(diff, diff);
    73.         len = step(len, _Threshold);
    74.         //if(len >= _Threshold)
    75.         //    original.rgb = 0;
    76.  
    77.         return len * lerp(original, _BgColor, _BgFade);          
    78.     }  
    79.    
    80.     inline half CheckSame (half2 centerNormal, float centerDepth, half4 theSample)
    81.     {
    82.         // difference in normals
    83.         // do not bother decoding normals - there's no need here
    84.         half2 diff = abs(centerNormal - theSample.xy) * _Sensitivity.y;
    85.         int isSameNormal = (diff.x + diff.y) * _Sensitivity.y < 0.1;
    86.         // difference in depth
    87.         float sampleDepth = DecodeFloatRG (theSample.zw);
    88.         float zdiff = abs(centerDepth-sampleDepth);
    89.         // scale the required threshold by the distance
    90.         int isSameDepth = zdiff * _Sensitivity.x < 0.09 * centerDepth;
    91.    
    92.         // return:
    93.         // 1 - if normals and depth are similar enough
    94.         // 0 - otherwise
    95.        
    96.         return isSameNormal * isSameDepth ? 1.0 : 0.0;
    97.     }  
    98.        
    99.     v2f vertRobert( appdata_img v )
    100.     {
    101.  
    102.         v2f o;
    103.         UNITY_SETUP_INSTANCE_ID(v);
    104.         o.pos = UnityObjectToClipPos(v.vertex);
    105.        
    106.         float2 uv = v.texcoord.xy;
    107.         o.uv[0] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    108.        
    109.         #if UNITY_UV_STARTS_AT_TOP
    110.         if (_MainTex_TexelSize.y < 0)
    111.             uv.y = 1-uv.y;
    112.         #endif
    113.                
    114.         // calc coord for the X pattern
    115.         // maybe nicer TODO for the future: 'rotated triangles'
    116.        
    117.         o.uv[1] = UnityStereoScreenSpaceUVAdjust(uv + _MainTex_TexelSize.xy * half2(1,1) * _SampleDistance, _MainTex_ST);
    118.         o.uv[2] = UnityStereoScreenSpaceUVAdjust(uv + _MainTex_TexelSize.xy * half2(-1,-1) * _SampleDistance, _MainTex_ST);
    119.         o.uv[3] = UnityStereoScreenSpaceUVAdjust(uv + _MainTex_TexelSize.xy * half2(-1,1) * _SampleDistance, _MainTex_ST);
    120.         o.uv[4] = UnityStereoScreenSpaceUVAdjust(uv + _MainTex_TexelSize.xy * half2(1,-1) * _SampleDistance, _MainTex_ST);
    121.                
    122.         return o;
    123.     }
    124.    
    125.     v2f vertThin( appdata_img v )
    126.     {
    127.  
    128.         v2f o;
    129.         UNITY_SETUP_INSTANCE_ID(v);
    130.         o.pos = UnityObjectToClipPos(v.vertex);
    131.        
    132.         float2 uv = v.texcoord.xy;
    133.         o.uv[0] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    134.        
    135.         #if UNITY_UV_STARTS_AT_TOP
    136.         if (_MainTex_TexelSize.y < 0)
    137.             uv.y = 1-uv.y;
    138.         #endif
    139.        
    140.         o.uv[1] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    141.         o.uv[4] = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
    142.                
    143.         // offsets for two additional samples
    144.         o.uv[2] = UnityStereoScreenSpaceUVAdjust(uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance, _MainTex_ST);
    145.         o.uv[3] = UnityStereoScreenSpaceUVAdjust(uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance, _MainTex_ST);
    146.        
    147.         return o;
    148.     }    
    149.    
    150.     v2fd vertD( appdata_img v )
    151.     {
    152.  
    153.         v2fd o;
    154.         UNITY_SETUP_INSTANCE_ID(v);
    155.         o.pos = UnityObjectToClipPos(v.vertex);
    156.        
    157.         float2 uv = v.texcoord.xy;
    158.         o.uv[0] = uv;
    159.        
    160.         #if UNITY_UV_STARTS_AT_TOP
    161.         if (_MainTex_TexelSize.y < 0)
    162.             uv.y = 1-uv.y;
    163.         #endif
    164.        
    165.         o.uv[1] = uv;
    166.        
    167.         return o;
    168.     }
    169.  
    170.     float4 fragDCheap(v2fd i) : SV_Target
    171.     {  
    172.         // inspired by borderlands implementation of popular "sobel filter"
    173.  
    174.         float centerDepth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv[1]));
    175.         float4 depthsDiag;
    176.         float4 depthsAxis;
    177.  
    178.         float2 uvDist = _SampleDistance * _MainTex_TexelSize.xy;
    179.  
    180.         depthsDiag.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist, _CameraDepthTexture_ST))); // TR
    181.         depthsDiag.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(-1,1), _CameraDepthTexture_ST))); // TL
    182.         depthsDiag.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(-1,1), _CameraDepthTexture_ST))); // BR
    183.         depthsDiag.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist, _CameraDepthTexture_ST))); // BL
    184.  
    185.         depthsAxis.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(0,1), _CameraDepthTexture_ST))); // T
    186.         depthsAxis.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(1,0), _CameraDepthTexture_ST))); // L
    187.         depthsAxis.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(1,0), _CameraDepthTexture_ST))); // R
    188.         depthsAxis.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(0,1), _CameraDepthTexture_ST))); // B
    189.  
    190.         depthsDiag -= centerDepth;
    191.         depthsAxis /= centerDepth;
    192.  
    193.         const float4 HorizDiagCoeff = float4(1,1,-1,-1);
    194.         const float4 VertDiagCoeff = float4(-1,1,-1,1);
    195.         const float4 HorizAxisCoeff = float4(1,0,0,-1);
    196.         const float4 VertAxisCoeff = float4(0,1,-1,0);
    197.  
    198.         float4 SobelH = depthsDiag * HorizDiagCoeff + depthsAxis * HorizAxisCoeff;
    199.         float4 SobelV = depthsDiag * VertDiagCoeff + depthsAxis * VertAxisCoeff;
    200.  
    201.         float SobelX = dot(SobelH, float4(1,1,1,1));
    202.         float SobelY = dot(SobelV, float4(1,1,1,1));
    203.         float Sobel = sqrt(SobelX * SobelX + SobelY * SobelY);
    204.  
    205.         Sobel = 1.0-pow(saturate(Sobel), _Exponent);
    206.         return Sobel * lerp(tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)), _BgColor, _BgFade);
    207.     }
    208.  
    209.     // pretty much also just a sobel filter, except for that edges "outside" the silhouette get discarded
    210.     //  which makes it compatible with other depth based post fx
    211.  
    212.     float4 fragD(v2fd i) : SV_Target
    213.     {  
    214.         // inspired by borderlands implementation of popular "sobel filter"
    215.  
    216.         float centerDepth = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1], _CameraDepthTexture_ST)));
    217.         float4 depthsDiag;
    218.         float4 depthsAxis;
    219.  
    220.         float2 uvDist = _SampleDistance * _MainTex_TexelSize.xy;
    221.  
    222.         depthsDiag.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist, _CameraDepthTexture_ST))); // TR
    223.         depthsDiag.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(-1,1), _CameraDepthTexture_ST))); // TL
    224.         depthsDiag.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(-1,1), _CameraDepthTexture_ST))); // BR
    225.         depthsDiag.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist, _CameraDepthTexture_ST))); // BL
    226.  
    227.         depthsAxis.x = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(0,1), _CameraDepthTexture_ST))); // T
    228.         depthsAxis.y = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(1,0), _CameraDepthTexture_ST))); // L
    229.         depthsAxis.z = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]+uvDist*float2(1,0), _CameraDepthTexture_ST))); // R
    230.         depthsAxis.w = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, UnityStereoScreenSpaceUVAdjust(i.uv[1]-uvDist*float2(0,1), _CameraDepthTexture_ST))); // B
    231.  
    232.         // make it work nicely with depth based image effects such as depth of field:
    233.         depthsDiag = (depthsDiag > centerDepth.xxxx) ? depthsDiag : centerDepth.xxxx;
    234.         depthsAxis = (depthsAxis > centerDepth.xxxx) ? depthsAxis : centerDepth.xxxx;
    235.  
    236.         depthsDiag -= centerDepth;
    237.         depthsAxis /= centerDepth;
    238.  
    239.         const float4 HorizDiagCoeff = float4(1,1,-1,-1);
    240.         const float4 VertDiagCoeff = float4(-1,1,-1,1);
    241.         const float4 HorizAxisCoeff = float4(1,0,0,-1);
    242.         const float4 VertAxisCoeff = float4(0,1,-1,0);
    243.  
    244.         float4 SobelH = depthsDiag * HorizDiagCoeff + depthsAxis * HorizAxisCoeff;
    245.         float4 SobelV = depthsDiag * VertDiagCoeff + depthsAxis * VertAxisCoeff;
    246.  
    247.         float SobelX = dot(SobelH, float4(1,1,1,1));
    248.         float SobelY = dot(SobelV, float4(1,1,1,1));
    249.         float Sobel = sqrt(SobelX * SobelX + SobelY * SobelY);
    250.  
    251.         Sobel = 1.0-pow(saturate(Sobel), _Exponent);
    252.         return Sobel * lerp(tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(i.uv[0].xy, _MainTex_ST)), _BgColor, _BgFade);
    253.     }
    254.  
    255.     half4 fragRobert(v2f i) : SV_Target {
    256.             UNITY_SETUP_INSTANCE_ID(i);
    257.            
    258.         half4 sample1 = tex2D(_CameraDepthNormalsTexture, i.uv[1].xy);
    259.         half4 sample2 = tex2D(_CameraDepthNormalsTexture, i.uv[2].xy);
    260.         half4 sample3 = tex2D(_CameraDepthNormalsTexture, i.uv[3].xy);
    261.         half4 sample4 = tex2D(_CameraDepthNormalsTexture, i.uv[4].xy);
    262.  
    263.         half edge = 1.0;
    264.        
    265.         edge *= CheckSame(sample1.xy, DecodeFloatRG(sample1.zw), sample2);
    266.         edge *= CheckSame(sample3.xy, DecodeFloatRG(sample3.zw), sample4);
    267.  
    268.         return edge * lerp(tex2D(_MainTex, i.uv[0]), _BgColor, _BgFade);
    269.     }
    270.    
    271.     half4 fragThin (v2f i) : SV_Target
    272.     {
    273.         half4 original = tex2D(_MainTex, i.uv[0]);
    274.        
    275.         half4 center = tex2D (_CameraDepthNormalsTexture, i.uv[1]);
    276.         half4 sample1 = tex2D (_CameraDepthNormalsTexture, i.uv[2]);
    277.         half4 sample2 = tex2D (_CameraDepthNormalsTexture, i.uv[3]);
    278.        
    279.         // encoded normal
    280.         half2 centerNormal = center.xy;
    281.         // decoded depth
    282.         float centerDepth = DecodeFloatRG (center.zw);
    283.        
    284.         half edge = 1.0;
    285.        
    286.         edge *= CheckSame(centerNormal, centerDepth, sample1);
    287.         edge *= CheckSame(centerNormal, centerDepth, sample2);
    288.            
    289.         return edge * lerp(original, _BgColor, _BgFade);
    290.     }
    291.    
    292.     ENDCG
    293.    
    294. Subshader {
    295. Pass {
    296.       ZTest Always Cull Off ZWrite Off
    297.  
    298.       CGPROGRAM
    299.       #include "UnityCG.cginc"
    300. #include "Include/GPUInstancerInclude.cginc"
    301.       #pragma multi_compile_instancing
    302.     #pragma instancing_options procedural:setupGPUI
    303.       #pragma vertex vertThin
    304.       #pragma fragment fragThin
    305.       ENDCG
    306.   }
    307. Pass {
    308.       ZTest Always Cull Off ZWrite Off
    309.  
    310.       CGPROGRAM
    311.       #include "UnityCG.cginc"
    312. #include "Include/GPUInstancerInclude.cginc"
    313.       #pragma multi_compile_instancing
    314.     #pragma instancing_options procedural:setupGPUI
    315.       #pragma vertex vertRobert
    316.       #pragma fragment fragRobert
    317.       ENDCG
    318.   }
    319. Pass {
    320.       ZTest Always Cull Off ZWrite Off
    321.  
    322.       CGPROGRAM
    323.       #include "UnityCG.cginc"
    324. #include "Include/GPUInstancerInclude.cginc"
    325.       #pragma multi_compile_instancing
    326.     #pragma instancing_options procedural:setupGPUI
    327.       #pragma target 3.0  
    328.       #pragma vertex vertD
    329.       #pragma fragment fragDCheap
    330.       ENDCG
    331.   }
    332. Pass {
    333.       ZTest Always Cull Off ZWrite Off
    334.  
    335.       CGPROGRAM
    336.       #include "UnityCG.cginc"
    337. #include "Include/GPUInstancerInclude.cginc"
    338.       #pragma multi_compile_instancing
    339.     #pragma instancing_options procedural:setupGPUI
    340.       #pragma target 3.0  
    341.       #pragma vertex vertD
    342.       #pragma fragment fragD
    343.       ENDCG
    344.   }
    345. Pass {
    346.       ZTest Always Cull Off ZWrite Off
    347.  
    348.       CGPROGRAM
    349.       #include "UnityCG.cginc"
    350. #include "Include/GPUInstancerInclude.cginc"
    351.       #pragma multi_compile_instancing
    352.     #pragma instancing_options procedural:setupGPUI
    353.       #pragma target 3.0  
    354.       #pragma vertex vertLum
    355.       #pragma fragment fragLum
    356.       ENDCG
    357.   }
    358. }
    359.  
    360. Fallback off
    361.    
    362. } // shader
    363.  
     
    Last edited: Mar 9, 2019
  15. Glitch12

    Glitch12

    Joined:
    Mar 23, 2018
    Posts:
    29
    Hello i test GPUInstancer but i have a problem with MainCamera.
    Can anyone tell me should I add to Player scripts so GPUInstancer can detect MainCamera.

    I apologize for my bad English.

    https://ibb.co/fMF6k6g


    PS: I added scripts GPUInstancerCameraHandler to Player and works, but if this is not the right way please write.
     
    Last edited: Mar 10, 2019
  16. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi there,
    Occlusion Culling is only for the prototypes added to the managers and it is designed to work well with objects which are suitable for GPU Instancing (with high instance counts). It does not effect other objects, and you can still use other solutions like Unity's built-in occlusion culling for the remaining objects.
    Yes, it uses the last frame depth buffer.
     
  17. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @wxxhrt
    Yes, you need to define a path relative to the folder that the shader file is in.

    The problem with the shader might be the depth order but I am not sure. If you can e-mail us a sample project and a screenshot showing the problem, we might be able to figure out what the problem is.
     
  18. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @Glitch12
    You can use the GPUInstancerCameraHandler. We added this component for use cases where you activate or change the camera during Play time. You can attach this component to the GameObjects with the Camera components, and it will automatically set the camera to the GPUI Managers when the Camera is activated.
     
    Glitch12 likes this.
  19. PicturesInDark

    PicturesInDark

    Joined:
    Jun 13, 2013
    Posts:
    89
    Last edited: Mar 11, 2019
  20. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,

    Yes, this looks like it would be an example case of a shader that does not define the UNITY_VERTEX_INPUT_INSTANCE_ID or set it up in the vertex function. If by "Hidden" shader, you mean a Unity built in shader, you can download it's source from the Unity Archives and put it anywhere in your project. Unity will use that file instead of the one embedded in the engine. You can edit the shader from there.

    If the shader is such a built-in shader, the manager should also be showing a warning for the prototype that uses it and gives you a button to quickly access the download link.

    On the other hand, if what you mean by "Hidden" shader is simply a shader that does not show in the inspector, it is a file that exists in your project but is not shown because its name starts with "/Hidden/...". You can simply edit such shaders by locating their files in your project.

    Please let us know if you need any further help with this.
     
    PicturesInDark likes this.
  21. PicturesInDark

    PicturesInDark

    Joined:
    Jun 13, 2013
    Posts:
    89
    Yes, it is the last case. Hidden/Nature/... In a material inside the tree prefab. I will find and I'll give a try. Thanks
     
  22. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    Sad... We already have a rather complex rendering pipeline and some rather huge scene with hundred of different objects type. (hundred of thousand of instances)

    Would be awesome if we could just supply an array of bounds (Maybe a depth map too), and have it return which are occluded or not.
     
  23. ohbado

    ohbado

    Joined:
    Aug 13, 2014
    Posts:
    37
    Hi.
    I split the scene with Terrain and BG objects and only enable them when the player approaches.
    All those scenes are initially disabled.
    DetailManager is also set to those divided scenes along with Terrain.The main camera requested by DetailManager is dynamically set from script.
    However, DetailManager does not work with errors when it is enabled.
    Do you have a good idea?

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    GPUInstancer.GPUInstancerDetailManager+<MergeVisibilityBufferFromActiveCellsCoroutine>c__Iterator1.MoveNext () (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:719)
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    GPUInstancer.GPUInstancerDetailManager:StartCoroutineAlt(IEnumerator) (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:560)
    GPUInstancer.GPUInstancerDetailManager:UpdateSpatialPartitioningCells(GPUInstancerCameraData) (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:151)
    GPUInstancer.GPUInstancerManager:UpdateBuffers(GPUInstancerCameraData) (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:508)
    GPUInstancer.GPUInstancerManager:LateUpdate() (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:239)​
     
  24. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    It looks like GPUI's internal runtime data list is changed after manager initialization - the counts that are registered do not match the counts at initialization. How are you handling the prototypes, and are you making any changes to internal variables?

    You can email us the relevant code sample that you are using and we can help identify the issue.
     
  25. PicturesInDark

    PicturesInDark

    Joined:
    Jun 13, 2013
    Posts:
    89
    Shader corrected. Now, the thress with colour are above camera Sin nombre.png Sin nombre2.png
     
  26. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    PicturesInDark likes this.
  27. PicturesInDark

    PicturesInDark

    Joined:
    Jun 13, 2013
    Posts:
    89
    Shader sended. Thanks
     
  28. PicturesInDark

    PicturesInDark

    Joined:
    Jun 13, 2013
    Posts:
    89
    No, this leads me to first situation. White trees around the camera.

    A momentary solution is to pass from Deferred to Forward rendering and disable HBAO plugin

    Regards
     
  29. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    Thanks so much for this in depth answer! The bit about setting the matrix to zero to not draw it was the part I was missing, and I would have never guessed that! I was able to get it all working now :).
     
    LouskRad and GurhanH like this.
  30. PicturesInDark

    PicturesInDark

    Joined:
    Jun 13, 2013
    Posts:
    89
    Thank you for your support. Now with the shader changes it works perfectly. Very good job! This is an awesome plugin
     
    LouskRad and GurhanH like this.
  31. ohbado

    ohbado

    Joined:
    Aug 13, 2014
    Posts:
    37
    Thank you.
    I sent an email about the sample code.
     
  32. peeka

    peeka

    Joined:
    Dec 3, 2014
    Posts:
    113
    for GC optimization, can you replace all the foreach with for when iteration through list? I would go in and change it myself but will have to merge when you release new update...
     
  33. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @peeka

    Foreach loops iterating over a List<T> should not create heap allocations. If you are referring to an old GC optimization documentation, there was unnecessary boxing which resulted in heap allocations prior to Unity 5.5. But this is no longer an issue for the newer compilers.
    During our tests, we did not see any GC allocations caused by GPUI update methods. If you see any unnecessary allocations, please send us the profiler data so that we can investigate.
     
    peeka likes this.
  34. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    422
    Hi @GurhanHazinedar Looking at the video 'GPU Instancer Tutorial - Detail Manager - Terrain Grass and Vegetation', it mentions that prototypes added to the Detail Manager have their Shader updated in order to support the GPU Instancing.
    - Can you clarify whether this is done to the original shader file itself, or is a copy created? I'm wondering if I need to back-up my original shaders if I want to use them in the same project but without GPU Instancer.
     
  35. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,

    GPUI creates a copy of the original shader with the "_GPUI" suffix in the file name, and keeps track of the original shader so that it re-generates its own copy when you make changes to the original.

    Thus you do not need to back-up your original shaders.
     
    jeromeWork likes this.
  36. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    422
    Yay! thanks for thinking of that in your code :)
     
    LouskRad likes this.
  37. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    to the author: First of all I want to tell you that I am impressed by this plugin and we are currently evaluating it to use in our future product.

    I have two questions:

    Do you think it would be possible to find a way to set the compute buffers outside the main thread? I am not sure if the upload to the GPU is async or not and what the synchronization points are, but I still wonder if it's possible.

    As creator of Svelto.ECS I wonder if I could use the plugin somehow to build my new demos. Currently I use Unity ECS renderer as it's surely not my intention to write a rendering framework in ECS, but I could just simply use compute shaders and your plugin too. However I understand that it may not be possible as there couldn't be any way for me to distribute it in my open source projects. I would be an interesting experiment never the less though.
     
    Last edited: Mar 20, 2019
  38. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there,
    and thank you for your kind words.

    Unity requires the SetData method that is used to set the compute buffers to be run on the main thread. There is, however, an overload which allows you to set partial data to the compute buffers, which could be used inside coroutines for achieving an effect similar to setting them async. We use this in some initialization code where it would be better.

    You are of course free to use GPUI in your demo builds, but not allowed to share the source code. Your intended usage definitely sounds interesting; if you need any help with using GPUI, please feel free to contact us.
     
  39. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    thank you a lot for your quick reply, I will then distribute the dll as if my demo were a game made with GPUI. This is of course for my personal projects, for my company projects, I will keep you updated!
     
  40. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    I'm afraid distributing GPUI as a dll is also not allowed since it could be re-usable in other projects. You can use GPUI in a build you make with Unity, but not in a Unity project that you distribute.

    Distribution in any form is not allowed by the Unity Asset Store Eula, you can check the section #2 of Asset Store End User License Agreement.
     
  41. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,594
    hmm I don't need to distribute the dll in the repository with the source code, but it seems I would be able to distribute the demo as executable as long as not part of the source code? It's a bit weird though as I may decide to build GPU instancer using asmdef therefore the dll could be taken from the bundled demo.
    Hence if you have a preferred way for me to show how to use GPUI with Svelto.ECS, I will be open to suggestions.
     
  42. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi there, and thanks!

    You can take a look at the included PrefabsWithoutGameObjects scene as an example for this. The GPUI API has two methods that you can use to define instance based variations by supplying the GPUI prototype and the colours that you want in an array. For this, you can use DefineAndAddVariationFromArray<T> and UpdateVariationFromArray<T>.
     
  43. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    One option would be to distribute your integration code in your repository and declare that the user needs to download GPUI from the Asset Store to compile/run the project. You could then distribute your demo build as an executable that showcases how the project would run with GPUI (pretty much like our demo builds).

    I am not really an expert on the copyright issues, you could ask the Unity support team to make sure since GPUI is bound by the Untiy EULA.
     
    sebas77 likes this.
  44. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    422
    Hi @GurhanHazinedar Started using GPU Instancer and very impressed with performance, but I'm finding that the Max Details Distance is capped - going above 80 makes no difference. Going the other way does reduce the distance as expected.

    I've seen this mentioned before on this forum by @shamsfk and all things that were mentioned didn't apply to me either.
    - Individual prototypes have their Max Distance set high (equal to the Max distance I want)
    - no LODs are being used on the prototypes.

    Did you ever find a solution to this?
     
  45. GurhanH

    GurhanH

    Joined:
    Apr 24, 2017
    Posts:
    474
    Hi @jeromeWork
    If there are multiple cameras in your scene, make sure that the correct camera is set on the manager. You can also try to disable Frustum and Occlusion Culling and if your objects starts to render, this usually means that the wrong camera is being used.
    upload_2019-3-21_2-55-0.png

    If this is not the case, please send us an e-mail with information on your manager setup and prototypes, so that we can investigate. If possible a sample project would be even better.
     
    jeromeWork likes this.
  46. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    422
    Thanks, sadly not multiple cameras. Sending you an email :)
     
  47. LouskRad

    LouskRad

    Joined:
    Feb 18, 2014
    Posts:
    904
    Hi Jerome,
    I have replied to your mail with this, but will also write here in case anyone faces the same issue.

    The max visible distance not being set correctly issue is caused by a material setting on the Meadow Environment asset. The grass that use the Advanced Grass Specular shader from this asset have a property on them called CullFarStart. When used on the Unity terrain, this property does not change anything since Unity uses its own shader, but GPUI runs the original shader to its full extent, and thus limits the visible distance to this value.

    You can simply increase this value on the materials that your prefabs use to solve this problem:

    upload_2019-3-21_20-58-26.png
     
    jeromeWork likes this.
  48. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    422
    Top marks for not just finding that but for taking the time to debug in such a thorough way. Now that deserves a 5 star review on the asset store! :D Thank you
     
    LouskRad and GurhanH like this.
  49. jeromeWork

    jeromeWork

    Joined:
    Sep 1, 2015
    Posts:
    422
    @LouskRad @GurhanHazinedar Are there any recommendations for using the Detail and Tree Managers on multiple terrains?
    I'm finding GPUI great on a single 512x512 terrain (200+ fps) using the Detail and Tree Managers but if I chunk this into quarters (256x256) I see a drastic fps drop (55fps).
    - at first I thoughts this might be caused by the reduced coverage (as the Best Practice docs mention, you get higher gains if there a large amounts of objects - so with less foliage per manager you get lower gains?)
    ... but then I tried copying the 512x512 terrain twice and similarly see a large drop.

    Not only that, but when I play the scene (driving down a road) the first terrain section plays fine, but towards the end of the second, just as the third is about to appear, I get a huge spikes on the profiler and the game (as well as the editor) come to a stuttering freeze.

    Running happily at 55fps:

    Start of spikes:


    I'm wanting to do an async scene load of each tile using WorldStreamer but as there are always likely to be at least three tiles loaded, it doesn't look like it's going to work.

    Any ideas, much appreciated! :)
     
  50. MTandi

    MTandi

    Joined:
    Aug 4, 2017
    Posts:
    10
    Hello!

    I have a 32x32 terrain that is getting resized to 128x128 on start and then I call
    GPUInstancerAPI.InitializeGPUInstancer(detailManager);


    After updating to the latest version of GPUInstancer, I'm getting following error during details manager initialization:

    IndexOutOfRangeException: Array index is out of range.
    GPUInstancer.GPUInstancerUtility.MirrorAndFlatten[Single] (System.Single[,] array2D, Int32 xBase, Int32 yBase, Int32 width, Int32 height) (at Assets/GPUInstancer/Scripts/Core/Static/GPUInstancerUtility.cs:2667)
    GPUInstancer.GPUInstancerDetailManager.FillCellsDetailDataThread (System.Object parameter) (at Assets/GPUInstancer/Scripts/GPUInstancerDetailManager.cs:1013)
    UnityEngine.Debug:LogException(Exception)
    GPUInstancer.GPUInstancerManager:LogThreadException() (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:744)
    GPUInstancer.GPUInstancerManager:Update() (at Assets/GPUInstancer/Scripts/Core/Contract/GPUInstancerManager.cs:217)

    It seems that during initialization, GPUInstancer uses previous size (array2D float[33, 33]).

    Am I missing something here?