Beispiel #1
0
        public void OnLight(LightNode node)
        {
            Debug.WriteLine("OnLight: " + node.NodeName);
            Asset asset = node.GetAsset();

            Debug.WriteLine("OnLight: Asset:" + ((asset != null) ? asset.Name : "Null"));
        }
        public static float GetLightContribution(this LightNode lightNode, Vector3 position, float chromacityWeight)
        {
            if (lightNode == null)
            {
                throw new ArgumentNullException("lightNode");
            }

            var     distance  = (position - lightNode.PoseWorld.Position).Length;
            Vector3 intensity = lightNode.Light.GetIntensity(distance);

            // Following formula is from
            //   Shader X3, Reduction of Lighting Calculations Using Spherical Harmonics.

            float intensityFactor = intensity.X + intensity.Y + intensity.Z;

            // ReSharper disable InconsistentNaming
            float deltaRG = Math.Abs(intensity.X - intensity.Y);
            float deltaGB = Math.Abs(intensity.Y - intensity.Z);
            float deltaRB = Math.Abs(intensity.X - intensity.Z);
            // ReSharper restore InconsistentNaming

            float chromacityFactor = Math.Max(deltaRG, Math.Max(deltaGB, deltaRB));

            return(chromacityFactor * chromacityWeight + intensityFactor * (1 - chromacityWeight));
        }
Beispiel #3
0
        private void CreateLights()
        {
            // Create a directional light source
            LightSource lightSource = new LightSource();

            lightSource.Direction = new Vector3(-1, -1, -1);
            lightSource.Diffuse   = Color.White.ToVector4();

            LightSource lightSource2 = new LightSource();

            lightSource2.Direction = new Vector3(1, 0, 0);
            lightSource2.Diffuse   = Color.White.ToVector4();

            LightSource lightSource3 = new LightSource();

            lightSource3.Direction = new Vector3(-0.5f, 0, 1);
            lightSource3.Diffuse   = new Vector4(0.5f, 0.5f, 0.5f, 1);

            // Create a light node to hold the light source
            LightNode lightNode1 = new LightNode();

            lightNode1.LightSource = lightSource;

            LightNode lightNode2 = new LightNode();

            lightNode2.LightSource = lightSource2;

            LightNode lightNode3 = new LightNode();

            lightNode3.LightSource = lightSource3;

            scene.RootNode.AddChild(lightNode1);
            scene.RootNode.AddChild(lightNode2);
            scene.RootNode.AddChild(lightNode3);
        }
Beispiel #4
0
        private Node CreateNode(Stream mdlStream, Stream mdxStream, Node parent)
        {
            byte[] buffer = new byte[2];
            mdlStream.Read(buffer, 0, 2);

            Node.Type nodeType = (Node.Type)BitConverter.ToUInt16(buffer, 0);

            Node node;

            if ((nodeType & Node.Type.Saber) == Node.Type.Saber)
            {
                node = new SaberNode(mdlStream, mdxStream, nodeType, this);
            }
            else if ((nodeType & Node.Type.Skin) == Node.Type.Skin)
            {
                node = new SkinnedMeshNode(mdlStream, mdxStream, nodeType, this);
            }
            else if ((nodeType & Node.Type.Mesh) == Node.Type.Mesh)
            {
                node = new MeshNode(mdlStream, mdxStream, nodeType, this);
            }
            else if ((nodeType & Node.Type.Light) == Node.Type.Light)
            {
                node = new LightNode(mdlStream, mdxStream, nodeType, this);
            }
            else
            {
                node = new Node(mdlStream, mdxStream, nodeType, this);
            }

            node.parent = parent;
            return(node);
        }
        protected override void OnUnload()
        {
            _cameraObject = null;

            // Detach and dispose the grouping scene node with all children.
            _groupNode.Parent.Children.Remove(_ambientLightNode);
            _groupNode.Dispose(false);

            // Dispose cloud textures.
            if (_enableCloudLayer)
            {
                _cloudMap0.Dispose();
                _cloudMap1.Dispose();
            }

            // Set all references to null.
            _groupNode         = null;
            _milkyWayNode      = null;
            _starfieldNode     = null;
            _sunNode           = null;
            _moonNode          = null;
            _scatteringSkyNode = null;
            _ambientLightNode  = null;
            _sunlightNode      = null;
            _moonlightNode     = null;
            _cloudLayerNode0   = null;
            _cloudLayerNode1   = null;
            _cloudMap0         = null;
            _cloudMap1         = null;
        }
