Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
FC2a: your own Material is Bevy's Material, not an extension: its own bindings, imports beside it, alpha mode, depth bias, cull mode; 3 shader ports (125/125)
shinyobjectza28118696eaa
diff --git a/bench/bevy-parity/examples.list b/bench/bevy-parity/examples.listindex 6d68928f..cb06661e 100644--- a/bench/bevy-parity/examples.list+++ b/bench/bevy-parity/examples.list@@ -122,3 +122,6 @@ animation/animated_transform3d/3d_shapes2d/sprite_scale2d/sprite_slice+shader/shader_material+shader/shader_defs+shader/shader_material_screenspace_texturediff --git a/bench/bevy-parity/runs.tsv b/bench/bevy-parity/runs.tsvindex 7d1214e4..8f92f935 100644--- a/bench/bevy-parity/runs.tsv+++ b/bench/bevy-parity/runs.tsv@@ -121,3 +121,6 @@ animation/animated_transform - 30,1653d/3d_shapes - 10,1202d/sprite_scale - 10,602d/sprite_slice - 10+shader/shader_material - 30+shader/shader_defs - 10+shader/shader_material_screenspace_texture - 10,60diff --git a/docs/bevy-parity.md b/docs/bevy-parity.mdindex 0ccf9a97..472a9d82 100644--- a/docs/bevy-parity.md+++ b/docs/bevy-parity.md@@ -4,7 +4,7 @@ Bevy v0.20.0's examples against their raea TSX ports (docs/control.feature FC0a)don't edit. An example passes when every probed frame passes pixels (SSIM 0.98 and no 32 px tile off by more than 24 of 255) and cost (batch keys andframe time at most 1.25x the example's). Wall time is one machine's, measured in the same run.-Examples: **438**, ported **122**, passing **122**, excluded **16** (docs/bevy-parity/excluded.tsv), left **300**.+Examples: **438**, ported **125**, passing **125**, excluded **16** (docs/bevy-parity/excluded.tsv), left **297**.raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the exampledoesn't pay.@@ -23,8 +23,6 @@ doesn't pay.| stress_tests/many_foxes | 60 | 0.990304 | 3 | 2 / 2 | 30464 / 31503 | 7 / 9 | 3 / 3 | 6.624 / 6.104 = 6.104 + 0 | yes | || animation/animated_mesh | 30 | 0.996636 | 1 | 2 / 2 | 472 / 534 | 7 / 9 | 3 / 3 | 24.794 / 3.223 = 3.223 + 0 | yes | || animation/animated_mesh | 60 | 0.996594 | 1 | 2 / 2 | 472 / 534 | 7 / 9 | 3 / 3 | 4.786 / 2.695 = 2.695 + 0 | yes | |-| shader/extended_material | 30 | 1.000000 | 0 | 0 / 0 | 448 / 503 | 6 / 8 | 1 / 2 | 21.382 / 2.074 = 2.074 + 0 | yes | |-| shader/extended_material | 60 | 1.000000 | 0 | 0 / 0 | 448 / 503 | 6 / 8 | 1 / 2 | 4.189 / 1.831 = 1.831 + 0 | yes | || 3d/orthographic | 10 | 0.999503 | 0 | 5 / 2 | 446 / 507 | 10 / 9 | 6 / 3 | 51.589 / 2.77 = 2.77 + 0 | yes | || 3d/parenting | 30 | 0.999969 | 0 | 1 / 1 | 443 / 504 | 6 / 8 | 2 / 2 | 20.823 / 2.408 = 2.408 + 0 | yes | || 3d/parenting | 60 | 0.999968 | 0 | 1 / 1 | 443 / 504 | 6 / 8 | 2 / 2 | 4.009 / 2.224 = 2.224 + 0 | yes | |@@ -41,8 +39,6 @@ doesn't pay.| transforms/scale | 300 | 1.000000 | 0 | 1 / 1 | 442 / 503 | 6 / 8 | 2 / 2 | 5.029 / 2.354 = 2.354 + 0 | yes | || transforms/scale | 60 | 1.000000 | 0 | 1 / 1 | 442 / 503 | 6 / 8 | 2 / 2 | 15.673 / 2.497 = 2.497 + 0 | yes | || 3d/texture | 10 | 0.999547 | 1 | 3 / 3 | 443 / 505 | 6 / 8 | 4 / 4 | 67.68 / 4.201 = 4.201 + 0 | yes | |-| shader/animate_shader | 30 | 1.000000 | 0 | 0 / 0 | 447 / 502 | 6 / 8 | 1 / 2 | 30.793 / 2.716 = 2.716 + 0 | yes | |-| shader/animate_shader | 60 | 1.000000 | 0 | 0 / 0 | 447 / 502 | 6 / 8 | 1 / 2 | 5.545 / 1.995 = 1.995 + 0 | yes | || 2d/sprite_sheet | 30 | 1.000000 | 0 | 0 / 0 | 441 / 502 | 5 / 7 | 1 / 1 | 25.581 / 2.276 = 2.276 + 0 | yes | || 2d/sprite_sheet | 60 | 1.000000 | 0 | 0 / 0 | 441 / 502 | 5 / 7 | 1 / 1 | 3.153 / 2.013 = 2.013 + 0 | yes | || 3d/pbr | 30 | 0.997686 | 8 | 56 / 56 | 499 / 558 | 6 / 8 | 57 / 57 | 28.617 / 2.192 = 2.192 + 0 | yes | |@@ -165,7 +161,6 @@ doesn't pay.| ui/text/multiline_text_input | 10 | 0.998036 | 6 | 0 / 0 | 487 / 500 | 5 / 7 | 1 / 1 | 50.979 / 2.309 = 2.309 + 0 | yes | || ui/text/multiple_text_inputs | 10 | 0.992332 | 12 | 0 / 0 | 517 / 500 | 5 / 7 | 1 / 1 | 49.55 / 2.642 = 2.642 + 0 | yes | || ui/text/text_input | 10 | 0.999094 | 12 | 0 / 0 | 448 / 500 | 5 / 7 | 1 / 1 | 52.918 / 2.118 = 2.118 + 0 | yes | |-| ui/ui_material | 10 | 0.999993 | 0 | 0 / 0 | 446 / 502 | 5 / 7 | 1 / 1 | 52.62 / 2.092 = 2.092 + 0 | yes | || ui/text/system_fonts | 10 | 0.987943 | 18 | 0 / 0 | 1992 / 500 | 5 / 7 | 1 / 1 | 122.191 / 1.88 = 1.88 + 0 | yes | || ui/text/font_atlas_debug | 10 | 0.999660 | 6 | 0 / 0 | 445 / 500 | 5 / 7 | 1 / 1 | 50.409 / 1.654 = 1.654 + 0 | yes | || 3d/two_passes | 10 | 0.999025 | 0 | 2 / 2 | 444 / 505 | 7 / 9 | 3 / 3 | 57.114 / 4.122 = 4.122 + 0 | yes | |@@ -185,6 +180,15 @@ doesn't pay.| 3d/fog | 120 | 0.996929 | 8 | 56 / 53 | 498 / 559 | 61 / 60 | 4 / 4 | 5.785 / 3.144 = 3.144 + 0 | yes | || 3d/3d_shapes | 10 | 0.998884 | 8 | 27 / 27 | 478 / 582 | 32 / 34 | 3 / 28 | 57.892 / 3.889 = 3.889 + 0 | yes | || 3d/3d_shapes | 120 | 0.998884 | 8 | 27 / 27 | 478 / 582 | 32 / 34 | 3 / 28 | 5.307 / 2.8 = 2.8 + 0 | yes | |+| shader/extended_material | 30 | 1.000000 | 0 | 0 / 0 | 448 / 509 | 6 / 8 | 1 / 2 | 18.314 / 1.414 = 1.414 + 0 | yes | |+| shader/extended_material | 60 | 1.000000 | 0 | 0 / 0 | 448 / 509 | 6 / 8 | 1 / 2 | 3.083 / 1.216 = 1.216 + 0 | yes | |+| shader/animate_shader | 30 | 1.000000 | 0 | 0 / 0 | 447 / 508 | 6 / 8 | 1 / 2 | 17.154 / 1.433 = 1.433 + 0 | yes | |+| shader/animate_shader | 60 | 1.000000 | 0 | 0 / 0 | 447 / 508 | 6 / 8 | 1 / 2 | 3.075 / 1.528 = 1.528 + 0 | yes | |+| ui/ui_material | 10 | 0.999993 | 0 | 0 / 0 | 446 / 508 | 5 / 7 | 1 / 1 | 45.765 / 1.985 = 1.985 + 0 | yes | |+| shader/shader_material | 30 | 1.000000 | 0 | 0 / 0 | 447 / 508 | 6 / 8 | 1 / 2 | 17.77 / 1.305 = 1.305 + 0 | yes | |+| shader/shader_defs | 10 | 0.999999 | 0 | 0 / 0 | 448 / 509 | 7 / 8 | 1 / 3 | 53.051 / 2.214 = 2.214 + 0 | yes | |+| shader/shader_material_screenspace_texture | 10 | 0.998864 | 2 | 1 / 1 | 449 / 510 | 7 / 9 | 2 / 3 | 63.846 / 2.498 = 2.498 + 0 | yes | |+| shader/shader_material_screenspace_texture | 60 | 0.998929 | 2 | 1 / 1 | 449 / 510 | 7 / 9 | 2 / 3 | 3.463 / 1.275 = 1.275 + 0 | yes | |## Excludeddiff --git a/docs/bevy-parity/results.jsonl b/docs/bevy-parity/results.jsonlindex b9d6015c..06e2bf1f 100644--- a/docs/bevy-parity/results.jsonl+++ b/docs/bevy-parity/results.jsonl@@ -10,8 +10,6 @@{"example":"stress_tests/many_foxes","frame":60,"ssim":0.990304,"tile":3,"bevy":{"batch_keys":2,"entities":30464,"extents":["23.6615 34.9370 84.2011","23.6615 34.9370 84.2012","2500.0000 0.0000 2500.0000","78.2183 34.9370 91.5996","80.4108 34.9370 91.8799","84.3248 34.9370 92.3804","86.0376 34.9370 92.5995","86.0377 34.9371 92.5995"],"frame":60,"frame_ms":6.624,"materials":3,"mesh_entities":1001,"meshes":7,"other_material":0,"visible":1001},"raea":{"frame":70,"entities":31503,"mesh_entities":1001,"visible":1001,"meshes":9,"materials":3,"batch_keys":2,"other_material":0,"extents":["23.6613 34.9370 84.2011","23.6613 34.9371 84.2011","2500.0000 0.0000 2500.0000","78.2186 34.9370 91.5996","80.4110 34.9370 91.8800","84.3247 34.9370 92.3804","86.0374 34.9370 92.5994","86.0374 34.9371 92.5994"],"frame_ms":6.104,"step_ms":null,"cost_ms":6.104},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"animation/animated_mesh","frame":30,"ssim":0.996636,"tile":1,"bevy":{"batch_keys":2,"entities":472,"extents":["15.4187 42.8200 84.0474","250000.0000 0.0000 250000.0000"],"frame":30,"frame_ms":24.794,"materials":3,"mesh_entities":2,"meshes":7,"other_material":0,"visible":2},"raea":{"frame":41,"entities":534,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":2,"other_material":0,"extents":["15.4187 42.8200 84.0474","250000.0000 0.0000 250000.0000"],"frame_ms":3.223,"step_ms":null,"cost_ms":3.223},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"animation/animated_mesh","frame":60,"ssim":0.996594,"tile":1,"bevy":{"batch_keys":2,"entities":472,"extents":["19.9546 34.9370 82.9540","250000.0000 0.0000 250000.0000"],"frame":60,"frame_ms":4.786,"materials":3,"mesh_entities":2,"meshes":7,"other_material":0,"visible":2},"raea":{"frame":71,"entities":534,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":2,"other_material":0,"extents":["19.9546 34.9370 82.9540","250000.0000 0.0000 250000.0000"],"frame_ms":2.695,"step_ms":null,"cost_ms":2.695},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}-{"example":"shader/extended_material","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":448,"extents":["0.9945 1.0000 1.0000"],"frame":30,"frame_ms":21.382,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":37,"entities":503,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.9945 1.0000 1.0000"],"frame_ms":2.074,"step_ms":null,"cost_ms":2.074},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}-{"example":"shader/extended_material","frame":60,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":448,"extents":["0.9945 1.0000 1.0000"],"frame":60,"frame_ms":4.189,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":67,"entities":503,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.9945 1.0000 1.0000"],"frame_ms":1.831,"step_ms":null,"cost_ms":1.831},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"3d/orthographic","frame":10,"ssim":0.999503,"tile":0,"bevy":{"batch_keys":5,"entities":446,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame":10,"frame_ms":51.589,"materials":6,"mesh_entities":5,"meshes":10,"other_material":0,"visible":5},"raea":{"frame":17,"entities":507,"mesh_entities":5,"visible":5,"meshes":9,"materials":3,"batch_keys":2,"other_material":0,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame_ms":2.77,"step_ms":null,"cost_ms":2.77},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"3d/parenting","frame":30,"ssim":0.999969,"tile":0,"bevy":{"batch_keys":1,"entities":443,"extents":["1.0000 1.0000 1.0000"],"frame":30,"frame_ms":20.823,"materials":2,"mesh_entities":2,"meshes":6,"other_material":0,"visible":2},"raea":{"frame":37,"entities":504,"mesh_entities":2,"visible":2,"meshes":8,"materials":2,"batch_keys":1,"other_material":0,"extents":["1.0000 1.0000 1.0000"],"frame_ms":2.408,"step_ms":null,"cost_ms":2.408},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"3d/parenting","frame":60,"ssim":0.999968,"tile":0,"bevy":{"batch_keys":1,"entities":443,"extents":["1.0000 1.0000 1.0000"],"frame":60,"frame_ms":4.009,"materials":2,"mesh_entities":2,"meshes":6,"other_material":0,"visible":2},"raea":{"frame":67,"entities":504,"mesh_entities":2,"visible":2,"meshes":8,"materials":2,"batch_keys":1,"other_material":0,"extents":["1.0000 1.0000 1.0000"],"frame_ms":2.224,"step_ms":null,"cost_ms":2.224},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}@@ -28,8 +26,6 @@{"example":"transforms/scale","frame":300,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":1,"entities":442,"extents":["0.5000 0.5000 0.5000"],"frame":300,"frame_ms":5.029,"materials":2,"mesh_entities":1,"meshes":6,"other_material":0,"visible":1},"raea":{"frame":307,"entities":503,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":1,"other_material":0,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.354,"step_ms":null,"cost_ms":2.354},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"transforms/scale","frame":60,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":1,"entities":442,"extents":["0.5000 0.5000 0.5000"],"frame":60,"frame_ms":15.673,"materials":2,"mesh_entities":1,"meshes":6,"other_material":0,"visible":1},"raea":{"frame":67,"entities":503,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":1,"other_material":0,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.497,"step_ms":null,"cost_ms":2.497},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"3d/texture","frame":10,"ssim":0.999547,"tile":1,"bevy":{"batch_keys":3,"entities":443,"extents":["4.0000 1.0000 0.0000"],"frame":10,"frame_ms":67.68,"materials":4,"mesh_entities":3,"meshes":6,"other_material":0,"visible":3},"raea":{"frame":17,"entities":505,"mesh_entities":3,"visible":3,"meshes":8,"materials":4,"batch_keys":3,"other_material":0,"extents":["4.0000 0.0000 1.0000"],"frame_ms":4.201,"step_ms":null,"cost_ms":4.201},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}-{"example":"shader/animate_shader","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":30,"frame_ms":30.793,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":37,"entities":502,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.716,"step_ms":null,"cost_ms":2.716},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}-{"example":"shader/animate_shader","frame":60,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":60,"frame_ms":5.545,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":67,"entities":502,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.995,"step_ms":null,"cost_ms":1.995},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"2d/sprite_sheet","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":441,"extents":[],"frame":30,"frame_ms":25.581,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":37,"entities":502,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.276,"step_ms":null,"cost_ms":2.276},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"2d/sprite_sheet","frame":60,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":441,"extents":[],"frame":60,"frame_ms":3.153,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":67,"entities":502,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.013,"step_ms":null,"cost_ms":2.013},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"3d/pbr","frame":30,"ssim":0.997686,"tile":8,"bevy":{"batch_keys":56,"entities":499,"extents":["0.4475 0.4500 0.4500"],"frame":30,"frame_ms":28.617,"materials":57,"mesh_entities":56,"meshes":6,"other_material":0,"visible":56},"raea":{"frame":37,"entities":558,"mesh_entities":56,"visible":56,"meshes":8,"materials":57,"batch_keys":56,"other_material":0,"extents":["0.4475 0.4500 0.4500"],"frame_ms":2.192,"step_ms":null,"cost_ms":2.192},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}@@ -152,7 +148,6 @@{"example":"ui/text/multiline_text_input","frame":10,"ssim":0.998036,"tile":6,"bevy":{"batch_keys":0,"entities":487,"extents":[],"frame":10,"frame_ms":50.979,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":500,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.309,"step_ms":null,"cost_ms":2.309},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"ui/text/multiple_text_inputs","frame":10,"ssim":0.992332,"tile":12,"bevy":{"batch_keys":0,"entities":517,"extents":[],"frame":10,"frame_ms":49.55,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":500,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.642,"step_ms":null,"cost_ms":2.642},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"ui/text/text_input","frame":10,"ssim":0.999094,"tile":12,"bevy":{"batch_keys":0,"entities":448,"extents":[],"frame":10,"frame_ms":52.918,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":500,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.118,"step_ms":null,"cost_ms":2.118},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}-{"example":"ui/ui_material","frame":10,"ssim":0.999993,"tile":0,"bevy":{"batch_keys":0,"entities":446,"extents":[],"frame":10,"frame_ms":52.62,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":502,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.092,"step_ms":null,"cost_ms":2.092},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"ui/text/system_fonts","frame":10,"ssim":0.987943,"tile":18,"bevy":{"batch_keys":0,"entities":1992,"extents":[],"frame":10,"frame_ms":122.191,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":500,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.88,"step_ms":null,"cost_ms":1.88},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"ui/text/font_atlas_debug","frame":10,"ssim":0.999660,"tile":6,"bevy":{"batch_keys":0,"entities":445,"extents":[],"frame":10,"frame_ms":50.409,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":500,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.654,"step_ms":null,"cost_ms":1.654},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"3d/two_passes","frame":10,"ssim":0.999025,"tile":0,"bevy":{"batch_keys":2,"entities":444,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame":10,"frame_ms":57.114,"materials":3,"mesh_entities":2,"meshes":7,"other_material":0,"visible":2},"raea":{"frame":17,"entities":505,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":2,"other_material":0,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame_ms":4.122,"step_ms":null,"cost_ms":4.122},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}@@ -172,3 +167,12 @@{"example":"3d/fog","frame":120,"ssim":0.996929,"tile":8,"bevy":{"batch_keys":56,"entities":498,"extents":["0.4972 0.5000 0.5000","0.5000 1.5000 0.5000","3.0000 0.2500 3.0000","3.5000 0.2500 3.5000","4.0000 0.2500 4.0000","4.5000 0.2500 4.5000","5.0000 0.2500 5.0000","5.5000 0.2500 5.5000"],"frame":120,"frame_ms":5.785,"materials":4,"mesh_entities":56,"meshes":61,"other_material":0,"visible":56},"raea":{"frame":127,"entities":559,"mesh_entities":56,"visible":56,"meshes":60,"materials":4,"batch_keys":53,"other_material":0,"extents":["0.4972 0.5000 0.5000","0.5000 1.5000 0.5000","3.0000 0.2500 3.0000","3.5000 0.2500 3.5000","4.0000 0.2500 4.0000","4.5000 0.2500 4.5000","5.0000 0.2500 5.0000","5.5000 0.2500 5.5000"],"frame_ms":3.144,"step_ms":null,"cost_ms":3.144},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"3d/3d_shapes","frame":10,"ssim":0.998884,"tile":8,"bevy":{"batch_keys":27,"entities":478,"extents":["0.4972 0.5000 0.5000","0.5000 0.0000 0.0000","0.5000 0.2500 0.0000","0.5000 0.2500 0.5000","0.5000 0.5000 0.5000","0.5000 1.0000 0.5000","1.0000 0.2500 1.0000","25.0000 0.0000 25.0000"],"frame":10,"frame_ms":57.892,"materials":3,"mesh_entities":27,"meshes":32,"other_material":0,"visible":27},"raea":{"frame":17,"entities":582,"mesh_entities":27,"visible":27,"meshes":34,"materials":28,"batch_keys":27,"other_material":0,"extents":["0.4972 0.5000 0.5000","0.4976 0.9976 0.5000","0.5000 0.0000 0.0000","0.5000 0.2500 0.0000","0.5000 0.2500 0.5000","0.5000 0.5000 0.5000","0.5000 1.0000 0.5000","1.0000 0.2500 1.0000"],"frame_ms":3.889,"step_ms":null,"cost_ms":3.889},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}{"example":"3d/3d_shapes","frame":120,"ssim":0.998884,"tile":8,"bevy":{"batch_keys":27,"entities":478,"extents":["0.4972 0.5000 0.5000","0.5000 0.0000 0.0000","0.5000 0.2500 0.0000","0.5000 0.2500 0.5000","0.5000 0.5000 0.5000","0.5000 1.0000 0.5000","1.0000 0.2500 1.0000","25.0000 0.0000 25.0000"],"frame":120,"frame_ms":5.307,"materials":3,"mesh_entities":27,"meshes":32,"other_material":0,"visible":27},"raea":{"frame":127,"entities":582,"mesh_entities":27,"visible":27,"meshes":34,"materials":28,"batch_keys":27,"other_material":0,"extents":["0.4972 0.5000 0.5000","0.4976 0.9976 0.5000","0.5000 0.0000 0.0000","0.5000 0.2500 0.0000","0.5000 0.2500 0.5000","0.5000 0.5000 0.5000","0.5000 1.0000 0.5000","1.0000 0.2500 1.0000"],"frame_ms":2.8,"step_ms":null,"cost_ms":2.8},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/extended_material","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":448,"extents":["0.9945 1.0000 1.0000"],"frame":30,"frame_ms":18.314,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":37,"entities":509,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.9945 1.0000 1.0000"],"frame_ms":1.414,"step_ms":null,"cost_ms":1.414},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/extended_material","frame":60,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":448,"extents":["0.9945 1.0000 1.0000"],"frame":60,"frame_ms":3.083,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":67,"entities":509,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.9945 1.0000 1.0000"],"frame_ms":1.216,"step_ms":null,"cost_ms":1.216},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/animate_shader","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":30,"frame_ms":17.154,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":37,"entities":508,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.433,"step_ms":null,"cost_ms":1.433},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/animate_shader","frame":60,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":60,"frame_ms":3.075,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":67,"entities":508,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.528,"step_ms":null,"cost_ms":1.528},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"ui/ui_material","frame":10,"ssim":0.999993,"tile":0,"bevy":{"batch_keys":0,"entities":446,"extents":[],"frame":10,"frame_ms":45.765,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":508,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.985,"step_ms":null,"cost_ms":1.985},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/shader_material","frame":30,"ssim":1.000000,"tile":0,"bevy":{"batch_keys":0,"entities":447,"extents":["0.5000 0.5000 0.5000"],"frame":30,"frame_ms":17.77,"materials":1,"mesh_entities":1,"meshes":6,"other_material":1,"visible":1},"raea":{"frame":38,"entities":508,"mesh_entities":1,"visible":1,"meshes":8,"materials":2,"batch_keys":0,"other_material":1,"extents":["0.5000 0.5000 0.5000"],"frame_ms":1.305,"step_ms":null,"cost_ms":1.305},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/shader_defs","frame":10,"ssim":0.999999,"tile":0,"bevy":{"batch_keys":0,"entities":448,"extents":["0.5000 0.5000 0.5000"],"frame":10,"frame_ms":53.051,"materials":1,"mesh_entities":2,"meshes":7,"other_material":2,"visible":2},"raea":{"frame":17,"entities":509,"mesh_entities":2,"visible":2,"meshes":8,"materials":3,"batch_keys":0,"other_material":2,"extents":["0.5000 0.5000 0.5000"],"frame_ms":2.214,"step_ms":null,"cost_ms":2.214},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/shader_material_screenspace_texture","frame":10,"ssim":0.998864,"tile":2,"bevy":{"batch_keys":1,"entities":449,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame":10,"frame_ms":63.846,"materials":2,"mesh_entities":2,"meshes":7,"other_material":1,"visible":2},"raea":{"frame":18,"entities":510,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":1,"other_material":1,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame_ms":2.498,"step_ms":null,"cost_ms":2.498},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}+{"example":"shader/shader_material_screenspace_texture","frame":60,"ssim":0.998929,"tile":2,"bevy":{"batch_keys":1,"entities":449,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame":60,"frame_ms":3.463,"materials":2,"mesh_entities":2,"meshes":7,"other_material":1,"visible":2},"raea":{"frame":68,"entities":510,"mesh_entities":2,"visible":2,"meshes":9,"materials":3,"batch_keys":1,"other_material":1,"extents":["0.5000 0.5000 0.5000","2.5000 0.0000 2.5000"],"frame_ms":1.275,"step_ms":null,"cost_ms":1.275},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}diff --git a/runtime/scene3d/src/shaded.rs b/runtime/scene3d/src/shaded.rsindex a6e89fd6..1c941ee1 100644--- a/runtime/scene3d/src/shaded.rs+++ b/runtime/scene3d/src/shaded.rs@@ -34,8 +34,7 @@ pub fn shade_rows(world: &mut World, inserted: &[Tup]) -> Result<(), String> {let mut made = Made::new();for e in todo {let Some(s) = world.entity_mut(e).take::<MeshShader>() else { continue };- let ext = shader_ext::build(world, &s.spec, plugins::image).map_err(|err| format!("mesh {}: shader: {err}", s.id))?;- shader_ext::shade(world, e, &ext, &mut made);+ shader_ext::put(world, e, &s.spec, plugins::image, &mut made).map_err(|err| format!("mesh {}: shader: {err}", s.id))?;}pass_rows(world, inserted)?;compute_rows(world, inserted)diff --git a/sdk/raea/bench/bevy-parity/shader/shader_defs.tsx b/sdk/raea/bench/bevy-parity/shader/shader_defs.tsxnew file mode 100644index 00000000..cd42e471--- /dev/null+++ b/sdk/raea/bench/bevy-parity/shader/shader_defs.tsx@@ -0,0 +1,30 @@+// Bevy v0.20.0 examples/shader/shader_defs.rs in raea's TSX (docs/control.feature FC0a, FC2a): two 1 m cubes with the+// example's own Material, assets/shaders/shader_defs.wesl as written (its uniform a CustomMaterial struct at binding+// 0, given as { color }): at x -1 LinearRgba::BLUE, and at x 1 LinearRgba::GREEN with is_red, which the example's+// specialize turns into the IS_RED shader def (here `defs`, each set compiling its own pipeline as Bevy's key does);+// the camera at (-2, 2.5, 5), in Bevy's default 1280 x 720 window.+import { Composition, registerRoot, staticFile } from "raea";+import { Transform } from "raea/transform";+import { Camera3d } from "raea/camera";+import { Cuboid, Mesh3d } from "raea/mesh";+import { Material } from "@raea/render/bevy3d"; // raea/pbr once scene-loop lands (its pbr.ts commit)++const SHADER = staticFile("shaders/shader_defs.wesl");++function Shot() {+ return (+ <>+ <Mesh3d transform={Transform.fromXyz(-1, 0.5, 0)}>+ <Cuboid half_size={[0.5, 0.5, 0.5]} />+ <Material fragment={SHADER} uniforms={{ material: { color: [0, 0, 1, 1] } }} />+ </Mesh3d>+ <Mesh3d transform={Transform.fromXyz(1, 0.5, 0)}>+ <Cuboid half_size={[0.5, 0.5, 0.5]} />+ <Material fragment={SHADER} uniforms={{ material: { color: [0, 1, 0, 1] } }} defs={{ IS_RED: true }} />+ </Mesh3d>+ <Camera3d transform={Transform.fromXyz(-2, 2.5, 5).lookingAt([0, 0, 0])} />+ </>+ );+}++registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);diff --git a/sdk/raea/bench/bevy-parity/shader/shader_material.tsx b/sdk/raea/bench/bevy-parity/shader/shader_material.tsxnew file mode 100644index 00000000..2c0fe7a8--- /dev/null+++ b/sdk/raea/bench/bevy-parity/shader/shader_material.tsx@@ -0,0 +1,28 @@+// Bevy v0.20.0 examples/shader/shader_material.rs in raea's TSX (docs/control.feature FC0a, FC2a): a 1 m cube at+// (0, 0.5, 0) with the example's own Material, assets/shaders/custom_material.wesl as written (its own bindings at 0, 1+// and 2 of the material's group, and `import super::custom_material_import` from beside it), LinearRgba::BLUE, the+// Bevy logo as its texture and AlphaMode::Blend; the camera at (-2, 2.5, 5), in Bevy's default 1280 x 720 window.+import { Composition, registerRoot, staticFile } from "raea";+import { Transform } from "raea/transform";+import { Camera3d } from "raea/camera";+import { Cuboid, Mesh3d } from "raea/mesh";+import { Material } from "@raea/render/bevy3d"; // raea/pbr once scene-loop lands (its pbr.ts commit)++function Shot() {+ return (+ <>+ <Mesh3d transform={Transform.fromXyz(0, 0.5, 0)}>+ <Cuboid half_size={[0.5, 0.5, 0.5]} />+ <Material+ fragment={staticFile("shaders/custom_material.wesl")}+ uniforms={{ material_color: [0, 0, 1, 1] }}+ textures={{ material_color_texture: staticFile("branding/icon.png") }}+ alpha_mode="Blend"+ />+ </Mesh3d>+ <Camera3d transform={Transform.fromXyz(-2, 2.5, 5).lookingAt([0, 0, 0])} />+ </>+ );+}++registerRoot(() => <Composition id="main" component={Shot} durationInFrames={31} fps={60} width={1280} height={720} />);diff --git a/sdk/raea/bench/bevy-parity/shader/shader_material_screenspace_texture.tsx b/sdk/raea/bench/bevy-parity/shader/shader_material_screenspace_texture.tsxnew file mode 100644index 00000000..5b23114e--- /dev/null+++ b/sdk/raea/bench/bevy-parity/shader/shader_material_screenspace_texture.tsx@@ -0,0 +1,37 @@+// Bevy v0.20.0 examples/shader/shader_material_screenspace_texture.rs in raea's TSX (docs/control.feature FC0a, FC2a):+// a 5 m plane of srgb(0.3, 0.5, 0.3), a default PointLight at (4, 8, 4), and a 1 m cube at (0, 0.5, 0) with the+// example's own Material, assets/shaders/custom_material_screenspace_texture.wesl as written (it samples the+// FlightHelmet's lens texture at the fragment's viewport uv, view.viewport from mesh_view_bindings); the camera starts+// at (4, 2.5, 4) and turns about the origin at 45 degrees a second (rotate_camera, no delta on the first update).+import { Composition, registerRoot, staticFile, useCurrentFrame } from "raea";+import { Transform } from "raea/transform";+import { Camera3d } from "raea/camera";+import { Cuboid, Mesh3d, Plane3d } from "raea/mesh";+import { StandardMaterial } from "raea/pbr";+import { PointLight } from "raea/light";+import { Material } from "@raea/render/bevy3d"; // raea/pbr once scene-loop lands (its pbr.ts commit)++function Shot() {+ const a = ((45 * Math.PI) / 180) * (useCurrentFrame() / 60);+ // Transform::rotate_around(ZERO, rotation about Y by a) of (4, 2.5, 4)+ const [x, z] = [4 * Math.cos(a) + 4 * Math.sin(a), -4 * Math.sin(a) + 4 * Math.cos(a)];+ return (+ <>+ <Mesh3d transform={Transform.IDENTITY}>+ <Plane3d half_size={[2.5, 2.5]} />+ <StandardMaterial base_color="rgb(76.5, 127.5, 76.5)" />+ </Mesh3d>+ <PointLight transform={Transform.fromXyz(4, 8, 4)} />+ <Mesh3d transform={Transform.fromXyz(0, 0.5, 0)}>+ <Cuboid half_size={[0.5, 0.5, 0.5]} />+ <Material+ fragment={staticFile("shaders/custom_material_screenspace_texture.wesl")}+ textures={{ texture: staticFile("models/FlightHelmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png") }}+ />+ </Mesh3d>+ <Camera3d transform={Transform.fromXyz(x, 2.5, z).lookingAt([0, 0, 0])} />+ </>+ );+}++registerRoot(() => <Composition id="main" component={Shot} durationInFrames={61} fps={60} width={1280} height={720} />);diff --git a/sdk/render/src/3d/materials.tsx b/sdk/render/src/3d/materials.tsxindex 205b1cdc..5f9c6015 100644--- a/sdk/render/src/3d/materials.tsx+++ b/sdk/render/src/3d/materials.tsx@@ -122,6 +122,17 @@ export interface SurfaceShaderSpec {/** shader defs: each NAME a WESL condition for `@if(NAME)` (a number is true), and a whole number also* `constants::NAME`; each set of defs compiles its own pipeline */defs?: ShaderDefs;+ /** a <Material>'s own (docs/control.feature FC2a): its vertex shader file and what its Material methods give; set by+ * <Material>, not on a ShaderExtension */+ own?: OwnMaterialFields;+}++/** What a <Material>'s Material methods give: vertex_shader, alpha_mode, depth_bias and the faces its specialize culls. */+export interface OwnMaterialFields {+ vertex?: string;+ alpha_mode?: unknown;+ depth_bias?: number;+ cull_mode?: "Front" | "Back" | null;}export type ShaderDefs = Record<string, boolean | number>;@@ -175,7 +186,7 @@ export function assetPath(p: string): string {/** A surface shader checked and given as the row's spec (its source, uniforms, textures). */export function surfaceShader(owner: string, sh: SurfaceShaderSpec, hook: RegExp = HOOK, hooks = "fn surface(in: VertexOutput, pbr: ptr<function, PbrInput>), fn lit(in: VertexOutput, pbr: PbrInput, color: vec4<f32>) -> vec4<f32>, or its own @fragment"): Record<string, unknown> {if (typeof sh !== "object" || sh === null) throw new TypeError(`${owner}: shader is { wesl | wgsl, uniforms, textures }`);- const { wesl, wgsl, fragment, uniforms = {}, textures = {}, defs } = sh;+ const { wesl, wgsl, fragment, uniforms = {}, textures = {}, defs, own } = sh;if ([wesl, wgsl, fragment].filter((s) => s !== undefined).length !== 1) throw new TypeError(`${owner}: shader gives its source as wesl, wgsl or a fragment path, one of them`);if (fragment !== undefined && (typeof fragment !== "string" || !fragment)) throw new TypeError(`${owner}: fragment is an asset path, got ${JSON.stringify(fragment)}`);const src = wesl ?? wgsl;@@ -185,11 +196,18 @@ export function surfaceShader(owner: string, sh: SurfaceShaderSpec, hook: RegExpif (us.length > 16) throw new RangeError(`${owner}: a shader has at most 16 uniforms, got ${us.length}`);for (const [k, v] of us) {if (!IDENT.test(k)) throw new TypeError(`${owner}: uniform ${JSON.stringify(k)} isn't a WGSL name`);+ // a Material's uniform of a struct type is { field: value }, each field checked where the struct is read+ if (own !== undefined && typeof v === "object" && v !== null && !Array.isArray(v)) continue;const ok = (typeof v === "number" && Number.isFinite(v)) || (Array.isArray(v) && v.length >= 2 && v.length <= 4 && v.every((x) => typeof x === "number" && Number.isFinite(x))) || (typeof v === "string" && /^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(v));if (!ok) throw new TypeError(`${owner}: uniform ${k} is a number, [x, y(, z(, w))] or "#rrggbb", got ${JSON.stringify(v)}`);}+ if (own !== undefined && fragment === undefined) throw new TypeError(`${owner}: a Material's own fields go with its fragment file`);checkTextures(owner, textures);- return { ...(fragment !== undefined ? { fragment: assetPath(fragment) } : wesl !== undefined ? { wesl } : { wgsl }), uniforms, textures, ...(defs !== undefined ? { defs: shaderDefs(owner, defs) } : {}) };+ // a picture's path found as the fragment's is (staticFile's /media/x); "render:NAME", data: URLs and pictures made in+ // code kept as given+ const file = (s: unknown) => (typeof s === "string" && !s.includes(":") ? assetPath(s) : s);+ const found = Object.fromEntries(Object.entries(textures).map(([k, t]) => [k, typeof t === "string" ? file(t) : t !== null && typeof t === "object" && "src" in t ? { ...t, src: file(t.src) } : t]));+ return { ...(fragment !== undefined ? { fragment: assetPath(fragment) } : wesl !== undefined ? { wesl } : { wgsl }), uniforms, textures: found, ...(defs !== undefined ? { defs: shaderDefs(owner, defs) } : {}), ...(own !== undefined ? { own, ...(own.vertex !== undefined ? { vertex: assetPath(own.vertex) } : {}) } : {}) };}/** A shader's textures checked: up to 4 pictures and one array (docs/shaders.feature SH9). */diff --git a/sdk/render/src/bevy3d/material.tsx b/sdk/render/src/bevy3d/material.tsxindex 5b09f7b8..c74b5209 100644--- a/sdk/render/src/bevy3d/material.tsx+++ b/sdk/render/src/bevy3d/material.tsx@@ -1,20 +1,38 @@-// Your own Material (docs/control.feature FC2a): Bevy's Material with its fragment_shader(), a file compiled as written.-import { ExtendedMaterial, ShaderExtension, StandardMaterial } from "./materials";+// Your own Material (docs/control.feature FC2a): Bevy's Material, its shaders the author's files compiled as written.+import { ExtendedMaterial, ShaderExtension, StandardMaterial, type AlphaMode } from "./materials";import type { SurfaceShaderSpec } from "../3d";-/** Your own Material (docs/control.feature FC2a, its first step): Bevy's `impl Material` with a fragment_shader(), the- * file compiled as written (its imports, its own @fragment, its own @binding(100) uniform struct if it has one, read- * from `uniforms`). Today it draws as an ExtendedMaterial whose own fragment replaces the surface, the base unused.+/** Your own Material (docs/control.feature FC2a): Bevy's `impl Material`, not an extension of StandardMaterial. Its+ * fragment_shader() (and vertex_shader(), when `vertex` names one) is the file compiled as written: its imports (a+ * `super::NAME` one reads NAME.wesl beside it), its own @fragment and its own `@group(MATERIAL_BIND_GROUP)` bindings,+ * up to 8 uniforms of any type (a struct's from { field: value }), 4 textures and their samplers, in its layout. A+ * uniform or texture it doesn't declare is refused. `alpha_mode` and `depth_bias` are its Material methods', and+ * `cull_mode` the faces its specialize culls (Back; null culls none).* @bevy bevy_pbr::material::Material */export interface MaterialProps {/** the shader file, staticFile("shaders/x.wesl"), as Bevy's Material::fragment_shader names one */fragment: string;- uniforms?: SurfaceShaderSpec["uniforms"];+ /** a vertex shader file, as Material::vertex_shader names one (Bevy's mesh vertex shader when not given) */+ vertex?: string;+ uniforms?: Record<string, number | number[] | string | Record<string, number | number[] | string>>;textures?: SurfaceShaderSpec["textures"];defs?: SurfaceShaderSpec["defs"];+ alpha_mode?: AlphaMode;+ depth_bias?: number;+ cull_mode?: "Front" | "Back" | null;}-export function Material({ fragment, uniforms, textures, defs }: MaterialProps) {+const ALPHA = ["Opaque", "Blend", "Premultiplied", "Add", "Multiply", "AlphaToCoverage"];++export function Material({ fragment, vertex, uniforms, textures, defs, alpha_mode, depth_bias, cull_mode }: MaterialProps) {if (typeof fragment !== "string" || !fragment) throw new TypeError(`Material: fragment is the shader file, staticFile("shaders/x.wesl"), got ${JSON.stringify(fragment)}`);- return <ExtendedMaterial base={<StandardMaterial />} extension={<ShaderExtension fragment={fragment} uniforms={uniforms} textures={textures} defs={defs} />} />;+ if (vertex !== undefined && (typeof vertex !== "string" || !vertex)) throw new TypeError(`Material: vertex is a shader file, got ${JSON.stringify(vertex)}`);+ const mask = typeof alpha_mode === "object" && alpha_mode !== null && Number.isFinite((alpha_mode as { Mask?: number }).Mask);+ if (alpha_mode !== undefined && !mask && !ALPHA.includes(alpha_mode as string)) throw new TypeError(`Material: alpha_mode is ${ALPHA.join(", ")} or { Mask: cutoff }, got ${JSON.stringify(alpha_mode)}`);+ if (depth_bias !== undefined && !Number.isFinite(depth_bias)) throw new TypeError(`Material: depth_bias is a number, got ${depth_bias}`);+ if (cull_mode !== undefined && cull_mode !== null && cull_mode !== "Front" && cull_mode !== "Back") throw new TypeError(`Material: cull_mode is "Front", "Back" or null, got ${JSON.stringify(cull_mode)}`);+ const own = { ...(vertex !== undefined ? { vertex } : {}), ...(alpha_mode !== undefined ? { alpha_mode } : {}), ...(depth_bias !== undefined ? { depth_bias } : {}), ...(cull_mode !== undefined ? { cull_mode } : {}) };+ // drawn by the engine as raea-sys-shader's OwnMaterial; the StandardMaterial is only what the rows carry it on+ const spec = { fragment, uniforms: uniforms as SurfaceShaderSpec["uniforms"], textures, defs, own };+ return <ExtendedMaterial base={<StandardMaterial />} extension={<ShaderExtension {...spec} />} />;}diff --git a/systems/shader/src/layout.rs b/systems/shader/src/layout.rsindex 563d548a..691ed83f 100644--- a/systems/shader/src/layout.rs+++ b/systems/shader/src/layout.rs@@ -124,6 +124,30 @@ pub fn pack(fields: &[(String, String)], uniforms: &[(String, Vec4)]) -> Result<Ok(out)}+/// A material's uniforms (`given`, {name: value}) in its own bindings' slots: `declared` is each binding's (name, WGSL+/// type) in slot order (ui_bind.rs's), and each value is packed in its type's layout, a scalar or vector from a number,+/// an array or a colour and a struct from {field: value}. A value for a uniform the source doesn't declare is refused,+/// as is a declared one without a value.+pub fn slots(src: &str, declared: &[(String, String)], given: &serde_json::Map<String, serde_json::Value>, defs: &[ShaderDefVal]) -> Result<[[Vec4; 16]; 8], String> {+ use raea_sys_material::shader_material::uniform;+ if let Some(k) = given.keys().find(|k| !declared.iter().any(|(n, _)| n == *k)) {+ return Err(format!("no uniform {k}"));+ }+ let mut out = [[Vec4::ZERO; 16]; 8];+ for (i, (name, ty)) in declared.iter().enumerate() {+ let v = given.get(name).ok_or_else(|| format!("its uniform {name} has no value"))?;+ out[i] = match v.as_object() {+ Some(o) => {+ let fields = struct_fields(src, ty, defs).map_err(|e| format!("uniform {name}: {e}"))?;+ let vals = o.iter().map(|(k, x)| uniform(k, x).map(|u| (u.name, u.value))).collect::<Result<Vec<_>, _>>()?;+ pack(&fields, &vals)?+ }+ None => pack(&[(name.clone(), ty.clone())], &[(name.clone(), uniform(name, v)?.value)])?,+ };+ }+ Ok(out)+}+#[cfg(test)]mod tests {use super::*;diff --git a/systems/shader/src/lib.rs b/systems/shader/src/lib.rsindex f7cfa2a7..9616ef4f 100644--- a/systems/shader/src/lib.rs+++ b/systems/shader/src/lib.rs@@ -27,6 +27,7 @@ use std::hash::{Hash, Hasher};use raea_sys_material::shader_material::{defs, ident, uniform, Uniform, SLOTS, TEXTURES};mod layout;+pub mod own;pub mod ui;mod ui_bind;@@ -40,6 +41,7 @@ pub fn install(app: &mut App) {let stub = module("", &[], &[], None);let _ = app.world_mut().resource_mut::<Assets<Shader>>().insert(&PLACEHOLDER, Shader::from_wesl(stub, "embedded://raea_sys_shader/placeholder.wesl"));app.add_plugins(MaterialPlugin::<ShadedMaterial>::default());+ own::install(app);ui::install(app);}@@ -298,6 +300,18 @@ pub fn build(world: &mut World, v: &Value, mut image: impl FnMut(&mut World, &VaOk(ShaderExt { slots, tex0: t.next().flatten(), tex1: t.next().flatten(), tex2: t.next().flatten(), tex3: t.next().flatten(), arr: ins.array.map(|a| a.1), shader: id })}+/// A mesh row's shader put on its part: a <Material>'s own (own.rs) or a ShaderExtension over its standard material.+pub fn put(world: &mut World, e: Entity, v: &Value, mut image: impl FnMut(&mut World, &Value) -> Result<Handle<Image>, String>, made: &mut HashMap<(AssetId<StandardMaterial>, u128), Handle<ShadedMaterial>>) -> Result<(), String> {+ if own::is_own(v) {+ let m = own::build(world, v, &mut image)?;+ own::put(world, e, m);+ return Ok(());+ }+ let ext = build(world, v, image)?;+ shade(world, e, &ext, made);+ Ok(())+}+/// A shaded part: the standard material the rows animate (sync_meshes writes it), copied onto the shaded one's base/// when it changes (sync_shaded).#[derive(Component, Clone)]diff --git a/systems/shader/src/own.rs b/systems/shader/src/own.rsnew file mode 100644index 00000000..795e3aea--- /dev/null+++ b/systems/shader/src/own.rs@@ -0,0 +1,259 @@+//! Your own Material (docs/control.feature FC2a, Bevy's shader/shader_material): raea/pbr's `<Material>` is Bevy's+//! `impl Material`, not an extension of StandardMaterial. Its fragment shader (and vertex shader, when it names one) is+//! the author's file compiled as written but for the numbers of its `@group(MATERIAL_BIND_GROUP)` bindings, which go to+//! this one Rust type's fixed slots in the order the source declares them (ui_bind.rs, as raea's UiMaterial does):+//! uniforms of any type up to 256 bytes at 0 to 7, packed in their declared types (layout.rs), textures at 8, 10, 12,+//! 14 and their samplers at 9, 11, 13, 15. A Rust Material's bind group is its type's, so raea's one type takes every+//! author's layout this way. Its alpha mode, depth bias and faces are the material's, as Bevy's methods give them.+//!+//! A file's `import super::NAME` reads NAME.wesl beside it: the file is registered as embedded://raea_sys_shader/+//! d{folder}/m{hash}.wesl and each module it imports from its folder as embedded://raea_sys_shader/d{folder}/NAME.wesl,+//! which is the module path WESL resolves `super::NAME` to.++use std::hash::{Hash, Hasher};++use bevy::asset::uuid_handle;+use bevy::mesh::MeshVertexBufferLayoutRef;+use bevy::pbr::{Material, MaterialPipeline, MaterialPipelineKey, MaterialPlugin};+use bevy::prelude::*;+use bevy::render::render_resource::{AsBindGroup, Face, RenderPipelineDescriptor, SpecializedMeshPipelineError};+use bevy::shader::{Shader, ShaderRef};+use serde_json::Value;++use crate::ui_bind::{rebind_in, Rebound};+use crate::{layout, register, Inputs, OwnSurface, Shaded};++/// The fragment shader every pipeline starts from, swapped in `specialize` for the material's own (its uuid).+const PLACEHOLDER: Handle<Shader> = uuid_handle!("5d1e7a3c-2b9f-4e6d-8a1c-3f7b9d2e6c41");+const STUB: &str = "import bevy_pbr::render::forward_io::VertexOutput;\n@fragment\nfn fragment(in: VertexOutput) -> @location(0) vec4<f32> { return vec4(1.0, 0.0, 1.0, 1.0); }\n";++/// How a source may write the material's group.+const GROUPS: &[&str] = &["constants::MATERIAL_BIND_GROUP", "#{MATERIAL_BIND_GROUP}", "3"];++/// One Rust type for every author's Material: eight uniform buffers of 256 bytes, four textures with their samplers,+/// the shaders that read them, and how it blends and culls.+#[derive(Asset, AsBindGroup, TypePath, Clone, Debug)]+#[bind_group_data(OwnKey)]+pub struct OwnMaterial {+ #[uniform(0)]+ u0: [Vec4; 16],+ #[uniform(1)]+ u1: [Vec4; 16],+ #[uniform(2)]+ u2: [Vec4; 16],+ #[uniform(3)]+ u3: [Vec4; 16],+ #[uniform(4)]+ u4: [Vec4; 16],+ #[uniform(5)]+ u5: [Vec4; 16],+ #[uniform(6)]+ u6: [Vec4; 16],+ #[uniform(7)]+ u7: [Vec4; 16],+ #[texture(8)]+ #[sampler(9)]+ t0: Option<Handle<Image>>,+ #[texture(10)]+ #[sampler(11)]+ t1: Option<Handle<Image>>,+ #[texture(12)]+ #[sampler(13)]+ t2: Option<Handle<Image>>,+ #[texture(14)]+ #[sampler(15)]+ t3: Option<Handle<Image>>,+ shader: u128,+ /// the vertex shader's uuid, 0 for Bevy's mesh vertex shader+ vertex: u128,+ alpha: AlphaMode,+ depth_bias: f32,+ /// the faces it culls (the pipeline's primitive.cull_mode), Back as Bevy's mesh pipeline has it+ cull: Option<Face>,+}++/// What picks a pipeline: the material's shaders and the faces it culls.+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]+pub struct OwnKey {+ shader: u128,+ vertex: u128,+ cull: Option<Face>,+}++impl From<&OwnMaterial> for OwnKey {+ fn from(m: &OwnMaterial) -> Self {+ OwnKey { shader: m.shader, vertex: m.vertex, cull: m.cull }+ }+}++fn uuid(id: u128) -> Handle<Shader> {+ Handle::Uuid(bevy::asset::uuid::Uuid::from_u128(id), core::marker::PhantomData)+}++impl Material for OwnMaterial {+ fn fragment_shader() -> ShaderRef {+ ShaderRef::Handle(PLACEHOLDER)+ }+ fn alpha_mode(&self) -> AlphaMode {+ self.alpha+ }+ fn depth_bias(&self) -> f32 {+ self.depth_bias+ }+ fn specialize(_: &MaterialPipeline, descriptor: &mut RenderPipelineDescriptor, _: &MeshVertexBufferLayoutRef, key: MaterialPipelineKey<Self>) -> Result<(), SpecializedMeshPipelineError> {+ let k = key.bind_group_data;+ if let Some(f) = descriptor.fragment.as_mut().filter(|f| f.shader.id() == PLACEHOLDER.id()) {+ f.shader = uuid(k.shader);+ }+ // the main pass's vertex stage only: the prepass and shadow pipelines keep Bevy's+ if k.vertex != 0 && descriptor.fragment.as_ref().is_some_and(|f| f.shader.id() == uuid(k.shader).id()) {+ descriptor.vertex.shader = uuid(k.vertex);+ }+ descriptor.primitive.cull_mode = k.cull;+ Ok(())+ }+}++pub fn install(app: &mut App) {+ let _ = app.world_mut().resource_mut::<Assets<Shader>>().insert(&PLACEHOLDER, Shader::from_wesl(STUB, "embedded://raea_sys_shader/own_placeholder.wesl"));+ app.add_plugins(MaterialPlugin::<OwnMaterial>::default());+}++/// Whether a mesh's shader spec is a `<Material>`'s (its `own`), not a ShaderExtension's.+pub fn is_own(spec: &Value) -> bool {+ spec.get("own").is_some()+}++/// The material a `<Material>` spec asks for: {fragment, vertex?, uniforms, textures, defs, own: {alpha_mode,+/// depth_bias, cull_mode}}, its shaders registered as written (bindings renumbered, imports beside them).+pub fn build(world: &mut World, v: &Value, image: &mut impl FnMut(&mut World, &Value) -> Result<Handle<Image>, String>) -> Result<OwnMaterial, String> {+ let what = "a Material";+ let o = v.as_object().ok_or_else(|| format!("{what} is {{fragment, uniforms, textures}}, got {v}"))?;+ let path = o.get("fragment").and_then(Value::as_str).ok_or_else(|| format!("{what}'s fragment is its shader file"))?;+ // the uniforms are packed in the source's own types below, so Inputs reads the rest+ let mut rest = o.clone();+ let given = rest.remove("uniforms").and_then(|u| u.as_object().cloned()).unwrap_or_default();+ let ins = Inputs::read(world, &rest, what, image)?;+ let Rebound { src, uniforms, textures, .. } = rebind_in(&ins.src, GROUPS, what).map_err(|e| format!("{path}: {e}"))?;+ let [u0, u1, u2, u3, u4, u5, u6, u7] = layout::slots(&src, &uniforms, &given, &ins.defs).map_err(|e| format!("{path}: {e}"))?;+ if let Some((k, _)) = ins.textures.iter().find(|(k, _)| !textures.contains(k)) {+ return Err(format!("{path} has no texture {k}"));+ }+ let mut t: [Option<Handle<Image>>; 4] = Default::default();+ for (i, name) in textures.iter().enumerate() {+ t[i] = Some(ins.textures.iter().find(|(k, _)| k == name).map(|x| x.1.clone()).ok_or_else(|| format!("{path}'s texture {name} has no picture"))?);+ }+ let krate = folder(world, path, &src)?;+ let shader = register(world, src, &ins.defs, "raea own material", &krate);+ let vertex = match o.get("vertex").and_then(Value::as_str) {+ None => 0,+ Some(p) => {+ let s = std::fs::read_to_string(p).map_err(|e| format!("{what}'s vertex {p}: {e}"))?;+ let s = rebind_in(&s, GROUPS, what).map_err(|e| format!("{p}: {e}"))?.src;+ let krate = folder(world, p, &s)?;+ register(world, s, &ins.defs, "raea own material vertex", &krate)+ }+ };+ let own = o.get("own").and_then(Value::as_object).cloned().unwrap_or_default();+ let alpha = alpha_mode(own.get("alpha_mode"))?;+ let depth_bias = own.get("depth_bias").and_then(Value::as_f64).unwrap_or(0.0) as f32;+ let cull = match own.get("cull_mode") {+ None => Some(Face::Back),+ Some(Value::Null) => None,+ Some(v) if v == "Front" => Some(Face::Front),+ Some(v) if v == "Back" => Some(Face::Back),+ Some(v) => return Err(format!("a Material's cull_mode is \"Front\", \"Back\" or null (none), got {v}")),+ };+ let [t0, t1, t2, t3] = t;+ Ok(OwnMaterial { u0, u1, u2, u3, u4, u5, u6, u7, t0, t1, t2, t3, shader, vertex, alpha, depth_bias, cull })+}++/// Bevy's AlphaMode as the SDK writes it: "Opaque", "Blend", {"Mask": cutoff}, "Premultiplied", "AlphaToCoverage",+/// "Add" or "Multiply".+fn alpha_mode(v: Option<&Value>) -> Result<AlphaMode, String> {+ Ok(match v {+ None => AlphaMode::Opaque,+ Some(Value::String(s)) => match s.as_str() {+ "Opaque" => AlphaMode::Opaque,+ "Blend" => AlphaMode::Blend,+ "Premultiplied" => AlphaMode::Premultiplied,+ "AlphaToCoverage" => AlphaMode::AlphaToCoverage,+ "Add" => AlphaMode::Add,+ "Multiply" => AlphaMode::Multiply,+ _ => return Err(format!("a Material's alpha_mode is Opaque, Blend, Mask, Premultiplied, AlphaToCoverage, Add or Multiply, got {s:?}")),+ },+ Some(v) => match v.get("Mask").and_then(Value::as_f64) {+ Some(c) => AlphaMode::Mask(c as f32),+ None => return Err(format!("a Material's alpha_mode is a name or {{\"Mask\": cutoff}}, got {v}")),+ },+ })+}++/// The embedded folder a file's module goes in (raea_sys_shader/d{hash of its folder}), with every module it imports+/// by `super::NAME` registered there from its own folder, and theirs in turn.+fn folder(world: &mut World, path: &str, src: &str) -> Result<String, String> {+ let dir = std::path::Path::new(path).parent().unwrap_or(std::path::Path::new("."));+ let mut h = std::collections::hash_map::DefaultHasher::new();+ dir.hash(&mut h);+ let krate = format!("raea_sys_shader/d{:016x}", h.finish());+ let mut todo: Vec<String> = siblings(src);+ let mut done: Vec<String> = Vec::new();+ while let Some(name) = todo.pop() {+ if done.contains(&name) {+ continue;+ }+ let file = ["wesl", "wgsl"].iter().map(|x| dir.join(format!("{name}.{x}"))).find(|f| f.exists()).ok_or_else(|| format!("{path} imports super::{name}, and {} has no {name}.wesl", dir.display()))?;+ let s = std::fs::read_to_string(&file).map_err(|e| format!("{}: {e}", file.display()))?;+ todo.extend(siblings(&s));+ let at = format!("embedded://{krate}/{name}.wesl");+ let mut h = std::collections::hash_map::DefaultHasher::new();+ (&at, &s).hash(&mut h);+ let id = AssetId::<Shader>::Uuid { uuid: bevy::asset::uuid::Uuid::from_u64_pair(h.finish(), 0x5d1e_7a3c) };+ let _ = world.resource_mut::<Assets<Shader>>().insert(id, Shader::from_wesl(s, at));+ done.push(name);+ }+ Ok(krate)+}++/// The modules a source imports from its own folder: each `super::NAME` of its `import` statements.+fn siblings(src: &str) -> Vec<String> {+ let mut out = Vec::new();+ for line in src.lines().map(str::trim).filter(|l| l.starts_with("import ")) {+ for (i, _) in line.match_indices("super::") {+ // super::NAME::item, or super::{NAME::item, OTHER::item}+ let after = &line[i + 7..];+ let parts: Vec<&str> = match after.strip_prefix('{') {+ Some(r) => r.split('}').next().unwrap_or("").split(',').collect(),+ None => vec![after],+ };+ for p in parts {+ let name: String = p.trim().chars().take_while(|c| c.is_ascii_alphanumeric() || *c == '_').collect();+ if !name.is_empty() && !out.contains(&name) {+ out.push(name);+ }+ }+ }+ }+ out+}++/// A part given its own Material: its MeshMaterial3d<StandardMaterial> swapped for the OwnMaterial, the standard one+/// kept aside as `Shaded` (so the rows' sync finds it) and the scene's <SurfaceShader> kept off it.+pub fn put(world: &mut World, e: Entity, m: OwnMaterial) -> bool {+ let Some(std) = world.get::<MeshMaterial3d<StandardMaterial>>(e).map(|m| m.0.clone()) else { return false };+ let h = world.resource_mut::<Assets<OwnMaterial>>().add(m);+ world.entity_mut(e).remove::<MeshMaterial3d<StandardMaterial>>().insert((MeshMaterial3d(h), Shaded { std }, OwnSurface));+ true+}++#[cfg(test)]+mod tests {+ #[test]+ fn a_files_own_folder_imports_are_found() {+ let src = "import bevy_pbr::forward_io::VertexOutput;\nimport super::custom_material_import::COLOR_MULTIPLIER;\nimport super::{a::X, b_2::Y};\nfn f() { super::not_an_import(); }\n";+ assert_eq!(super::siblings(src), vec!["custom_material_import".to_string(), "a".into(), "b_2".into()]);+ assert!(super::alpha_mode(Some(&serde_json::json!("Blend"))).unwrap() == bevy::prelude::AlphaMode::Blend);+ assert!(super::alpha_mode(Some(&serde_json::json!({"Mask": 0.5}))).unwrap() == bevy::prelude::AlphaMode::Mask(0.5));+ assert!(super::alpha_mode(Some(&serde_json::json!("Clear"))).is_err());+ }+}diff --git a/systems/shader/src/ui.rs b/systems/shader/src/ui.rsindex 72618fbf..53547655 100644--- a/systems/shader/src/ui.rs+++ b/systems/shader/src/ui.rs@@ -22,7 +22,7 @@ use bevy::render::render_resource::{AsBindGroup, RenderPipelineDescriptor, Textuuse bevy::render::renderer::{RenderDevice, RenderQueue};use bevy::render::texture::GpuImage;use bevy::render::{Render, RenderApp, RenderSystems};-use bevy::shader::{Shader, ShaderDefVal, ShaderRef};+use bevy::shader::{Shader, ShaderRef};use bevy::ui::UiTargetCamera;use bevy::ui_render::prelude::{MaterialNode, UiMaterial, UiMaterialKey, UiMaterialPlugin};use serde_json::Value;@@ -281,14 +281,7 @@ fn build(world: &mut World, state: &mut UiMats, o: &serde_json::Map<String, Valulet defs = raea_sys_material::shader_material::defs(o, "a UiMaterial")?;let Rebound { src, uniforms, textures, .. } = rebind(&src).map_err(|e| format!("{path}: {e}"))?;let given = o.get("uniforms").and_then(Value::as_object).cloned().unwrap_or_default();- if let Some(k) = given.keys().find(|k| !uniforms.iter().any(|(n, _)| n == *k)) {- return Err(format!("{path} has no uniform {k}"));- }- let mut slots = [[Vec4::ZERO; 16]; 8];- for (i, (name, ty)) in uniforms.iter().enumerate() {- let v = given.get(name).ok_or_else(|| format!("{path}'s uniform {name} has no value"))?;- slots[i] = pack(&src, name, ty, v, &defs).map_err(|e| format!("{path}: {e}"))?;- }+ let slots = layout::slots(&src, &uniforms, &given, &defs).map_err(|e| format!("{path}: {e}"))?;let given = o.get("textures").and_then(Value::as_object).cloned().unwrap_or_default();if let Some(k) = given.keys().find(|k| !textures.contains(k)) {return Err(format!("{path} has no texture {k}"));@@ -304,18 +297,6 @@ fn build(world: &mut World, state: &mut UiMats, o: &serde_json::Map<String, ValuOk(RaeaUiMaterial { u0, u1, u2, u3, u4, u5, u6, u7, t0, t1, t2, t3, shader })}-/// A uniform's value in its declared type's layout: a scalar or vector from a number, an array or a colour; a struct-/// from {field: value}.-fn pack(src: &str, name: &str, ty: &str, v: &Value, defs: &[ShaderDefVal]) -> Result<[Vec4; 16], String> {- if let Some(o) = v.as_object() {- let fields = layout::struct_fields(src, ty, defs).map_err(|e| format!("uniform {name}: {e}"))?;- let vals = o.iter().map(|(k, x)| raea_sys_material::shader_material::uniform(k, x).map(|u| (u.name, u.value))).collect::<Result<Vec<_>, _>>()?;- return layout::pack(&fields, &vals);- }- let u = raea_sys_material::shader_material::uniform(name, v)?;- layout::pack(&[(name.to_string(), ty.to_string())], &[(name.to_string(), u.value)])-}-/// A picture file as an Image, decoded once (sRGB, as asset_server.load reads a colour texture).fn picture(world: &mut World, state: &mut UiMats, path: &str) -> Result<Handle<Image>, String> {if let Some(h) = state.pictures.get(path) {diff --git a/systems/shader/src/ui_bind.rs b/systems/shader/src/ui_bind.rsindex e6b5140a..53d80f2b 100644--- a/systems/shader/src/ui_bind.rs+++ b/systems/shader/src/ui_bind.rs@@ -18,10 +18,15 @@ pub struct Rebound {pub samplers: usize,}-/// `src`'s `@group(1)` declarations renumbered into raea's slots (see the module's doc); bindings of other groups left-/// as written. Refused: a group-1 binding that isn't a uniform, a texture_2d or a sampler, and more of each than raea-/// has slots for.+/// `src`'s `@group(1)` declarations renumbered into raea's slots (see the module's doc), a UiMaterial's.pub fn rebind(src: &str) -> Result<Rebound, String> {+ rebind_in(src, &["1"], "a UiMaterial")+}++/// `src`'s declarations in any of `groups` (as the source writes the group: `1`, `constants::MATERIAL_BIND_GROUP`)+/// renumbered into raea's slots; bindings of other groups left as written. Refused: a binding that isn't a uniform, a+/// texture_2d or a sampler, and more of each than raea has slots for (`what` names the material in errors).+pub fn rebind_in(src: &str, groups: &[&str], what: &str) -> Result<Rebound, String> {let mut out = String::with_capacity(src.len());let (mut uniforms, mut textures, mut samplers) = (Vec::new(), Vec::new(), 0usize);let mut rest = src;@@ -37,37 +42,37 @@ pub fn rebind(src: &str) -> Result<Rebound, String> {let Some(end) = rest[i..].find(';').map(|n| i + n) else { return Err("a @binding declaration has no ';'".into()) };let stmt = &rest[stmt_start..end];let close = i + rest[i..].find(')').ok_or("@binding( has no ')'")?;- if group(stmt) != Some("1") {+ if !group(stmt).is_some_and(|g| groups.contains(&g)) {out += &rest[..close + 1];rest = &rest[close + 1..];continue;}- let decl = stmt.split_once("var").map(|(_, d)| d).ok_or_else(|| format!("a @group(1) binding is a var, got {:?}", stmt.trim()))?;+ let decl = stmt.split_once("var").map(|(_, d)| d).ok_or_else(|| format!("{what}'s binding is a var, got {:?}", stmt.trim()))?;let (uniform, decl) = match decl.trim_start().strip_prefix("<uniform>") {Some(d) => (true, d),None => (false, decl),};- let (name, ty) = decl.split_once(':').map(|(n, t)| (n.trim().to_string(), t.trim().to_string())).ok_or_else(|| format!("a @group(1) binding is `var NAME: TYPE`, got {:?}", stmt.trim()))?;+ let (name, ty) = decl.split_once(':').map(|(n, t)| (n.trim().to_string(), t.trim().to_string())).ok_or_else(|| format!("{what}'s binding is `var NAME: TYPE`, got {:?}", stmt.trim()))?;let slot = if uniform {uniforms.push((name.clone(), ty));if uniforms.len() > UNIFORMS {- return Err(format!("a UiMaterial binds at most {UNIFORMS} uniforms, {name} is one more"));+ return Err(format!("{what} binds at most {UNIFORMS} uniforms, {name} is one more"));}uniforms.len() - 1} else if ty.starts_with("texture_2d<") {textures.push(name.clone());if textures.len() > TEXTURES {- return Err(format!("a UiMaterial binds at most {TEXTURES} textures, {name} is one more"));+ return Err(format!("{what} binds at most {TEXTURES} textures, {name} is one more"));}UNIFORMS + 2 * (textures.len() - 1)} else if ty == "sampler" {samplers += 1;if samplers > TEXTURES {- return Err(format!("a UiMaterial binds at most {TEXTURES} samplers, {name} is one more"));+ return Err(format!("{what} binds at most {TEXTURES} samplers, {name} is one more"));}UNIFORMS + 2 * (samplers - 1) + 1} else {- return Err(format!("a UiMaterial's @group(1) binding {name} is a var<uniform>, a texture_2d<f32> or a sampler, got {ty} (the rest are FC2a's to come)"));+ return Err(format!("{what}'s binding {name} is a var<uniform>, a texture_2d<f32> or a sampler, got {ty} (the rest are FC2a's to come)"));};out += &rest[..i];out += &format!("@binding({slot})");@@ -75,7 +80,7 @@ pub fn rebind(src: &str) -> Result<Rebound, String> {}out += rest;if samplers > textures.len() {- return Err(format!("a UiMaterial's samplers are its textures', one each: {samplers} samplers for {} textures", textures.len()));+ return Err(format!("{what}'s samplers are its textures', one each: {samplers} samplers for {} textures", textures.len()));}Ok(Rebound { src: out, uniforms, textures, samplers })}