@woosh/meep-engine 3.75.0 → 3.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/engine/asset/GameAssetType.d.ts +1 -0
- package/src/engine/asset/GameAssetType.js +5 -1
- package/src/engine/asset/loaders/GroomAssetLoader.d.ts +33 -0
- package/src/engine/asset/loaders/GroomAssetLoader.d.ts.map +1 -0
- package/src/engine/asset/loaders/GroomAssetLoader.js +99 -0
- package/src/engine/graphics/ecs/hair/Hair.d.ts +47 -0
- package/src/engine/graphics/ecs/hair/Hair.d.ts.map +1 -0
- package/src/engine/graphics/ecs/hair/Hair.js +61 -0
- package/src/engine/graphics/hair/Groom.d.ts +130 -0
- package/src/engine/graphics/hair/Groom.d.ts.map +1 -0
- package/src/engine/graphics/hair/Groom.js +193 -0
- package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts +24 -0
- package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts.map +1 -0
- package/src/engine/graphics/hair/GroomSerializationAdapter.js +77 -0
- package/src/engine/graphics/hair/groom_build_group.d.ts +85 -0
- package/src/engine/graphics/hair/groom_build_group.d.ts.map +1 -0
- package/src/engine/graphics/hair/groom_build_group.js +487 -0
- package/src/engine/graphics/hair/groom_generate_scalp.d.ts +29 -0
- package/src/engine/graphics/hair/groom_generate_scalp.d.ts.map +1 -0
- package/src/engine/graphics/hair/groom_generate_scalp.js +184 -0
- package/src/engine/graphics/hair/groom_rank_order.d.ts +15 -0
- package/src/engine/graphics/hair/groom_rank_order.d.ts.map +1 -0
- package/src/engine/graphics/hair/groom_rank_order.js +53 -0
- package/src/engine/graphics/hair/groom_root_spacing.d.ts +12 -0
- package/src/engine/graphics/hair/groom_root_spacing.d.ts.map +1 -0
- package/src/engine/graphics/hair/groom_root_spacing.js +120 -0
- package/src/engine/graphics3/HairSystem.d.ts +102 -0
- package/src/engine/graphics3/HairSystem.d.ts.map +1 -0
- package/src/engine/graphics3/HairSystem.js +456 -0
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- package/src/shade/assets/textures/hair_scattering.bin +0 -0
- package/src/shade/device/pipeline/PipelineEnquiry.d.ts +11 -0
- package/src/shade/device/pipeline/PipelineEnquiry.d.ts.map +1 -1
- package/src/shade/device/pipeline/PipelineEnquiry.js +13 -0
- package/src/shade/playground/hair/index.html +50 -0
- package/src/shade/playground/hair/main.d.ts +2 -0
- package/src/shade/playground/hair/main.d.ts.map +1 -0
- package/src/shade/playground/hair/main.js +274 -0
- package/src/shade/playground/screen_probes/README.md +54 -0
- package/src/shade/playground/screen_probes/index.html +271 -0
- package/src/shade/playground/screen_probes/main.d.ts +8 -0
- package/src/shade/playground/screen_probes/main.d.ts.map +1 -0
- package/src/shade/playground/screen_probes/main.js +527 -0
- package/src/shade/renderer/Renderer.d.ts.map +1 -1
- package/src/shade/renderer/Renderer.js +54 -8
- package/src/shade/renderer/STATIC_GRAPHICS_ENGINE_ASSETS.d.ts +6 -0
- package/src/shade/renderer/STATIC_GRAPHICS_ENGINE_ASSETS.d.ts.map +1 -1
- package/src/shade/renderer/STATIC_GRAPHICS_ENGINE_ASSETS.js +10 -0
- package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
- package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
- package/src/shade/renderer/deferred/chunk_read_gBuffer_material.d.ts.map +1 -1
- package/src/shade/renderer/deferred/chunk_read_gBuffer_material.js +3 -1
- package/src/shade/renderer/deferred/chunk_shade_direct_lights.d.ts +23 -0
- package/src/shade/renderer/deferred/chunk_shade_direct_lights.d.ts.map +1 -0
- package/src/shade/renderer/deferred/chunk_shade_direct_lights.js +111 -0
- package/src/shade/renderer/deferred/chunk_shade_directional_lights.d.ts +17 -6
- package/src/shade/renderer/deferred/chunk_shade_directional_lights.d.ts.map +1 -1
- package/src/shade/renderer/deferred/chunk_shade_directional_lights.js +26 -21
- package/src/shade/renderer/deferred/chunk_shade_standard_material_direct.d.ts +12 -22
- package/src/shade/renderer/deferred/chunk_shade_standard_material_direct.d.ts.map +1 -1
- package/src/shade/renderer/deferred/chunk_shade_standard_material_direct.js +20 -100
- package/src/shade/renderer/deferred/chunk_shade_standard_material_direct_restir.d.ts.map +1 -1
- package/src/shade/renderer/deferred/chunk_shade_standard_material_direct_restir.js +6 -4
- package/src/shade/renderer/deferred/chunk_standard_material_direct_light_lobe.d.ts +15 -0
- package/src/shade/renderer/deferred/chunk_standard_material_direct_light_lobe.d.ts.map +1 -0
- package/src/shade/renderer/deferred/chunk_standard_material_direct_light_lobe.js +47 -0
- package/src/shade/renderer/extension/ViewLighting.d.ts +101 -0
- package/src/shade/renderer/extension/ViewLighting.d.ts.map +1 -0
- package/src/shade/renderer/extension/ViewLighting.js +168 -0
- package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
- package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
- package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -7
- package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
- package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
- package/src/shade/renderer/global_illumination/brick4/gpu/draw/shader_brick4_indirect_lighting.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/brick4/gpu/draw/shader_brick4_indirect_lighting.js +3 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_indirect_lighting.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_indirect_lighting.js +3 -1
- package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.d.ts +15 -7
- package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.js +40 -9
- package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.d.ts +23 -0
- package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.js +26 -0
- package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeDebugView.d.ts +1 -0
- package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeDebugView.js +6 -0
- package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.d.ts +13 -1
- package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.js +23 -1
- package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.js +2 -0
- package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.d.ts +29 -0
- package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.d.ts.map +1 -0
- package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.js +102 -0
- package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.d.ts +8 -1
- package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.js +27 -1
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.d.ts +4 -1
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.js +4 -1
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.d.ts +11 -5
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.js +28 -10
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.d.ts +36 -2
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.js +149 -4
- package/src/shade/renderer/global_illumination/shader_resolve_indirect_lighting.d.ts.map +1 -1
- package/src/shade/renderer/global_illumination/shader_resolve_indirect_lighting.js +3 -1
- package/src/shade/renderer/hair/GPUHairSystem.d.ts +159 -0
- package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -0
- package/src/shade/renderer/hair/GPUHairSystem.js +1132 -0
- package/src/shade/renderer/hair/HAIR.d.ts +102 -0
- package/src/shade/renderer/hair/HAIR.d.ts.map +1 -0
- package/src/shade/renderer/hair/HAIR.js +115 -0
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts +17 -0
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts.map +1 -0
- package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.js +71 -0
- package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.d.ts +11 -0
- package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.d.ts.map +1 -0
- package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.js +48 -0
- package/src/shade/renderer/hair/HairFrame.d.ts +41 -0
- package/src/shade/renderer/hair/HairFrame.d.ts.map +1 -0
- package/src/shade/renderer/hair/HairFrame.js +76 -0
- package/src/shade/renderer/hair/chunk_hair_bsdf.d.ts +42 -0
- package/src/shade/renderer/hair/chunk_hair_bsdf.d.ts.map +1 -0
- package/src/shade/renderer/hair/chunk_hair_bsdf.js +170 -0
- package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts +30 -0
- package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts.map +1 -0
- package/src/shade/renderer/hair/chunk_hair_dual_scattering.js +131 -0
- package/src/shade/renderer/hair/chunk_hair_pixel.d.ts +32 -0
- package/src/shade/renderer/hair/chunk_hair_pixel.d.ts.map +1 -0
- package/src/shade/renderer/hair/chunk_hair_pixel.js +116 -0
- package/src/shade/renderer/hair/chunk_hair_strand.d.ts +40 -0
- package/src/shade/renderer/hair/chunk_hair_strand.d.ts.map +1 -0
- package/src/shade/renderer/hair/chunk_hair_strand.js +85 -0
- package/src/shade/renderer/hair/chunk_hair_volume.d.ts +31 -0
- package/src/shade/renderer/hair/chunk_hair_volume.d.ts.map +1 -0
- package/src/shade/renderer/hair/chunk_hair_volume.js +106 -0
- package/src/shade/renderer/hair/hair_id_draw.d.ts +24 -0
- package/src/shade/renderer/hair/hair_id_draw.d.ts.map +1 -0
- package/src/shade/renderer/hair/hair_id_draw.js +135 -0
- package/src/shade/renderer/hair/hair_lighting.d.ts +53 -0
- package/src/shade/renderer/hair/hair_lighting.d.ts.map +1 -0
- package/src/shade/renderer/hair/hair_lighting.js +270 -0
- package/src/shade/renderer/hair/hair_scattering_lut.d.ts +75 -0
- package/src/shade/renderer/hair/hair_scattering_lut.d.ts.map +1 -0
- package/src/shade/renderer/hair/hair_scattering_lut.js +271 -0
- package/src/shade/renderer/hair/hair_stamp.d.ts +33 -0
- package/src/shade/renderer/hair/hair_stamp.d.ts.map +1 -0
- package/src/shade/renderer/hair/hair_stamp.js +175 -0
- package/src/shade/renderer/hair/shader_hair_classes.d.ts +21 -0
- package/src/shade/renderer/hair/shader_hair_classes.d.ts.map +1 -0
- package/src/shade/renderer/hair/shader_hair_classes.js +86 -0
- package/src/shade/renderer/hair/shader_hair_cull.d.ts +31 -0
- package/src/shade/renderer/hair/shader_hair_cull.d.ts.map +1 -0
- package/src/shade/renderer/hair/shader_hair_cull.js +194 -0
- package/src/shade/renderer/hair/shader_hair_lod.d.ts +33 -0
- package/src/shade/renderer/hair/shader_hair_lod.d.ts.map +1 -0
- package/src/shade/renderer/hair/shader_hair_lod.js +268 -0
- package/src/shade/renderer/hair/shader_hair_volume.d.ts +28 -0
- package/src/shade/renderer/hair/shader_hair_volume.d.ts.map +1 -0
- package/src/shade/renderer/hair/shader_hair_volume.js +167 -0
- package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
- package/src/shade/renderer/loader/usd/usd_build_scene.d.ts +31 -0
- package/src/shade/renderer/loader/usd/usd_build_scene.d.ts.map +1 -1
- package/src/shade/renderer/loader/usd/usd_build_scene.js +36 -21
- package/src/shade/renderer/loader/usd/usd_groom_extension.d.ts +60 -0
- package/src/shade/renderer/loader/usd/usd_groom_extension.d.ts.map +1 -0
- package/src/shade/renderer/loader/usd/usd_groom_extension.js +417 -0
- package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.d.ts.map +1 -1
- package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.js +4 -1
- package/src/shade/renderer/path_tracer/shader/chunk_shading_closure_from_material_data.d.ts.map +1 -1
- package/src/shade/renderer/path_tracer/shader/chunk_shading_closure_from_material_data.js +3 -1
- package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
- package/src/shade/renderer/postprocess/ssr/SSR.d.ts +4 -1
- package/src/shade/renderer/postprocess/ssr/SSR.d.ts.map +1 -1
- package/src/shade/renderer/postprocess/ssr/SSR.js +9 -0
- package/src/shade/renderer/postprocess/ssr/resolve/chunk_ssr_sample_radiance.d.ts +16 -1
- package/src/shade/renderer/postprocess/ssr/resolve/chunk_ssr_sample_radiance.d.ts.map +1 -1
- package/src/shade/renderer/postprocess/ssr/resolve/chunk_ssr_sample_radiance.js +47 -3
- package/src/shade/renderer/postprocess/ssr/resolve/ssr_resolve_shader.d.ts.map +1 -1
- package/src/shade/renderer/postprocess/ssr/resolve/ssr_resolve_shader.js +5 -3
- package/src/shade/renderer/postprocess/ssr/ssr_combine_shader.d.ts.map +1 -1
- package/src/shade/renderer/postprocess/ssr/ssr_combine_shader.js +6 -5
- package/src/shade/renderer/rasterize/forward/chunk_forward_shade_standard_fragment.d.ts.map +1 -1
- package/src/shade/renderer/rasterize/forward/chunk_forward_shade_standard_fragment.js +5 -2
- package/src/shade/renderer/rasterize/native/avboit/avboit_draw_fragment_body.d.ts.map +1 -1
- package/src/shade/renderer/rasterize/native/avboit/avboit_draw_fragment_body.js +5 -0
- package/src/shade/renderer/rasterize/native/avboit/shader_avboit_splat.d.ts.map +1 -1
- package/src/shade/renderer/rasterize/native/avboit/shader_avboit_splat.js +4 -1
- package/src/shade/renderer/rasterize/native/oit/oit_resolve_fragment_body.d.ts.map +1 -1
- package/src/shade/renderer/rasterize/native/oit/oit_resolve_fragment_body.js +5 -1
- package/src/shade/renderer/rasterize/native/oit/shader_oit_generate_moments.d.ts.map +1 -1
- package/src/shade/renderer/rasterize/native/oit/shader_oit_generate_moments.js +7 -4
- package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.d.ts +13 -8
- package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.d.ts.map +1 -1
- package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.js +18 -14
- package/src/shade/renderer/shader/chunk/light/chunk_compute_multiscattering_specular.d.ts +3 -2
- package/src/shade/renderer/shader/chunk/light/chunk_compute_multiscattering_specular.d.ts.map +1 -1
- package/src/shade/renderer/shader/chunk/light/chunk_compute_multiscattering_specular.js +12 -4
- package/src/shade/renderer/shader/chunk/material/MATERIAL_SHADING_INFO_STRUCT.d.ts.map +1 -1
- package/src/shade/renderer/shader/chunk/material/MATERIAL_SHADING_INFO_STRUCT.js +1 -0
- package/src/shade/renderer/shader/chunk/material/chunk_compute_indirect_specular.js +1 -1
- package/src/shade/renderer/shader/chunk/material/chunk_metalness_to_specular_F90.d.ts +16 -0
- package/src/shade/renderer/shader/chunk/material/chunk_metalness_to_specular_F90.d.ts.map +1 -0
- package/src/shade/renderer/shader/chunk/material/chunk_metalness_to_specular_F90.js +25 -0
- package/src/shade/renderer/shader/chunk/material/chunk_re_direct_multiscatter.js +2 -2
- package/src/shade/renderer/shader/compiler/ShaderSwitch.d.ts +1 -1
- package/src/shade/renderer/shader/compiler/ShaderSwitchSet.d.ts +1 -1
- package/src/shade/renderer/shader/resource/ShaderResourceDescriptor.d.ts +1 -1
- package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_sample_point2.d.ts +2 -2
- package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_sample_point2.js +2 -2
- package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hair_scattering_lut.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/hair_scattering_lut.js"],"names":[],"mappings":"AAkCA;;;;;GAKG;AACH,gDAHW,MAAM,GACJ,MAAM,CAMlB;AAiCD;;;;;;;;;;;;GAYG;AACH,gCARW,MAAM,KACN,MAAM,WACN,MAAM,OACN,MAAM,cACN,MAAM,aACN,MAAM,OACN,YAAY,QA8CtB;AAED;;;;;;;;;GASG;AACH,qCAPW,MAAM,WACN,MAAM,OACN,MAAM,cACN,MAAM,aACN,MAAM,GACJ,MAAM,CAclB;AAOD;;;;;;;;GAQG;AACH,6CANW,MAAM,aACN,MAAM,SACN,MAAM,cACN,MAAM,GACJ,MAAM,EAAE,CA+DpB;AAED;;;;;;GAMG;AACH;IAH4B,SAAS,GAA1B,MAAM;IACJ,YAAY,CA4BxB;AA9QD;;;;;;;;;GASG;AAEH;;GAEG;AACH,wCAFU,MAAM,CAE4B;AAE5C;;GAEG;AACH,4CAFU,MAAM,CAEgC;AAEhD;;GAEG;AACH,wCAFU,MAAM,CAE4B"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hair's average scattering table, which dual scattering reads (Zinke et al. 2008, as Unreal 5.4 tabulates it in
|
|
3
|
+
* HairStrandsLUT.usf): for a fibre seen at `sin θ_v = |V·T|`, of longitudinal roughness `r` and colour `C`, the
|
|
4
|
+
* single-scattering BSDF integrated over the hemisphere of directions in front of the view (`A_front`, what passes
|
|
5
|
+
* through) and behind it (`A_back`, what comes back), no cosine, each clamped to [0, 1].
|
|
6
|
+
*
|
|
7
|
+
* Laid out as Unreal's: x is `sin θ_v`, y is `r`, z is `sqrt(C)`, each at texel centres; two channels, front then back.
|
|
8
|
+
* The BSDF is `chunk_hair_shading` at area 0 and backlit 1, here as a lobe-wise twin that `hair_scattering_lut.spec.js`
|
|
9
|
+
* holds to the shader.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @type {number}
|
|
14
|
+
*/
|
|
15
|
+
export const HAIR_SCATTERING_LUT_THETA = 32;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @type {number}
|
|
19
|
+
*/
|
|
20
|
+
export const HAIR_SCATTERING_LUT_ROUGHNESS = 32;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @type {number}
|
|
24
|
+
*/
|
|
25
|
+
export const HAIR_SCATTERING_LUT_COLOR = 16;
|
|
26
|
+
|
|
27
|
+
const B = 0.3;
|
|
28
|
+
const D = 5.969 - 0.215 * B + 2.532 * B ** 2 - 10.73 * B ** 3 + 5.574 * B ** 4 + 0.245 * B ** 5;
|
|
29
|
+
|
|
30
|
+
const SHIFT = 0.035;
|
|
31
|
+
const ALPHA_R = -SHIFT * 2;
|
|
32
|
+
const ALPHA_TT = SHIFT;
|
|
33
|
+
const ALPHA_TRT = SHIFT * 4;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The absorption whose colour after multiple scattering is `color` (`hair_color_to_absorption`).
|
|
37
|
+
*
|
|
38
|
+
* @param {number} color
|
|
39
|
+
* @returns {number}
|
|
40
|
+
*/
|
|
41
|
+
export function hair_color_to_absorption(color) {
|
|
42
|
+
const l = Math.log(Math.max(color, 1e-4)) / D;
|
|
43
|
+
|
|
44
|
+
return l * l;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {number} absorption
|
|
49
|
+
* @returns {number}
|
|
50
|
+
*/
|
|
51
|
+
function hair_absorption_to_color(absorption) {
|
|
52
|
+
return Math.exp(-Math.sqrt(absorption) * D);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {number} cos_theta
|
|
57
|
+
* @returns {number}
|
|
58
|
+
*/
|
|
59
|
+
function fresnel(cos_theta) {
|
|
60
|
+
const F0 = 0.04652;
|
|
61
|
+
const x = 1 - cos_theta;
|
|
62
|
+
const x2 = x * x;
|
|
63
|
+
|
|
64
|
+
return F0 + (1 - F0) * x2 * x2 * x;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {number} b
|
|
69
|
+
* @param {number} theta
|
|
70
|
+
* @returns {number}
|
|
71
|
+
*/
|
|
72
|
+
function gaussian(b, theta) {
|
|
73
|
+
const w = Math.max(b, 1e-5);
|
|
74
|
+
|
|
75
|
+
return Math.exp(-0.5 * theta * theta / (w * w)) / (2.5066283 * w);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One lobe of `hair_shading`, apart: the width and the centre in `sin θ_l` of its longitudinal Gaussian, and the rest
|
|
80
|
+
* of it at `sin θ_l = u`, for the fibre's tangent along +z (towards the root), the view at `sin θ_v = u_v` in the
|
|
81
|
+
* x-z plane and the light at azimuth `cos φ` from it.
|
|
82
|
+
*
|
|
83
|
+
* @param {number} lobe 0 R, 1 TT, 2 TRT
|
|
84
|
+
* @param {number} u sin θ_l
|
|
85
|
+
* @param {number} cos_phi
|
|
86
|
+
* @param {number} u_v sin θ_v
|
|
87
|
+
* @param {number} absorption
|
|
88
|
+
* @param {number} roughness
|
|
89
|
+
* @param {Float64Array} out width, centre, value
|
|
90
|
+
*/
|
|
91
|
+
export function hair_lobe(lobe, u, cos_phi, u_v, absorption, roughness, out) {
|
|
92
|
+
const r = Math.min(Math.max(roughness, 1 / 255), 1);
|
|
93
|
+
const r2 = r * r;
|
|
94
|
+
|
|
95
|
+
const sin_l = Math.min(Math.max(u, -1), 1);
|
|
96
|
+
const sin_v = Math.min(Math.max(u_v, -1), 1);
|
|
97
|
+
|
|
98
|
+
const cos_d = Math.max(Math.cos(0.5 * Math.abs(Math.asin(sin_v) - Math.asin(sin_l))), 1e-4);
|
|
99
|
+
|
|
100
|
+
// the shader normalizes the projections with 1e-4 under the root, which matters near the poles
|
|
101
|
+
const projected = (1 - sin_l * sin_l) * (1 - sin_v * sin_v);
|
|
102
|
+
cos_phi = cos_phi * Math.sqrt(projected / (projected + 1e-4));
|
|
103
|
+
|
|
104
|
+
const cos_half_phi = Math.sqrt(Math.min(Math.max(0.5 + 0.5 * cos_phi, 0), 1));
|
|
105
|
+
const n_prime = 1.19 / cos_d + 0.36 * cos_d;
|
|
106
|
+
|
|
107
|
+
if (lobe === 0) {
|
|
108
|
+
const sa = Math.sin(ALPHA_R);
|
|
109
|
+
const ca = Math.cos(ALPHA_R);
|
|
110
|
+
const shift = 2 * sa * (ca * cos_half_phi * Math.sqrt(1 - sin_v * sin_v) + sa * sin_v);
|
|
111
|
+
|
|
112
|
+
// V·L, with the view at azimuth 0
|
|
113
|
+
const cos_l = Math.sqrt(1 - sin_l * sin_l);
|
|
114
|
+
const cos_v = Math.sqrt(1 - sin_v * sin_v);
|
|
115
|
+
const vol = cos_v * cos_l * cos_phi + sin_v * sin_l;
|
|
116
|
+
|
|
117
|
+
out[0] = r2 * 1.4142135 * cos_half_phi;
|
|
118
|
+
out[1] = shift - sin_v;
|
|
119
|
+
out[2] = 0.25 * cos_half_phi * fresnel(Math.sqrt(Math.min(Math.max(0.5 + 0.5 * vol, 0), 1)));
|
|
120
|
+
} else if (lobe === 1) {
|
|
121
|
+
const a = 1 / n_prime;
|
|
122
|
+
const h = cos_half_phi * (1 + a * (0.6 - 0.8 * cos_phi));
|
|
123
|
+
const f = fresnel(cos_d * Math.sqrt(Math.min(Math.max(1 - h * h, 0), 1)));
|
|
124
|
+
|
|
125
|
+
out[0] = r2 * 0.5;
|
|
126
|
+
out[1] = ALPHA_TT - sin_v;
|
|
127
|
+
out[2] = Math.exp(-3.65 * cos_phi - 3.98) * (1 - f) * (1 - f) * Math.exp(-absorption * 2 * Math.abs(1 - (h * a) * (h * a) / cos_d));
|
|
128
|
+
} else {
|
|
129
|
+
const f = fresnel(cos_d * 0.5);
|
|
130
|
+
|
|
131
|
+
out[0] = r2 * 2;
|
|
132
|
+
out[1] = ALPHA_TRT - sin_v;
|
|
133
|
+
out[2] = Math.exp(17 * cos_phi - 16.78) * (1 - f) * (1 - f) * f * Math.pow(hair_absorption_to_color(absorption), 0.8 / cos_d);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* `hair_shading` at area 0 and backlit 1, summed from {@link hair_lobe}: the twin the spec compares with the shader.
|
|
139
|
+
*
|
|
140
|
+
* @param {number} u sin θ_l
|
|
141
|
+
* @param {number} cos_phi
|
|
142
|
+
* @param {number} u_v
|
|
143
|
+
* @param {number} absorption
|
|
144
|
+
* @param {number} roughness
|
|
145
|
+
* @returns {number}
|
|
146
|
+
*/
|
|
147
|
+
export function hair_shading_twin(u, cos_phi, u_v, absorption, roughness) {
|
|
148
|
+
const lobe = new Float64Array(3);
|
|
149
|
+
|
|
150
|
+
let sum = 0;
|
|
151
|
+
|
|
152
|
+
for (let p = 0; p < 3; p++) {
|
|
153
|
+
hair_lobe(p, u, cos_phi, u_v, absorption, roughness, lobe);
|
|
154
|
+
|
|
155
|
+
sum += gaussian(lobe[0], u + u_v - (lobe[1] + u_v)) * lobe[2];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return Math.max(sum, 0);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Gauss-Hermite, 16 nodes: the positive half of the nodes and their weights over sqrt(pi)
|
|
162
|
+
const GH_X = [0.27348104613815, 0.82295144914466, 1.38025853919888, 1.95178799091625, 2.54620215784748, 3.17699916197996, 3.86944790486012, 4.68873893930582];
|
|
163
|
+
const GH_W = [0.50792947901661, 0.28064745852853, 0.08381004139899, 0.01288031153551, 0.00093228400862, 0.00002711860093, 0.00000023209808, 0.00000000026548];
|
|
164
|
+
const SQRT_PI = Math.sqrt(Math.PI);
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The average front and back scattering of one table entry.
|
|
168
|
+
*
|
|
169
|
+
* @param {number} u_v sin θ_v
|
|
170
|
+
* @param {number} roughness
|
|
171
|
+
* @param {number} color
|
|
172
|
+
* @param {number} [phi_steps] over the whole turn
|
|
173
|
+
* @returns {number[]} [A_front, A_back]
|
|
174
|
+
*/
|
|
175
|
+
export function hair_average_scattering(u_v, roughness, color, phi_steps = 128) {
|
|
176
|
+
const absorption = hair_color_to_absorption(color);
|
|
177
|
+
const lobe = new Float64Array(3);
|
|
178
|
+
|
|
179
|
+
let front = 0;
|
|
180
|
+
let back = 0;
|
|
181
|
+
|
|
182
|
+
const d_phi = 2 * Math.PI / phi_steps;
|
|
183
|
+
|
|
184
|
+
for (let k = 0; k < phi_steps; k++) {
|
|
185
|
+
const phi = (k + 0.5) * d_phi;
|
|
186
|
+
const cos_phi = Math.cos(phi);
|
|
187
|
+
|
|
188
|
+
let sum = 0;
|
|
189
|
+
|
|
190
|
+
for (let p = 0; p < 3; p++) {
|
|
191
|
+
// the Gaussian's width and centre do not depend on u
|
|
192
|
+
hair_lobe(p, 0, cos_phi, u_v, absorption, roughness, lobe);
|
|
193
|
+
|
|
194
|
+
const beta = Math.max(lobe[0], 1e-5);
|
|
195
|
+
const centre = lobe[1];
|
|
196
|
+
|
|
197
|
+
if (beta < 0.06) {
|
|
198
|
+
// narrow: Gauss-Hermite about the centre, nodes outside [-1, 1] dropped
|
|
199
|
+
for (let i = 0; i < 8; i++) {
|
|
200
|
+
for (const sign of [-1, 1]) {
|
|
201
|
+
const u = centre + sign * Math.SQRT2 * beta * GH_X[i];
|
|
202
|
+
|
|
203
|
+
if (u < -1 || u > 1) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
hair_lobe(p, u, cos_phi, u_v, absorption, roughness, lobe);
|
|
208
|
+
|
|
209
|
+
sum += GH_W[i] / SQRT_PI * lobe[2];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
// wide: the midpoint rule over [-1, 1], 32 steps a width at least
|
|
214
|
+
const steps = Math.min(1024, Math.max(64, Math.ceil(64 / beta)));
|
|
215
|
+
const du = 2 / steps;
|
|
216
|
+
|
|
217
|
+
for (let i = 0; i < steps; i++) {
|
|
218
|
+
const u = -1 + (i + 0.5) * du;
|
|
219
|
+
|
|
220
|
+
hair_lobe(p, u, cos_phi, u_v, absorption, roughness, lobe);
|
|
221
|
+
|
|
222
|
+
sum += gaussian(beta, u - centre) * lobe[2] * du;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// the view is at azimuth 0: the front hemisphere is behind the fibre from it
|
|
228
|
+
if (cos_phi < 0) {
|
|
229
|
+
front += sum * d_phi;
|
|
230
|
+
} else {
|
|
231
|
+
back += sum * d_phi;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return [Math.min(Math.max(front, 0), 1), Math.min(Math.max(back, 0), 1)];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* The whole table, front and back interleaved, x fastest, then y, then z.
|
|
240
|
+
*
|
|
241
|
+
* @param {Object} [options]
|
|
242
|
+
* @param {number} [options.phi_steps]
|
|
243
|
+
* @returns {Float32Array}
|
|
244
|
+
*/
|
|
245
|
+
export function hair_scattering_lut_generate({ phi_steps = 128 } = {}) {
|
|
246
|
+
const nx = HAIR_SCATTERING_LUT_THETA;
|
|
247
|
+
const ny = HAIR_SCATTERING_LUT_ROUGHNESS;
|
|
248
|
+
const nz = HAIR_SCATTERING_LUT_COLOR;
|
|
249
|
+
|
|
250
|
+
const out = new Float32Array(nx * ny * nz * 2);
|
|
251
|
+
|
|
252
|
+
for (let z = 0; z < nz; z++) {
|
|
253
|
+
const s = (z + 0.5) / nz;
|
|
254
|
+
const color = s * s;
|
|
255
|
+
|
|
256
|
+
for (let y = 0; y < ny; y++) {
|
|
257
|
+
const roughness = (y + 0.5) / ny;
|
|
258
|
+
|
|
259
|
+
for (let x = 0; x < nx; x++) {
|
|
260
|
+
const u_v = (x + 0.5) / nx;
|
|
261
|
+
const [front, back] = hair_average_scattering(u_v, roughness, color, phi_steps);
|
|
262
|
+
const at = ((z * ny + y) * nx + x) * 2;
|
|
263
|
+
|
|
264
|
+
out[at] = front;
|
|
265
|
+
out[at + 1] = back;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return out;
|
|
271
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bindings of {@link HAIR_STAMP_PIPELINE} and {@link HAIR_MOTION_PIPELINE}, one layout for both: `camera`,
|
|
3
|
+
* `hair_view`, `hair_lod`, `hair_points`, `hair_ids` (the hair id target), `scene_depth` (the depth the strands
|
|
4
|
+
* were drawn into) and the two matrices of `view_velocity_matrices`.
|
|
5
|
+
*
|
|
6
|
+
* @type {ShaderResourceSetDescriptor}
|
|
7
|
+
*/
|
|
8
|
+
export const HAIR_STAMP_RESOURCES: ShaderResourceSetDescriptor;
|
|
9
|
+
/**
|
|
10
|
+
* Writes a black metal into the G-buffer under every pixel a strand covers, an instance a row of the instance table,
|
|
11
|
+
* each over its screen rectangle (4 vertices, a triangle strip): metalness one, albedo zero, roughness one, nothing
|
|
12
|
+
* occluded, no emission, both normals the strand's normal towards the eye, and `VISIBILITY_NONE`. A metal with no
|
|
13
|
+
* colour reflects nothing at any angle (`metalness_to_specular_F90`), direct or indirect, so the deferred passes
|
|
14
|
+
* leave the pixel unlit for the hair lighting pass. The normals are for what reads the G-buffer's geometry: ambient
|
|
15
|
+
* occlusion, the screen probes, reflections.
|
|
16
|
+
*
|
|
17
|
+
* Five targets, loaded: the four G-buffer targets in `G_BUFFER_COLOR_TARGETS`' order, then the visibility buffer.
|
|
18
|
+
*
|
|
19
|
+
* @type {RenderPipelineDescriptor}
|
|
20
|
+
*/
|
|
21
|
+
export const HAIR_STAMP_PIPELINE: RenderPipelineDescriptor;
|
|
22
|
+
/**
|
|
23
|
+
* The velocity under every pixel a strand covers, over each instance's screen rectangle as
|
|
24
|
+
* {@link HAIR_STAMP_PIPELINE}: the pixel's point moved as the strand's point under it did, between its place a frame
|
|
25
|
+
* ago and now (`chunk_velocity_texel`). Its own pass: with the stamp's targets it would pass the device floor's
|
|
26
|
+
* attachment bytes.
|
|
27
|
+
*
|
|
28
|
+
* @type {RenderPipelineDescriptor}
|
|
29
|
+
*/
|
|
30
|
+
export const HAIR_MOTION_PIPELINE: RenderPipelineDescriptor;
|
|
31
|
+
import { ShaderResourceSetDescriptor } from "../shader/resource/ShaderResourceSetDescriptor.js";
|
|
32
|
+
import { RenderPipelineDescriptor } from "../../descriptor/pipeline/render/RenderPipelineDescriptor.js";
|
|
33
|
+
//# sourceMappingURL=hair_stamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hair_stamp.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/hair_stamp.js"],"names":[],"mappings":"AAsHA;;;;;;GAMG;AACH,mCAFU,2BAA2B,CAES;AAI9C;;;;;;;;;;;GAWG;AACH,kCAFU,wBAAwB,CAe/B;AAEH;;;;;;;GAOG;AACH,mCAFU,wBAAwB,CAY/B;4CAnKyC,mDAAmD;yCAVtD,8DAA8D"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { ColorTargetState } from "../../descriptor/pipeline/render/ColorTargetState.js";
|
|
2
|
+
import { RenderPipelineDescriptor } from "../../descriptor/pipeline/render/RenderPipelineDescriptor.js";
|
|
3
|
+
import { CAMERA_RESOURCE } from "../camera/CAMERA_RESOURCE.js";
|
|
4
|
+
import { G_BUFFER_COLOR_TARGETS } from "../gbuffer/G_BUFFER_COLOR_TARGETS.js";
|
|
5
|
+
import { chunk_velocity_texel } from "../postprocess/velocity/chunk_velocity_texel.js";
|
|
6
|
+
import { VELOCITY_FORMAT } from "../postprocess/velocity/VELOCITY_BUFFER.js";
|
|
7
|
+
import { VISIBILITY_FORMAT, VISIBILITY_NONE } from "../rasterize/visibility/VISIBILITY_BUFFER.js";
|
|
8
|
+
import { chunk_rgbe9995_encode } from "../shader/chunk/color/rgbe9995/chunk_rgbe9995_encode.js";
|
|
9
|
+
import { chunk_encode_g_buffer_face_normal } from "../shader/chunk/geometry/normal/chunk_encode_g_buffer_face_normal.js";
|
|
10
|
+
import { chunk_encode_g_buffer_normal } from "../shader/chunk/geometry/normal/chunk_encode_g_buffer_normal.js";
|
|
11
|
+
import { CodeChunk } from "../shader/compiler/CodeChunk.js";
|
|
12
|
+
import { ShaderResourceSetDescriptor } from "../shader/resource/ShaderResourceSetDescriptor.js";
|
|
13
|
+
import { ShaderDescriptor } from "../shader/ShaderDescriptor.js";
|
|
14
|
+
import { mat4x4f, vec4u } from "../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
|
|
15
|
+
import { WebGPUArray } from "../shader/type/WebGPUArray.js";
|
|
16
|
+
import { chunk_hair_pixel, chunk_hair_quad_vertex } from "./chunk_hair_pixel.js";
|
|
17
|
+
import { HAIR_LOD_STRUCT, HAIR_VIEW_STRUCT } from "./HAIR_FRAME_STRUCTS.js";
|
|
18
|
+
|
|
19
|
+
const resources = new ShaderResourceSetDescriptor();
|
|
20
|
+
|
|
21
|
+
resources.createGroup()
|
|
22
|
+
.add(CAMERA_RESOURCE)
|
|
23
|
+
.addUniform("hair_view", HAIR_VIEW_STRUCT)
|
|
24
|
+
.addStorageBuffer("hair_lod", WebGPUArray.from(HAIR_LOD_STRUCT))
|
|
25
|
+
.addStorageBuffer("hair_points", WebGPUArray.from(vec4u))
|
|
26
|
+
.addTexture("hair_ids", "uint")
|
|
27
|
+
.addTexture("scene_depth")
|
|
28
|
+
.addUniform("inverse_view_projection", mat4x4f)
|
|
29
|
+
.addUniform("view_projection_previous", mat4x4f);
|
|
30
|
+
|
|
31
|
+
const vertex_body = CodeChunk.from(
|
|
32
|
+
//language=WGSL
|
|
33
|
+
`
|
|
34
|
+
@vertex
|
|
35
|
+
fn vs_main(@builtin(vertex_index) vertex: u32, @builtin(instance_index) row: u32) -> HairQuadVertex {
|
|
36
|
+
return hair_quad_vertex(vertex, row);
|
|
37
|
+
}
|
|
38
|
+
`, [chunk_hair_quad_vertex]);
|
|
39
|
+
|
|
40
|
+
const stamp_body = CodeChunk.from(
|
|
41
|
+
//language=WGSL
|
|
42
|
+
`
|
|
43
|
+
struct HairStampOutput {
|
|
44
|
+
@location(0) pbr: vec4<f32>,
|
|
45
|
+
@location(1) normal: u32,
|
|
46
|
+
@location(2) albedo: vec4<f32>,
|
|
47
|
+
@location(3) emissive: u32,
|
|
48
|
+
@location(4) visibility: u32,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@fragment
|
|
52
|
+
fn fs_main(in: HairQuadVertex) -> HairStampOutput {
|
|
53
|
+
var hair: HairPixel;
|
|
54
|
+
|
|
55
|
+
if (!hair_pixel(in.position.xy, in.row, &hair)) {
|
|
56
|
+
discard;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let tangent = hair_pixel_tangent(hair);
|
|
60
|
+
let point = mix(hair.a.xyz, hair.b.xyz, hair.along);
|
|
61
|
+
let normal = hair_normal(tangent, normalize(camera.transform[3].xyz - point));
|
|
62
|
+
|
|
63
|
+
var out: HairStampOutput;
|
|
64
|
+
|
|
65
|
+
// a black metal: the deferred passes light it with nothing, and the hair pass lights it instead
|
|
66
|
+
out.pbr = vec4<f32>(1.0, 1.0, encode_g_buffer_face_normal(normal));
|
|
67
|
+
out.normal = encode_g_buffer_normal(normal);
|
|
68
|
+
out.albedo = vec4<f32>(0.0, 0.0, 0.0, 1.0);
|
|
69
|
+
out.emissive = rgbe9995_encode(vec3<f32>(0.0));
|
|
70
|
+
|
|
71
|
+
// no meshlet is under a strand
|
|
72
|
+
out.visibility = ${VISIBILITY_NONE}u;
|
|
73
|
+
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
`, [
|
|
77
|
+
chunk_hair_quad_vertex,
|
|
78
|
+
chunk_hair_pixel,
|
|
79
|
+
chunk_encode_g_buffer_normal,
|
|
80
|
+
chunk_encode_g_buffer_face_normal,
|
|
81
|
+
chunk_rgbe9995_encode,
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
const motion_body = CodeChunk.from(
|
|
85
|
+
//language=WGSL
|
|
86
|
+
`
|
|
87
|
+
@fragment
|
|
88
|
+
fn fs_main(in: HairQuadVertex) -> @location(0) vec4<f32> {
|
|
89
|
+
var hair: HairPixel;
|
|
90
|
+
|
|
91
|
+
if (!hair_pixel(in.position.xy, in.row, &hair)) {
|
|
92
|
+
discard;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let pixel = in.position.xy;
|
|
96
|
+
let size = hair_view.resolution;
|
|
97
|
+
|
|
98
|
+
let depth = textureLoad(scene_depth, vec2<i32>(pixel), 0).r;
|
|
99
|
+
let here = inverse_view_projection * vec4<f32>(pixel.x / size.x * 2.0 - 1.0, 1.0 - pixel.y / size.y * 2.0, depth, 1.0);
|
|
100
|
+
|
|
101
|
+
// the pixel's point moved as the strand's point under it did
|
|
102
|
+
let moved = mix(hair.a.xyz, hair.b.xyz, hair.along) - mix(hair.a_before, hair.b_before, hair.along);
|
|
103
|
+
|
|
104
|
+
let before = view_projection_previous * vec4<f32>(here.xyz / here.w - moved, 1.0);
|
|
105
|
+
|
|
106
|
+
// this frame's clip w, the point's view depth, is the reciprocal of the w its unprojection came out with
|
|
107
|
+
return velocity_texel(pixel, 1.0 / here.w, before, size);
|
|
108
|
+
}
|
|
109
|
+
`, [
|
|
110
|
+
chunk_hair_quad_vertex,
|
|
111
|
+
chunk_hair_pixel,
|
|
112
|
+
chunk_velocity_texel,
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
const vertex_descriptor = ShaderDescriptor.from({ label: "Hair Rect", body: vertex_body, resources });
|
|
116
|
+
const stamp_descriptor = ShaderDescriptor.from({ label: "Hair Stamp", body: stamp_body, resources });
|
|
117
|
+
const motion_descriptor = ShaderDescriptor.from({ label: "Hair Motion", body: motion_body, resources });
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The bindings of {@link HAIR_STAMP_PIPELINE} and {@link HAIR_MOTION_PIPELINE}, one layout for both: `camera`,
|
|
121
|
+
* `hair_view`, `hair_lod`, `hair_points`, `hair_ids` (the hair id target), `scene_depth` (the depth the strands
|
|
122
|
+
* were drawn into) and the two matrices of `view_velocity_matrices`.
|
|
123
|
+
*
|
|
124
|
+
* @type {ShaderResourceSetDescriptor}
|
|
125
|
+
*/
|
|
126
|
+
export const HAIR_STAMP_RESOURCES = resources;
|
|
127
|
+
|
|
128
|
+
const layout = resources.generatePipelineLayout(GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT);
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Writes a black metal into the G-buffer under every pixel a strand covers, an instance a row of the instance table,
|
|
132
|
+
* each over its screen rectangle (4 vertices, a triangle strip): metalness one, albedo zero, roughness one, nothing
|
|
133
|
+
* occluded, no emission, both normals the strand's normal towards the eye, and `VISIBILITY_NONE`. A metal with no
|
|
134
|
+
* colour reflects nothing at any angle (`metalness_to_specular_F90`), direct or indirect, so the deferred passes
|
|
135
|
+
* leave the pixel unlit for the hair lighting pass. The normals are for what reads the G-buffer's geometry: ambient
|
|
136
|
+
* occlusion, the screen probes, reflections.
|
|
137
|
+
*
|
|
138
|
+
* Five targets, loaded: the four G-buffer targets in `G_BUFFER_COLOR_TARGETS`' order, then the visibility buffer.
|
|
139
|
+
*
|
|
140
|
+
* @type {RenderPipelineDescriptor}
|
|
141
|
+
*/
|
|
142
|
+
export const HAIR_STAMP_PIPELINE = RenderPipelineDescriptor.from({
|
|
143
|
+
label: "Hair Stamp",
|
|
144
|
+
layout,
|
|
145
|
+
vertex: { module: { code: vertex_descriptor.source }, entryPoint: "vs_main" },
|
|
146
|
+
fragment: {
|
|
147
|
+
module: { code: stamp_descriptor.source },
|
|
148
|
+
entryPoint: "fs_main",
|
|
149
|
+
targets: [
|
|
150
|
+
...G_BUFFER_COLOR_TARGETS.map(target => ColorTargetState.from({ format: target.format })),
|
|
151
|
+
ColorTargetState.from({ format: VISIBILITY_FORMAT }),
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
primitive: { topology: "triangle-strip", cullMode: "none" },
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The velocity under every pixel a strand covers, over each instance's screen rectangle as
|
|
159
|
+
* {@link HAIR_STAMP_PIPELINE}: the pixel's point moved as the strand's point under it did, between its place a frame
|
|
160
|
+
* ago and now (`chunk_velocity_texel`). Its own pass: with the stamp's targets it would pass the device floor's
|
|
161
|
+
* attachment bytes.
|
|
162
|
+
*
|
|
163
|
+
* @type {RenderPipelineDescriptor}
|
|
164
|
+
*/
|
|
165
|
+
export const HAIR_MOTION_PIPELINE = RenderPipelineDescriptor.from({
|
|
166
|
+
label: "Hair Motion",
|
|
167
|
+
layout,
|
|
168
|
+
vertex: { module: { code: vertex_descriptor.source }, entryPoint: "vs_main" },
|
|
169
|
+
fragment: {
|
|
170
|
+
module: { code: motion_descriptor.source },
|
|
171
|
+
entryPoint: "fs_main",
|
|
172
|
+
targets: [ColorTargetState.from({ format: VELOCITY_FORMAT })],
|
|
173
|
+
},
|
|
174
|
+
primitive: { topology: "triangle-strip", cullMode: "none" },
|
|
175
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lays the frame's draw list out by point class, once the level of detail has added every instance's prefix to its
|
|
3
|
+
* class's: a thread a class, writing where its region starts, the classes' prefixes summed in class order, as its
|
|
4
|
+
* region's start and as its append cursor. A region holds every strand its class can be asked for. One workgroup.
|
|
5
|
+
*
|
|
6
|
+
* @type {ComputeShader}
|
|
7
|
+
*/
|
|
8
|
+
export const shader_hair_regions: ComputeShader;
|
|
9
|
+
export const HAIR_DRAW_ARGS_SETTINGS: WebGPUStruct;
|
|
10
|
+
/**
|
|
11
|
+
* The id raster's indirect draws, one a point class (`HAIR_DRAW_ARGS_WORDS` words each, at the class's index): a
|
|
12
|
+
* triangle strip of `2 (2^class + 1)` vertices an instance, an instance a strand the cull appended to the class's
|
|
13
|
+
* region, the instances starting at the region's start (`first_instance`). What the list could not hold is not
|
|
14
|
+
* drawn. Written by a pass of its own, so the render pass that draws through it binds it read-only. One workgroup.
|
|
15
|
+
*
|
|
16
|
+
* @type {ComputeShader}
|
|
17
|
+
*/
|
|
18
|
+
export const shader_hair_draw_args: ComputeShader;
|
|
19
|
+
import { ComputeShader } from "../shader/ComputeShader.js";
|
|
20
|
+
import { WebGPUStruct } from "../shader/type/WebGPUStruct.js";
|
|
21
|
+
//# sourceMappingURL=shader_hair_classes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader_hair_classes.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/shader_hair_classes.js"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,kCAFU,aAAa,CAoBpB;AAEH,mDAG2B;AAU3B;;;;;;;GAOG;AACH,oCAFU,aAAa,CAqBpB;8BApF2B,4BAA4B;6BAI7B,gCAAgC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { CodeChunk } from "../shader/compiler/CodeChunk.js";
|
|
2
|
+
import { ComputeShader } from "../shader/ComputeShader.js";
|
|
3
|
+
import { ShaderResourceSetDescriptor } from "../shader/resource/ShaderResourceSetDescriptor.js";
|
|
4
|
+
import { atomic_u32, u32 } from "../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
|
|
5
|
+
import { WebGPUArray } from "../shader/type/WebGPUArray.js";
|
|
6
|
+
import { WebGPUStruct } from "../shader/type/WebGPUStruct.js";
|
|
7
|
+
import {
|
|
8
|
+
HAIR_CLASS_COUNT,
|
|
9
|
+
HAIR_COUNTER_BASES,
|
|
10
|
+
HAIR_COUNTER_CURSORS,
|
|
11
|
+
HAIR_DRAW_ARGS_WORDS
|
|
12
|
+
} from "./HAIR.js";
|
|
13
|
+
|
|
14
|
+
const regions_resources = new ShaderResourceSetDescriptor();
|
|
15
|
+
|
|
16
|
+
regions_resources.createGroup()
|
|
17
|
+
.addStorageBuffer("hair_counters", WebGPUArray.from(atomic_u32), true);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Lays the frame's draw list out by point class, once the level of detail has added every instance's prefix to its
|
|
21
|
+
* class's: a thread a class, writing where its region starts, the classes' prefixes summed in class order, as its
|
|
22
|
+
* region's start and as its append cursor. A region holds every strand its class can be asked for. One workgroup.
|
|
23
|
+
*
|
|
24
|
+
* @type {ComputeShader}
|
|
25
|
+
*/
|
|
26
|
+
export const shader_hair_regions = ComputeShader.from({
|
|
27
|
+
label: "Hair Regions",
|
|
28
|
+
resources: regions_resources,
|
|
29
|
+
body: CodeChunk.from(
|
|
30
|
+
//language=WGSL
|
|
31
|
+
`
|
|
32
|
+
@compute @workgroup_size(${HAIR_CLASS_COUNT}, 1, 1)
|
|
33
|
+
fn main(@builtin(local_invocation_index) point_class: u32) {
|
|
34
|
+
var start = 0u;
|
|
35
|
+
|
|
36
|
+
for (var c = 0u; c < point_class; c++) {
|
|
37
|
+
start += atomicLoad(&hair_counters[c]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
atomicStore(&hair_counters[${HAIR_COUNTER_BASES}u + point_class], start);
|
|
41
|
+
atomicStore(&hair_counters[${HAIR_COUNTER_CURSORS}u + point_class], start);
|
|
42
|
+
}
|
|
43
|
+
`),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const HAIR_DRAW_ARGS_SETTINGS = WebGPUStruct.from({
|
|
47
|
+
/** entries the frame's draw list holds */
|
|
48
|
+
list_capacity: u32,
|
|
49
|
+
}, "HairDrawArgsSettings");
|
|
50
|
+
|
|
51
|
+
const args_resources = new ShaderResourceSetDescriptor();
|
|
52
|
+
|
|
53
|
+
args_resources.setImmediate("settings", HAIR_DRAW_ARGS_SETTINGS);
|
|
54
|
+
|
|
55
|
+
args_resources.createGroup()
|
|
56
|
+
.addStorageBuffer("hair_counters", WebGPUArray.u32, false)
|
|
57
|
+
.addStorageBuffer("hair_draw_args", WebGPUArray.u32, true);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The id raster's indirect draws, one a point class (`HAIR_DRAW_ARGS_WORDS` words each, at the class's index): a
|
|
61
|
+
* triangle strip of `2 (2^class + 1)` vertices an instance, an instance a strand the cull appended to the class's
|
|
62
|
+
* region, the instances starting at the region's start (`first_instance`). What the list could not hold is not
|
|
63
|
+
* drawn. Written by a pass of its own, so the render pass that draws through it binds it read-only. One workgroup.
|
|
64
|
+
*
|
|
65
|
+
* @type {ComputeShader}
|
|
66
|
+
*/
|
|
67
|
+
export const shader_hair_draw_args = ComputeShader.from({
|
|
68
|
+
label: "Hair Draw Args",
|
|
69
|
+
resources: args_resources,
|
|
70
|
+
body: CodeChunk.from(
|
|
71
|
+
//language=WGSL
|
|
72
|
+
`
|
|
73
|
+
@compute @workgroup_size(${HAIR_CLASS_COUNT}, 1, 1)
|
|
74
|
+
fn main(@builtin(local_invocation_index) point_class: u32) {
|
|
75
|
+
let start = hair_counters[${HAIR_COUNTER_BASES}u + point_class];
|
|
76
|
+
let end = min(hair_counters[${HAIR_COUNTER_CURSORS}u + point_class], settings.list_capacity);
|
|
77
|
+
|
|
78
|
+
let at = point_class * ${HAIR_DRAW_ARGS_WORDS}u;
|
|
79
|
+
|
|
80
|
+
hair_draw_args[at] = 2u * ((1u << point_class) + 1u);
|
|
81
|
+
hair_draw_args[at + 1u] = select(0u, end - start, end > start);
|
|
82
|
+
hair_draw_args[at + 2u] = 0u;
|
|
83
|
+
hair_draw_args[at + 3u] = start;
|
|
84
|
+
}
|
|
85
|
+
`),
|
|
86
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const HAIR_CULL_SETTINGS: WebGPUStruct;
|
|
2
|
+
/**
|
|
3
|
+
* Deforms and lists the frame's strands, a thread a point of every instance's prefix (dispatched through
|
|
4
|
+
* `shader_prefix_sum_to_command`'s folded command over the sums of the instances' points, `prefix × (2^class + 1)`).
|
|
5
|
+
*
|
|
6
|
+
* A thread finds its row from the sums, and from its place among the row's threads its strand's rank and its point
|
|
7
|
+
* along the strand. The strand is kept when its rank is under its own share of the group (`hair_kept_fraction` at
|
|
8
|
+
* its root's view depth), and then drawn wider by the reciprocal of that share, the strand at the boundary narrowed
|
|
9
|
+
* by how far it is past it, so the kept strands' widths sum to the group's at every distance and none appears or
|
|
10
|
+
* vanishes at once.
|
|
11
|
+
*
|
|
12
|
+
* The point, every `2^level`-th of the strand's rest points, is carried by its entity's world matrix as it is and as
|
|
13
|
+
* it was a frame ago into its place in `hair_points` (`HAIR.js`). No point is drawn narrower than the view's pixel
|
|
14
|
+
* floor, so one narrower than it would be drawn wider than it is: a point of width `w` under the floor `p` at its
|
|
15
|
+
* own depth is drawn, at `p`, only by the strands whose share of the floor (a number in [0, 1) stratified over
|
|
16
|
+
* ranks) is under `w / p`, and at no width by the rest (a negative width). The drawn area is then the strands' own
|
|
17
|
+
* wherever they are, the tapering tips of a thinned fringe included.
|
|
18
|
+
*
|
|
19
|
+
* The thread also lays the segment from its point to the next into the instance's density volume (`HAIR.js`), at
|
|
20
|
+
* the strand's drawn width, which carries the share kept, so a prefix gives an unbiased estimate of the whole group.
|
|
21
|
+
* The volume was cleared by `shader_hair_volume_clear`.
|
|
22
|
+
*
|
|
23
|
+
* The thread of a kept strand's root appends it to its class's region of `hair_list` (`chunk_subgroup_keyed_append`
|
|
24
|
+
* on the class's cursor) as its slot and class. An entry the list cannot hold is dropped; the cursor still counts it.
|
|
25
|
+
*
|
|
26
|
+
* @type {ComputeShader}
|
|
27
|
+
*/
|
|
28
|
+
export const shader_hair_cull: ComputeShader;
|
|
29
|
+
import { WebGPUStruct } from "../shader/type/WebGPUStruct.js";
|
|
30
|
+
import { ComputeShader } from "../shader/ComputeShader.js";
|
|
31
|
+
//# sourceMappingURL=shader_hair_cull.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader_hair_cull.d.ts","sourceRoot":"","sources":["../../../../../src/shade/renderer/hair/shader_hair_cull.js"],"names":[],"mappings":"AAuBA,8CASuB;AAmIvB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,+BAFU,aAAa,CAMpB;6BAjL0B,gCAAgC;8BAL/B,4BAA4B"}
|