Beispiel #6
0
        private void ConfigureState()
        {
            State.LineManager.LineShader      = new GoblinXNA.Shaders.Line3DShader("LineRendering.fx");
            State.LineManager.ShaderTechnique = "LineRendering3D";
            State.ShowFPS           = true;
            State.ShowNotifications = true;

            scene.PreferPerPixelLighting = true;
            scene.EnableShadowMapping    = true;

            Notifier.Placement             = Notifier.NotifierPlacement.TopRight;
            Notifier.Color                 = Color.Red;
            Notifier.CustomStartLocation   = new Vector2(1300, 350);
            Notifier.CustomAppearDirection = new Vector2(0, 20);
            Notifier.FadeOutTime           = 2000;

            LightSource lightSource1 = new LightSource();

            lightSource1.Direction = new Vector3(-1, -2, 0);
            lightSource1.Diffuse   = Color.White.ToVector4();
            lightSource1.Specular  = new Vector4(0.6f, 0.6f, 0.6f, 1);
            // Create a light node to hold the light sources
            LightNode lightNode1 = new LightNode();

            lightNode1.LightSource = lightSource1;
            scene.RootNode.AddChild(lightNode1);


            useStaticImage = false;
        }
Beispiel #7
0
        private void CreateLights()
        {
            // Create two directional light sources
            LightSource lightSource1 = new LightSource();

            lightSource1.Direction = new Vector3(-1, -1, -1);
            lightSource1.Diffuse   = Color.White.ToVector4();
            lightSource1.Specular  = new Vector4(0.6f, 0.6f, 0.6f, 1);

            LightSource lightSource2 = new LightSource();

            lightSource2.Direction = new Vector3(0, 1, 0);
            lightSource2.Diffuse   = Color.White.ToVector4() * .2f;
            lightSource2.Specular  = new Vector4(0.2f, 0.2f, 0.2f, 1);

            // Create a light node to hold the light sources
            LightNode lightNode1 = new LightNode();

            lightNode1.LightSource = lightSource1;

            LightNode lightNode2 = new LightNode();

            lightNode2.LightSource = lightSource2;

            // Add this light node to the root node
            scene.RootNode.AddChild(lightNode1);
            scene.RootNode.AddChild(lightNode2);
        }
Beispiel #8
0
        void RemoveSource()
        {
            bool blockLight = false;

            while (lightQueue.Count > 0)
            {
                LightNode node = lightQueue.Dequeue();

                byte light = node.GetLight(blockLight);

                chunksToUpdate.Add(node.Chunk);

                node.SetLight(0, blockLight);

                GetNeighborValues(node.Y, node.X, node.Z, blockLight);

                for (int i = 0; i < 6; i++)
                {
                    if (lightValues[i] == (byte)(light - 1))
                    {
                        lightQueue.Enqueue(nodes[i]);
                    }
                }
            }

            foreach (Chunk chunk in chunksToUpdate)
            {
                chunk.UpdateMesh = true;
            }

            chunksToUpdate.Clear();
        }
Beispiel #9
0
        private void CreateLights()
        {
            // Create a directional light source
            LightSource lightSource = new LightSource();

            lightSource.Direction = new Vector3(1, -1, -1);
            lightSource.Diffuse   = Color.White.ToVector4();
            lightSource.Specular  = new Vector4(0.6f, 0.6f, 0.6f, 1);

            // Create a light node to hold the light source
            LightNode lightNode = new LightNode();

            lightNode.LightSource = lightSource;

            // Set this light node to cast shadows (by just setting this to true will not cast any shadows,
            // scene.ShadowMap needs to be set to a valid IShadowMap and Model.Shader needs to be set to
            // a proper IShadowShader implementation
            lightNode.CastShadows = true;

            // You should also set the light projection when casting shadow from this light
            lightNode.LightProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                            1, 1f, 500);

            scene.RootNode.AddChild(lightNode);
        }
