Example #1
0
        public override bool Update(LightComponent lightComponent)
        {
            var range = Math.Max(0.001f, Range);
            InvSquareRange = 1.0f / (range * range);
            var innerAngle = Math.Min(AngleInner, AngleOuter);
            var outerAngle = Math.Max(AngleInner, AngleOuter);
            var cosInner = (float)Math.Cos(MathUtil.DegreesToRadians(innerAngle / 2));
            var cosOuter = (float)Math.Cos(MathUtil.DegreesToRadians(outerAngle / 2));
            LightAngleScale = 1.0f / Math.Max(0.001f, cosInner - cosOuter);
            LightAngleOffset = -cosOuter * LightAngleScale;

            LightRadiusAtTarget = (float)Math.Abs(Range * Math.Sin(MathUtil.DegreesToRadians(outerAngle / 2.0f)));

            return true;
        }
Example #2
0
 public override bool Update(LightComponent lightComponent)
 {
     return true;
 }
 public LightEntry(int currentLightGroupIndex, int currentLightGroupIndexNoShadows, LightComponent light, LightShadowMapTexture shadow)
 {
     GroupIndex = currentLightGroupIndex;
     GroupIndexNoShadows = currentLightGroupIndexNoShadows;
     Light = light;
     Shadow = shadow;
 }
        private LightComponentCollectionGroup GetLightGroup(LightComponent light)
        {
            LightComponentCollectionGroup lightGroup;

            var directLight = light.Type as IDirectLight;
            var lightGroups = directLight != null && directLight.Shadow.Enabled && shadowMapRenderer != null
                ? activeLightGroupsWithShadows
                : activeLightGroups;

            var type = light.Type.GetType();
            if (!lightGroups.TryGetValue(type, out lightGroup))
            {
                lightGroup = new LightComponentCollectionGroup();
                lightGroups.Add(type, lightGroup);
            }
            return lightGroup;
        }
Example #5
0
 public override bool Update(LightComponent lightComponent)
 {
     var range = Math.Max(0.001f, Radius);
     InvSquareRadius = 1.0f / (range * range);
     return true;
 }
        public void Initialize(LightComponent lightComponent, IDirectLight light, LightShadowMap shadowMap, int size, ILightShadowMapRenderer renderer)
        {
            if (lightComponent == null) throw new ArgumentNullException("lightComponent");
            if (light == null) throw new ArgumentNullException("light");
            if (shadowMap == null) throw new ArgumentNullException("shadowMap");
            if (renderer == null) throw new ArgumentNullException("renderer");
            LightComponent = lightComponent;
            Light = light;
            Shadow = shadowMap;
            Size = size;
            FilterType = Shadow.Filter == null || !Shadow.Filter.RequiresCustomBuffer() ? null : Shadow.Filter.GetType();
            Renderer = renderer;
            Atlas = null; // Reset the atlas, It will be setup after

            ShadowType = renderer.GetShadowType(Shadow);
        }
        protected override async Task LoadContent()
        {
            CreatePipeline();

            await base.LoadContent();

            IsMouseVisible = true;
            rotateLights = true;

            // load the model
            characterEntity = Asset.Load<Entity>("character_00");
            characterEntity.Transformation.Rotation = Quaternion.RotationAxis(Vector3.UnitX, (float)(0.5 * Math.PI));
            characterEntity.Transformation.Translation = characterInitPos;
            Entities.Add(characterEntity);

            // create the stand
            var material = Asset.Load<Material>("character_00_material_mc00");
            var standEntity = CreateStand(material);
            standEntity.Transformation.Translation = new Vector3(0, 0, -80);
            standEntity.Transformation.Rotation = Quaternion.RotationAxis(Vector3.UnitX, (float)(0.5 * Math.PI));
            Entities.Add(standEntity);

            var standBorderEntity = CreateStandBorder(material);
            standBorderEntity.Transformation.Translation = new Vector3(0, 0, -80);
            standBorderEntity.Transformation.Rotation = Quaternion.RotationAxis(Vector3.UnitX, (float)(0.5 * Math.PI));
            Entities.Add(standBorderEntity);

            // create the lights
            var directLightEntity = CreateDirectLight(new Vector3(-1, 1, -1), new Color3(1, 1, 1), 0.9f);
            directionalLight = directLightEntity.Get<LightComponent>();
            Entities.Add(directLightEntity);

            var spotLightEntity = CreateSpotLight(new Vector3(0, -500, 600), new Vector3(0, -200, 0), 15, 20, new Color3(1, 1, 1), 0.9f);
            Entities.Add(spotLightEntity);
            spotLight = spotLightEntity.Get<LightComponent>();

            var rand = new Random();
            for (var i = -800; i <= 800; i = i + 200)
            {
                for (var j = -800; j <= 800; j = j + 200)
                {
                    var position = new Vector3(i, j, (float)(rand.NextDouble()*150));
                    var color = new Color3((float)rand.NextDouble() + 0.3f, (float)rand.NextDouble() + 0.3f, (float)rand.NextDouble() + 0.3f);
                    var light = CreatePointLight(position, color);
                    pointLights.Add(light.Get<LightComponent>());
                    pointLightEntities.Add(light);
                    Entities.Add(light);
                }
            }

            // set the camera
            var targetEntity = new Entity(characterInitPos);
            var cameraEntity = CreateCamera(cameraInitPos, targetEntity, (float)GraphicsDevice.BackBuffer.Width / (float)GraphicsDevice.BackBuffer.Height);
            camera = cameraEntity.Get<CameraComponent>();
            Entities.Add(cameraEntity);
            RenderSystem.Pipeline.SetCamera(camera);

            // UI
            CreateUI();

            // Add a custom script
            Script.Add(UpdateScene);
        }
Example #8
0
 public abstract bool Update(LightComponent lightComponent);
Example #9
0
        public static async Task AnimateLight(EngineContext engineContext, int index, LightComponent lightComponent)
        {
            // Wait different time for each light
            await TaskEx.Delay(index * 20);
            var startIntensity = lightComponent.Intensity;

            // Turn light off
            var startTime = DateTime.UtcNow;
            while (true)
            {
                await engineContext.Scheduler.NextFrame();
                var elapsedTime = (DateTime.UtcNow - startTime).Seconds * 0.2f;
                if (elapsedTime > 1.0f)
                    break;
                lightComponent.Intensity = startIntensity * (1.0f - elapsedTime);
            }

            // Turn light on
       
            lightComponent.Intensity = startIntensity;
        }
Example #10
0
 public bool Update(LightComponent lightComponent)
 {
     SkyMatrix = Matrix.RotationQuaternion(lightComponent.Entity.Transform.Rotation);
     SkyboxComponent = lightComponent.Entity.Get<SkyboxComponent>();
     return SkyboxComponent != null && SkyboxComponent.Skybox != null;
 }