protected void ShotLight() { if (hitBody != null && hitBody.gameObject.layer == LayerMask.NameToLayer("LightDetector")) { LightDetectorPuzzle newHitScript = (hitBody.transform.parent.gameObject).GetComponent <LightDetectorPuzzle>(); Assert.IsNotNull(newHitScript); // remove last if (hitScript != newHitScript) { RemoveLightPointInDetector(); } // create or update new hitScript = newHitScript; LightInfo info = new LightInfo(); info.name = gameObject.ToString(); info.eulerAngles = transform.eulerAngles; info.raycastLayer = raycastLayer; info.hitPoint = hitPoint; hitScript.AddLightPoint(gameObject, info); isHit = true; } else { RemoveLightPointInDetector(); } }
public void GetNextZone(int upOrDown) { if (upOrDown + mainGame.currentZone > lowestFloor) { lowestFloor = upOrDown + mainGame.currentZone; } if (upOrDown < 0 && mainGame.currentZone == 0) { player.hasControl = false; LightSource.canUpdate = false; StartCoroutine(Instance.FadeScreen(false, () => { SceneManager.LoadScene(3); })); } else { mainGame.GetNextZone(upOrDown); int test1 = mainGame.currentZone; LightInfo test2 = lightLevelsPerUpgrade[lightUpgrade - 1]; if (lightLevelsPerUpgrade.Count < lightUpgrade - 1 && lightLevelsPerUpgrade[lightUpgrade - 1].lightLevelPerFloor.Count < mainGame.currentZone) { LightSource.SetLightLevel(lightLevelsPerUpgrade[lightUpgrade - 1].lightLevelPerFloor[mainGame.currentZone]); } } }
public void Register(LightInfo light) { LightBehaviour l = light.Light; l.Init(); l.transform.parent = transform; }
void CreateReflectLight() { foreach (KeyValuePair <GameObject, LightInfo> kvp in lights) { if (reflectLights.ContainsKey(kvp.Key) == false) { GameObject reflect = new GameObject(); reflect.transform.parent = transform; ReflectLightPuzzle script = reflect.AddComponent <ReflectLightPuzzle>(); Assert.IsNotNull(script); script.raycastLayer = kvp.Value.raycastLayer; reflectLights.Add(kvp.Key, reflect); } else { GameObject reflect = reflectLights[kvp.Key]; Assert.IsNotNull(reflect); LightInfo lightInfo = kvp.Value; Vector3 point = new Vector3(lightInfo.hitPoint.x, lightInfo.hitPoint.y, transform.position.z); Vector3 offset = transform.TransformDirection(Vector3.up) * 0.1f; point -= offset; reflect.transform.position = point; float normalizeMirrorAngle = transform.eulerAngles.z > 0.0f ? transform.eulerAngles.z : transform.eulerAngles.z + 360.0f; float normalizeLightAngle = lightInfo.eulerAngles.z > 0.0f ? lightInfo.eulerAngles.z : lightInfo.eulerAngles.z + 360.0f; float angleOffset = normalizeMirrorAngle - normalizeLightAngle; float angles = 0.0f; angles = -180.0f + angleOffset; angles = angles > 0.0f ? angles : angles + 360.0f; reflect.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, angles); } } }
static void Main(string[] args) { RemoteControlInfo remoteControl = new RemoteControlInfo(); LightInfo livingRoomLight = new LightInfo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); Console.WriteLine("--== Living Room Light ==--"); remoteControl.OnButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); CeilingFanInfo drawingRoomCeilingFan = new CeilingFanInfo("Drawing Room"); CeilingFanHighCommand drawingRoomCeilingFanHigh = new CeilingFanHighCommand(drawingRoomCeilingFan); CeilingFanLowCommand drawingRoomCeilingFanLow = new CeilingFanLowCommand(drawingRoomCeilingFan); remoteControl.SetCommand(1, drawingRoomCeilingFanHigh, drawingRoomCeilingFanLow); Console.WriteLine("--== Drawing Room Ceiling Fan ==--"); remoteControl.OnButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OffButtonWasPushed(1); Console.ReadLine(); }
public Light(Colour32 ambient, Colour32 diffuse, Colour32 specular, double spec_power = 1000.0, v4?direction = null, v4?position = null) : this( direction != null ? LightInfo.Directional(direction.Value, ambient, diffuse, specular, (float)spec_power, 0) : position != null ? LightInfo.Point(position.Value, ambient, diffuse, specular, (float)spec_power, 0) : LightInfo.Ambient(ambient)) { }
public CustomMarkerLightInfo(LightInfo hi) : this() { LI = hi; //string c = AppDomain.CurrentDomain.BaseDirectory; //string path = c + @"Image\Markers\" + ((int)li.RealTimeFault).ToString() + ".png"; //image.Source = new BitmapImage(new Uri(path, UriKind.Absolute)); //ellipse.ToolTip = tooltip; //this.ToolTip = tooltip; //popup = new Popup(); //label = new Label(); //popup.Placement = PlacementMode.Mouse; //label.Background = Brushes.Blue; //label.Foreground = Brushes.White; //label.BorderBrush = Brushes.WhiteSmoke; //label.BorderThickness = new Thickness(2); //label.Padding = new Thickness(5); //label.FontSize = 22; //label.Content = tooltip; //popup.Child = label; //this.MouseEnter += CustomMarkerLightInfo_MouseEnter; //this.MouseLeave += CustomMarkerLightInfo_MouseLeave; }
public ELight(LightInfo info) { this.LightInfo = info; position = info.transMatrix.GetPosition(); rotation = info.transMatrix.GetRotation().eulerAngles; scale = info.transMatrix.GetScale(); }
public GameObject CreateLight(DetectionBox box, Vector3 hitPoint, bool debug = false) { if (PointLightPrefab == null) { Debug.Log("please assign to light prefab."); return(null); } GameObject lightObject = Instantiate(PointLightPrefab); lightObject.transform.position = hitPoint; lightObject.transform.eulerAngles = Quaternion.identity.eulerAngles; lightObject.transform.SetParent(this.gameObject.transform); LightInfo lightInfo = new LightInfo() { position = lightObject.transform.position, rotation = lightObject.transform.eulerAngles, light = ApplyLightProperties(lightObject, box), collider = lightObject.GetComponent <BoxCollider>() }; AddLight(lightInfo); if (debug) { CreateDebugBox(lightInfo, box); } return(lightObject); }
public void StopDynamicLight(string name) { if (!string.IsNullOrEmpty(name)) { LightInfo info = _activeDynamicLights.Find(delegate(LightInfo li) { return(li._name == name); }); StopDynamicLightInternal(info); } }
public bool Update(LightInfo li) { if (li != null) { return(new BLL.tLightInfoes().Update(li.T)); } return(false); }
public bool Add(LightInfo li) { if (li != null) { return(new BLL.tLightInfoes().Add(li.T)); } return(false); }
public void MapRefreshLightInfo(LightInfo light, LightInfoLightGroupInfo newLightInfoGroupInfo, LightInfoLightGroupInfo backLightInfoGroupInfo) { // 更新地图,如果存在 GMapMarker g; if (appState.MapDatas.DicLightInfoMarker.TryGetValue(light.GUID, out g)) { g.Position = new PointLatLng(light.Lat, light.Lng); //((CustomMarkerLightInfo)g.Shape).Title = light.Name; } // 更新左侧树形 if (newLightInfoGroupInfo != backLightInfoGroupInfo) { // 移除旧的分组 TreeHostInfo thi = null; TreeLightGroupInfo tlgi = null; TreeLightInfo tli = null; foreach (TreeGroupInfo t in appState.TreeDatas.TreeGroupInfos) { thi = t.TreeHostInfos.FirstOrDefault(a => a.HostInfo.GUID == light.HostGUID); if (thi != null) { break; } } if (backLightInfoGroupInfo != null) { if (thi != null) { tlgi = thi.TreeLightGroupInfos.FirstOrDefault(a => a.LightGroupInfo.GUID != "" && a.LightGroupInfo.GUID.Trim() == backLightInfoGroupInfo.LightGroupInfoGUID.Trim()); if (tlgi != null) { tli = tlgi.TreeLightInfos.FirstOrDefault(a => a.LightInfo.GUID.Trim() == light.GUID.Trim()); if (tli != null) { tlgi.TreeLightInfos.Remove(tli); } } } } // 增加新的分组 if (thi != null) { tlgi = thi.TreeLightGroupInfos.FirstOrDefault(a => a.LightGroupInfo.GUID.Trim() == newLightInfoGroupInfo.LightGroupInfoGUID.Trim()); if (tlgi != null) { tlgi.TreeLightInfos.Add(new TreeLightInfo() { LightInfo = light }); } } } }
// Update is called once per frame void Update() { if (loaded) { if (useTestFog && Camera.main.renderingPath == RenderingPath.DeferredShading) { // Fog doesn't work for deferred Camera.main.renderingPath = RenderingPath.Forward; } bool fogSet = false; if (simulateSectorLoading) { for (int i = 0; i < lights.Count; i++) { LightInfo l = lights[i]; if (l.containingSectors.FirstOrDefault(s => (neighborSectorLights ? s.Loaded : s.Active)) != null) { l.Light.Activate(); if (useTestFog && l.type == 6 && !fogSet) { RenderSettings.fog = true; RenderSettings.fogColor = Color.Lerp(RenderSettings.fogColor, l.Light.color, 0.5f * Time.deltaTime); RenderSettings.fogMode = FogMode.Linear; RenderSettings.fogStartDistance = Mathf.Lerp(RenderSettings.fogStartDistance, l.near, 0.5f * Time.deltaTime); RenderSettings.fogEndDistance = Mathf.Lerp(RenderSettings.fogEndDistance, l.far * 5f, 0.5f * Time.deltaTime); Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, l.Light.backgroundColor, 0.5f * Time.deltaTime); fogSet = true; } } else { l.Light.Deactivate(); } } } else { for (int i = 0; i < lights.Count; i++) { LightInfo l = lights[i]; l.Light.Activate(); } } if (useTestFog && !fogSet) { Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, Color.black, 0.5f * Time.deltaTime); RenderSettings.fogColor = Color.Lerp(RenderSettings.fogColor, Color.black, 0.5f * Time.deltaTime); RenderSettings.fogStartDistance += 50 * Time.deltaTime; RenderSettings.fogEndDistance += 50 * Time.deltaTime; if (RenderSettings.fogStartDistance > 500) { RenderSettings.fog = false; } } } }
static void GenerateLightmapInfo(GameObject root, List <RendererInfo> rendererInfos, List <Texture2D> lightmaps, List <Texture2D> lightmapsDir, List <Texture2D> shadowMasks, List <LightInfo> lightsInfo) { var renderers = root.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer renderer in renderers) { if (renderer.lightmapIndex != -1) { RendererInfo info = new RendererInfo(); info.renderer = renderer; if (renderer.lightmapScaleOffset != Vector4.zero) { //1ibrium's pointed out this issue : https://docs.unity3d.com/ScriptReference/Renderer-lightmapIndex.html if (renderer.lightmapIndex < 0 || renderer.lightmapIndex == 0xFFFE) { continue; } info.lightmapOffsetScale = renderer.lightmapScaleOffset; Texture2D lightmap = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapColor; Texture2D lightmapDir = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapDir; Texture2D shadowMask = LightmapSettings.lightmaps[renderer.lightmapIndex].shadowMask; info.lightmapIndex = lightmaps.IndexOf(lightmap); if (info.lightmapIndex == -1) { info.lightmapIndex = lightmaps.Count; lightmaps.Add(lightmap); lightmapsDir.Add(lightmapDir); shadowMasks.Add(shadowMask); } rendererInfos.Add(info); } } } var lights = root.GetComponentsInChildren <Light>(true); foreach (Light l in lights) { LightInfo lightInfo = new LightInfo(); lightInfo.light = l; lightInfo.lightmapBaketype = (int)l.lightmapBakeType; #if UNITY_2020_1_OR_NEWER lightInfo.mixedLightingMode = (int)UnityEditor.Lightmapping.lightingSettings.mixedBakeMode; #elif UNITY_2018_1_OR_NEWER lightInfo.mixedLightingMode = (int)UnityEditor.LightmapEditorSettings.mixedBakeMode; #else lightInfo.mixedLightingMode = (int)l.bakingOutput.lightmapBakeType; #endif lightsInfo.Add(lightInfo); } }
/// <summary> /// 增加单灯与分组的真正关系 /// </summary> /// <param name="l"></param> /// <param name="t"></param> public void UIAddLightInfoLightGroupInfo(LightInfo l, TreeLightGroupInfo t) { // 更新左侧列表 if (t != null) { t.TreeLightInfos.Add(new TreeLightInfo() { LightInfo = l }); } }
public ConditionLight(ConditionIds id, ConditionFlags type, int ticks, bool buff, uint subId, byte lightLevel, byte lightColor) : base(id, type, ticks, buff, subId) { LightInfo = new LightInfo { Level = lightLevel, Color = lightColor }; InternalLightTicks = 0; LightChangeInterval = 0; }
public static LightInfo GetLightSourceInfo(Map map, LightType type) { float num = GenLocalDate.DayPercent(map); bool flag; float intensity; switch (type) { case LightType.Shadow: flag = IsDaytime(CurCelestialSunGlow(map)); intensity = CurShadowStrength(map); break; case LightType.LightingSun: flag = true; intensity = Mathf.Clamp01((CurCelestialSunGlow(map) - 0.6f + 0.2f) / 0.15f); break; case LightType.LightingMoon: flag = false; intensity = Mathf.Clamp01((0f - (CurCelestialSunGlow(map) - 0.6f - 0.2f)) / 0.15f); break; default: Log.ErrorOnce("Invalid light type requested", 64275614); flag = true; intensity = 0f; break; } float t; float num2; float num3; if (flag) { t = num; num2 = -1.5f; num3 = 15f; } else { t = ((!(num > 0.5f)) ? (0.5f + Mathf.InverseLerp(0f, 0.5f, num) * 0.5f) : (Mathf.InverseLerp(0.5f, 1f, num) * 0.5f)); num2 = -0.9f; num3 = 15f; } float num4 = Mathf.LerpUnclamped(0f - num3, num3, t); float y = num2 - 2.5f * (num4 * num4 / 100f); LightInfo result = default(LightInfo); result.vector = new Vector2(num4, y); result.intensity = intensity; return(result); }
internal override LightInfo ToLightInfo() { LightInfo li = new LightInfo(); li.intensity = Intensity; li.position = Position; li.direction = new Mathematics.Vector3(float.NaN); li.color = Color.ToVector(); li.isShadowCaster = IsShadowCaster; li.type = LightType.Point; return(li); }
void bwRealData_DoWork(object sender, DoWorkEventArgs e) { //throw new NotImplementedException(); while (true) { if (bwRealData.CancellationPending) { break; } if (!bwLoadData.IsBusy) { // 请求最新的数据 this.Dispatcher.Invoke((Action)(() => { ShowState("更新后台数据中..."); })); Thread.Sleep(1000); List <HostInfo> list = new HostInfoBLL().GetModelByPrjGUID(appState.CurrentUserInfo.ProjectGUID); if (list != null && list.Count > 0) { LightInfoBLL liBLL = new LightInfoBLL(); foreach (HostInfo hi in list) { HostInfo h = appState.TreeDatas.ListHostInfo.FirstOrDefault(a => a.GUID == hi.GUID); if (h != null) { h.Online = hi.Online; } // 更新单灯 List <LightInfo> listLI = liBLL.GetModelByHost(h); if (listLI != null && listLI.Count > 0) { foreach (LightInfo li in listLI) { LightInfo l = appState.TreeDatas.ListLightInfo.FirstOrDefault(b => b.GUID == li.GUID); if (l != null) { l.LightStateInfo = li.LightStateInfo; //Debug.WriteLine(l.LightStateInfo.ToString()); } } } } } this.Dispatcher.Invoke((Action)(() => { ShowState("更新后台数据成功"); })); } Thread.Sleep(10000); } }
public void Init(LightManager lm, LightInfo li) { this.li = li; li.light = this; // very dirty this.lightManager = lm; name = (li.name == null ? "Light" : li.name) + " @ " + li.Offset + " | " + "Type: " + Type + " - Far: " + Far + " - Near: " + Near + //" - FogBlendNear: " + FogBlendNear + " - FogBlendFar: " + FogBlendFar + " - AlphaLF: " + AlphaLightFlag + " - PaintingLF: " + PaintingLightFlag + " - ObjectLF: " + li.objectLightedFlag; Vector3 pos = li.transMatrix.GetPosition(convertAxes: true); Quaternion rot = li.transMatrix.GetRotation(convertAxes: true) * Quaternion.Euler(-90, 0, 0); Vector3 scale = li.transMatrix.GetScale(convertAxes: true); transform.SetParent(lm.transform); transform.localPosition = pos; transform.localRotation = rot; transform.localScale = scale; this.pos = pos; this.rot = rot; this.scl = scale; //color = new Color(Mathf.Clamp01(r3l.color.x), Mathf.Clamp01(r3l.color.y), Mathf.Clamp01(r3l.color.z), Mathf.Clamp01(r3l.color.w)); intensity = Mathf.Max(li.color.x, li.color.y, li.color.z); if (intensity > 1) { Vector3 colorVector = new Vector3(li.color.x / intensity, li.color.y / intensity, li.color.z / intensity); color = new Color(Mathf.Clamp01(colorVector.x), Mathf.Clamp01(colorVector.y), Mathf.Clamp01(colorVector.z), Mathf.Clamp01(li.color.w)); } else if (intensity > 0) { color = new Color(Mathf.Clamp01(li.color.x), Mathf.Clamp01(li.color.y), Mathf.Clamp01(li.color.z), Mathf.Clamp01(li.color.w)); } else { // shadow, can't display it since colors are additive in Unity } backgroundColor = new Color(Mathf.Clamp01(li.background_color.x), Mathf.Clamp01(li.background_color.y), Mathf.Clamp01(li.background_color.z), Mathf.Clamp01(li.background_color.w)); /*if (li.alphaLightFlag != 0) { * color = new Color(color.r * li.color.w, color.g * li.color.w, color.b * li.color.w); * backgroundColor = new Color( * backgroundColor.r * li.background_color.w, * backgroundColor.g * li.background_color.w, * backgroundColor.b * li.background_color.w); * }*/ col = color; bckCol = backgroundColor; loaded = true; }
public GameObject CreateDebugBox(LightInfo lightInfo, DetectionBox originInfo) { GameObject debugBox = Instantiate(DebugBoxPrefab); debugBox.transform.SetParent(DebugCanvasTransform); debugBox.transform.position = lightInfo.position; string lightType = (originInfo.id == 1 ? "Area" : (originInfo.id == 2 ? "Point" : "Spot")); DebugBoxManager debugBoxManager = debugBox.GetComponent <DebugBoxManager>() as DebugBoxManager; debugBoxManager.SetParams(lightType, lightInfo.light.intensity, lightInfo.light.color); return(debugBox); }
public LightBehaviour Register(LightInfo light) { LightBehaviour l = lights.FirstOrDefault(li => li.li == light); if (l == null) { GameObject gao = new GameObject("LightInfo @ " + light.Offset); l = gao.AddComponent <LightBehaviour>(); l.Init(this, light); l.transform.parent = transform; lights.Add(l); } return(l); }
private void RegisterLight(GameObject t, string name, bool interruptable, bool stopOnExitAnim) { if (t != null) { LightInfo li = new LightInfo(); t.SetActive(true); li._light = t; li._interruptable = interruptable; li._stopOnExitAnim = stopOnExitAnim; li._name = name; li._clipHash = GetCurrentAnimHash(); _activeDynamicLights.Add(li); } }
public void ApplyLightInfo() { if (m_LightInfos != null && m_LightInfos.Length > 0) { for (int iInfo = 0; iInfo < m_LightInfos.Length; iInfo++) { LightInfo info = m_LightInfos[iInfo]; if (info.m_Render != null) { info.m_Render.lightmapIndex = info.m_BakedLightmapIndex; info.m_Render.lightmapScaleOffset = info.m_BakedLightmapScaleOffset; info.m_Render.realtimeLightmapIndex = info.m_RealLightmapIndex; info.m_Render.realtimeLightmapScaleOffset = info.m_RealLightmapScaleOffest; } } } }
static void GenerateLightmapInfo(GameObject root, List <RendererInfo> rendererInfos, List <Texture2D> lightmaps, List <Texture2D> lightmapsDir, List <Texture2D> shadowMasks, List <LightInfo> lightsInfo) { var renderers = root.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer renderer in renderers) { if (renderer.lightmapIndex != -1) { RendererInfo info = new RendererInfo(); info.renderer = renderer; if (renderer.lightmapScaleOffset != Vector4.zero) { info.lightmapOffsetScale = renderer.lightmapScaleOffset; Texture2D lightmap = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapColor; Texture2D lightmapDir = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapDir; Texture2D shadowMask = LightmapSettings.lightmaps[renderer.lightmapIndex].shadowMask; info.lightmapIndex = lightmaps.IndexOf(lightmap); if (info.lightmapIndex == -1) { info.lightmapIndex = lightmaps.Count; lightmaps.Add(lightmap); lightmapsDir.Add(lightmapDir); shadowMasks.Add(shadowMask); } rendererInfos.Add(info); } } } var lights = root.GetComponentsInChildren <Light>(true); foreach (Light l in lights) { LightInfo lightInfo = new LightInfo(); lightInfo.light = l; lightInfo.lightmapBaketype = (int)l.lightmapBakeType; lightInfo.mixedLightingMode = (int)UnityEditor.LightmapEditorSettings.mixedBakeMode; lightsInfo.Add(lightInfo); } }
public override sealed bool ExecuteCondition(Creature creature, int interval) { InternalLightTicks = (uint)(InternalLightTicks + interval); if (InternalLightTicks >= LightChangeInterval) { InternalLightTicks = 0; LightInfo creatureLight = creature.GetCreatureLight(); if (creatureLight.Level > 0) { --creatureLight.Level; //creature.InternalLight = creatureLight; //TODO: Check this out Game.ChangeLight(creature); } } return(base.ExecuteCondition(creature, interval)); }
public LightInfoEditDlg(MainWindow main, string title, LightInfo li) : this() { this.Title = title; mainWindow = main; lightInfo = li; // 初始化基本数据 txtLightID.Text = lightInfo.ID; txtLightLat.Text = lightInfo.Lat.ToString(); txtLightLng.Text = lightInfo.Lng.ToString(); txtLightName.Text = lightInfo.Name; txtLightPhyID.Text = lightInfo.PhyID; txtLightRemark.Text = lightInfo.Remark; txtLightVersion.Text = lightInfo.Version; foreach (LightTypeItem a in cbLightType.Items) { if (a.Value == ((LightType)lightInfo.Type)) { cbLightType.SelectedItem = a; } } cbLightEnable.IsChecked = lightInfo.Enable == 1 ? true : false; // 加载与该分组相关的分组信息 List <LightGroupInfo> lgi = new LightGroupInfoBLL().GetAllLightGroupInfoByHostGUID(lightInfo.HostGUID); combLightGroupInfo.ItemsSource = lgi; combLightGroupInfo.DisplayMemberPath = "Name"; // 加载该单灯所属的分组 if (lgi != null) { List <LightInfoLightGroupInfo> list = new LightInfoLightGroupInfoBLL().GetByLightGUID(lightInfo.GUID.Trim()); if (list != null && list.Count > 0) { lightInfoLightGroupInfo = list[0]; lightInfoLightGroupInfoBack = (LightInfoLightGroupInfo)lightInfoLightGroupInfo.Clone(); combLightGroupInfo.SelectedItem = lgi.FirstOrDefault(t => t.GUID.Trim() == lightInfoLightGroupInfo.LightGroupInfoGUID); } } }
/// <summary> /// 增加单灯,更新左侧列表的全部组,增加地图标记,增加全局缓冲单灯 /// </summary> /// <param name="l"></param> public void UIAddLightInfo(LightInfo l, TreeLightGroupInfo t) { // 更新左侧列表 if (t != null) { t.TreeLightInfos.Add(new TreeLightInfo() { LightInfo = l }); } // 增加地图标记 GMapMarker g = MapAddLightInfo(l, map); if (g != null) { appState.MapDatas.DicLightInfoMarker.Add(l.GUID, g); } // 增加全局缓冲区 appState.TreeDatas.ListLightInfo.Add(l); }
private static LightInfo LoadLight(XElement singleLight) { try { LightInfo light = new LightInfo(); Color cOut; float fOut; Vector3 v3Out; v3Out = Util.ConvertStringToVector3(singleLight.Element("Position").Value.ToString()); light.position = v3Out; v3Out = Util.ConvertStringToVector3(singleLight.Element("EulerAngles").Value.ToString()); light.eulerAngles = v3Out; cOut = Util.ConvertStringToColor32(singleLight.Element("Color").Value.ToString()); light.color = cOut; light.type = (LightType)Enum.Parse(typeof(LightType), singleLight.Element("Type").Value.ToString()); float.TryParse(singleLight.Element("Intensity").Value.ToString(), out fOut); light.intensity = fOut; float.TryParse(singleLight.Element("Range").Value.ToString(), out fOut); light.range = fOut; float.TryParse(singleLight.Element("SpotAngle").Value.ToString(), out fOut); light.spotAngle = fOut; light.enabled = true; return(light); } catch (Exception e) { Debug.LogError(e); } return(null); }
public static extern int AnLight_Set_S(IntPtr ctx, IntPtr dev, out LightInfo info, UInt16 r, UInt16 g, UInt16 b);
public void setup(LightStripController[] lightGroup, LightInfo lightInfo,MonoBehaviour monoBehavior, float animationLength) { lights = lightGroup; this.lightInfo = lightInfo; currentColor = lightInfo.color; currentIntensity = lightInfo.defaltIntensity; this.animationLength = animationLength; }
public LightInfo getLightInfo() { LightInfo lightInfo = new LightInfo(); lightInfo.defaltIntensity = defaltIntensity; lightInfo.maxIntensity = maxIntensity; lightInfo.color = color; return lightInfo; }
public static async Task Run(EngineContext engineContext) { var renderingSetup = RenderingSetup.Singleton; renderingSetup.Initialize(engineContext); renderingSetup.RegisterLighting(engineContext); #if XENKO_YEBIS YebisPlugin yebisPlugin; if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("YebisPlugin", out yebisPlugin)) { yebisPlugin.Glare.Enable = true; yebisPlugin.ToneMap.Exposure = 1.0f; yebisPlugin.ToneMap.Gamma = 2.2f; } #endif var lightPrepassPlugin = (LightingPrepassPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue("LightingPrepassPlugin"); var gbufferPlugin = (GBufferPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue("GBufferPlugin"); EffectOld effect = engineContext.RenderContext.BuildEffect("SimpleCube") .Using(new BasicShaderPlugin("ShaderBase") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin("TransformationWVP") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin("AlbedoSpecularBase") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin("AlbedoDiffuseBase") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin("NormalVSGBuffer") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin("SpecularPowerPerMesh") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin("PositionVSGBuffer") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin("BRDFDiffuseLambert") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin("BRDFSpecularBlinnPhong") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin(new ShaderMixinSource() { new ShaderComposition("albedoDiffuse", new ShaderClassSource("ComputeColorStream"))}) { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new BasicShaderPlugin(new ShaderMixinSource() { new ShaderComposition("albedoSpecular", new ShaderClassSource("ComputeColorSynthetic"))}) { RenderPassPlugin = renderingSetup.MainTargetPlugin }) .Using(new GBufferShaderPlugin { RenderPassPlugin = gbufferPlugin }) .Using(new DeferredLightingShaderPlugin() { RenderPassPlugin = lightPrepassPlugin }) .Using(new LightingShaderPlugin() { RenderPassPlugin = (LightingPlugin)engineContext.DataContext.RenderPassPlugins.TryGetValue("LightingPlugin") }) .Using(new BasicShaderPlugin("LightDirectionalShading") { RenderPassPlugin = renderingSetup.MainTargetPlugin }) ; var shadowMap1 = new ShadowMap(new DirectionalLight() { LightColor = new Color3(1.0f, 1.0f, 1.0f), LightDirection = new Vector3(1.0f, 1.0f, 1.0f) }); effect.Permutations.Set(ShadowMapPermutationArray.Key, new ShadowMapPermutationArray { ShadowMaps = { shadowMap1 } }); var r = new Random(0); VirtualFileSystem.MountFileSystem("/global_data", "..\\..\\deps\\data\\"); VirtualFileSystem.MountFileSystem("/global_data2", "..\\..\\data\\"); SkyBoxPlugin skyBoxPlugin; if (engineContext.DataContext.RenderPassPlugins.TryGetValueCast("SkyBoxPlugin", out skyBoxPlugin)) { var skyBoxTexture = (Texture2D)await engineContext.AssetManager.LoadAsync<Texture>("/global_data/gdc_demo/bg/GDC2012_map_sky.dds"); skyBoxPlugin.Texture = skyBoxTexture; } var effectMeshGroup = new RenderPassListEnumerator(); engineContext.RenderContext.RenderPassEnumerators.Add(effectMeshGroup); var groundMesh = new EffectMesh(effect, MeshDataHelper.CreateBox(10000, 10000, 1, Color.White)); groundMesh.KeepAliveBy(engineContext.SimpleComponentRegistry); effectMeshGroup.AddMesh(groundMesh); groundMesh.Parameters.Set(TransformationKeys.World, Matrix.Translation(new Vector3(0, 0, 0))); // Lights for (int i = 0; i < 1024; ++i) { Color3 color = (Color3)Color.White; switch (i % 4) { case 0: color = (Color3)Color.DarkOrange; break; case 1: color = (Color3)Color.DarkGoldenrod; break; case 2: color = (Color3)Color.DarkSalmon; break; case 3: color = (Color3)Color.DarkRed; break; } var effectMesh = new EffectMesh(lightPrepassPlugin.Lights); effectMesh.Parameters.Set(LightKeys.LightRadius, (float)r.NextDouble() * 200 + 200.0f); effectMesh.Parameters.Set(LightKeys.LightColor, color); effectMesh.KeepAliveBy(engineContext.SimpleComponentRegistry); effectMeshGroup.AddMesh(effectMesh); } EffectOld effectLight = lightPrepassPlugin.Lights; var lightInfo = new LightInfo[effectLight != null ? effectLight.Meshes.Count : 0]; for (int i = 0; i < lightInfo.Length; ++i) { lightInfo[i].Radius = (float)r.NextDouble() * 7000.0f + 500.0f; lightInfo[i].Phase = (float)(r.NextDouble() * Math.PI * 2.0); lightInfo[i].Z = (float)r.NextDouble() * 3000.0f; ; } float time = 0.0f; // Meshes (quad) that will later be generated by the engine (light pre pass, SSAO, etc...) // Lights //var effectMesh = new EffectMesh(setup.LightingPrepassPlugin.Lights); //effectMesh.Parameters.Set(LightKeys.LightRadius, 1000.0f); //effectMesh.Parameters.Set(LightKeys.LightColor, new R32G32B32_Float(1.0f, 1.0f, 1.0f)); //effectMesh.Parameters.Set(LightKeys.LightPosition, new R32G32B32_Float(0, 0, 1200)); //effectMesh.KeepAliveBy(engineContext.SimpleComponentRegistry); //effectMeshGroup.AddMesh(effectMesh); //var boxMesh = new EffectMesh(effect, MeshDataHelper.CreateBox(300, R8G8B8A8.LightBlue)); //boxMesh.KeepAliveBy(engineContext.SimpleComponentRegistry); //boxMesh.Parameters.Set(TransformationKeys.World, Matrix.Translation(new R32G32B32_Float(0, 0, 200))); //effectMeshGroup.AddMesh(boxMesh); var clock = new Stopwatch(); clock.Start(); int sizeX = 10; int sizeY = 10; var spheres = new Sphere[sizeY,sizeX]; Random random = new Random(0); int size = 200; var meshData = MeshDataHelper.CreateSphere(size, 30, 30, Color.Gray); for (int iy = 0; iy < sizeY; iy++) { for (int ix = 0; ix < sizeX; ix++) { var sphere = new Sphere(); sphere.Mesh = new EffectMesh(effect, meshData); sphere.Phase = (float)random.NextDouble(); sphere.Speed = (float)random.NextDouble(); spheres[iy, ix] = sphere; effectMeshGroup.AddMesh(sphere.Mesh); } } while (true) { await Scheduler.Current.NextFrame(); for (int iy = 0; iy < sizeY; iy++) { for (int ix = 0; ix < sizeX; ix++) { var iFactor = (float)(iy * sizeY + ix) / (sizeX * sizeY); var sphere = spheres[iy, ix]; var sphereMesh = sphere.Mesh; var specularColor = Color.SmoothStep(Color.GreenYellow, Color.Gray, iFactor); // Matrix.RotationX((float)Math.PI/2.0f) * M sphereMesh.Parameters.Set( TransformationKeys.World, Matrix.Translation( new Vector3( (ix - sizeX / 2) * (size * 1.2f) * 2.0f, (iy - sizeY / 2) * (size * 1.2f) * 2.0f, (float)(2000 * (0.5 + 0.5 * Math.Sin(clock.ElapsedMilliseconds / 1000.0f * sphere.Speed * 0.5f + Math.PI * sphere.Phase)))))); sphereMesh.Parameters.Set(MaterialKeys.SpecularPower, iFactor * 0.9f); sphereMesh.Parameters.Set(MaterialKeys.SpecularColor, specularColor); } } time = clock.ElapsedMilliseconds / 1000.0f; if (lightInfo.Length > 0) { int index = 0; foreach (var mesh in effectLight.Meshes) { mesh.Parameters.Set(LightKeys.LightPosition, new Vector3(lightInfo[index].Radius * (float)Math.Cos(-time * 0.17f + lightInfo[index].Phase), lightInfo[index].Radius * (float)Math.Sin(-time * 0.05f + lightInfo[index].Phase), lightInfo[index].Z * (0.5f + 0.5f * (float)Math.Sin(-time * 0.1f + lightInfo[index].Phase * 2.0f)))); index++; } } } }
public static async Task MoveLights(EngineContext engineContext) { var r = new Random(0); var config = AppConfig.GetConfiguration<Config>("LightScript2"); LightingPrepassPlugin lightingPrepassPlugin; if (!engineContext.DataContext.RenderPassPlugins.TryGetValueCast("LightingPrepassPlugin", out lightingPrepassPlugin)) return; var effectMeshGroup = new RenderPassListEnumerator(); engineContext.RenderContext.RenderPassEnumerators.Add(effectMeshGroup); // Lights for (int i = 0; i < 1024; ++i) { var effectMesh = new EffectMesh(lightingPrepassPlugin.Lights); Color3 color = (Color3)Color.White; switch (i % 7) { case 0: color = new Color3(0.7f, 0.0f, 0.0f); break; case 1: color = new Color3(0.0f, 0.7f, 0.0f); break; case 2: color = new Color3(0.0f, 0.0f, 0.7f); break; case 3: color = new Color3(0.7f, 0.7f, 0.0f); break; case 4: color = new Color3(0.7f, 0.0f, 0.7f); break; case 5: color = new Color3(0.0f, 0.7f, 0.7f); break; case 6: color = new Color3(0.7f, 0.7f, 0.7f); break; } effectMesh.Parameters.Set(LightKeys.LightRadius, 60.0f); effectMesh.Parameters.Set(LightKeys.LightColor, color); effectMesh.Parameters.Set(LightKeys.LightIntensity, 1.0f); effectMesh.KeepAliveBy(engineContext.SimpleComponentRegistry); effectMeshGroup.AddMesh(effectMesh); } bool animatedLights = config.AnimatedLights; EffectOld effectLight = null; try { effectLight = engineContext.RenderContext.RenderPassPlugins.OfType<LightingPrepassPlugin>().FirstOrDefault().Lights; } catch { return; } var lightInfo = new LightInfo[effectLight != null ? effectLight.Meshes.Count : 0]; for (int i = 0; i < lightInfo.Length; ++i) { lightInfo[i].Radius = (float)r.NextDouble() * 1000.0f + 500.0f; lightInfo[i].Phase = (float)r.NextDouble() * 10.0f; lightInfo[i].Z = (float)r.NextDouble() * 150.0f + 150.0f; } float time = 0.0f; var st = new Stopwatch(); var lastTickCount = 0; var st2 = new Stopwatch(); st2.Start(); bool firstTime = true; while (true) { await Scheduler.NextFrame(); time += 0.003f; if (lightInfo.Length > 0) { if (animatedLights || firstTime) { int index = 0; foreach (var mesh in effectLight.Meshes) { mesh.Parameters.Set(LightKeys.LightPosition, new Vector3(lightInfo[index].Radius * (float)Math.Cos(time * 3.0f + lightInfo[index].Phase), lightInfo[index].Radius * (float)Math.Sin(time * 3.0f + lightInfo[index].Phase), lightInfo[index].Z)); index++; } firstTime = false; } } } }
public static extern int AnLight_Info_S(IntPtr ctx, IntPtr dev, out LightInfo info);