Beispiel #10
0
        LightElem RegisterToThreeScene(LightNode n)
        {
            LightElem node = null;

            if (n.Type == LightType.Point)
            {
                node = new PointLightElem(n);
            }
            else if (n.Type == LightType.Directional)
            {
                node = new DirectionalLightElem(n);
            }
            else if (n.Type == LightType.Spot)
            {
                node = new SpotLightElem(n);
            }

            if (node != null)
            {
                node.Uuid = n.Guid;

                var parent = objNodeTable[n.CurrentObject.GetInstanceID().ToString()];
                parent.AddChild(node);
                return(node);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        public override void SetParameters(List <LightNode> globalLights, List <LightNode> localLights)
        {
            if ((globalLights.Count + localLights.Count) == 0)
            {
                lightDirection.SetValue(Vector3.Zero);
                return;
            }

            LightNode lNode = null;

            if (globalLights.Count >= 1)
            {
                lNode = globalLights[0];
            }
            else
            {
                lNode = localLights[localLights.Count - 1];
            }

            tmpVec1 = lNode.LightSource.TransformedDirection;
            tmpVec1.Normalize();
            lightDirection.SetValue(-tmpVec1);

            lAmbiColor = lNode.AmbientLightColor;
            ambientLightColor.SetValue(lAmbiColor);

            lColor = lNode.LightSource.Diffuse;
            lightColor.SetValue(lColor);
        }
Beispiel #12
0
    /**
     * GetLightColor
     *
     * @param tree
     * @param point
     * @param normal
     * @param currentObj
     * @param color
     */
    private void GetLightColor(OctNode tree, Point point, Vector normal, ObjectType currentObj, Color color)
    {
        Ray       shadow  = new Ray();
        LightNode current = lights;
        double    maxt;

        while (current != null)
        {
            shadow.SetOrigin(point);
            shadow.GetDirection().Sub(current.GetLight().GetPosition(), point);
            maxt = shadow.GetDirection().Length();
            shadow.GetDirection().Normalize();
            shadow.SetID(RayID);
            this.RayID = this.RayID + 1;
            if (!FindLightBlock(tree, shadow, maxt))
            {
                double factor = Math.Max(0.0f, normal.Dot(shadow.GetDirection()));
                if (factor != 0.0)
                {
                    color.Mix(factor, current.GetLight().GetColor(), currentObj.GetMaterial().GetDiffColor());
                }
            }
            current = current.Next();
        }
    }
Beispiel #13
0
    /**
     * ReadLight
     *
     * @param infile
     */
    private void ReadLight()
    {
        String temp;

        double[] input = new double[3];
        int      i;

        temp = readString();
        temp = temp.Substring(11);
        for (i = 0; i < 2; i++)
        {
            input[i] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' ')));
            temp     = temp.Substring(temp.IndexOf(' ') + 1);
        }
        input[2] = (double)Double.Parse(temp);
        Point position = new Point(input[0], input[1], input[2]);

        temp = readString();
        temp = temp.Substring(8);
        for (i = 0; i < 2; i++)
        {
            input[i] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' ')));
            temp     = temp.Substring(temp.IndexOf(' ') + 1);
        }
        input[2] = (double)Double.Parse(temp);
        Color color = new Color(input[0], input[1], input[2]);

        temp = readString();
        Light     newlight = new Light(position, color);
        LightNode newnode  = new LightNode(newlight, lights);

        lights = newnode;
    }
Beispiel #14
0
        protected override void Start()
        {
            // 3D scene with Octree
            Scene             = new Scene(Context);
            Octree            = Scene.CreateComponent <Octree>();
            RootNode          = Scene.CreateChild("RootNode");
            RootNode.Position = new Vector3(x: 0, y: 0, z: 8);

            LightNode = Scene.CreateChild("DirectionalLight");
            LightNode.SetDirection(new Vector3(0.5f, 0.0f, 0.8f));
            Light                   = LightNode.CreateComponent <Light>();
            Light.LightType         = LightType.Directional;
            Light.CastShadows       = true;
            Light.ShadowBias        = new BiasParameters(0.00025f, 0.5f);
            Light.ShadowCascade     = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f);
            Light.SpecularIntensity = 0.5f;
            Light.Color             = new Color(1.2f, 1.2f, 1.2f);

            // Camera
            CameraNode = Scene.CreateChild(name: "Camera");
            Camera     = CameraNode.CreateComponent <Camera>();

            // Viewport
            Viewport = new Viewport(Context, Scene, Camera, null);
            Renderer.SetViewport(0, Viewport);
            Viewport.SetClearColor(Color.White);

            // Subscribe to Esc key:
            Input.SubscribeToKeyDown(args => { if (args.Key == Key.Esc)
                                               {
                                                   Exit();
                                               }
                                     });
        }
