bool Layout(int shadowWidth, int shadowHeight) { allCachedShadowInfos.Sort(); float curx = 0, cury = 0, curh = 0, xmax = shadowWidth, ymax = shadowHeight; for (int i = 0; i < allCachedShadowInfos.Count; i++) { // shadow atlas layouting CachedShadowInfo info = allCachedShadowInfos[i]; Rect vp = info.viewport; curh = curh >= vp.height ? curh : vp.height; if (curx + vp.width > xmax) { curx = 0; cury += curh; curh = vp.width; } if (curx + vp.width > xmax || cury + curh > ymax) { return(false); } vp.x = curx; vp.y = cury; info.viewport = vp; allCachedShadowInfos[i] = info; curx += vp.width; } return(true); }
private bool CollectStaticShadowmaps() { int shadowWidth = m_staticShadowMapResolution.value.vector2IntValue.x; int shadowHeight = m_staticShadowMapResolution.value.vector2IntValue.y; allCachedShadowInfos.Clear(); csdIndex.Clear(); for (int i = 0; i < allCachedShadows.Count; i++) { var csd = allCachedShadows[i]; Light l = csd.GetComponent <Light>(); AdditionalShadowData asd = csd.GetComponent <AdditionalShadowData>(); if (l != null && l.shadows != LightShadows.None && (csd.shadowUpdateType == ShadowUpdateType.Static || (l.type == LightType.Directional && csd.UseStaticShadowmapForLastCascade))) { CachedShadowInfo info = new CachedShadowInfo(); uint staticShadowmapRes = l.type == LightType.Directional ? csd.StaticShadowResolution : (uint)asd.shadowResolution; info.viewport = new Rect(0, 0, staticShadowmapRes, staticShadowmapRes); allCachedShadowInfos.Add(info); csdIndex.Add(i); } } return(Layout(shadowWidth, shadowHeight)); }