Exemple #1
0
 public PointLightBufferLayout(IPointLight pointLight)
 {
     Position             = new Vector4(pointLight.Position, 1);
     Ambient              = pointLight.Ambient * pointLight.Intensity.X;
     Diffuse              = pointLight.Diffuse * pointLight.Intensity.Y;
     Specular             = pointLight.Specular * pointLight.Intensity.Z;
     ConstantAttenuation  = pointLight.Attenuation.X;
     LinearAttenuation    = pointLight.Attenuation.Y;
     QuadraticAttenuation = pointLight.Attenuation.Z;
     Dummy = 0;
 }
        public PlasmaGunProjectile(ICanyonShooterGame game, Vector3 startPosition, Vector3 direction, PlasmaGun owner, WeaponHolderType weaponHolderType)
            : base(game, startPosition, direction, "RocketLaunch", weaponHolderType)
        {
            this.game  = game;
            this.owner = owner;
            // assign a Model
            SetModel("PlasmaGun");

            // effect light
            light        = new PointLight(game, Color.Azure, 1.0f);
            light.Parent = this;
            game.World.AddPointLight(light);



            // rotate the projectile into the direction
            Vector3 defaultDirection = new Vector3(0, 0, -1);

            if (defaultDirection != Direction)
            {
                Direction.Normalize();
                defaultDirection.Normalize();
                Vector3 rotationAxe = Vector3.Cross(defaultDirection, Direction);
                rotationAxe.Normalize();
                float angle = (float)Math.Acos(Vector3.Dot(Direction, defaultDirection));
                LocalRotation = Quaternion.CreateFromAxisAngle(rotationAxe, angle);
            }

            // set speed and direction of the projectile:
            velocity = Direction * owner.ProjectileSpeed + owner.Velocity;
            Velocity = velocity;

            InfluencedByGravity = false;

            /*
             * // create smoke effect
             * SmokeEmitter = game.Effects.CreateEffect("RocketSmoke");
             *
             * // connect the smoke to the this projectile-object:
             * SmokeEmitter.Parent = this;
             *
             * // place the smoke at the end of the rocket:
             * SmokeEmitter.LocalPosition = new Vector3(0, 0, 3.5f);
             *
             * // add smoke to the world
             * game.World.AddEffect(SmokeEmitter);
             *
             * // Loop Smoke until Destruction
             * SmokeEmitter.Play();
             */
        }
Exemple #3
0
        public void AddPointLight(IPointLight light)
        {
            if (light == null)
            {
                throw new Exception("Ein Licht darf nicht NULL sein! Ich bin dein Vater!");
            }

            if (pointLights.Contains(light))
            {
                throw new Exception("Element bereits im Index.");
            }

            pointLights.Add(light);
        }
