示例#1
0
        private void UpdateScene(DeviceContext context)
        {
            var perFrame = new ConstantBuffer.PerFrame {
                CameraPosition = Scene.CameraPosition
            };

            LightScene(ref perFrame);
            context.UpdateSubresource(ref perFrame, PerFrameBuffer);
        }
示例#2
0
        private void LightScene(ref ConstantBuffer.PerFrame perFrame)
        {
            var dirLight   = Lights.Where(l => l is DirectionalLight).FirstOrDefault();
            var pointLight = Lights.Where(l => l is PointLight).FirstOrDefault();
            var spotLight  = Lights.Where(l => l is SpotLight).FirstOrDefault();

            var ligthMat  = Matrix.RotationY(360 * Scene.Time / 1000);
            var lightDir0 = Vector3.Transform(dirLight.Direction, Scene.Model * (dirLight.IsDynamic ? ligthMat : Matrix.Identity));
            var lightDir1 = Vector3.Transform(pointLight.Direction, Scene.Model * (pointLight.IsDynamic ? ligthMat : Matrix.Identity));
            var lightDir2 = Vector3.Transform(spotLight.Direction, Scene.Model * (spotLight.IsDynamic ? ligthMat : Matrix.Identity));

            perFrame.Light0.Direction = new Vector3(lightDir0.X, lightDir0.Y, lightDir0.Z);
            perFrame.Light1.Direction = new Vector3(lightDir1.X, lightDir1.Y, lightDir1.Z);
            perFrame.Light2.Direction = new Vector3(lightDir2.X, lightDir2.Y, lightDir2.Z);

            perFrame.Light0.On = dirLight.IsOn ? 1u : 0;
            perFrame.Light1.On = pointLight.IsOn ? 1u : 0;
            perFrame.Light2.On = spotLight.IsOn ? 1u : 0;

            perFrame.Light0.Color = dirLight.Color;
            perFrame.Light1.Color = pointLight.Color;
            perFrame.Light2.Color = spotLight.Color;
        }