#ifndef __INSTANCING_INC #define __INSTANCING_INC #include "globals.cginc" #include "interpolators.cginc" void instance_distance_culling(inout v2f i) { #if defined(_INSTANCE_DISTANCE_CULLING) // We want to measure the distance from the instance's transform to the camera. float3 instance_pos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1)).xyz; float distance = length(_WorldSpaceCameraPos - instance_pos); if (distance > _Instance_Distance_Culling_Distance) { discard; } #endif // _INSTANCE_DISTANCE_CULLING } void instancing_frag(v2f i) { instance_distance_culling(i); } #endif // __INSTANCING_INC