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 reflectance: vec3<f32>,
11 perceptual_roughness: f32,
12 metallic: 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_SPECULAR_TEXTURE_BIT: u32 = 262144u;
56const STANDARD_MATERIAL_FLAGS_SPECULAR_TINT_TEXTURE_BIT: u32 = 524288u;
57const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_RESERVED_BITS: u32 = 3758096384u; // (0b111u32 << 29)
58const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE: u32 = 0u; // (0u32 << 29)
59const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MASK: u32 = 536870912u; // (1u32 << 29)
60const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_BLEND: u32 = 1073741824u; // (2u32 << 29)
61const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_PREMULTIPLIED: u32 = 1610612736u; // (3u32 << 29)
62const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD: u32 = 2147483648u; // (4u32 << 29)
63const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_MULTIPLY: u32 = 2684354560u; // (5u32 << 29)
64const STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ALPHA_TO_COVERAGE: u32 = 3221225472u; // (6u32 << 29)
65// ↑ To calculate/verify the values above, use the following playground:
66// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7792f8dd6fc6a8d4d0b6b1776898a7f4
69// Creates a StandardMaterial with default values
70fn standard_material_new() -> StandardMaterial {
71 var material: StandardMaterial;
73 // NOTE: Keep in-sync with src/pbr_material.rs!
74 material.base_color = vec4<f32>(1.0, 1.0, 1.0, 1.0);
75 material.emissive = vec4<f32>(0.0, 0.0, 0.0, 1.0);
76 material.perceptual_roughness = 0.5;
77 material.metallic = 0.00;
78 material.reflectance = vec3<f32>(0.5);
79 material.diffuse_transmission = 0.0;
80 material.specular_transmission = 0.0;
81 material.thickness = 0.0;
82 material.ior = 1.5;
83 material.attenuation_distance = 1.0;
84 material.attenuation_color = vec4<f32>(1.0, 1.0, 1.0, 1.0);
85 material.clearcoat = 0.0;
86 material.clearcoat_perceptual_roughness = 0.0;
87 material.flags = STANDARD_MATERIAL_FLAGS_ALPHA_MODE_OPAQUE;
88 material.alpha_cutoff = 0.5;
89 material.parallax_depth_scale = 0.1;
90 material.max_parallax_layer_count = 16.0;
91 material.max_relief_mapping_search_steps = 5u;
92 material.deferred_lighting_pass_id = 1u;
93 // scale 1, translation 0, rotation 0
94 material.uv_transform = mat3x3<f32>(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
96 return material;
99struct PbrInput {
100 material: StandardMaterial,
101 // Note: this gets monochromized upon deferred PbrInput reconstruction.
102 diffuse_occlusion: vec3<f32>,
103 // Note: this is 1.0 (entirely unoccluded) when SSAO and SSR are off.
104 specular_occlusion: f32,
105 frag_coord: vec4<f32>,
106 world_position: vec4<f32>,
107 // Normalized world normal used for shadow mapping as normal-mapping is not used for shadow
108 // mapping
109 world_normal: vec3<f32>,
110 // Normalized normal-mapped world normal used for lighting
111 N: vec3<f32>,
112 // Normalized view vector in world space, pointing from the fragment world position toward the
113 // view world position
114 V: vec3<f32>,
115 lightmap_light: vec3<f32>,
116 clearcoat_N: vec3<f32>,
117 anisotropy_strength: f32,
118 // These two aren't specific to anisotropy, but we only fill them in if
119 // we're doing anisotropy, so they're prefixed with `anisotropy_`.
120 anisotropy_T: vec3<f32>,
121 anisotropy_B: vec3<f32>,
122 is_orthographic: bool,
123 flags: u32,
124};
126// Creates a PbrInput with default values
127fn pbr_input_new() -> PbrInput {
128 var pbr_input: PbrInput;
130 pbr_input.material = standard_material_new();
131 pbr_input.diffuse_occlusion = vec3<f32>(1.0);
132 // 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).
133 pbr_input.specular_occlusion = 1.0;
135 pbr_input.frag_coord = vec4<f32>(0.0, 0.0, 0.0, 1.0);
136 pbr_input.world_position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
137 pbr_input.world_normal = vec3<f32>(0.0, 0.0, 1.0);
139 pbr_input.is_orthographic = false;
141 pbr_input.N = vec3<f32>(0.0, 0.0, 1.0);
142 pbr_input.V = vec3<f32>(1.0, 0.0, 0.0);
144 pbr_input.clearcoat_N = vec3<f32>(0.0);
145 pbr_input.anisotropy_T = vec3<f32>(0.0);
146 pbr_input.anisotropy_B = vec3<f32>(0.0);
148 pbr_input.lightmap_light = vec3<f32>(0.0);
150 pbr_input.flags = 0u;
152 return pbr_input;
Contents