Beispiel #15
0
        // OnLoad() is called when the GameObject is added to the IGameObjectService.
        protected override void OnLoad()
        {
            var ambientLight = new AmbientLight
            {
                //Color = new Vector3F(0.05333332f, 0.09882354f, 0.1819608f),  // XNA BasicEffect Values
                Color     = new Vector3F(0.5f),                        // Make ambient light brighter.
                Intensity = 1,
                HemisphericAttenuation = 1,
            };

            _ambientLightNode = new LightNode(ambientLight);

            var keyLight = new DirectionalLight
            {
                Color             = new Vector3F(1, 0.9607844f, 0.8078432f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 1,
            };

            _keyLightNode = new LightNode(keyLight)
            {
                Name      = "KeyLight",
                Priority  = 10, // This is the most important light.
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(-0.5265408f, -0.5735765f, -0.6275069f))),
            };

            var fillLight = new DirectionalLight
            {
                Color             = new Vector3F(0.9647059f, 0.7607844f, 0.4078432f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 0,
            };

            _fillLightNode = new LightNode(fillLight)
            {
                Name      = "FillLight",
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(0.7198464f, 0.3420201f, 0.6040227f))),
            };

            var backLight = new DirectionalLight
            {
                Color             = new Vector3F(0.3231373f, 0.3607844f, 0.3937255f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 1,
            };

            _backLightNode = new LightNode(backLight)
            {
                Name      = "BackLight",
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(0.4545195f, -0.7660444f, 0.4545195f))),
            };

            var scene = _services.GetInstance <IScene>();

            scene.Children.Add(_ambientLightNode);
            scene.Children.Add(_keyLightNode);
            scene.Children.Add(_fillLightNode);
            scene.Children.Add(_backLightNode);
        }
Beispiel #16
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            SCNTransaction.Begin();
            SCNTransaction.AnimationDuration = 0;

            switch (index)
            {
            case 0:
                // Set the slide's title and subtile and add some text
                TextManager.SetTitle("Node Attributes");
                TextManager.SetSubtitle("Lights");

                TextManager.AddBulletAtLevel("SCNLight", 0);
                TextManager.AddBulletAtLevel("Four light types", 0);
                TextManager.AddBulletAtLevel("Omni", 1);
                TextManager.AddBulletAtLevel("Directional", 1);
                TextManager.AddBulletAtLevel("Spot", 1);
                TextManager.AddBulletAtLevel("Ambient", 1);
                break;

            case 1:
                // Add some code
                var codeExampleNode = TextManager.AddCode("#aNode.#Light# = SCNLight.Create (); \naNode.Light.LightType = SCNLightType.Omni;#");
                codeExampleNode.Position = new SCNVector3(14, 11, 1);

                // Add a light to the scene
                LightNode                 = SCNNode.Create();
                LightNode.Light           = SCNLight.Create();
                LightNode.Light.LightType = SCNLightType.Omni;
                LightNode.Light.Color     = NSColor.Black;             // initially off
                LightNode.Light.SetAttribute(new NSNumber(30), SCNLightAttribute.AttenuationStartKey);
                LightNode.Light.SetAttribute(new NSNumber(40), SCNLightAttribute.AttenuationEndKey);
                LightNode.Position = new SCNVector3(5, 3.5f, 0);
                ContentNode.AddChildNode(LightNode);

                // Load two images to help visualize the light (on and off)
                LightOffImageNode        = Utils.SCPlaneNode(NSBundle.MainBundle.PathForResource("Images/light-off", "tiff"), 7, false);
                LightOnImageNode         = Utils.SCPlaneNode(NSBundle.MainBundle.PathForResource("Images/light-on", "tiff"), 7, false);
                LightOnImageNode.Opacity = 0;

                LightNode.AddChildNode(LightOnImageNode);
                LightNode.AddChildNode(LightOffImageNode);
                break;

            case 2:
                // Switch the light on
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                LightNode.Light.Color            = NSColor.FromCalibratedRgba(1, 1, 0.8f, 1);
                LightOnImageNode.Opacity         = 1.0f;
                LightOffImageNode.Opacity        = 0.0f;
                SCNTransaction.Commit();
                break;
            }
            SCNTransaction.Commit();
        }
