コード例 #1
0
ファイル: LightNode.cs プロジェクト: NinjaSteph/SureShot
        /// <summary>
        /// Creates a node that can hold a light source.
        /// </summary>
        /// <param name="name">The name of this light node</param>
        public LightNode(String name)
            : base(name)
        {
            lightSource = new LightSource();
            global = true;
            castShadows = true;
            worldTransform = Matrix.Identity;
            lightViewProjection = Matrix.Identity;
            ambientLightColor = new Vector4(0, 0, 0, 1);
            hasChanged = true;

            lightProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1, 1, 1000);
            lightFrustum = new BoundingFrustum(lightProjection);

            zero = Vector3.Zero;
            up = Vector3.Up;
        }
コード例 #2
0
        private void CreateLights()
        {
            // Create a directional light source
            LightSource lightSource = new LightSource();
            lightSource.Direction = new Vector3(-1, -1, 0);
            lightSource.Diffuse = Color.White.ToVector4();
            lightSource.Specular = Color.White.ToVector4();

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

            // Add this light node to the root node
            scene.RootNode.AddChild(lightNode);
        }
コード例 #3
0
ファイル: Tutorial8.cs プロジェクト: NinjaSteph/SureShot
        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);
        }
コード例 #4
0
ファイル: Tutorial13.cs プロジェクト: nmrabinovich/MedAR
        private void CreateLights()
        {
            // Create a directional light source
            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);

            // Create a light node to hold the light source
            LightNode lightNode = new LightNode();
            // Add an ambient component
            lightNode.AmbientLightColor = new Vector4(0.3f, 0.3f, 0.3f, 1);
            lightNode.LightSources.Add(lightSource);

            // Add this light node to the root node
            groundMarkerNode.AddChild(lightNode);
        }
コード例 #5
0
ファイル: LightNode.cs プロジェクト: NinjaSteph/SureShot
        public override void Load(XmlElement xmlNode)
        {
            base.Load(xmlNode);

            if (xmlNode.HasAttribute("Global"))
                global = bool.Parse(xmlNode.GetAttribute("Global"));
            if (xmlNode.HasAttribute("CastShadows"))
                castShadows = bool.Parse(xmlNode.GetAttribute("CastShadows"));
            if (xmlNode.HasAttribute("AmbientLightColor"))
                ambientLightColor = Vector4Helper.FromString(xmlNode.GetAttribute("AmbientLightColor"));

            XmlElement lightSourceXml = (XmlElement)xmlNode.ChildNodes[0];
            lightSource = (LightSource)Activator.CreateInstance(
                Type.GetType(lightSourceXml.Name));
            lightSource.Load(lightSourceXml);
        }
コード例 #6
0
ファイル: Tutorial13.cs プロジェクト: NinjaSteph/SureShot
        private void CreateLights()
        {
            // Create a directional light source
            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);

            // Create a light node to hold the light source
            LightNode lightNode = new LightNode();
            lightNode.CastShadows = true;
            lightNode.LightProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                1, 1f, 500);
            // Add an ambient component
            lightNode.AmbientLightColor = new Vector4(0.3f, 0.3f, 0.3f, 1);
            lightNode.LightSource = lightSource;

            // Add this light node to the root node
            groundMarkerNode.AddChild(lightNode);
        }
コード例 #7
0
ファイル: Tutorial17.cs プロジェクト: NinjaSteph/SureShot
        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);
        }
コード例 #8
0
ファイル: DirectXShader.cs プロジェクト: NinjaSteph/SureShot
 private void SetUpSingleLightSource(LightSource lightSource)
 {
     light.StructureMembers["direction"].SetValue(lightSource.Direction);
     light.StructureMembers["position"].SetValue(lightSource.Position);
     light.StructureMembers["falloff"].SetValue(lightSource.Falloff);
     light.StructureMembers["range"].SetValue(lightSource.Range);
     light.StructureMembers["color"].SetValue(lightSource.Diffuse);
     light.StructureMembers["attenuation0"].SetValue(lightSource.Attenuation0);
     light.StructureMembers["attenuation1"].SetValue(lightSource.Attenuation1);
     light.StructureMembers["attenuation2"].SetValue(lightSource.Attenuation2);
     light.StructureMembers["innerConeAngle"].SetValue(lightSource.InnerConeAngle);
     light.StructureMembers["outerConeAngle"].SetValue(lightSource.OuterConeAngle);
 }
