Ejemplo n.º 1
0
 public static Light Dummy()
 {
     Light retlight = new Light();
     retlight.Radius = 0.0001f;
     retlight.Intensity = 0.0001f;
     retlight.Shadow = false;
     retlight.LightType = "dummy";
     return retlight;
 }
Ejemplo n.º 2
0
 public MovingLight(Vector3 centrePoint, float radius, float intensity = 1.0f)
     : base(Vector3.Zero, Quaternion.Identity, Vector3.One)
 {
     Light light = new Light();
     light.Radius = 15.0f;
     light.Intensity = intensity;
     _centre = centrePoint;
     _radius = radius;
     Lights.Add(light);
 }
Ejemplo n.º 3
0
 public BareBulb(Vector3 position, Vector3 scale, Color color, float radius, float intensity)
 {
     _scale = scale;
     _position = position;
     _light = new Light();
     _light.LightType = "BakedShadow";
     _light.Color = color;
     _light.Radius = radius;
     _light.Intensity = intensity;
     _light.LocalTransform = Matrix.CreateTranslation(-Vector3.UnitY * (100.0f / 64.0f));
 }
Ejemplo n.º 4
0
 public MovingLight(Vector3 centrePoint, float radius, Color color, float intensity = 1.0f)
     : base(Vector3.Zero, Quaternion.Identity, Vector3.One)
 {
     Light light = new Light();
     light.Radius = 25.0f;
     light.Intensity = intensity;
     light.Color = color;
     light.Shadow = true;
     _centre = centrePoint;
     _radius = radius;
     Lights.Add(light);
 }
Ejemplo n.º 5
0
 public FollowLight(float radius, float intensity, Color color, Camera cam)
     : base(Vector3.Zero, Quaternion.Identity, Vector3.One)
 {
     _camera = cam;
     Light light;
     light = new Light();
     light.Color = color;
     light.Radius = radius;
     light.Intensity = intensity;
     light.LocalTransform = Matrix.Identity;
     light.Shadow = false;
     Lights.Add(light);
 }
Ejemplo n.º 6
0
 public PulsingLight(Vector3 position, Color color, float radius, float maxintensity, float minintensity, double period)
 {
     Components.Add(new Component(position, Quaternion.Identity, Vector3.One));
     _period = period;
     _light = new Light();
     _light.LightType = "BakedShadow";
     _light.Color = color;
     _light.Radius = radius;
     _light.Intensity = maxintensity;
     _light.LocalTransform = Matrix.Identity;
     Components[0].Lights.Add(_light);
     _minintensity = minintensity;
     _halfmax = (maxintensity - minintensity) / 2;
 }