Beispiel #17
0
        // OnUnload() is called when the GameObject is removed from the IGameObjectService.
        protected override void OnUnload()
        {
            _godRayFilter.Scale = _defaultScale;

            if (_directionalLightNode != null)
            {
                _directionalLightNode.SceneChanged -= OnDirectionalLightNodeChanged;
                _directionalLightNode = null;
            }
        }
Beispiel #18
0
        // Creates light sources with the same settings as BasicEffect.EnableDefaultLighting()
        // in the XNA Framework.
        internal static void InitializeDefaultXnaLights(Scene scene)
        {
            var ambientLight = new AmbientLight
            {
                Color     = new Vector3F(0.05333332f, 0.09882354f, 0.1819608f),
                Intensity = 1,
                HemisphericAttenuation = 0,
            };

            scene.Children.Add(new LightNode(ambientLight));

            var keyLight = new DirectionalLight
            {
                Color             = new Vector3F(1, 0.9607844f, 0.8078432f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 1,
            };
            var keyLightNode = new LightNode(keyLight)
            {
                Name      = "KeyLight",
                Priority  = 10, // This is the most important light.
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(-0.5265408f, -0.5735765f, -0.6275069f))),
            };

            scene.Children.Add(keyLightNode);

            var fillLight = new DirectionalLight
            {
                Color             = new Vector3F(0.9647059f, 0.7607844f, 0.4078432f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 0,
            };
            var fillLightNode = new LightNode(fillLight)
            {
                Name      = "FillLight",
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(0.7198464f, 0.3420201f, 0.6040227f))),
            };

            scene.Children.Add(fillLightNode);

            var backLight = new DirectionalLight
            {
                Color             = new Vector3F(0.3231373f, 0.3607844f, 0.3937255f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 1,
            };
            var backLightNode = new LightNode(backLight)
            {
                Name      = "BackLight",
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(0.4545195f, -0.7660444f, 0.4545195f))),
            };

            scene.Children.Add(backLightNode);
        }
Beispiel #19
0
        public VarianceShadowSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            _graphicsScreen = new DeferredGraphicsScreen(Services)
            {
                // For debugging: Disable materials and only show light buffer.
                DebugMode = DeferredGraphicsDebugMode.VisualizeDiffuseLightBuffer
            };
            _graphicsScreen.DrawReticle = true;
            GraphicsService.Screens.Insert(0, _graphicsScreen);

            GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services));

            Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer);
            Services.Register(typeof(IScene), null, _graphicsScreen.Scene);

            // Add gravity and damping to the physics simulation.
            Simulation.ForceEffects.Add(new Gravity());
            Simulation.ForceEffects.Add(new Damping());

            // Add a custom game object which controls the camera.
            var cameraGameObject = new CameraObject(Services);

            GameObjectService.Objects.Add(cameraGameObject);
            _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

            GameObjectService.Objects.Add(new GrabObject(Services));

            // Create test scene.
            ShadowSample.CreateScene(Services, ContentManager, _graphicsScreen);

            // Get directional light created by the DynamicSkyObject and replace the default
            // shadow with our custom VSM shadow.
            _lightNode      = _graphicsScreen.Scene.GetDescendants().OfType <LightNode>().First(n => n.Shadow is CascadedShadow);
            _varianceShadow = new VarianceShadow
            {
                // If a target area is set, the VSM covers the given area.
                // If no target area is set, the VSM covers the area in front of the camera.
                TargetArea = new Aabb(new Vector3(-100, 0, -100), new Vector3(100, 50, 100)),
            };
            _lightNode.Shadow = _varianceShadow;

            // Apply a blur filter to the shadow map.
            _varianceShadow.Filter = new Blur(GraphicsService);
            _varianceShadow.Filter.InitializeGaussianBlur(11, 3, false);

            // Register our custom shadow map and shadow mask renderers.
            _graphicsScreen.ShadowMapRenderer.Renderers.Add(new VarianceShadowMapRenderer(_graphicsScreen.ShadowMapRenderer.RenderCallback));
            _graphicsScreen.ShadowMaskRenderer.Renderers.Add(new VarianceShadowMaskRenderer(GraphicsService));

            CreateGuiControls();
        }
