コード例 #1
0
            private void Core_OnUpdateLightSource(object sender, ShadowMapCore.UpdateLightSourceEventArgs e)
            {
                CameraCore camera = LightCamera ?? null;

                if (LightCamera == null)
                {
                    var lights = e.Context.RenderHost.PerFrameLights.Take(Constants.MaxLights);
                    foreach (var light in lights)
                    {
                        if (light.LightType == LightType.Directional)
                        {
                            var dlight = light.RenderCore as DirectionalLightCore;
                            var dir    = Vector3.TransformNormal(dlight.Direction, dlight.ModelMatrix).Normalized();
                            if (AutoCoverCompleteScene)
                            {
                                if (sceneChanged || e.Context.UpdateSceneGraphRequested || IsSceneDynamic)
                                {
                                    sceneChanged = false;
                                    var boundingBox = FindSceneBound(e.Context.RenderHost.PerFrameOpaqueNodes);
                                    if (!CreateCameraFromBound(ref boundingBox, ref dir))
                                    {
                                        SetOrthoCameraParameters(ref dir);
                                    }
                                }
                            }
                            else
                            {
                                SetOrthoCameraParameters(ref dir);
                            }
                            camera = orthoCamera;
                            break;
                        }
                        else if (light.LightType == LightType.Spot)
                        {
                            var splight = light.RenderCore as SpotLightCore;
                            persCamera.Position = (splight.Position + splight.ModelMatrix.Row4.ToVector3());
                            var look = Vector3.TransformNormal(splight.Direction, splight.ModelMatrix);
                            persCamera.LookDirection    = look;
                            persCamera.FarPlaneDistance = (float)splight.Range;
                            persCamera.FieldOfView      = (float)splight.OuterAngle;
                            persCamera.UpDirection      = Vector3.UnitZ;
                            camera = persCamera;
                            break;
                        }
                    }
                }
                if (camera == null)
                {
                    shadowCore.FoundLightSource = false;
                }
                else
                {
                    shadowCore.FoundLightSource = true;
                    shadowCore.LightView        = camera.CreateViewMatrix();
                    shadowCore.LightProjection  = camera.CreateProjectionMatrix(shadowCore.Width / shadowCore.Height);
                }
            }
コード例 #2
0
        private void Core_OnUpdateLightSource(object sender, ShadowMapCore.UpdateLightSourceEventArgs e)
        {
            CameraCore camera = LightCamera ?? null;

            if (LightCamera == null)
            {
                var lights = e.Context.RenderHost.PerFrameLights.Take(Constants.MaxLights);
                foreach (var light in lights)
                {
                    if (light.LightType == LightType.Directional)
                    {
                        var dlight = light.RenderCore as DirectionalLightCore;
                        var dir    = Vector4.Transform(dlight.Direction.ToVector4(0), dlight.ModelMatrix).Normalized() * distance;
                        var pos    = -dir;
                        orthoCamera.LookDirection = new Vector3(dir.X, dir.Y, dir.Z);
                        orthoCamera.Position      = new Vector3(pos.X, pos.Y, pos.Z);
                        orthoCamera.UpDirection   = Vector3.UnitZ;
                        orthoCamera.Width         = orthoWidth;
                        camera = orthoCamera;
                        break;
                    }
                    else if (light.LightType == LightType.Spot)
                    {
                        var splight = light.RenderCore as SpotLightCore;
                        persCamera.Position = (splight.Position + splight.ModelMatrix.Row4.ToVector3());
                        var look = Vector4.Transform(splight.Direction.ToVector4(0), splight.ModelMatrix);
                        persCamera.LookDirection    = new Vector3(look.X, look.Y, look.Z);
                        persCamera.FarPlaneDistance = (float)splight.Range;
                        persCamera.FieldOfView      = (float)splight.OuterAngle;
                        persCamera.UpDirection      = Vector3.UnitZ;
                        camera = persCamera;
                        break;
                    }
                }
            }
            if (camera == null)
            {
                shadowCore.FoundLightSource = false;
            }
            else
            {
                shadowCore.FoundLightSource       = true;
                shadowCore.LightViewProjectMatrix = camera.CreateViewMatrix() * camera.CreateProjectionMatrix(shadowCore.Width / shadowCore.Height);
            }
        }
コード例 #3
0
 /// <summary>
 /// Obtains the view transform matrix for a camera. (see page 327)
 /// </summary>
 /// <param name="camera">
 /// Camera to obtain the ViewMatrix for
 /// </param>
 /// <returns>
 /// A Matrix object with the camera view transform matrix, or a Matrix with all zeros if the "camera" is null.
 /// </returns>
 public static Matrix GetViewMatrix(this CameraCore camera)
 {
     return(camera.CreateViewMatrix());
 }