public void Import(SyncLight syncLight, GameObject parent) { // Convert syncLight intensity to unity light intensity var intensity = k_DefaultIntensity; if (syncLight.Intensity > 0) { intensity = ImportersUtils.GetCandelasIntensity(syncLight.Intensity, syncLight.IntensityUnit, syncLight.Type, syncLight.SpotAngle); intensity = (float)(k_IntensityMultiplier * Math.Pow(intensity, k_IntensityExponent)); } // Compute the range if not provided var range = syncLight.Range; if (range <= 0) { range = (float)Math.Sqrt(intensity / k_IntensityAtRange); } // TODO Investigate why Light.UseColorTemperature is not exposed to C# and let the light do this calculation var cct = ImportersUtils.ColorFromTemperature(syncLight.Temperature); var filter = new Color(syncLight.Color.R, syncLight.Color.G, syncLight.Color.B); var light = parent.AddComponent <Light>(); light.color = cct * filter; light.colorTemperature = syncLight.Temperature; switch (syncLight.Type) { case SyncLightType.Spot: { light.spotAngle = syncLight.SpotAngle; light.shadows = LightShadows.Hard; light.range = range; light.type = LightType.Spot; light.intensity = intensity; } break; case SyncLightType.Point: { light.type = LightType.Point; light.range = range; light.intensity = intensity; } break; case SyncLightType.Directional: { light.type = LightType.Directional; light.intensity = intensity; } break; } }
protected void ExtractBasicMaterialInfo(SyncMaterial syncMaterial, out bool transparent, out bool emission, out Color color) { transparent = StandardShaderHelper.IsTransparent(syncMaterial); emission = syncMaterial.Emission != SyncColor.Black || syncMaterial.EmissionMap.TextureId != SyncId.None; var tint = ImportersUtils.GetUnityColor(syncMaterial.Tint, false); color = tint * ImportersUtils.GetUnityColor(syncMaterial.AlbedoColor, false); if (transparent) { color.a = syncMaterial.Alpha; } }
public static SyncObjectBinding CreateInstance(Transform root, string source, SyncObjectInstance instance, IObjectCache objectCache) { var objectKey = new StreamKey(source, PersistentKey.GetKey <SyncObject>(instance.ObjectId)); var syncObject = objectCache.CreateInstance(objectKey); if (syncObject == null) { Debug.LogWarning("Unable to instantiate SyncObject '" + instance.ObjectId + "'"); return(null); } var gameObject = syncObject.gameObject; gameObject.name = instance.Name; gameObject.transform.parent = root; ImportersUtils.SetTransform(gameObject.transform, instance.Transform); ImportersUtils.SetMetadata(gameObject, instance.Metadata); return(syncObject); }
protected override void SetMaterialPropertiesInternal(SyncedData <SyncMaterial> syncedMaterial, Material material, ITextureCache textureCache) { var syncMaterial = syncedMaterial.data; var sourceId = syncedMaterial.key.source; ExtractBasicMaterialInfo(syncMaterial, out var transparent, out var emission, out var color); // Albedo material.SetColor("_BaseColor", color); AssignMap(material, sourceId, "_BaseColorMap", syncMaterial.AlbedoMap, textureCache); // Metallic material.SetFloat("_Metallic", syncMaterial.Metallic); if (syncMaterial.MetallicMap.TextureId != SyncId.None) { // TODO } // Smoothness material.SetFloat("_Smoothness", syncMaterial.Glossiness); if (syncMaterial.GlossinessMap.TextureId != SyncId.None) { // TODO } // Normal if (syncMaterial.NormalMap.TextureId != SyncId.None) { AssignMap(material, sourceId, "_NormalMap", syncMaterial.NormalMap, textureCache); material.SetFloat("_NormalScale", syncMaterial.NormalScale); material.EnableKeyword("_NORMALMAP"); material.EnableKeyword("_NORMALMAP_TANGENT_SPACE"); } // Transparency if (!emission && transparent) { material.SetColor("_Color", color); material.SetFloat("_SurfaceType", 1); material.SetFloat("_BlendMode", 0); material.SetFloat("_DstBlend", 10); material.SetFloat("_AlphaDstBlend", 10); material.SetFloat("_AlphaCutoffEnable", 0); material.SetFloat("_EnableBlendModePreserveSpecularLighting", 1); material.renderQueue = (int)RenderQueue.Transparent; material.EnableKeyword("_BLENDMODE_ALPHA"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); } // Cutout // TODO Not supported? // Emission if (emission) { var emissionColor = ImportersUtils.GetUnityColor(syncMaterial.Emission); material.SetColor("_EmissiveColor", emissionColor); material.SetColor("_EmissiveColorLDR", emissionColor); if (syncMaterial.EmissionMap.TextureId != SyncId.None) { AssignMap(material, sourceId, "_EmissiveColorMap", syncMaterial.EmissionMap, textureCache); } material.SetInt("_UseEmissiveIntensity", 1); //material.EnableKeyword("_Emissive"); material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive; } }