Beispiel #20
0
        // OnUnload() is called when the GameObject is removed from the IGameObjectService.
        protected override void OnUnload()
        {
            // Clean up.
            _campfire.Parent.Children.Remove(_campfire);
            _campfire.Dispose(false);
            _campfire = null;

            _fireParticles  = null;
            _smokeParticles = null;
            _light          = null;
            _random         = null;
        }
Beispiel #21
0
        private void InitializeLights()
        {
            // This scene node is used as the parent of all light nodes created here.
            _lightGroupNode = new SceneNode
            {
                Name     = "SkyGroup",
                Children = new SceneNodeCollection()
            };
            _scene.Children.Add(_lightGroupNode);

            // Add an ambient light.
            var ambientLight = new AmbientLight
            {
                HemisphericAttenuation = 1,
            };

            _ambientLightNode = new LightNode(ambientLight)
            {
                Name = "Ambient",
            };
            _lightGroupNode.Children.Add(_ambientLightNode);

            // Add a directional light for the sun.
            _sunlightNode = new LightNode(new DirectionalLight())
            {
                Name     = "Sunlight",
                Priority = 10, // This is the most important light.

                // This light uses Cascaded Shadow Mapping.
                Shadow = new CascadedShadow
                {
                    PreferredSize     = 1024,
                    DepthBiasScale    = new Vector4F(0.99f),
                    DepthBiasOffset   = new Vector4F(0),
                    FadeOutDistance   = 20,
                    MaxDistance       = 30,
                    MinLightDistance  = 100,
                    ShadowFog         = 0.5f,
                    JitterResolution  = 3000,
                    SplitDistribution = 0.7f
                }
            };
            _lightGroupNode.Children.Add(_sunlightNode);

            // Add a directional light for the moonlight.
            _moonlightNode = new LightNode(new DirectionalLight())
            {
                Name     = "Moonlight",
                Priority = 5,
            };
            _lightGroupNode.Children.Add(_moonlightNode);
        }
        public void CreateLights(Vector3 light_vector)
        {
            // Create a directional light source
            lightSource           = new LightSource();
            lightSource.Direction = light_vector;
            lightSource.Diffuse   = Color.White.ToVector4();
            lightSource.Specular  = new Vector4(0.6f, 0.6f, 0.6f, 1);

            // Create a light node to hold the light source
            lightNode = new LightNode();
            lightNode.AmbientLightColor = new Vector4(0.5f, 0.5f, 0.5f, 1);
            lightNode.LightSource       = lightSource;
        }
Beispiel #23
0
        // OnLight marks the beginning of export of a light which is enabled for rendering.
        // This method is only called for interface IPhotoRenderContext.
        public void OnLight(
            LightNode InLightNode             // light output node
            )
        {
            // Keep track of the world transform for the light being processed.
            WorldTransformStack.Push(WorldTransformStack.Peek().Multiply(InLightNode.GetTransform()));

            // Add a light actor in the hierarchy of Datasmith actors being processed.
            AddLightActor(WorldTransformStack.Peek(), InLightNode.GetAsset());

            // Forget the current light world transform.
            WorldTransformStack.Pop();
        }
Beispiel #24
0
        private void CreateLights()
        {
            LightSource lightSource = new LightSource();
            lightSource.Direction = new Vector3(1, -1, -1);
            lightSource.Diffuse = new Vector4(0.8f, 0.8f, 0.8f, 1);
            lightSource.Specular = new Vector4(0.6f, 0.6f, 0.6f, 1);

            LightNode lightNode = new LightNode();
            lightNode.AmbientLightColor = new Vector4(0.2f, 0.2f, 0.2f, 1);
            lightNode.LightSource = lightSource;

            scene.RootNode.AddChild(lightNode);
        }
Beispiel #25
0
        public DirectionalLightElem(LightNode node)
        {
            //this.Name = node.Value.name;
            this.Name = string.Format("{0}_{1}", node.Value.name, Type);

            //var dir = node.Direction;
            this.UnityMatrix = Matrix4x4.identity;

            this.Intensity  = node.Intensity;
            this.UnityColor = node.Color;

            // TODO shadow : cast
        }
