// OnLoad() is called when the GameObject is added to the IGameObjectService. protected override void OnLoad() { FogNode = new FogNode(new Fog()) { IsEnabled = false, Name = "Fog", }; var scene = _services.GetInstance <IScene>(); if (!_attachToCamera) { scene.Children.Add(FogNode); } else { var cameraNode = ((Scene)scene).GetSceneNode("PlayerCamera"); if (cameraNode.Children == null) { cameraNode.Children = new SceneNodeCollection(); } cameraNode.Children.Add(FogNode); } }
/// <summary> /// Gets the fog intensity at the specified target position. /// </summary> /// <param name="fogNode">The fog node.</param> /// <param name="cameraNode">The camera node.</param> /// <param name="targetPosition">The target position.</param> /// <returns>The fog intensity (0 = no fog; 1 = full fog, nothing else visible).</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="fogNode"/> or <paramref name="cameraNode"/> is <see langword="null"/>. /// </exception> public float GetIntensity(FogNode fogNode, CameraNode cameraNode, Vector3 targetPosition) { if (fogNode == null) { throw new ArgumentNullException("fogNode"); } if (cameraNode == null) { throw new ArgumentNullException("cameraNode"); } return(OnGetIntensity(fogNode, cameraNode, targetPosition)); }
/// <summary> /// Called to compute the fog intensity for <see cref="GetIntensity"/>. /// </summary> /// <param name="fogNode">The fog node. (Is never <see langword="null"/>.)</param> /// <param name="cameraNode">The camera node. (Is never <see langword="null"/>.)</param> /// <param name="targetPosition">The target position.</param> /// <returns>The fog intensity (0 = no fog; 1 = full fog, nothing else visible).</returns> /*protected virtual*/ private float OnGetIntensity(FogNode fogNode, CameraNode cameraNode, Vector3 targetPosition) { // These computations are the same as in FogRenderer and the Fog shader files. if (Numeric.IsZero(Density)) { return(0); } Vector3 cameraToPosition = targetPosition - cameraNode.PoseWorld.Position; float distance = cameraToPosition.Length; // The distance traveled inside the fog. Vector3 cameraToPositionDirection = cameraToPosition / distance; // Compute a value that is 0 at Start and 1 at End. float ramp = (distance - Start) / (End - Start); // Smoothstep distance fog float smoothRamp = InterpolationHelper.HermiteSmoothStep(ramp); // Exponential Fog float referenceHeight = cameraNode.PoseWorld.Position.Y - fogNode.PoseWorld.Position.Y + cameraToPositionDirection.Y * Start; float distanceInFog = distance - Start; var fogDirection = cameraToPositionDirection; if (HeightFalloff * fogDirection.Y < 0) { referenceHeight += fogDirection.Y * distanceInFog; fogDirection = -fogDirection; } float referenceDensity = Density * (float)Math.Pow(2, -HeightFalloff * referenceHeight); float opticalLength = GetOpticalLengthInHeightFog(distanceInFog, referenceDensity, fogDirection * distanceInFog, HeightFalloff); float heightFog = (1 - (float)Math.Pow(2, -opticalLength * 1)); // Get alpha from BottomColor and TopColor. // (Note: We have to avoid division by zero.) float height = targetPosition.Y - fogNode.PoseWorld.Position.Y; float p = MathHelper.Clamp((height - Height0) / Math.Max(Height1 - Height0, 0.0001f), 0, 1); float alpha = InterpolationHelper.Lerp(Color0.W, Color1.W, p); return(smoothRamp * heightFog * alpha); }
// 랜덤한 종류의 노드를 생성해서 반환한다. public Node GetRandomNode() { Node node = null; NodeName rand = (NodeName)Random.Range((int)NodeName.StartNode, (int)NodeName.EndNode); switch (rand) { case NodeName.StartNode: node = new Node(nTree.Root); break; case NodeName.MonsterNode: node = new MonsterNode(nTree.Root); break; case NodeName.EliteMonstaerNode: node = new EliteMonsterNode(nTree.Root); break; case NodeName.EventNode: node = new EventNode(nTree.Root); break; case NodeName.FogNode: node = new FogNode(nTree.Root); break; case NodeName.ShopNode: node = new ShopNode(nTree.Root); break; case NodeName.CampNode: node = new CampNode(nTree.Root); break; default: Debug.Log("RandomNode Error"); break; } return(node); }
// OnUnload() is called when the GameObject is removed from the IGameObjectService. protected override void OnUnload() { FogNode.Parent.Children.Remove(FogNode); FogNode.Dispose(false); FogNode = null; }
// OnLoad() is called when the GameObject is added to the IGameObjectService. protected override void OnLoad() { FogNode = new FogNode(new Fog()) { IsEnabled = false, Name = "Fog", }; AddFogNodeToScene(); // Add GUI controls to the Options window. var sampleFramework = _services.GetInstance <SampleFramework>(); var optionsPanel = sampleFramework.AddOptions("Game Objects"); var panel = SampleHelper.AddGroupBox(optionsPanel, "FogObject"); SampleHelper.AddCheckBox( panel, "Enable fog", FogNode.IsEnabled, isChecked => FogNode.IsEnabled = isChecked); SampleHelper.AddCheckBox( panel, "Attach to camera", AttachToCamera, isChecked => AttachToCamera = isChecked); SampleHelper.AddSlider( panel, "Fog ramp start", "F2", 0, 1000, FogNode.Fog.Start, value => FogNode.Fog.Start = value); SampleHelper.AddSlider( panel, "Fog ramp end", "F2", 0, 5000, FogNode.Fog.End, value => FogNode.Fog.End = value); SampleHelper.AddSlider( panel, "Density", "F2", 0.0f, 2, FogNode.Fog.Density, value => FogNode.Fog.Density = value); SampleHelper.AddSlider( panel, "Height falloff", "F2", -1, 1, FogNode.Fog.HeightFalloff, value => FogNode.Fog.HeightFalloff = value); SampleHelper.AddSlider( panel, "Height Y", "F2", -100, 100, FogNode.PoseWorld.Position.Y, value => { var pose = FogNode.PoseWorld; pose.Position.Y = value; FogNode.PoseWorld = pose; }); }