| … | … | @@ -0,0 +1,37 @@ |
| 1 | shader_type spatial; |
| 2 | |
| 3 | // ── Virtual Texture atlas and page table ──────────────────────────────────── |
| 4 | uniform sampler2D vt_atlas : source_color, filter_linear, repeat_disable; |
| 5 | uniform sampler2D vt_page_table : filter_nearest, repeat_disable; |
| 6 | |
| 7 | // Cache geometry: 1.0 / cache_grid_size (e.g. 1/32 = 0.03125) |
| 8 | uniform float tile_size_uv; |
| 9 | // Virtual tiles per edge at mip 0 (e.g. 128) |
| 10 | uniform float page_table_size; |
| 11 | |
| 12 | // ── Material fallbacks (used when tile not yet resident) ──────────────────── |
| 13 | uniform vec4 albedo_color : source_color = vec4(0.8, 0.8, 0.8, 1.0); |
| 14 | uniform float roughness : hint_range(0,1) = 0.5; |
| 15 | uniform float metallic : hint_range(0,1) = 0.0; |
| 16 | |
| 17 | void fragment() { |
| 18 | // Virtual tile address from UV |
| 19 | vec2 vt_coord = UV * page_table_size; |
| 20 | ivec2 tile_id = ivec2(floor(vt_coord)); |
| 21 | vec2 in_tile_frac = fract(vt_coord); |
| 22 | |
| 23 | // Page table texel: R=atlas_x, G=atlas_y, B=valid, A=0 |
| 24 | vec4 page = texelFetch(vt_page_table, tile_id, 0); |
| 25 | |
| 26 | if (page.b > 0.5) { |
| 27 | // Tile is resident — sample from atlas |
| 28 | vec2 atlas_uv = (vec2(page.r, page.g) * 255.0 + in_tile_frac) * tile_size_uv; |
| 29 | ALBEDO = texture(vt_atlas, atlas_uv).rgb; |
| 30 | } else { |
| 31 | // Tile not loaded — use fallback color |
| 32 | ALBEDO = albedo_color.rgb; |
| 33 | } |
| 34 | |
| 35 | ROUGHNESS = roughness; |
| 36 | METALLIC = metallic; |
| 37 | } |