Beispiel #26
0
        protected override void OnUnload()
        {
            // Detach the scene nodes from the scene.
            if (_skyGroupNode.Parent != null)
            {
                _skyGroupNode.Parent.Children.Remove(_skyGroupNode);
            }

            _lightGroupNode.Parent.Children.Remove(_lightGroupNode);

            // Dispose allocated resources.
            _skyGroupNode.Dispose(false);
            _lightGroupNode.Dispose(false);

            if (_enableClouds)
            {
                _cloudLayerNode0.CloudMap.Dispose();
                _cloudLayerNode1.CloudMap.Dispose();
            }

            if (_cacheSky)
            {
                _sceneCaptureNode.RenderToTexture.Texture.Dispose();
                _sceneCaptureNode.Dispose(false);
                _cloudMapRenderer.Dispose();
                _skyRenderer.Dispose();
                _colorEncoder.Dispose();
                _sceneCaptureRenderer.Dispose();
            }

            // Set references to null.
            _cameraObject         = null;
            _skyGroupNode         = null;
            _lightGroupNode       = null;
            _milkyWayNode         = null;
            _starfieldNode        = null;
            _sunNode              = null;
            _moonNode             = null;
            _scatteringSkyNode    = null;
            _ambientLightNode     = null;
            _sunlightNode         = null;
            _moonlightNode        = null;
            _cloudLayerNode0      = null;
            _cloudLayerNode1      = null;
            _sceneCaptureNode     = null;
            SkyboxNode            = null;
            _cloudMapRenderer     = null;
            _skyRenderer          = null;
            _colorEncoder         = null;
            _sceneCaptureRenderer = null;
        }
Beispiel #27
0
        private void InitializeLights()
        {
            // This scene node is used as the parent of all light nodes created here.
            _lightGroupNode = new SceneNode
            {
                Name     = "SkyGroup",
                Children = new SceneNodeCollection()
            };
            _scene.Children.Add(_lightGroupNode);

            // Add an ambient light.
            var ambientLight = new AmbientLight
            {
                HemisphericAttenuation = 1,
            };

            _ambientLightNode = new LightNode(ambientLight)
            {
                Name      = "Ambient",
                IsEnabled = _enableAmbientLight,
            };
            _lightGroupNode.Children.Add(_ambientLightNode);

            // Add a directional light for the sun.
            _sunlightNode = new LightNode(new DirectionalLight())
            {
                Name     = "Sunlight",
                Priority = 10, // This is the most important light.

                // This light uses Cascaded Shadow Mapping.
                Shadow = new CascadedShadow
                {
#if XBOX
                    PreferredSize = 512,
#else
                    PreferredSize = 1024,
#endif
                    Prefer16Bit      = true,
                    MinLightDistance = 1000,
                }
            };
            _lightGroupNode.Children.Add(_sunlightNode);

            // Add a directional light for the moonlight.
            _moonlightNode = new LightNode(new DirectionalLight())
            {
                Name     = "Moonlight",
                Priority = 5,
            };
            _lightGroupNode.Children.Add(_moonlightNode);
        }
Beispiel #28
0
        protected override void Start()
        {
            // 3D scene with Octree
            Scene             = new Scene(Context);
            Octree            = Scene.CreateComponent <Octree>();
            Zone              = Scene.CreateComponent <Zone>();
            Zone.AmbientColor = new Color(0.6f, 0.6f, 0.6f);
            RootNode          = Scene.CreateChild("RootNode");
            RootNode.Position = new Vector3(x: 0, y: -2, z: 8);

            // Camera
            CameraNode          = Scene.CreateChild(name: "Camera");
            CameraNode.Rotation = new Quaternion(Pitch = 0, 0, 0);
            Camera = CameraNode.CreateComponent <Camera>();

            // Light
            LightNode          = CameraNode.CreateChild();
            LightNode.Position = new Vector3(-5, 10, 0);
            Light            = LightNode.CreateComponent <Light>();
            Light.Range      = 100;
            Light.Brightness = 0.5f;
            Light.LightType  = LightType.Point;

            // Viewport
            Viewport = new Viewport(Context, Scene, Camera, null);
            Renderer.SetViewport(0, Viewport);
            Viewport.SetClearColor(new Color(0.88f, 0.88f, 0.88f));

            if (Platform.IsMobile())
            {
                Viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA2);
            }
            else if (Platform != Platforms.UWP && Platform != Platforms.SharpReality)
            {
                ResourceCache.AutoReloadResources = true;
                Renderer.HDRRendering             = true;
                Viewport.RenderPath.Append(CoreAssets.PostProcess.BloomHDR);
                Viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA3);
            }