コード例 #9
0
ファイル: DirectXShader.cs プロジェクト: NinjaSteph/SureShot
 static private int compareLightSource(LightSource l1, LightSource l2)
 {
     if ((int)l1.Type > (int)l2.Type)
     {
         return 1;
     }
     else if (l1.Type == l2.Type)
     {
         return 0;
     }
     else
     {
         return -1;
     }
 }
コード例 #10
0
ファイル: LightSource.cs プロジェクト: NinjaSteph/SureShot
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="light"></param>
 public LightSource(LightSource light)
 {
     position = light.Position;
     direction = light.Direction;
     lightType = light.Type;
     enabled = light.Enabled;
     diffuse = light.Diffuse;
     specular = light.Specular;
     attenuation0 = light.Attenuation0;
     attenuation1 = light.Attenuation1;
     attenuation2 = light.Attenuation2;
     falloff = light.Falloff;
     innerConeAngle = light.InnerConeAngle;
     outerConeAngle = light.OuterConeAngle;
     range = light.Range;
     hasChanged = true;
 }
コード例 #11
0
ファイル: DirectXShader.cs プロジェクト: NinjaSteph/SureShot
        public override void SetParameters(List<LightNode> globalLights, List<LightNode> localLights)
        {
            bool ambientSet = false;
            this.lightSources.Clear();
            LightNode lNode = null;
            Vector4 ambientLightColor = new Vector4(0, 0, 0, 1);

            // traverse the local lights in reverse order in order to get closest light sources
            // in the scene graph
            for (int i = localLights.Count - 1; i >= 0; i--)
            {
                lNode = localLights[i];
                // only set the ambient light color if it's not set yet and not the default color (0, 0, 0, 1)
                if (!ambientSet && (!lNode.AmbientLightColor.Equals(ambientLightColor)))
                {
                    ambientLightColor = lNode.AmbientLightColor;
                    ambientSet = true;
                }

                // skip the light source if not enabled
                if (!lNode.LightSource.Enabled)
                    continue;

                LightSource source = new LightSource(lNode.LightSource);
                if (lNode.LightSource.Type != LightType.Directional)
                    source.Position = lNode.LightSource.TransformedPosition;
                if (lNode.LightSource.Type != LightType.Point)
                    source.Direction = lNode.LightSource.TransformedDirection;

                lightSources.Add(source);
            }

            // Next, traverse the global lights in normal order
            for (int i = 0; i < globalLights.Count; i++)
            {
                lNode = globalLights[i];
                // only set the ambient light color if it's not set yet and not the default color (0, 0, 0, 1)
                if (!ambientSet && (!lNode.AmbientLightColor.Equals(ambientLightColor)))
                {
                    ambientLightColor = lNode.AmbientLightColor;
                    ambientSet = true;
                }

                // skip the light source if not enabled
                if (!lNode.LightSource.Enabled)
                    continue;

                LightSource source = new LightSource(lNode.LightSource);
                if (lNode.LightSource.Type != LightType.Directional)
                    source.Position = lNode.LightSource.TransformedPosition;
                if (lNode.LightSource.Type != LightType.Point)
                    source.Direction = lNode.LightSource.TransformedDirection;

                lightSources.Add(source);
            }

            dirLightSources.Clear();
            pointLightSources.Clear();
            spotLightSources.Clear();
            foreach (LightSource l in lightSources)
            {
                switch (l.Type)
                {
                    case LightType.Directional:
                        dirLightSources.Add(l);
                        break;
                    case LightType.Point:
                        pointLightSources.Add(l);
                        break;
                    case LightType.SpotLight:
                        spotLightSources.Add(l);
                        break;
                }
            }
            this.ambientLightColor.SetValue(ambientLightColor);
        }
コード例 #12
0
ファイル: Tutorial8.cs プロジェクト: cjoelrun/Battle-Royal
        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;

            scene.RootNode.AddChild(lightNode);
        }
