Skip to content
0.2.0-dev Download ZIP
24 lines ·862 B Raw
1// Helper functions for texture streaming feedback.
2// Used by the Forward+ and Mobile renderers.
3
4// Reference texture size used for LOD normalization: 4096x4096.
5#define STREAMING_LOD_REFERENCE_LOG2 12.0
6
7// Returns the squared pixel footprint in UV space.
8float streaming_footprint_sq(vec2 uv_ddx, vec2 uv_ddy) {
9 float uv_ddx_sq = dot(uv_ddx, uv_ddx);
10 float uv_ddy_sq = dot(uv_ddy, uv_ddy);
11
12 // Limit anisotropic filtering to 16x.
13 const float MAX_ANISOTROPY = 16.0;
14
15 return max(
16 min(uv_ddx_sq, uv_ddy_sq),
17 max(uv_ddx_sq, uv_ddy_sq) / (MAX_ANISOTROPY * MAX_ANISOTROPY));
18}
19
20// Undoes the reference offset on a shader-supplied STREAMING_LOD, so both feedback paths
21// hand the same squared UV footprint to the encoder.
22float streaming_footprint_sq_from_lod(float lod) {
23 return exp2(2.0 * (clamp(lod, -32.0, 32.0) - STREAMING_LOD_REFERENCE_LOG2));
24}