protected void SetColor(int R, int G, int B) { _lightColor.X = R; _lightColor.Y = G; _lightColor.Z = B; _light.SetColor(255, R, G, B); }
public void Update(ILight owner, float frametime) { if (flickering) { if (lightOn == false) { if (timer.ElapsedMilliseconds >= 50 && IoCManager.Resolve <IRand>().Next(1, 6) == 2) { flickerCount++; lightOn = true; owner.SetColor(_lightColorOriginal); owner.LightArea.Calculated = false; timer.Reset(); if (flickerCount >= 2 && IoCManager.Resolve <IRand>().Next(1, 6) == 2) { flickering = false; } } } else if (timer.ElapsedMilliseconds >= 50 && IoCManager.Resolve <IRand>().Next(1, 6) == 2) { owner.SetColor((_lightColorOriginal.A / 2), (_lightColorOriginal.R / 2), (_lightColorOriginal.G / 2), (_lightColorOriginal.B / 2)); owner.LightArea.Calculated = false; lightOn = false; timer.Reset(); } } else { if (timer.Elapsed.Seconds >= 4 && IoCManager.Resolve <IRand>().Next(1, 5) == 2) { flickering = true; flickerCount = 0; lightOn = false; owner.SetColor((_lightColorOriginal.A / 2), (_lightColorOriginal.R / 2), (_lightColorOriginal.G / 2), (_lightColorOriginal.B / 2)); owner.LightArea.Calculated = false; timer.Reset(); } } }
public void Update(ILight owner, float frametime) { if (flickering) { if (lightOn == false) { if (timer.Milliseconds >= 50 && IoCManager.Resolve<IRand>().Next(1, 6) == 2) { flickerCount++; lightOn = true; owner.SetColor(_lightColorOriginal); owner.LightArea.Calculated = false; timer.Reset(); if (flickerCount >= 2 && IoCManager.Resolve<IRand>().Next(1, 6) == 2) flickering = false; } } else if (timer.Milliseconds >= 50 && IoCManager.Resolve<IRand>().Next(1, 6) == 2) { owner.SetColor((_lightColorOriginal.A/2), (_lightColorOriginal.R/2), (_lightColorOriginal.G/2), (_lightColorOriginal.B/2)); owner.LightArea.Calculated = false; lightOn = false; timer.Reset(); } } else { if (timer.Seconds >= 4 && IoCManager.Resolve<IRand>().Next(1, 5) == 2) { flickering = true; flickerCount = 0; lightOn = false; owner.SetColor((_lightColorOriginal.A/2), (_lightColorOriginal.R/2), (_lightColorOriginal.G/2), (_lightColorOriginal.B/2)); owner.LightArea.Calculated = false; timer.Reset(); } } }
//When added, set up the light. public override void OnAdd(Entity owner) { base.OnAdd(owner); _light = IoCManager.Resolve <ILightManager>().CreateLight(); IoCManager.Resolve <ILightManager>().AddLight(_light); _light.SetRadius(_lightRadius); _light.SetColor(255, (int)_lightColor.X, (int)_lightColor.Y, (int)_lightColor.Z); _light.Move(Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position + _lightOffset); _light.SetMask(_mask); Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).OnMove += OnMove; }
//When added, set up the light. public override void OnAdd(Entity owner) { base.OnAdd(owner); _light = IoCManager.Resolve<ILightManager>().CreateLight(); IoCManager.Resolve<ILightManager>().AddLight(_light); _light.SetRadius(_lightRadius); _light.SetColor(255, (int) _lightColor.X, (int) _lightColor.Y, (int) _lightColor.Z); _light.Move(Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position + _lightOffset); _light.SetMask(_mask); Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += OnMove; }
public void OnRemove(ILight owner) { owner.SetColor(_lightColorOriginal); owner.LightArea.Calculated = false; }
public void Startup() { LastUpdate = DateTime.Now; Now = DateTime.Now; _cleanupList = new List<RenderTarget>(); _cleanupSpriteList = new List<CluwneSprite>(); UserInterfaceManager.DisposeAllComponents(); //Init serializer var serializer = IoCManager.Resolve<ISS14Serializer>(); _entityManager = new EntityManager(NetworkManager); IoCManager.Resolve<IEntityManagerContainer>().EntityManager = _entityManager; NetworkManager.MessageArrived += NetworkManagerMessageArrived; NetworkManager.RequestMap(); IoCManager.Resolve<IMapManager>().TileChanged += OnTileChanged; IoCManager.Resolve<IPlayerManager>().OnPlayerMove += OnPlayerMove; // TODO This should go somewhere else, there should be explicit session setup and teardown at some point. NetworkManager.SendClientName(ConfigurationManager.GetPlayerName()); // Create new _baseTarget = new RenderImage("baseTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, true); _cleanupList.Add(_baseTarget); //_baseTargetSprite = new CluwneSprite(_baseTarget); //_cleanupSpriteList.Add(_baseTargetSprite); _sceneTarget = new RenderImage("sceneTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, true); _cleanupList.Add(_sceneTarget); _tilesTarget = new RenderImage("tilesTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, true); _cleanupList.Add(_tilesTarget); _overlayTarget = new RenderImage("OverlayTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, true); _cleanupList.Add(_overlayTarget); // _overlayTarget.SourceBlend = AlphaBlendOperation.SourceAlpha; // _overlayTarget.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; // _overlayTarget.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha; //_overlayTarget.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha; _composedSceneTarget = new RenderImage("composedSceneTarget", (uint)CluwneLib.Screen.GetView().Size.X, (uint)CluwneLib.Screen.GetView().Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(_composedSceneTarget); _lightTarget = new RenderImage("lightTarget", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(_lightTarget); _lightTargetSprite = new CluwneSprite("lightTargetSprite", _lightTarget) { DepthWriteEnabled = false }; _cleanupSpriteList.Add(_lightTargetSprite); _lightTargetIntermediate = new RenderImage("lightTargetIntermediate", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(_lightTargetIntermediate); _lightTargetIntermediateSprite = new CluwneSprite("lightTargetIntermediateSprite", _lightTargetIntermediate) { DepthWriteEnabled = false }; _cleanupSpriteList.Add(_lightTargetIntermediateSprite); _gasBatch = new SpriteBatch(); //_gasBatch.SourceBlend = AlphaBlendOperation.SourceAlpha; //_gasBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; //_gasBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha; //_gasBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha; _wallTopsBatch = new SpriteBatch(); //_wallTopsBatch.SourceBlend = AlphaBlendOperation.SourceAlpha; //_wallTopsBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; //_wallTopsBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha; //_wallTopsBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha; _decalBatch = new SpriteBatch(); //_decalBatch.SourceBlend = AlphaBlendOperation.SourceAlpha; //_decalBatch.DestinationBlend = AlphaBlendOperation.InverseSourceAlpha; //_decalBatch.SourceBlendAlpha = AlphaBlendOperation.SourceAlpha; //_decalBatch.DestinationBlendAlpha = AlphaBlendOperation.InverseSourceAlpha; _floorBatch = new SpriteBatch(); _wallBatch = new SpriteBatch(); _gaussianBlur = new GaussianBlur(ResourceManager); _realScreenWidthTiles = (float)CluwneLib.Screen.Size.X / MapManager.TileSize; _realScreenHeightTiles = (float)CluwneLib.Screen.Size.Y / MapManager.TileSize; //Init GUI components _gameChat = new Chatbox(ResourceManager, UserInterfaceManager, KeyBindingManager); _gameChat.TextSubmitted += ChatTextboxTextSubmitted; UserInterfaceManager.AddComponent(_gameChat); //UserInterfaceManager.AddComponent(new StatPanelComponent(ConfigurationManager.GetPlayerName(), PlayerManager, NetworkManager, ResourceManager)); var statusBar = new StatusEffectBar(ResourceManager, PlayerManager); statusBar.Position = new Point((int)CluwneLib.Screen.Size.X - 800, 10); UserInterfaceManager.AddComponent(statusBar); var hotbar = new Hotbar(ResourceManager); hotbar.Position = new Point(5, (int)CluwneLib.Screen.Size.Y - hotbar.ClientArea.Height - 5); hotbar.Update(0); UserInterfaceManager.AddComponent(hotbar); #region Lighting quadRenderer = new QuadRenderer(); quadRenderer.LoadContent(); shadowMapResolver = new ShadowMapResolver(quadRenderer, ShadowmapSize.Size1024, ShadowmapSize.Size1024, ResourceManager); shadowMapResolver.LoadContent(); lightArea128 = new LightArea(ShadowmapSize.Size128); lightArea256 = new LightArea(ShadowmapSize.Size256); lightArea512 = new LightArea(ShadowmapSize.Size512); lightArea1024 = new LightArea(ShadowmapSize.Size1024); screenShadows = new RenderImage("screenShadows", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(screenShadows); screenShadows.UseDepthBuffer = false; shadowIntermediate = new RenderImage("shadowIntermediate", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(shadowIntermediate); shadowIntermediate.UseDepthBuffer = false; shadowBlendIntermediate = new RenderImage("shadowBlendIntermediate", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(shadowBlendIntermediate); shadowBlendIntermediate.UseDepthBuffer = false; playerOcclusionTarget = new RenderImage("playerOcclusionTarget", CluwneLib.CurrentClippingViewport.Width, CluwneLib.CurrentClippingViewport.Height, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(playerOcclusionTarget); playerOcclusionTarget.UseDepthBuffer = false; LightblendTechnique = IoCManager.Resolve<IResourceManager>().GetTechnique("lightblend"); Lightmap = IoCManager.Resolve<IResourceManager>().GetShader("lightmap"); playerVision = IoCManager.Resolve<ILightManager>().CreateLight(); playerVision.SetColor(0, 0, 0, 0); playerVision.SetRadius(1024); playerVision.Move(Vector2.Zero); #endregion _handsGui = new HandsGui(); _handsGui.Position = new Point(hotbar.Position.X + 5, hotbar.Position.Y + 7); UserInterfaceManager.AddComponent(_handsGui); var combo = new HumanComboGui(PlayerManager, NetworkManager, ResourceManager, UserInterfaceManager); combo.Update(0); combo.Position = new Point(hotbar.ClientArea.Right - combo.ClientArea.Width + 5, hotbar.Position.Y - combo.ClientArea.Height - 5); UserInterfaceManager.AddComponent(combo); var healthPanel = new HealthPanel(); healthPanel.Position = new Point(hotbar.ClientArea.Right - 1, hotbar.Position.Y + 11); healthPanel.Update(0); UserInterfaceManager.AddComponent(healthPanel); var targetingUi = new TargetingGui(); targetingUi.Update(0); targetingUi.Position = new Point(healthPanel.Position.X + healthPanel.ClientArea.Width, healthPanel.Position.Y - 40); UserInterfaceManager.AddComponent(targetingUi); var inventoryButton = new ImageButton { ImageNormal = "button_inv", Position = new Point(hotbar.Position.X + 172, hotbar.Position.Y + 2) }; inventoryButton.Update(0); inventoryButton.Clicked += inventoryButton_Clicked; UserInterfaceManager.AddComponent(inventoryButton); var statusButton = new ImageButton { ImageNormal = "button_status", Position = new Point(inventoryButton.ClientArea.Right, inventoryButton.Position.Y) }; statusButton.Update(0); statusButton.Clicked += statusButton_Clicked; UserInterfaceManager.AddComponent(statusButton); var craftButton = new ImageButton { ImageNormal = "button_craft", Position = new Point(statusButton.ClientArea.Right, statusButton.Position.Y) }; craftButton.Update(0); craftButton.Clicked += craftButton_Clicked; UserInterfaceManager.AddComponent(craftButton); var menuButton = new ImageButton { ImageNormal = "button_menu", Position = new Point(craftButton.ClientArea.Right, craftButton.Position.Y) }; menuButton.Update(0); menuButton.Clicked += menuButton_Clicked; UserInterfaceManager.AddComponent(menuButton); }
void Init(IntPtr pParam) { TMatrix4x4 mat = TMatrix4x4.MatrixIdentity; transform = new TTransformStack(ref mat); rand = new Random(); IEngineSubSystem p_sub_sys = null; IResourceManager p_res_man = null; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out p_sub_sys); p_res_man = (IResourceManager)p_sub_sys; pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out p_sub_sys); p_render = (IRender)p_sub_sys; p_render.GetRender3D(out pRender3D); IEngineBaseObject p_obj = null; p_res_man.Load(RESOURCE_PATH + "textures\\floor.dds", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D); pTexFloor = (ITexture)p_obj; p_res_man.Load(RESOURCE_PATH + "sprites\\light.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_2D); pTexLight = (ITexture)p_obj; // some global lighting pRender3D.ToggleLighting(true); TColor4 col = TColor4.ColorBlack(); pRender3D.SetGlobalAmbientLighting(ref col); // turn off ambient lighting // setup lights // use single directional light to simulate ambient lighting p_res_man.CreateLight(out pLightDirect); pLightDirect.SetType(E_LIGHT_TYPE.LT_DIRECTIONAL); col = TColor4.ColorGray(); pLightDirect.SetColor(ref col); // dim light TPoint3 p3 = new TPoint3(-0.5f, 0.5f, 0.75f); pLightDirect.SetDirection(ref p3); pLightDirect.SetEnabled(true); // Position is ignored for direction lights but is used by engine for debug drawing. // Use "rnd3d_draw_lights 1" console command to debug lights. p3 = new TPoint3(0f, 7.5f, 0f); pLightDirect.SetPosition(ref p3); // create light for the table-lamp p_res_man.CreateLight(out pLightSpot); pLightSpot.SetType(E_LIGHT_TYPE.LT_SPOT); col = TColor4.ColorYellow(); pLightSpot.SetColor(ref col); pLightSpot.SetSpotAngle(100f); p3 = new TPoint3(0.15f, 0f, -1f); pLightSpot.SetDirection(ref p3); pLightSpot.SetEnabled(true); // create and setup materials and load models ITexture p_tex; IMaterial p_mat; // desk p_res_man.CreateMaterial(out p_mat); p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\desk\\desk_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D); p_tex = (ITexture)p_obj; p_mat.SetDiffuseTexture(p_tex); p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\desk\\desk.dmd", out p_obj, 0); pMdlDesk = (IModel)p_obj; pMdlDesk.SetModelMaterial(p_mat); // table-lamp p_res_man.CreateMaterial(out p_mat); p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\table_lamp\\lamp_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D); p_tex = (ITexture)p_obj; p_mat.SetDiffuseTexture(p_tex); p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\table_lamp\\lamp.dmd", out p_obj, 0); pMdlLamp = (IModel)p_obj; pMdlLamp.SetModelMaterial(p_mat); // chair p_res_man.CreateMaterial(out p_mat); p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\chair\\chair_diff.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D); p_tex = (ITexture)p_obj; p_mat.SetDiffuseTexture(p_tex); p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\chair\\chair.dmd", out p_obj, 0); pMdlChair = (IModel)p_obj; pMdlChair.SetModelMaterial(p_mat); // music box p_res_man.CreateMaterial(out p_mat); p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\music_box\\mbox_d.dds", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D); p_tex = (ITexture)p_obj; p_mat.SetDiffuseTexture(p_tex); p_res_man.Load(RESOURCE_PATH + "meshes\\furniture\\music_box\\music_box.dmd", out p_obj, 0); pMdlMusicBox = (IModel)p_obj; pMdlMusicBox.SetModelMaterial(p_mat); // church p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church.dmd", out p_obj, 0); pModelChurch = (IModel)p_obj; pModelChurch.SetModelMaterial(p_mat); p_res_man.CreateMaterial(out p_mat); col = TColor4.ColorSilver(); p_mat.SetDiffuseColor(ref col); col = TColor4.ColorWhite(); p_mat.SetSpecularColor(ref col); p_mat.SetShininess(25f); pModelChurch.SetMeshMaterial(0, p_mat); p_res_man.CreateMaterial(out p_mat); p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church_roof.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D); p_tex = (ITexture)p_obj; p_mat.SetDiffuseTexture(p_tex); pModelChurch.SetMeshMaterial(1, p_mat); p_res_man.CreateMaterial(out p_mat); p_res_man.Load(RESOURCE_PATH + "meshes\\church\\church_main.jpg", out p_obj, (uint)E_TEXTURE_LOAD_FLAGS.TEXTURE_LOAD_DEFAULT_3D); p_tex = (ITexture)p_obj; p_mat.SetDiffuseTexture(p_tex); pModelChurch.SetMeshMaterial(2, p_mat); // snow globe p_res_man.Load(RESOURCE_PATH + "meshes\\snow_globe.dmd", out p_obj, 0); pSnowGlobe = (IModel)p_obj; p_res_man.CreateMaterial(out p_mat); col = TColor4.ColorWhite(); p_mat.SetDiffuseColor(ref col); pSnowGlobe.SetMeshMaterial(0, p_mat); p_res_man.CreateMaterial(out p_mat); col = TColor4.ColorBrown(); p_mat.SetDiffuseColor(ref col); col = TColor4.ColorWhite(); p_mat.SetSpecularColor(ref col); p_mat.SetShininess(25f); pSnowGlobe.SetMeshMaterial(2, p_mat); p_res_man.CreateMaterial(out p_mat); col = TColor4.ColorWhite(100); p_mat.SetDiffuseColor(ref col); col = TColor4.ColorWhite(); p_mat.SetSpecularColor(ref col); p_mat.SetShininess(50f); p_mat.SetBlending(true, E_BLENDING_EFFECT.BE_NORMAL); // When material with blending is set model will sort mesh order for meshes with blending to be the last. pSnowGlobe.SetMeshMaterial(1, p_mat); // We will use black fog to simulate darkness. col = TColor4.ColorBlack(); pRender3D.SetFogColor(ref col); pRender3D.SetLinearFogBounds(12.5f, 20f); pRender3D.ToggleFog(true); }
private void InitalizeLighting() { shadowMapResolver = new ShadowMapResolver(ShadowmapSize.Size1024, ShadowmapSize.Size1024, ResourceManager); shadowMapResolver.LoadContent(); lightArea128 = new LightArea(ShadowmapSize.Size128); lightArea256 = new LightArea(ShadowmapSize.Size256); lightArea512 = new LightArea(ShadowmapSize.Size512); lightArea1024 = new LightArea(ShadowmapSize.Size1024); screenShadows = new RenderImage("screenShadows", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(screenShadows); screenShadows.UseDepthBuffer = false; shadowIntermediate = new RenderImage("shadowIntermediate", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(shadowIntermediate); shadowIntermediate.UseDepthBuffer = false; shadowBlendIntermediate = new RenderImage("shadowBlendIntermediate", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(shadowBlendIntermediate); shadowBlendIntermediate.UseDepthBuffer = false; playerOcclusionTarget = new RenderImage("playerOcclusionTarget", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y, ImageBufferFormats.BufferRGB888A8); _cleanupList.Add(playerOcclusionTarget); playerOcclusionTarget.UseDepthBuffer = false; LightblendTechnique = IoCManager.Resolve<IResourceManager>().GetTechnique("lightblend"); Lightmap = IoCManager.Resolve<IResourceManager>().GetShader("lightmap"); playerVision = IoCManager.Resolve<ILightManager>().CreateLight(); playerVision.SetColor(Color.Blue); playerVision.SetRadius(1024); playerVision.Move(new Vector2f()); _occluderDebugTarget = new RenderImage("debug", CluwneLib.Screen.Size.X, CluwneLib.Screen.Size.Y); }