|
19 | 19 | //! - [ ] light tiling
|
20 | 20 | //! - [ ] occlusion culling
|
21 | 21 | //! - [x] physically based shading
|
22 |
| -//! - [x] user interface "colored text" shading (uses opacity glyphs in an |
23 | 22 | //! atlas)
|
24 |
| -//! - [x] no shading |
25 |
| -//! - [ ] gltf support |
26 |
| -//! - [ ] scenes, nodes |
| 23 | +//! - [x] gltf support |
| 24 | +//! - [x] scenes, nodes |
27 | 25 | //! - [x] cameras
|
28 | 26 | //! - [x] meshes
|
29 | 27 | //! - [x] materials
|
@@ -261,7 +259,7 @@ mod test {
|
261 | 259 | use pretty_assertions::assert_eq;
|
262 | 260 | use renderling_shader::{
|
263 | 261 | gltf as gl,
|
264 |
| - stage::{gltf_vertex, light::*, Camera, GpuEntity, RenderUnit, Transform, Vertex}, |
| 262 | + stage::{light::*, Camera, RenderUnit, Transform, Vertex}, |
265 | 263 | };
|
266 | 264 |
|
267 | 265 | #[test]
|
@@ -876,149 +874,123 @@ mod test {
|
876 | 874 | fn scene_parent_sanity() {
|
877 | 875 | let mut r = Renderling::headless(100, 100);
|
878 | 876 | r.set_background_color(Vec4::splat(0.0));
|
| 877 | + let stage = r.new_stage(); |
| 878 | + stage.configure_graph(&mut r, true); |
879 | 879 | let (projection, view) = camera::default_ortho2d(100.0, 100.0);
|
880 |
| - let mut builder = r.new_scene().with_camera(projection, view); |
| 880 | + let camera = stage.append(&Camera::new(projection, view)); |
881 | 881 | let size = 1.0;
|
882 |
| - let root = builder.new_entity().with_scale([25.0, 25.0, 1.0]).build(); |
883 |
| - let cyan_tri = builder |
884 |
| - .new_entity() |
885 |
| - .with_meshlet(vec![ |
886 |
| - Vertex { |
887 |
| - position: Vec4::new(0.0, 0.0, 0.0, 0.0), |
888 |
| - color: Vec4::new(0.0, 1.0, 1.0, 1.0), |
889 |
| - ..Default::default() |
890 |
| - }, |
891 |
| - Vertex { |
892 |
| - position: Vec4::new(size, size, 0.0, 0.0), |
893 |
| - color: Vec4::new(0.0, 1.0, 1.0, 1.0), |
894 |
| - ..Default::default() |
895 |
| - }, |
896 |
| - Vertex { |
897 |
| - position: Vec4::new(size, 0.0, 0.0, 0.0), |
898 |
| - color: Vec4::new(0.0, 1.0, 1.0, 1.0), |
899 |
| - ..Default::default() |
900 |
| - }, |
901 |
| - ]) |
902 |
| - .with_position([1.0, 1.0, 0.0]) |
903 |
| - .with_parent(root) |
904 |
| - .build(); |
905 |
| - let yellow_tri = builder // |
906 |
| - .new_entity() |
907 |
| - .with_meshlet(vec![ |
908 |
| - Vertex { |
909 |
| - position: Vec4::new(0.0, 0.0, 0.0, 0.0), |
910 |
| - color: Vec4::new(1.0, 1.0, 0.0, 1.0), |
911 |
| - ..Default::default() |
912 |
| - }, |
913 |
| - Vertex { |
914 |
| - position: Vec4::new(size, size, 0.0, 0.0), |
915 |
| - color: Vec4::new(1.0, 1.0, 0.0, 1.0), |
916 |
| - ..Default::default() |
917 |
| - }, |
918 |
| - Vertex { |
919 |
| - position: Vec4::new(size, 0.0, 0.0, 0.0), |
920 |
| - color: Vec4::new(1.0, 1.0, 0.0, 1.0), |
921 |
| - ..Default::default() |
922 |
| - }, |
923 |
| - ]) |
924 |
| - .with_position([1.0, 1.0, 0.0]) |
925 |
| - .with_parent(&cyan_tri) |
926 |
| - .build(); |
927 |
| - let _red_tri = builder |
928 |
| - .new_entity() |
929 |
| - .with_meshlet(vec![ |
930 |
| - Vertex { |
931 |
| - position: Vec4::new(0.0, 0.0, 0.0, 0.0), |
932 |
| - color: Vec4::new(1.0, 0.0, 0.0, 1.0), |
933 |
| - ..Default::default() |
934 |
| - }, |
935 |
| - Vertex { |
936 |
| - position: Vec4::new(size, size, 0.0, 0.0), |
937 |
| - color: Vec4::new(1.0, 0.0, 0.0, 1.0), |
938 |
| - ..Default::default() |
939 |
| - }, |
940 |
| - Vertex { |
941 |
| - position: Vec4::new(size, 0.0, 0.0, 0.0), |
942 |
| - color: Vec4::new(1.0, 0.0, 0.0, 1.0), |
943 |
| - ..Default::default() |
944 |
| - }, |
945 |
| - ]) |
946 |
| - .with_position([1.0, 1.0, 0.0]) |
947 |
| - .with_parent(&yellow_tri) |
948 |
| - .build(); |
| 882 | + let cyan_material = stage.append(&PbrMaterial { |
| 883 | + albedo_factor: Vec4::new(0.0, 1.0, 1.0, 1.0), |
| 884 | + lighting_model: LightingModel::NO_LIGHTING, |
| 885 | + ..Default::default() |
| 886 | + }); |
| 887 | + let yellow_material = stage.append(&PbrMaterial { |
| 888 | + albedo_factor: Vec4::new(1.0, 1.0, 0.0, 1.0), |
| 889 | + lighting_model: LightingModel::NO_LIGHTING, |
| 890 | + ..Default::default() |
| 891 | + }); |
| 892 | + let red_material = stage.append(&PbrMaterial { |
| 893 | + albedo_factor: Vec4::new(1.0, 0.0, 0.0, 1.0), |
| 894 | + lighting_model: LightingModel::NO_LIGHTING, |
| 895 | + ..Default::default() |
| 896 | + }); |
949 | 897 |
|
950 |
| - assert_eq!( |
951 |
| - vec![ |
952 |
| - GpuEntity { |
953 |
| - id: Id::new(0), |
954 |
| - position: Vec4::new(0.0, 0.0, 0.0, 0.0), |
955 |
| - scale: Vec4::new(25.0, 25.0, 1.0, 1.0), |
| 898 | + let cyan_primitive = stage.new_primitive( |
| 899 | + [ |
| 900 | + Vertex::default().with_position([0.0, 0.0, 0.0]), |
| 901 | + Vertex::default().with_position([size, size, 0.0]), |
| 902 | + Vertex::default().with_position([size, 0.0, 0.0]), |
| 903 | + ], |
| 904 | + [], |
| 905 | + cyan_material, |
| 906 | + ); |
| 907 | + let yellow_primitive = { |
| 908 | + let mut p = cyan_primitive; |
| 909 | + p.material = yellow_material; |
| 910 | + p |
| 911 | + }; |
| 912 | + let red_primitive = { |
| 913 | + let mut p = cyan_primitive; |
| 914 | + p.material = red_material; |
| 915 | + p |
| 916 | + }; |
| 917 | + |
| 918 | + let root_node = stage.allocate::<gl::GltfNode>(); |
| 919 | + let cyan_node = stage.allocate::<gl::GltfNode>(); |
| 920 | + let yellow_node = stage.allocate::<gl::GltfNode>(); |
| 921 | + let red_node = stage.allocate::<gl::GltfNode>(); |
| 922 | + |
| 923 | + // Write the nodes now that we have references to them all |
| 924 | + stage |
| 925 | + .write( |
| 926 | + root_node, |
| 927 | + &gl::GltfNode { |
| 928 | + children: stage.append_array(&[cyan_node]), |
| 929 | + scale: Vec3::new(25.0, 25.0, 1.0), |
956 | 930 | ..Default::default()
|
957 | 931 | },
|
958 |
| - GpuEntity { |
959 |
| - id: Id::new(1), |
960 |
| - parent: Id::new(0), |
961 |
| - position: Vec4::new(1.0, 1.0, 0.0, 0.0), |
962 |
| - scale: Vec4::new(1.0, 1.0, 1.0, 1.0), |
963 |
| - mesh_first_vertex: 0, |
964 |
| - mesh_vertex_count: 3, |
| 932 | + ) |
| 933 | + .unwrap(); |
| 934 | + stage |
| 935 | + .write( |
| 936 | + cyan_node, |
| 937 | + &gl::GltfNode { |
| 938 | + mesh: stage.append(&gl::GltfMesh { |
| 939 | + primitives: stage.append_array(&[cyan_primitive]), |
| 940 | + ..Default::default() |
| 941 | + }), |
| 942 | + children: stage.append_array(&[yellow_node]), |
| 943 | + translation: Vec3::new(1.0, 1.0, 0.0), |
965 | 944 | ..Default::default()
|
966 | 945 | },
|
967 |
| - GpuEntity { |
968 |
| - id: Id::new(2), |
969 |
| - parent: Id::new(1), |
970 |
| - position: Vec4::new(1.0, 1.0, 0.0, 0.0), |
971 |
| - scale: Vec4::new(1.0, 1.0, 1.0, 1.0), |
972 |
| - mesh_first_vertex: 3, |
973 |
| - mesh_vertex_count: 3, |
| 946 | + ) |
| 947 | + .unwrap(); |
| 948 | + stage |
| 949 | + .write( |
| 950 | + yellow_node, |
| 951 | + &gl::GltfNode { |
| 952 | + mesh: stage.append(&gl::GltfMesh { |
| 953 | + primitives: stage.append_array(&[yellow_primitive]), |
| 954 | + ..Default::default() |
| 955 | + }), |
| 956 | + children: stage.append_array(&[red_node]), |
| 957 | + translation: Vec3::new(1.0, 1.0, 0.0), |
974 | 958 | ..Default::default()
|
975 | 959 | },
|
976 |
| - GpuEntity { |
977 |
| - id: Id::new(3), |
978 |
| - parent: Id::new(2), |
979 |
| - position: Vec4::new(1.0, 1.0, 0.0, 0.0), |
980 |
| - scale: Vec4::new(1.0, 1.0, 1.0, 1.0), |
981 |
| - mesh_first_vertex: 6, |
982 |
| - mesh_vertex_count: 3, |
| 960 | + ) |
| 961 | + .unwrap(); |
| 962 | + stage |
| 963 | + .write( |
| 964 | + red_node, |
| 965 | + &gl::GltfNode { |
| 966 | + mesh: stage.append(&gl::GltfMesh { |
| 967 | + primitives: stage.append_array(&[red_primitive]), |
| 968 | + ..Default::default() |
| 969 | + }), |
| 970 | + translation: Vec3::new(1.0, 1.0, 0.0), |
983 | 971 | ..Default::default()
|
984 |
| - } |
985 |
| - ], |
986 |
| - builder.entities |
987 |
| - ); |
988 |
| - let tfrm = yellow_tri.get_world_transform(&builder.entities); |
989 |
| - assert_eq!( |
990 |
| - ( |
991 |
| - Vec3::new(50.0, 50.0, 0.0), |
992 |
| - Quat::IDENTITY, |
993 |
| - Vec3::new(25.0, 25.0, 1.0), |
994 |
| - ), |
995 |
| - tfrm |
996 |
| - ); |
997 |
| - // while we're at it let's also check that skinning doesn't affect |
998 |
| - // entities/vertices that aren't skins |
999 |
| - let vertex = &builder.vertices[yellow_tri.mesh_first_vertex as usize]; |
1000 |
| - let skin_matrix = vertex.get_skin_matrix(&yellow_tri.skin_joint_ids, &builder.entities); |
1001 |
| - assert_eq!(Mat4::IDENTITY, skin_matrix); |
| 972 | + }, |
| 973 | + ) |
| 974 | + .unwrap(); |
1002 | 975 |
|
1003 |
| - let entities = builder.entities.clone(); |
1004 |
| - let scene = builder.build().unwrap(); |
1005 |
| - r.setup_render_graph(RenderGraphConfig { |
1006 |
| - scene: Some(scene), |
1007 |
| - with_screen_capture: true, |
1008 |
| - with_bloom: false, |
| 976 | + let _cyan_unit = stage.draw_unit(&RenderUnit { |
| 977 | + camera, |
| 978 | + vertex_count: 3, |
| 979 | + node_path: stage.append_array(&[root_node, cyan_node]), |
| 980 | + ..Default::default() |
| 981 | + }); |
| 982 | + let _yellow_unit = stage.draw_unit(&RenderUnit { |
| 983 | + camera, |
| 984 | + vertex_count: 3, |
| 985 | + node_path: stage.append_array(&[root_node, cyan_node, yellow_node]), |
| 986 | + ..Default::default() |
| 987 | + }); |
| 988 | + let _red_unit = stage.draw_unit(&RenderUnit { |
| 989 | + camera, |
| 990 | + vertex_count: 3, |
| 991 | + node_path: stage.append_array(&[root_node, cyan_node, yellow_node, red_node]), |
1009 | 992 | ..Default::default()
|
1010 | 993 | });
|
1011 |
| - |
1012 |
| - let gpu_entities = futures_lite::future::block_on( |
1013 |
| - r.graph |
1014 |
| - .get_resource::<Scene>() |
1015 |
| - .unwrap() |
1016 |
| - .unwrap() |
1017 |
| - .entities |
1018 |
| - .read_gpu(r.get_device(), r.get_queue(), 0, entities.len()), |
1019 |
| - ) |
1020 |
| - .unwrap(); |
1021 |
| - assert_eq!(entities, gpu_entities); |
1022 | 994 |
|
1023 | 995 | let img = r.render_image().unwrap();
|
1024 | 996 | img_diff::assert_img_eq("scene_parent_sanity.png", img);
|
|
0 commit comments