Exemple #4
0
        public void RenderPointLight(IPointLight pointLight)
        {
            if (deferredPointLightEffect == null)
            {
                deferredPointLightEffect = AssetManager.GetAsset <Effect>("Shaders/Deferred/DeferredPointLight");
            }

            if (pointLightVolumeModel == null)
            {
                pointLightVolumeModel = AssetManager.GetAsset <Model>("Models/sphere2");
            }

            //set the G-Buffer parameters
            deferredPointLightEffect.Parameters["halfPixel"].SetValue(halfPixel);
            deferredPointLightEffect.Parameters["normalMap"].SetValue(normalMap);
            deferredPointLightEffect.Parameters["depthMap"].SetValue(depthMap);
            deferredPointLightEffect.Parameters["sgrMap"].SetValue(SGRMap);

            //compute the light world matrix
            //scale according to light radius, and translate it to light position
            Matrix sphereWorldMatrix = Matrix.CreateScale(pointLight.Radius) * Matrix.CreateTranslation(pointLight.Position);

            deferredPointLightEffect.Parameters["World"].SetValue(sphereWorldMatrix);
            deferredPointLightEffect.Parameters["View"].SetValue(Camera.View);
            deferredPointLightEffect.Parameters["Projection"].SetValue(Camera.Projection);
            //light position
            deferredPointLightEffect.Parameters["lightPosition"].SetValue(pointLight.Position);

            //set the color, radius and Intensity
            deferredPointLightEffect.Parameters["Color"].SetValue(pointLight.Color.ToVector3());
            deferredPointLightEffect.Parameters["lightRadius"].SetValue(pointLight.Radius);
            deferredPointLightEffect.Parameters["lightIntensity"].SetValue(pointLight.Intensity);

            //parameters for specular computations
            deferredPointLightEffect.Parameters["cameraPosition"].SetValue(Camera.Position);
            deferredPointLightEffect.Parameters["InvertViewProjection"].SetValue(Matrix.Invert(Camera.View * Camera.Projection));

            if (transforms == null || transforms.Length < pointLightVolumeModel.Bones.Count)
            {
                transforms = new Matrix[pointLightVolumeModel.Bones.Count];
            }

            pointLightVolumeModel.CopyAbsoluteBoneTransformsTo(transforms);

            int mc = pointLightVolumeModel.Meshes.Count;

            for (int m = 0; m < mc; m++)
            {
                // Do the world stuff.
                // Scale * transform * pos * rotation
                Matrix meshWorld;
                Matrix meshWVP;

                meshWorld = transforms[pointLightVolumeModel.Meshes[m].ParentBone.Index] * sphereWorldMatrix;
                meshWVP   = meshWorld * Camera.View * Camera.Projection;

                if (deferredPointLightEffect.Parameters["world"] != null)
                {
                    deferredPointLightEffect.Parameters["world"].SetValue(meshWorld);
                }
                if (deferredPointLightEffect.Parameters["wvp"] != null)
                {
                    deferredPointLightEffect.Parameters["wvp"].SetValue(meshWVP);
                }

                deferredPointLightEffect.CurrentTechnique.Passes[0].Apply();

                int mpc = pointLightVolumeModel.Meshes[m].MeshParts.Count;
                for (int mp = 0; mp < mpc; mp++)
                {
                    GraphicsDevice.SetVertexBuffer(pointLightVolumeModel.Meshes[m].MeshParts[mp].VertexBuffer);
                    GraphicsDevice.Indices = pointLightVolumeModel.Meshes[m].MeshParts[mp].IndexBuffer;
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, pointLightVolumeModel.Meshes[m].MeshParts[mp].NumVertices, pointLightVolumeModel.Meshes[m].MeshParts[mp].StartIndex, pointLightVolumeModel.Meshes[m].MeshParts[mp].PrimitiveCount);
                }
            }
        }
        public void RenderPointLight(IPointLight pointLight)
        {
            if (deferredPointLightEffect == null)
                deferredPointLightEffect = AssetManager.GetAsset<Effect>("Shaders/Deferred/DeferredPointLight");

            if (pointLightVolumeModel == null)
                pointLightVolumeModel = AssetManager.GetAsset<Model>("Models/sphere2");

            //set the G-Buffer parameters
            deferredPointLightEffect.Parameters["halfPixel"].SetValue(halfPixel);
            deferredPointLightEffect.Parameters["normalMap"].SetValue(normalMap);
            deferredPointLightEffect.Parameters["depthMap"].SetValue(depthMap);
            deferredPointLightEffect.Parameters["sgrMap"].SetValue(SGRMap);

            //compute the light world matrix
            //scale according to light radius, and translate it to light position
            Matrix sphereWorldMatrix = Matrix.CreateScale(pointLight.Radius) * Matrix.CreateTranslation(pointLight.Position);
            deferredPointLightEffect.Parameters["World"].SetValue(sphereWorldMatrix);
            deferredPointLightEffect.Parameters["View"].SetValue(Camera.View);
            deferredPointLightEffect.Parameters["Projection"].SetValue(Camera.Projection);
            //light position
            deferredPointLightEffect.Parameters["lightPosition"].SetValue(pointLight.Position);

            //set the color, radius and Intensity
            deferredPointLightEffect.Parameters["Color"].SetValue(pointLight.Color.ToVector3());
            deferredPointLightEffect.Parameters["lightRadius"].SetValue(pointLight.Radius);
            deferredPointLightEffect.Parameters["lightIntensity"].SetValue(pointLight.Intensity);

            //parameters for specular computations
            deferredPointLightEffect.Parameters["cameraPosition"].SetValue(Camera.Position);
            deferredPointLightEffect.Parameters["InvertViewProjection"].SetValue(Matrix.Invert(Camera.View * Camera.Projection));

            if (transforms == null || transforms.Length < pointLightVolumeModel.Bones.Count)
            {
                transforms = new Matrix[pointLightVolumeModel.Bones.Count];
            }
            
            pointLightVolumeModel.CopyAbsoluteBoneTransformsTo(transforms);

            int mc = pointLightVolumeModel.Meshes.Count;
            for(int m = 0;m<mc;m++)
            {
                // Do the world stuff. 
                // Scale * transform * pos * rotation
                Matrix meshWorld;
                Matrix meshWVP;

                meshWorld = transforms[pointLightVolumeModel.Meshes[m].ParentBone.Index] * sphereWorldMatrix;
                meshWVP = meshWorld * Camera.View * Camera.Projection;

                if (deferredPointLightEffect.Parameters["world"] != null)
                    deferredPointLightEffect.Parameters["world"].SetValue(meshWorld);
                if (deferredPointLightEffect.Parameters["wvp"] != null)
                    deferredPointLightEffect.Parameters["wvp"].SetValue(meshWVP);

                deferredPointLightEffect.CurrentTechnique.Passes[0].Apply();

                int mpc = pointLightVolumeModel.Meshes[m].MeshParts.Count;
                for(int mp = 0;mp<mpc;mp++)
                {
                    GraphicsDevice.SetVertexBuffer(pointLightVolumeModel.Meshes[m].MeshParts[mp].VertexBuffer);
                    GraphicsDevice.Indices = pointLightVolumeModel.Meshes[m].MeshParts[mp].IndexBuffer;
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, pointLightVolumeModel.Meshes[m].MeshParts[mp].NumVertices, pointLightVolumeModel.Meshes[m].MeshParts[mp].StartIndex, pointLightVolumeModel.Meshes[m].MeshParts[mp].PrimitiveCount);
                }
            }
        }
Exemple #6
0
 public void RemovePointLight(IPointLight light)
 {
     components.Remove(light);
     pointLights.Remove(light);
 }