Ejemplo n.º 7
0
        public virtual void DrawOcclusion(Camera camera, GraphicsDevice graphicsDevice, Light light, bool front = true)
        {
            if (Draw)
            {
                Vector3 LightPos = light.Transform.Translation;
                BoundingBox bb;
                float val;
                if (front)
                {
                    bb = new BoundingBox(LightPos - ((Vector3.UnitZ + Vector3.UnitX) * light.Radius), LightPos + (Vector3.One * light.Radius));
                    val = 1.0f;
                }
                else
                {
                    bb = new BoundingBox(LightPos - (Vector3.One * light.Radius), LightPos + ((Vector3.UnitZ + Vector3.UnitX) * light.Radius));
                    val = -1.0f;
                }

                foreach (ModelMesh mesh in _model.Meshes)
                {
                    if (bb.Intersects(Helpers.TransformSphere(mesh.BoundingSphere, m[mesh.ParentBone.Index])) || Game1.drawall)
                    {
                        foreach (EffectMaterial effect in mesh.Effects)
                        {
                            effect.CurrentTechnique = effect.Techniques["ShadowMap"];
                            effect.Parameters["Dir"].SetValue(val);
                            effect.Parameters["LightWorldView"].SetValue(m[mesh.ParentBone.Index] * light.LightView);
                            effect.Parameters["LightWorldViewProjection"].SetValue(m[mesh.ParentBone.Index] * light.LightViewProj);
                            effect.Parameters["LightPosition"].SetValue(LightPos);
                            effect.Parameters["LightClip"].SetValue(light.Radius);
                            mesh.Draw();
                            Game1.occluders++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void GenerateDPSShadowMap(Camera camera, Light light, List<LPPMesh> occludingMeshes, RenderTarget2D target)
        {
            _currentOccluders.Clear();

            foreach (LPPMesh occluder in occludingMeshes)
            {
                if (occluder.BoundingSphere.Intersects(light.BoundingSphere))
                    _currentOccluders.Add(occluder);
            }
            _graphicsDevice.BlendState = BlendState.Opaque;
            _graphicsDevice.DepthStencilState = DepthStencilState.Default;
            _graphicsDevice.SetRenderTarget(target);
            _clearShadow.CurrentTechnique.Passes[0].Apply();
            _quadRenderer.RenderQuad(GraphicsDevice, -Vector2.One, Vector2.One, pixelSize / 2);

            foreach (LPPMesh occluder in _currentOccluders)
            {
                occluder.DrawOcclusion(camera, GraphicsDevice, light);
                //Game1.occluders++;
            }
            _graphicsDevice.SetRenderTarget(target);
            _clearShadow.CurrentTechnique.Passes[0].Apply();
            _quadRenderer.RenderQuad(GraphicsDevice, -Vector2.One, Vector2.One, pixelSize / 2);

            foreach (LPPMesh occluder in _currentOccluders)
            {
                occluder.DrawOcclusion(camera, GraphicsDevice, light, false);
            }
            Game1.shadowmaps++;
            _graphicsDevice.SetRenderTarget(null);
        }
Ejemplo n.º 9
0
 public void Remove(Light light)
 {
     Lights.Remove(light);
 }
Ejemplo n.º 10
0
 public void Add(Light light)
 {
     Lights.Add(light);
 }
Ejemplo n.º 11
0
        public override void InitializeComponents()
        {
            Component shade;
            Light shadeLight;

            var toplink = new Component(Position, Quaternion.Identity, scalevec / 32.0f);
            toplink.Mesh = new LPPMesh(segmentModel);
            toplink.SetCollision(segmentPhys, true);

            Components.Add(toplink);

            Vector3 yVec = new Vector3(0.0f, scalevec.Y, 0.0f);

            var lastlink = toplink;

            for (int i = 0; i < numSegments; i++)
            {
                var link = new Component(Position - (yVec * (float)i * linklength), Quaternion.Identity, scalevec / 32.0f);
                link.Mesh = new LPPMesh(segmentModel);
                link.SetCollision(segmentPhys, false);
                CollisionRules.AddRule(lastlink.Entity, link.Entity, CollisionRule.NoBroadPhase);
                var joint = new DistanceJoint(lastlink.Entity, link.Entity, link.Position, link.Position);

                joint.SpringSettings.Advanced.UseAdvancedSettings = true;
                joint.SpringSettings.Advanced.ErrorReductionFactor = 0.99f;
                joint.SpringSettings.Advanced.Softness = 0.1f;

                Components.Add(link);
                Components.Add(new DummyComponent(joint));
                lastlink = link;
            }

            shade = new Component(Position - (yVec * ((numSegments * linklength) + 0.25f)), Quaternion.Identity, scalevec / 32.0f);
            shade.Mesh = new LPPMesh(lampModel);

            shadeLight = new Light();
            shadeLight.LocalTransform = Matrix.CreateTranslation(yVec * -0.3f);
            shadeLight.Shadow = true;
            shadeLight.LightType = "BakedShadow";
            shadeLight.Radius = 12.5f;
            shadeLight.Intensity = 0.75f;
            shadeLight.Color = lightColor;
            PhysicsInfo PI = new PhysicsInfo(lampPhys);
            PI.Density /= scalevec.Length() / Vector3.One.Length();
            shade.SetCollision(PI, false);
            shade.Lights.Add(shadeLight);
            shade.Entity.Tag = new EntityTag(this, shade);

            shadeLight = new Light();
            shadeLight.Color = lightColor;
            shadeLight.LocalTransform = Matrix.CreateTranslation(yVec);
            shadeLight.Radius = 11.9f;
            shadeLight.Intensity = 0.75f;
            shadeLight.Shadow = false;
            shade.Lights.Add(shadeLight);

            shadeLight = new Light();
            shadeLight.Intensity = 1.0f;
            shadeLight.Radius = 0.5f;
            shade.Lights.Add(shadeLight);
            Components.Add(shade);

            CollisionRules.AddRule(shade.Entity, lastlink.Entity, CollisionRule.NoBroadPhase);
            var joint1 = new DistanceJoint(lastlink.Entity, shade.Entity, shade.Position, lastlink.Position);
            joint1.SpringSettings.DampingConstant = 1000000f;
            joint1.SpringSettings.StiffnessConstant = 600000f;
            var angularMotor1 = new AngularMotor(lastlink.Entity, shade.Entity);
            angularMotor1.Settings.MaximumForce = 50f;
            Components.Add(new DummyComponent(joint1));
            Components.Add(new DummyComponent(angularMotor1));
            base.InitializeComponents();
        }