コード例 #13
0
ファイル: designAR.cs プロジェクト: bludman/designAR
        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;
        }
コード例 #14
0
        private void CreateLights()
        {
            // Create a directional light source
            LightSource lightSource = new LightSource();
            lightSource.Direction = new Vector3(-0.8f, -0.5f, -1f);
            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.AmbientLightColor = new Vector4(0.2f, 0.2f, 0.2f, 1);
            lightNode.LightSource = lightSource;

            // Add this light node to the root node
            scene.RootNode.AddChild(lightNode);
        }
コード例 #15
0
        public void SetParameters(List<LightNode> globalLights, List<LightNode> localLights)
        {
            bool ambientSet = false;
            ClearBasicEffectLights();
            lightSources.Clear();
            LightNode lNode = null;
            Vector4 ambientLightColor = new Vector4(0, 0, 0, 1);

            // traverse the local lights in reverse order in order to get closest light sources
            // in the scene graph
            for (int i = localLights.Count - 1; i >= 0; i--)
            {
                lNode = localLights[i];
                // only set the ambient light color if it's not set yet and not the default color (0, 0, 0, 1)
                if (!ambientSet && (!lNode.AmbientLightColor.Equals(ambientLightColor)))
                {
                    ambientLightColor = lNode.AmbientLightColor;
                    ambientSet = true;
                }

                if (lightSources.Count < MaxLights)
                {
                    // skip the light source if not enabled or not a directional light
                    if (!lNode.LightSource.Enabled || (lNode.LightSource.Type != LightType.Directional))
                        continue;

                    LightSource source = new LightSource();
                    source.Diffuse = lNode.LightSource.Diffuse;
                    source.Direction = lNode.LightSource.TransformedDirection;
                    source.Specular = lNode.LightSource.Specular;

                    lightSources.Add(source);

                    // If there are already 3 lights, then skip other lights
                    if (lightSources.Count >= MaxLights)
                        break;
                }
            }

            // Next, traverse the global lights in normal order
            for (int i = 0; i < globalLights.Count; i++)
            {
                lNode = globalLights[i];
                // only set the ambient light color if it's not set yet and not the default color (0, 0, 0, 1)
                if (!ambientSet && (!lNode.AmbientLightColor.Equals(ambientLightColor)))
                {
                    ambientLightColor = lNode.AmbientLightColor;
                    ambientSet = true;
                }

                if (lightSources.Count < MaxLights)
                {
                    // skip the light source if not enabled or not a directional light
                    if (!lNode.LightSource.Enabled || (lNode.LightSource.Type != LightType.Directional))
                        continue;

                    LightSource source = new LightSource();
                    source.Diffuse = lNode.LightSource.Diffuse;
                    source.Direction = lNode.LightSource.TransformedDirection;
                    source.Specular = lNode.LightSource.Specular;

                    lightSources.Add(source);

                    // If there are already 3 lights, then skip other lights
                    if (lightSources.Count >= MaxLights)
                        break;
                }
            }
            
            ambientLight = Vector3Helper.GetVector3(ambientLightColor);

            if (lightSources.Count > 0)
            {
                DirectionalLight[] lights = {basicEffect.DirectionalLight0,
                    basicEffect.DirectionalLight1, basicEffect.DirectionalLight2};

                bool atLeastOneLight = false;
                int numLightSource = lightSources.Count;
                for (int i = 0; i < numLightSource; i++)
                {
                    lights[i].Enabled = true;
                    lights[i].DiffuseColor = Vector3Helper.GetVector3(lightSources[i].Diffuse);
                    lights[i].Direction = lightSources[i].Direction;
                    lights[i].SpecularColor = Vector3Helper.GetVector3(lightSources[i].Specular);
                    atLeastOneLight = true;
                }

                basicEffect.LightingEnabled = atLeastOneLight;
            }

            basicEffect.AmbientLightColor = ambientLight;
            lightsChanged = true;
        }
コード例 #16
0
ファイル: Tutorial14.cs プロジェクト: NinjaSteph/SureShot
        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);
        }