#if DESKTOP
            Input.SubscribeToMouseWheel(args => CameraNode.Translate(-Vector3.UnitZ * 1f * args.Wheel * -1));
            Input.SetMouseVisible(true, true);
            Input.SubscribeToKeyDown(args => {
                if (args.Key == Key.Esc)
                {
                    Exit();
                }
            });
#endif
        }
Beispiel #29
0
        // OnUnload() is called when the GameObject is removed from the IGameObjectService.
        protected override void OnUnload()
        {
            _skyboxNode.Parent.Children.Remove(_skyboxNode);
            _skyboxNode.Dispose(false);
            _skyboxNode = null;

            _ambientLightNode.Parent.Children.Remove(_ambientLightNode);
            _ambientLightNode.Dispose(false);
            _ambientLightNode = null;

            _sunlightNode.Parent.Children.Remove(_sunlightNode);
            _sunlightNode.Dispose(false);
            _sunlightNode = null;
        }
Beispiel #30
0
    public LightNode MarchLightTree(LightSource source, Dictionary <PlayObject, List <LightBeam> > collisions, int maxDepth)
    {
        LightNode root = new LightNode {
            Object     = source,
            Position   = WorldPositionToGrid(source.transform.position),
            LightBeams = source.ComputeOutgoingLightBeams(null)
        };

        foreach (LightBeam lightBeam in root.LightBeams)
        {
            root.LightNodes.Add(March(root.Position, lightBeam, collisions, maxDepth));
        }
        return(root);
    }
Beispiel #31
0
	/**
	 * ReadLight
	 *
	 * @param infile
	 */
	private void ReadLight()
	{
		String temp;
		double[] input = new double[3];
		int i;

		temp = readString();
		temp = temp.Substring(11);
		for(i = 0; i < 2; i++)
		{
			input[i] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' ')));
			temp = temp.Substring(temp.IndexOf(' ') + 1);
		}
		input[2] = (double)Double.Parse(temp);
		Point position = new Point(input[0], input[1], input[2]);
		temp = readString();
		temp = temp.Substring(8);
		for(i = 0; i < 2; i++)
		{
			input[i] = (double)Double.Parse(temp.Substring(0, temp.IndexOf(' ')));
			temp = temp.Substring(temp.IndexOf(' ') + 1);
		}
		input[2] = (double)Double.Parse(temp);
		Color color = new Color(input[0], input[1], input[2]);
		temp = readString();
		Light newlight = new Light(position, color);
		LightNode newnode = new LightNode(newlight, lights);
		lights = newnode;
	}
 public void OnLight(LightNode inNode)
 {
 }
Beispiel #33
0
        public void OnLight(LightNode node)
        {
            // More info about lights can be acquired here using the standard Light API

            return;
        }
Beispiel #34
0
	/**
	 * LoadSceneOrig
	 *
	 * @param filename
	 * @return int
	 */
	private int LoadSceneOrig(String filename)
	{
		sceneLines = File.ReadAllLines(filename);
		scenePos = 0;

		int numObj = 0, ObjID = 0;

		camera = null;
		lights = null;
		objects = null;
		materials = null;
		MaxX = MinX = MaxY = MinY = MaxZ = MinZ = 0.0f;
		String input;

		input = readString();

		while(input != null)
		{
			if(input.Equals("camera {"))
			{
				ReadCamera();
			}
			else if(input.Equals("point_light {"))
			{
				ReadLight();
			}
			else if(input.Equals("sphere {"))
			{
				numObj += ReadSphere(ObjID);
			}
			else if(input.Equals("poly_set {"))
			{
				numObj += ReadPoly(ObjID);
			}
			else
			{ ;}

			input = readString();
		}

		return (numObj);
	}