pub const fn vec4(x: f32, y: f32, z: f32, w: f32) -> Vec4Expand description
Creates a 4-dimensional vector.
Examples found in repository?
More examples
examples/3d/atmosphere.rs (line 301)
268fn spawn_water(
269 commands: &mut Commands,
270 asset_server: &AssetServer,
271 meshes: &mut Assets<Mesh>,
272 water_materials: &mut Assets<ExtendedMaterial<StandardMaterial, Water>>,
273) {
274 commands.spawn((
275 Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))),
276 MeshMaterial3d(
277 water_materials.add(ExtendedMaterial {
278 base: StandardMaterial {
279 base_color: BLACK.into(),
280 perceptual_roughness: 0.0,
281 ..default()
282 },
283 extension: Water {
284 normals: asset_server
285 .load_builder()
286 .with_settings(|settings: &mut ImageLoaderSettings| {
287 settings.is_srgb = false;
288 settings.sampler = ImageSampler::Descriptor(ImageSamplerDescriptor {
289 address_mode_u: ImageAddressMode::Repeat,
290 address_mode_v: ImageAddressMode::Repeat,
291 mag_filter: ImageFilterMode::Linear,
292 min_filter: ImageFilterMode::Linear,
293 ..default()
294 });
295 })
296 .load("textures/water_normals.png"),
297 // These water settings are just random values to create some
298 // variety.
299 settings: WaterSettings {
300 octave_vectors: [
301 vec4(0.080, 0.059, 0.073, -0.062),
302 vec4(0.153, 0.138, -0.149, -0.195),
303 ],
304 octave_scales: vec4(1.0, 2.1, 7.9, 14.9) * 500.0,
305 octave_strengths: vec4(0.16, 0.18, 0.093, 0.044) * 0.2,
306 },
307 },
308 }),
309 ),
310 Transform::from_scale(Vec3::splat(100.0)),
311 ));
312}examples/3d/ssr.rs (line 416)
383fn spawn_water(
384 commands: &mut Commands,
385 asset_server: &AssetServer,
386 meshes: &mut Assets<Mesh>,
387 water_materials: &mut Assets<ExtendedMaterial<StandardMaterial, Water>>,
388) {
389 commands.spawn((
390 Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))),
391 MeshMaterial3d(
392 water_materials.add(ExtendedMaterial {
393 base: StandardMaterial {
394 base_color: BLACK.into(),
395 perceptual_roughness: 0.09,
396 ..default()
397 },
398 extension: Water {
399 normals: asset_server
400 .load_builder()
401 .with_settings::<ImageLoaderSettings>(|settings| {
402 settings.is_srgb = false;
403 settings.sampler = ImageSampler::Descriptor(ImageSamplerDescriptor {
404 address_mode_u: ImageAddressMode::Repeat,
405 address_mode_v: ImageAddressMode::Repeat,
406 mag_filter: ImageFilterMode::Linear,
407 min_filter: ImageFilterMode::Linear,
408 ..default()
409 });
410 })
411 .load("textures/water_normals.png"),
412 // These water settings are just random values to create some
413 // variety.
414 settings: WaterSettings {
415 octave_vectors: [
416 vec4(0.080, 0.059, 0.073, -0.062),
417 vec4(0.153, 0.138, -0.149, -0.195),
418 ],
419 octave_scales: vec4(1.0, 2.1, 7.9, 14.9) * 5.0,
420 octave_strengths: vec4(0.16, 0.18, 0.093, 0.044),
421 },
422 },
423 }),
424 ),
425 Transform::from_scale(Vec3::splat(100.0)),
426 WaterModel,
427 ));
428}examples/shader_advanced/specialized_mesh_pipeline.rs (line 78)
58fn setup(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
59 // Build a custom triangle mesh with colors
60 // We define a custom mesh because the examples only uses a limited
61 // set of vertex attributes for simplicity
62 let mesh = Mesh::new(
63 PrimitiveTopology::TriangleList,
64 RenderAssetUsages::default(),
65 )
66 .with_inserted_indices(Indices::U32(vec![0, 1, 2]))
67 .with_inserted_attribute(
68 Mesh::ATTRIBUTE_POSITION,
69 vec![
70 vec3(-0.5, -0.5, 0.0),
71 vec3(0.5, -0.5, 0.0),
72 vec3(0.0, 0.25, 0.0),
73 ],
74 )
75 .with_inserted_attribute(
76 Mesh::ATTRIBUTE_COLOR,
77 vec![
78 vec4(1.0, 0.0, 0.0, 1.0),
79 vec4(0.0, 1.0, 0.0, 1.0),
80 vec4(0.0, 0.0, 1.0, 1.0),
81 ],
82 );
83
84 // spawn 3 triangles to show that batching works
85 for (x, y) in [-0.5, 0.0, 0.5].into_iter().zip([-0.25, 0.5, -0.25]) {
86 // Spawn an entity with all the required components for it to be rendered with our custom pipeline
87 commands.spawn((
88 // We use a marker component to identify the mesh that will be rendered
89 // with our specialized pipeline
90 CustomRenderedEntity,
91 // We need to add the mesh handle to the entity
92 Mesh3d(meshes.add(mesh.clone())),
93 Transform::from_xyz(x, y, 0.0),
94 ));
95 }
96 commands.spawn((
97 // We use a marker component to identify the mesh that will be rendered
98 // with our specialized pipeline
99 CustomRenderedEntity,
100 // We need to add the mesh handle to the entity
101 Mesh3d(
102 meshes.add(
103 Rectangle::new(0.5, 0.5)
104 .mesh()
105 .build()
106 .with_removed_attribute(Mesh::ATTRIBUTE_NORMAL)
107 .with_removed_attribute(Mesh::ATTRIBUTE_UV_0)
108 .compressed_mesh(&MeshCompressionArgs::regular())
109 .unwrap(),
110 ),
111 ),
112 Transform::from_xyz(0.0, -1.0 / 3.0, -1.0),
113 ));
114
115 // Spawn the camera.
116 commands.spawn((
117 Camera3d::default(),
118 // Move the camera back a bit to see all the triangles
119 Transform::from_xyz(0.0, 0.0, 3.0).looking_at(Vec3::ZERO, Vec3::Y),
120 ));
121}