Difference between revisions of "Mesh/Download Weight"
Kireji Haiku (talk | contribs) m (added intra-wiki links and applied cpp highlighting) |
m (→Implementation) |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Navbox/Mesh|tech}} | {{Navbox/Mesh|tech}} | ||
== Motivation == | == Motivation == | ||
Previously used methods of [ | Previously used methods of [[Mesh_and_LOD#Level_Of_Detail|LOD]] enforcement and [[Mesh]] cost have proved ineffective and difficult to adhere to. Proposed here is an algorithm for determining cost of a [[Mesh/Mesh_Asset_Format|Mesh asset]] (in terms of prim parcel cost) that correlates strongly to the actual load of streaming and displaying a [[Mesh]] in a general way, without making assumptions about triangle/vertex limits and ratios between levels of detail. The artist need not adhere to any arbitrary restrictions with respect to what [[Mesh_and_LOD#Level_Of_Detail|LODs]] must be supplied and what the parameters of those [[Mesh_and_LOD#Level_Of_Detail|LODs]] are, but providing proper [[Mesh_and_LOD#Level_Of_Detail|LODs]] will greatly reduce the cost of an [[Object|object]] in terms of parcel limits, effectively allowing regions with efficient content to carry more content, while regions with inefficient content can carry less. This should allow greater control from Linden Lab in terms of acceptable rendering and streaming budgets while also giving artists complete control over how they build. | ||
== Concept == | == Concept == | ||
The streaming and rendering cost of a | The streaming and rendering cost of a [[Mesh]] is directly related to the number of bytes in a [[Mesh/Mesh_Asset_Format|Mesh asset]] [[Mesh_and_LOD#Level_Of_Detail|LOD]] slot, and the likelihood that a given [[Mesh_and_LOD#Level_Of_Detail|LOD]] will be downloaded and displayed can be computed based on the size of the object. Imagine a set of 3 concentric circles centered on an object where each circle represents the transition boundary between [[Mesh_and_LOD#Level_Of_Detail|LODs]]. The streaming/rendering cost of that object can be determined by examining the size of those circles vs the number of bytes in the relevant [[Mesh_and_LOD#Level_Of_Detail|LODs]]. Uploading a high [[Mesh_and_LOD#Level_Of_Detail|LOD]] only will result in the load of the high lod being applied to the entire 256m, while uploading appropriate [[Mesh_and_LOD#Level_Of_Detail|LODs]] will result in the lion's share of 256m being applied to the lowest [[Mesh_and_LOD#Level_Of_Detail|LOD]]. | ||
== Equation == | == Equation == | ||
# Compute the distance at which each [ | # Compute the distance at which each [[Mesh_and_LOD#Level_Of_Detail|LOD]] is displayed | ||
# Compute the area in which each [ | # Compute the area in which each [[Mesh_and_LOD#Level_Of_Detail|LOD]] is relevant | ||
# Adjust for missiing [ | # Adjust for missiing [[Mesh_and_LOD#Level_Of_Detail|LODs]] | ||
# Scale relative weights of each [ | # Scale relative weights of each [[Mesh_and_LOD#Level_Of_Detail|LOD]] based on what percentage of the [[Region|region]] each [[Mesh_and_LOD#Level_Of_Detail|LOD]] covers. | ||
# Compute cost based on relevant range and bytes in [ | # Compute cost based on relevant range and bytes in [[Mesh_and_LOD#Level_Of_Detail|LOD]] | ||
Traditional parametric prims have their streaming weights (called "download" in the viewer) capped at 1.0. Sculpted prims are capped at 2.0. <sup>[[Release Notes/Second Life Server/12#12.07.31.262785|1]]</sup> | |||
To compute the distance at which each [ | === [[Mesh_and_LOD#Level_Of_Detail|LOD]] Transition Distances === | ||
To compute the distance at which each [[Mesh_and_LOD#Level_Of_Detail|LOD]] is displayed, take the radius of the [[Object|object]]'s bounding box (R) and divide by the [[Mesh_and_LOD#Level_Of_Detail|LOD]] ratios used in the viewer: | |||
<pre> | |||
Dlowest = distance at which lowest LOD begins to be displayed. | |||
Dlow = distance at which low LOD begins to be displayed. | |||
Dmid = distance at which mid LOD begins to be displayed. | |||
Dhigh = distance at which high LOD begins to be displayed. | |||
Dlowest = R / 0.03 | |||
Dlow = R / 0.06 | |||
Dmid = R / 0.24 | |||
Dhigh = 0.0 | |||
lowest_circle = max area | |||
low_circle = PI * Dlowest ^2 | |||
mid_circle = PI * Dlow ^2 | |||
high_circle = PI * Dmid^2 | |||
lowest_area = lowest_circle - low_circle | |||
low_area = low_circle - mid_circle | |||
mid_area = mid_circle - high_circle | |||
high_area = high_circle | |||
</pre> | |||
=== Relevant [ | === Relevant [[Mesh_and_LOD#Level_Of_Detail|LOD]] Ranges === | ||
The relevant range of each [ | The relevant range of each [[Mesh_and_LOD#Level_Of_Detail|LOD]] is the distance between which that [[Mesh_and_LOD#Level_Of_Detail|LOD]] becomes visible and the distance at which that [[Mesh_and_LOD#Level_Of_Detail|LOD]] is no longer displayed, clamped to a 256m circle. | ||
<pre> | <pre> | ||
Line 48: | Line 51: | ||
</pre> | </pre> | ||
==== Adjusting for missing [ | ==== Adjusting for missing [[Mesh_and_LOD#Level_Of_Detail|LODs]] ==== | ||
if any lod is missing, substitute bytes in next highest available [ | if any lod is missing, substitute bytes in next highest available [[Mesh_and_LOD#Level_Of_Detail|LOD]]. That is, if <code>BYTES_IN_MID</code> is zero, substitute <code>BYTES_IN_HIGH</code> for <code>BYTES_IN_MID</code>, and so on. | ||
==== Computing Cost ==== | ==== Computing Cost ==== | ||
Line 62: | Line 65: | ||
</pre> | </pre> | ||
In the details of the implementation, the | In the details of the implementation, the <code>cost_scalar</code> is based on a target triangle budget, and efforts are made to convert <code>bytes_in_foo</code> to an estimated triangle count. | ||
=== Implementation === | === Implementation === | ||
<cpp> | <source lang="cpp"> | ||
// Get the streaming cost for the given mesh | // Get the streaming cost for the given mesh | ||
// header -- header of mesh as described in mesh asset format | // header -- header of mesh as described in mesh asset format | ||
Line 72: | Line 75: | ||
// bytes_visible -- if not NULL, gets number of bytes in specified lod (for debugging) | // bytes_visible -- if not NULL, gets number of bytes in specified lod (for debugging) | ||
// lod -- currently visible lod (for debugging) | // lod -- currently visible lod (for debugging) | ||
F32 LLMeshRepository::getStreamingCost(LLSD& header, F32 radius, S32* bytes, S32* bytes_visible, S32 lod) | F32 LLMeshRepository::getStreamingCost(LLSD& header, F32 radius, S32* bytes, S32* bytes_visible, S32 lod) | ||
{ | { | ||
Line 166: | Line 170: | ||
return weighted_avg/gSavedSettings.getU32("MeshTriangleBudget")*15000.f; | return weighted_avg/gSavedSettings.getU32("MeshTriangleBudget")*15000.f; | ||
} | } | ||
</ | </source> | ||
== Issues == | == Issues == | ||
* Providing identical models for every [ | * Providing identical models for every [[Mesh_and_LOD#Level_Of_Detail|LOD]] results in a cost identical to providing a single [[Mesh_and_LOD#Level_Of_Detail|LOD]], but results in 4x the bandwidth usage. | ||
* Changing the scale of an object changes its cost, which can be confusing. | * Changing the scale of an object changes its cost, which can be confusing. | ||
* For viewers with a view distance greater than 256m, the clamping to 256m is unrealistic. | * For viewers with a view distance greater than 256m, the clamping to 256m is unrealistic. | ||
* Some validating of [ | * Some validating of [[Mesh_and_LOD#Level_Of_Detail|LODs]] is still necessary. | ||
** The highest [ | ** The highest [[Mesh_and_LOD#Level_Of_Detail|LOD]] must be specified. | ||
** Each [ | ** Each [[Mesh_and_LOD#Level_Of_Detail|LOD]] must have the same number of faces as the highest [[Mesh_and_LOD#Level_Of_Detail|LOD]]. | ||
== Related Articles == | == Related Articles == | ||
* [[Mesh Accounting Test]] | * [[Mesh Accounting Test]] | ||
* [[Mesh/Mesh physics|Mesh physics]] | * [[Mesh/Mesh physics|Mesh physics]] |
Latest revision as of 19:36, 31 January 2015
Motivation
Previously used methods of LOD enforcement and Mesh cost have proved ineffective and difficult to adhere to. Proposed here is an algorithm for determining cost of a Mesh asset (in terms of prim parcel cost) that correlates strongly to the actual load of streaming and displaying a Mesh in a general way, without making assumptions about triangle/vertex limits and ratios between levels of detail. The artist need not adhere to any arbitrary restrictions with respect to what LODs must be supplied and what the parameters of those LODs are, but providing proper LODs will greatly reduce the cost of an object in terms of parcel limits, effectively allowing regions with efficient content to carry more content, while regions with inefficient content can carry less. This should allow greater control from Linden Lab in terms of acceptable rendering and streaming budgets while also giving artists complete control over how they build.
Concept
The streaming and rendering cost of a Mesh is directly related to the number of bytes in a Mesh asset LOD slot, and the likelihood that a given LOD will be downloaded and displayed can be computed based on the size of the object. Imagine a set of 3 concentric circles centered on an object where each circle represents the transition boundary between LODs. The streaming/rendering cost of that object can be determined by examining the size of those circles vs the number of bytes in the relevant LODs. Uploading a high LOD only will result in the load of the high lod being applied to the entire 256m, while uploading appropriate LODs will result in the lion's share of 256m being applied to the lowest LOD.
Equation
- Compute the distance at which each LOD is displayed
- Compute the area in which each LOD is relevant
- Adjust for missiing LODs
- Scale relative weights of each LOD based on what percentage of the region each LOD covers.
- Compute cost based on relevant range and bytes in LOD
Traditional parametric prims have their streaming weights (called "download" in the viewer) capped at 1.0. Sculpted prims are capped at 2.0. 1
LOD Transition Distances
To compute the distance at which each LOD is displayed, take the radius of the object's bounding box (R) and divide by the LOD ratios used in the viewer:
Dlowest = distance at which lowest LOD begins to be displayed. Dlow = distance at which low LOD begins to be displayed. Dmid = distance at which mid LOD begins to be displayed. Dhigh = distance at which high LOD begins to be displayed. Dlowest = R / 0.03 Dlow = R / 0.06 Dmid = R / 0.24 Dhigh = 0.0 lowest_circle = max area low_circle = PI * Dlowest ^2 mid_circle = PI * Dlow ^2 high_circle = PI * Dmid^2 lowest_area = lowest_circle - low_circle low_area = low_circle - mid_circle mid_area = mid_circle - high_circle high_area = high_circle
Relevant LOD Ranges
The relevant range of each LOD is the distance between which that LOD becomes visible and the distance at which that LOD is no longer displayed, clamped to a 256m circle.
Example: For an object with a bounding box R of 10m, The Dhigh LOD will be displayed while the camera is within 0m to 42m from the object's center. The Dmid LOD will be displayed while the camera is within 42m to 166.67m (10/0.24) from the object's center. The Dlow LOD will be displayed while the camera is within 166.67m to 333.3m from the object's center. The Dlowest LOD will be displayed while the camera is further than 333.37m from the object's center.
Adjusting for missing LODs
if any lod is missing, substitute bytes in next highest available LOD. That is, if BYTES_IN_MID
is zero, substitute BYTES_IN_HIGH
for BYTES_IN_MID
, and so on.
Computing Cost
At the simplest level, streaming cost is computed as:
Streaming Cost = ( (lowest_area / total_area) * bytes_in_lowest + (low_area / total_area) * bytes_in_low + (mid_area / total_area) * bytes_in_mid + (high_area / total_area) * bytes_in_high ) * cost_scalar
In the details of the implementation, the cost_scalar
is based on a target triangle budget, and efforts are made to convert bytes_in_foo
to an estimated triangle count.
Implementation
// Get the streaming cost for the given mesh
// header -- header of mesh as described in mesh asset format
// radius -- magnitude of the mesh object scale, divided by two
// bytes -- if not NULL, gets number of bytes in this mesh (for debugging)
// bytes_visible -- if not NULL, gets number of bytes in specified lod (for debugging)
// lod -- currently visible lod (for debugging)
F32 LLMeshRepository::getStreamingCost(LLSD& header, F32 radius, S32* bytes, S32* bytes_visible, S32 lod)
{
F32 max_distance = 512.f;
F32 dlowest = llmin(radius/0.03f, max_distance);
F32 dlow = llmin(radius/0.06f, max_distance);
F32 dmid = llmin(radius/0.24f, max_distance);
// discount 128 bytes to cover the cost of LLSD tags and compression domain overhead
F32 METADATA_DISCOUNT = (F32) gSavedSettings.getU32("MeshMetaDataDiscount");
// make sure nothing is "free"
F32 MINIMUM_SIZE = (F32) gSavedSettings.getU32("MeshMinimumByteSize");
F32 bytes_per_triangle = (F32) gSavedSettings.getU32("MeshBytesPerTriangle");
S32 bytes_lowest = header["lowest_lod"]["size"].asInteger();
S32 bytes_low = header["low_lod"]["size"].asInteger();
S32 bytes_mid = header["medium_lod"]["size"].asInteger();
S32 bytes_high = header["high_lod"]["size"].asInteger();
if (bytes_high == 0)
{
return 0.f;
}
if (bytes_mid == 0)
{
bytes_mid = bytes_high;
}
if (bytes_low == 0)
{
bytes_low = bytes_mid;
}
if (bytes_lowest == 0)
{
bytes_lowest = bytes_low;
}
F32 triangles_lowest = llmax((F32) bytes_lowest-METADATA_DISCOUNT, MINIMUM_SIZE)/bytes_per_triangle;
F32 triangles_low = llmax((F32) bytes_low-METADATA_DISCOUNT, MINIMUM_SIZE)/bytes_per_triangle;
F32 triangles_mid = llmax((F32) bytes_mid-METADATA_DISCOUNT, MINIMUM_SIZE)/bytes_per_triangle;
F32 triangles_high = llmax((F32) bytes_high-METADATA_DISCOUNT, MINIMUM_SIZE)/bytes_per_triangle;
if (bytes)
{
*bytes = 0;
*bytes += header["lowest_lod"]["size"].asInteger();
*bytes += header["low_lod"]["size"].asInteger();
*bytes += header["medium_lod"]["size"].asInteger();
*bytes += header["high_lod"]["size"].asInteger();
}
if (bytes_visible)
{
lod = LLMeshRepository::getActualMeshLOD(header, lod);
if (lod >= 0 && lod <= 3)
{
*bytes_visible = header[header_lod[lod]]["size"].asInteger();
}
}
F32 max_area = 102932.f; //area of circle that encompasses region
F32 min_area = 1.f;
F32 high_area = llmin(F_PI*dmid*dmid, max_area);
F32 mid_area = llmin(F_PI*dlow*dlow, max_area);
F32 low_area = llmin(F_PI*dlowest*dlowest, max_area);
F32 lowest_area = max_area;
lowest_area -= low_area;
low_area -= mid_area;
mid_area -= high_area;
high_area = llclamp(high_area, min_area, max_area);
mid_area = llclamp(mid_area, min_area, max_area);
low_area = llclamp(low_area, min_area, max_area);
lowest_area = llclamp(lowest_area, min_area, max_area);
F32 total_area = high_area + mid_area + low_area + lowest_area;
high_area /= total_area;
mid_area /= total_area;
low_area /= total_area;
lowest_area /= total_area;
F32 weighted_avg = triangles_high*high_area +
triangles_mid*mid_area +
triangles_low*low_area +
triangles_lowest*lowest_area;
return weighted_avg/gSavedSettings.getU32("MeshTriangleBudget")*15000.f;
}
Issues
- Providing identical models for every LOD results in a cost identical to providing a single LOD, but results in 4x the bandwidth usage.
- Changing the scale of an object changes its cost, which can be confusing.
- For viewers with a view distance greater than 256m, the clamping to 256m is unrealistic.
- Some validating of LODs is still necessary.