private VirtualLight CreateVirtualLight(Light light, int cascade) { var hasShadow = light as HasShadow; var virtualLight = new VirtualLight(light.Color) { UseOnlyShadow = true, DoesCastShadow = true, ShadowCameraNear = hasShadow.ShadowCameraNear, ShadowCameraFar = hasShadow.ShadowCameraFar, ShadowCameraLeft = hasShadow.ShadowCameraLeft, ShadowCameraRight = hasShadow.ShadowCameraRight, ShadowCameraBottom = hasShadow.ShadowCameraBottom, ShadowCameraTop = hasShadow.ShadowCameraTop, ShadowCameraVisible = hasShadow.ShadowCameraVisible, ShadowDarkness = hasShadow.ShadowDarkness, ShadowBias = hasShadow.ShadowCascadeBias[cascade], ShadowMapWidth = hasShadow.ShadowCascadeWidth[cascade], ShadowMapHeight = hasShadow.ShadowCascadeHeight[cascade], PointsWorld = new List<Vector3>(), PointsFrustum = new List<Vector3>() }; for (var i = 0; i < 8; i++) { virtualLight.PointsWorld.Add(Vector3.Zero); } var nearZ = hasShadow.ShadowCascadeNearZ[cascade]; var farZ = hasShadow.ShadowCascadeFarZ[cascade]; virtualLight.PointsFrustum.Add(new Vector3(-1, -1, nearZ)); virtualLight.PointsFrustum.Add(new Vector3(1, -1, nearZ)); virtualLight.PointsFrustum.Add(new Vector3(-1, 1, nearZ)); virtualLight.PointsFrustum.Add(new Vector3(1, 1, nearZ)); virtualLight.PointsFrustum.Add(new Vector3(-1, -1, farZ)); virtualLight.PointsFrustum.Add(new Vector3(1, -1, farZ)); virtualLight.PointsFrustum.Add(new Vector3(-1, 1, farZ)); virtualLight.PointsFrustum.Add(new Vector3(1, 1, farZ)); return virtualLight; }
// Synchronize virtual light with the original light private void UpdateVirtualLight(Light light, int cascade) { var shadowLight = light as HasShadow; var hasTarget = light as HasTarget; var virtualLight = shadowLight.ShadowCascadeArray[cascade]; virtualLight.Position = light.Position; virtualLight.Target = hasTarget.Target; virtualLight.LookAt(virtualLight.Target); virtualLight.ShadowCameraVisible = shadowLight.ShadowCameraVisible; virtualLight.ShadowDarkness = shadowLight.ShadowDarkness; virtualLight.ShadowBias = shadowLight.ShadowCascadeBias[cascade]; var nearZ = shadowLight.ShadowCascadeNearZ[cascade]; var farZ = shadowLight.ShadowCascadeFarZ[cascade]; Debug.Assert(virtualLight.PointsFrustum.Count == 8); for (var p = 0; p < 8; p++) { var point = virtualLight.PointsFrustum[p]; point.z = p < 4 ? nearZ : farZ; virtualLight.PointsFrustum[p] = point; } }
private void UpdateShadowCamera(Camera camera, Light light) { throw new NotImplementedException(); }