Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#define_import_path bevy_pbr::pbr_types
3// Since this is a hot path, try to keep the alignment and size of the struct members in mind.
4// You can find the alignment and sizes at <https://www.w3.org/TR/WGSL/#alignment-and-size>.
5struct StandardMaterial {
6 base_color: vec4<f32>,
7 emissive: vec4<f32>,
8 attenuation_color: vec4<f32>,
9 uv_transform: mat3x3<f32>,
10 perceptual_roughness: f32,
11 metallic: f32,
12 reflectance: f32,
13 diffuse_transmission: f32,
14 specular_transmission: f32,
15 thickness: f32,
16 ior: f32,
17 attenuation_distance: f32,
18 clearcoat: f32,
19 clearcoat_perceptual_roughness: f32,
20 anisotropy_strength: f32,
21 anisotropy_rotation: vec2<f32>,
22 // 'flags' is a bit field indicating various options. u32 is 32 bits so we have up to 32 options.
23 flags: u32,
24 alpha_cutoff: f32,
25 parallax_depth_scale: f32,
26 max_parallax_layer_count: f32,
27 lightmap_exposure: f32,
28 max_relief_mapping_search_steps: u32,
29 /// ID for specifying which deferred lighting pass should be used for rendering this material, if any.
30 deferred_lighting_pass_id: u32,
31};
33// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34// NOTE: if these flags are updated or changed. Be sure to also update
35// deferred_flags_from_mesh_material_flags and mesh_material_flags_from_deferred_flags
36// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37const STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT: u32 = 1u;
38const STANDARD_MATERIAL_FLAGS_EMISSIVE_TEXTURE_BIT: u32 = 2u;
39const STANDARD_MATERIAL_FLAGS_METALLIC_ROUGHNESS_TEXTURE_BIT: u32 = 4u;
40const STANDARD_MATERIAL_FLAGS_OCCLUSION_TEXTURE_BIT: u32 = 8u;
41const STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT: u32 = 16u;
42const STANDARD_MATERIAL_FLAGS_UNLIT_BIT: u32 = 32u;
43const STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP: u32 = 64u;
44const STANDARD_MATERIAL_FLAGS_FLIP_NORMAL_MAP_Y: u32 = 128u;
45const STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT: u32 = 256u;
46const STANDARD_MATERIAL_FLAGS_DEPTH_MAP_BIT: u32 = 512u;
47const STANDARD_MATERIAL_FLAGS_SPECULAR_TRANSMISSION_TEXTURE_BIT: u32 = 1024u;
48const STANDARD_MATERIAL_FLAGS_THICKNESS_TEXTURE_BIT: u32 = 2048u;
49const STANDARD_MATERIAL_FLAGS_DIFFUSE_TRANSMISSION_TEXTURE_BIT: u32 = 4096u;
50const STANDARD_MATERIAL_FLAGS_ATTENUATION_ENABLED_BIT: u32 = 8192u;
51const STANDARD_MATERIAL_FLAGS_CLEARCOAT_TEXTURE_BIT: u32 = 16384u;
52const STANDARD_MATERIAL_FLAGS_CLEARCOAT_ROUGHNESS_TEXTURE_BIT: u32 = 32768u;
53const STANDARD_MATERIAL_FLAGS_CLEARCOAT_NORMAL_TEXTURE_BIT: u32 = 65536u;
54const STANDARD_MATERIAL_FLAGS_ANISOTROPY_TEXTURE_BIT: u32 = 131072u;
55const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS: u32 = 3758096384u; // (0b111u32 << 29)
56const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE: u32 = 0u; // (0u32 << 29)
57const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MASK: u32 = 536870912u; // (1u32 << 29)
58const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND: u32 = 1073741824u; // (2u32 << 29)
59const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_PREMULTIPLIED: u32 = 1610612736u; // (3u32 << 29)
60const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD: u32 = 2147483648u; // (4u32 << 29)
61const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MULTIPLY: u32 = 2684354560u; // (5u32 << 29)
62const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ALPHA_TO_COVERAGE: u32 = 3221225472u; // (6u32 << 29)
63// ↑ To calculate/verify the values above, use the following playground:
64// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7792f8dd6fc6a8d4d0b6b1776898a7f4
67// Creates a StandardMaterial with default values
68fn standard_material_new() -> StandardMaterial {
69 var material: StandardMaterial;
71 // NOTE: Keep in-sync with src/pbr_material.rs!
72 material.base_color = vec4<f32>(1.0, 1.0, 1.0, 1.0);
73 material.emissive = vec4<f32>(0.0, 0.0, 0.0, 1.0);
74 material.perceptual_roughness = 0.5;
75 material.metallic = 0.00;
76 material.reflectance = 0.5;
77 material.diffuse_transmission = 0.0;
78 material.specular_transmission = 0.0;
79 material.thickness = 0.0;
80 material.ior = 1.5;
81 material.attenuation_distance = 1.0;
82 material.attenuation_color = vec4<f32>(1.0, 1.0, 1.0, 1.0);
83 material.clearcoat = 0.0;
84 material.clearcoat_perceptual_roughness = 0.0;
85 material.flags = STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE;
86 material.alpha_cutoff = 0.5;
87 material.parallax_depth_scale = 0.1;
88 material.max_parallax_layer_count = 16.0;
89 material.max_relief_mapping_search_steps = 5u;
90 material.deferred_lighting_pass_id = 1u;
91 // scale 1, translation 0, rotation 0
92 material.uv_transform = mat3x3<f32>(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
94 return material;
97struct PbrInput {
98 material: StandardMaterial,
99 // Note: this gets monochromized upon deferred PbrInput reconstruction.
100 diffuse_occlusion: vec3<f32>,
101 // Note: this is 1.0 (entirely unoccluded) when SSAO and SSR are off.
102 specular_occlusion: f32,
103 frag_coord: vec4<f32>,
104 world_position: vec4<f32>,
105 // Normalized world normal used for shadow mapping as normal-mapping is not used for shadow
106 // mapping
107 world_normal: vec3<f32>,
108 // Normalized normal-mapped world normal used for lighting
109 N: vec3<f32>,
110 // Normalized view vector in world space, pointing from the fragment world position toward the
111 // view world position
112 V: vec3<f32>,
113 lightmap_light: vec3<f32>,
114 clearcoat_N: vec3<f32>,
115 anisotropy_strength: f32,
116 // These two aren't specific to anisotropy, but we only fill them in if
117 // we're doing anisotropy, so they're prefixed with `anisotropy_`.
118 anisotropy_T: vec3<f32>,
119 anisotropy_B: vec3<f32>,
120 is_orthographic: bool,
121 flags: u32,
122};
124// Creates a PbrInput with default values
125fn pbr_input_new() -> PbrInput {
126 var pbr_input: PbrInput;
128 pbr_input.material = standard_material_new();
129 pbr_input.diffuse_occlusion = vec3<f32>(1.0);
130 // If SSAO is enabled, then this gets overwritten with proper specular occlusion. If its not, then we get specular environment map unoccluded (we have no data with which to occlude it with).
131 pbr_input.specular_occlusion = 1.0;
133 pbr_input.frag_coord = vec4<f32>(0.0, 0.0, 0.0, 1.0);
134 pbr_input.world_position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
135 pbr_input.world_normal = vec3<f32>(0.0, 0.0, 1.0);
137 pbr_input.is_orthographic = false;
139 pbr_input.N = vec3<f32>(0.0, 0.0, 1.0);
140 pbr_input.V = vec3<f32>(1.0, 0.0, 0.0);
142 pbr_input.clearcoat_N = vec3<f32>(0.0);
143 pbr_input.anisotropy_T = vec3<f32>(0.0);
144 pbr_input.anisotropy_B = vec3<f32>(0.0);
146 pbr_input.lightmap_light = vec3<f32>(0.0);
148 pbr_input.flags = 0u;
150 return pbr_input;
Contents