public MaterialVariable Register(IMaterial material, IRenderTechnique technique) { if (material == null || technique.IsNull) { return(EmptyMaterialVariable.EmptyVariable); } var guid = material.Guid; var techGuid = technique.GUID; lock (dictionary) { if (dictionary.TryGetValue(guid, techGuid, out MaterialVariable value)) { value.IncRef(); return(value); } else { var v = material.CreateMaterialVariables(effectsManager, technique); v.Initialize(); v.Disposed += (s, e) => { lock (dictionary) { dictionary.Remove(guid, techGuid); } }; dictionary.Add(guid, techGuid, v); if (IDMAX - (ushort)Count > 1000) { IDMAX = 0; foreach (var m in dictionary) { m.Value.ID = ++IDMAX; } } else { v.ID = ++IDMAX; } return(v); } } }