code wiki / (root) / nx_world_cloud_transport_t155.nx

nx_world_cloud_transport_t155.nx source

↩ module page · 114 lines · 12835 B

1// Private coherent cloud transport qualification; canonical density/terrain/cast unchanged. 2// Relative scene radiance is reconstructed by inverse of nx_tonemap_aces Q10 rational fit plus nx_atmosphere sqrt convention. 3// This cannot recover clipped physical energy. Palette1 is representative primary-land albedo, not measured hemispheric irradiance. 4// Solar irradiance uses existing solar display reference and Lambertian pi convention; coefficients remain relative artistic inputs. 5// Two scattering octaves (half extinction, half contribution, half anisotropy) approximate higher orders, not a path-traced solution. 6// One cloud tone/display encode after linear composite. Incumbent final world grade remains downstream. 7import "nx_world_shader_src.nx" 8func ws_fn_cloud_decode_t155(m: *i64) -> i64 { 9 let f: i64 = sir_func(m, "cloud_decode" as *u8, T_V3F) 10 sir_param(m, f, "display" as *u8, T_V3F) 11 ws_st(m, f, sir_let(m, "d" as *u8, T_V3F, ws_c3(m, "clamp" as *u8, ws_id(m, "display" as *u8, T_V3F), ws_v1(m, T_V3F, ws_f(m, "0.0" as *u8)), ws_v1(m, T_V3F, ws_f(m, "1.0" as *u8)), T_V3F))) 12 ws_st(m, f, sir_let(m, "y" as *u8, T_V3F, ws_bin(m, "*" as *u8, ws_id(m, "d" as *u8, T_V3F), ws_id(m, "d" as *u8, T_V3F), T_V3F))) 13 ws_st(m, f, sir_let(m, "a" as *u8, T_V3F, ws_bin(m, "-" as *u8, ws_v1(m, T_V3F, ws_f(m, "2.509765625" as *u8)), ws_bin(m, "*" as *u8, ws_f(m, "2.4296875" as *u8), ws_id(m, "y" as *u8, T_V3F), T_V3F), T_V3F))) 14 ws_st(m, f, sir_let(m, "b" as *u8, T_V3F, ws_bin(m, "-" as *u8, ws_v1(m, T_V3F, ws_f(m, "0.0302734375" as *u8)), ws_bin(m, "*" as *u8, ws_f(m, "0.58984375" as *u8), ws_id(m, "y" as *u8, T_V3F), T_V3F), T_V3F))) 15 ws_st(m, f, sir_let(m, "disc" as *u8, T_V3F, ws_bin(m, "+" as *u8, ws_bin(m, "*" as *u8, ws_id(m, "b" as *u8, T_V3F), ws_id(m, "b" as *u8, T_V3F), T_V3F), ws_bin(m, "*" as *u8, ws_bin(m, "*" as *u8, ws_f(m, "4.0" as *u8), ws_id(m, "a" as *u8, T_V3F), T_V3F), ws_bin(m, "*" as *u8, ws_f(m, "0.1396484375" as *u8), ws_id(m, "y" as *u8, T_V3F), T_V3F), T_V3F), T_V3F))) 16 ws_st(m, f, ws_ret(m, ws_bin(m, "/" as *u8, ws_bin(m, "+" as *u8, ws_bin(m, "-" as *u8, ws_v1(m, T_V3F, ws_f(m, "0.0" as *u8)), ws_id(m, "b" as *u8, T_V3F), T_V3F), ws_c1(m, "sqrt" as *u8, ws_id(m, "disc" as *u8, T_V3F), T_V3F), T_V3F), ws_bin(m, "*" as *u8, ws_f(m, "2.0" as *u8), ws_id(m, "a" as *u8, T_V3F), T_V3F), T_V3F))) 17 return f 18} 19func ws_fn_cloud_encode_t155(m: *i64) -> i64 { 20 let f: i64 = sir_func(m, "cloud_encode" as *u8, T_V3F) 21 sir_param(m, f, "radiance" as *u8, T_V3F) 22 ws_st(m, f, sir_let(m, "x" as *u8, T_V3F, ws_c2(m, "max" as *u8, ws_id(m, "radiance" as *u8, T_V3F), ws_v1(m, T_V3F, ws_f(m, "0.0" as *u8)), T_V3F))) 23 ws_st(m, f, sir_let(m, "num" as *u8, T_V3F, ws_bin(m, "*" as *u8, ws_id(m, "x" as *u8, T_V3F), ws_bin(m, "+" as *u8, ws_bin(m, "*" as *u8, ws_f(m, "2.509765625" as *u8), ws_id(m, "x" as *u8, T_V3F), T_V3F), ws_v1(m, T_V3F, ws_f(m, "0.0302734375" as *u8)), T_V3F), T_V3F))) 24 ws_st(m, f, sir_let(m, "den" as *u8, T_V3F, ws_bin(m, "+" as *u8, ws_bin(m, "*" as *u8, ws_id(m, "x" as *u8, T_V3F), ws_bin(m, "+" as *u8, ws_bin(m, "*" as *u8, ws_f(m, "2.4296875" as *u8), ws_id(m, "x" as *u8, T_V3F), T_V3F), ws_v1(m, T_V3F, ws_f(m, "0.58984375" as *u8)), T_V3F), T_V3F), ws_v1(m, T_V3F, ws_f(m, "0.1396484375" as *u8)), T_V3F))) 25 ws_st(m, f, ws_ret(m, ws_c1(m, "sqrt" as *u8, ws_c3(m, "clamp" as *u8, ws_bin(m, "/" as *u8, ws_id(m, "num" as *u8, T_V3F), ws_id(m, "den" as *u8, T_V3F), T_V3F), ws_v1(m, T_V3F, ws_f(m, "0.0" as *u8)), ws_v1(m, T_V3F, ws_f(m, "1.0" as *u8)), T_V3F), T_V3F))) 26 return f 27} 28func ws_fn_cloud_phase_t155(m: *i64) -> i64 { 29 let f: i64 = sir_func(m, "cloud_phase" as *u8, T_F32) 30 sir_param(m, f, "mu" as *u8, T_F32) 31 sir_param(m, f, "g" as *u8, T_F32) 32 ws_st(m, f, ws_ret(m, ws_bin(m, "/" as *u8, ws_bin(m, "-" as *u8, ws_f(m, "1.0" as *u8), ws_bin(m, "*" as *u8, ws_id(m, "g" as *u8, T_F32), ws_id(m, "g" as *u8, T_F32), T_F32), T_F32), ws_bin(m, "*" as *u8, ws_f(m, "12.566370614359172" as *u8), ws_c2(m, "pow" as *u8, ws_bin(m, "-" as *u8, ws_bin(m, "+" as *u8, ws_f(m, "1.0" as *u8), ws_bin(m, "*" as *u8, ws_id(m, "g" as *u8, T_F32), ws_id(m, "g" as *u8, T_F32), T_F32), T_F32), ws_bin(m, "*" as *u8, ws_bin(m, "*" as *u8, ws_f(m, "2.0" as *u8), ws_id(m, "g" as *u8, T_F32), T_F32), ws_c3(m, "clamp" as *u8, ws_id(m, "mu" as *u8, T_F32), ws_f(m, "-1.0" as *u8), ws_f(m, "1.0" as *u8), T_F32), T_F32), T_F32), ws_f(m, "1.5" as *u8), T_F32), T_F32), T_F32))) 33 return f 34} 35func ws_fn_cloud_incident_t155(m: *i64) -> i64 { 36 let f: i64 = sir_func(m, "cloud_incident" as *u8, T_V3F) 37 sir_param(m, f, "p" as *u8, T_V3F) 38 sir_param(m, f, "mu" as *u8, T_F32) 39 ws_st(m, f, sir_let(m, "skyL" as *u8, T_V3F, ws_bin(m, "*" as *u8, ws_bin(m, "+" as *u8, ws_c1(m, "cloud_decode" as *u8, ws_id(m, "skt" as *u8, T_V3F), T_V3F), ws_c1(m, "cloud_decode" as *u8, ws_id(m, "skh" as *u8, T_V3F), T_V3F), T_V3F), ws_f(m, "0.5" as *u8), T_V3F))) 40 ws_st(m, f, sir_let(m, "solarL" as *u8, T_V3F, ws_c1(m, "cloud_decode" as *u8, ws_v3f(m, "1.0" as *u8, "0.98" as *u8, "0.88" as *u8), T_V3F))) 41 ws_st(m, f, sir_let(m, "groundA" as *u8, T_V3F, ws_bin(m, "*" as *u8, ws_sw(m, sir_index(m, ws_id(m, "pal" as *u8, T_V4F), ws_i(m, "1" as *u8), T_V4F), "xyz" as *u8, T_V3F), ws_sw(m, sir_index(m, ws_id(m, "pal" as *u8, T_V4F), ws_i(m, "1" as *u8), T_V4F), "xyz" as *u8, T_V3F), T_V3F))) 42 ws_st(m, f, sir_let(m, "groundL" as *u8, T_V3F, ws_bin(m, "*" as *u8, ws_id(m, "groundA" as *u8, T_V3F), ws_bin(m, "+" as *u8, ws_id(m, "skyL" as *u8, T_V3F), ws_bin(m, "*" as *u8, ws_id(m, "solarL" as *u8, T_V3F), ws_bin(m, "*" as *u8, ws_bin(m, "*" as *u8, ws_f(m, CB_DIRECT), ws_id(m, "sun" as *u8, T_F32), T_F32), ws_c2(m, "max" as *u8, ws_sx(m, "sund" as *u8, T_V3F, "y" as *u8, T_F32), ws_f(m, "0.0" as *u8), T_F32), T_F32), T_V3F), T_V3F), T_V3F))) 43 ws_st(m, f, sir_let(m, "ambientL" as *u8, T_V3F, ws_bin(m, "*" as *u8, ws_bin(m, "+" as *u8, ws_id(m, "skyL" as *u8, T_V3F), ws_id(m, "groundL" as *u8, T_V3F), T_V3F), ws_bin(m, "*" as *u8, ws_f(m, "0.5" as *u8), ws_f(m, CB_AMBIENT), T_F32), T_V3F))) 44 ws_st(m, f, sir_let(m, "T" as *u8, T_F32, ws_c1(m, "csun" as *u8, ws_id(m, "p" as *u8, T_V3F), T_F32))) 45 ws_st(m, f, sir_let(m, "single" as *u8, T_F32, ws_bin(m, "*" as *u8, ws_id(m, "T" as *u8, T_F32), ws_c2(m, "cloud_phase" as *u8, ws_id(m, "mu" as *u8, T_F32), ws_f(m, CB_PHASE_G), T_F32), T_F32))) 46 ws_st(m, f, sir_let(m, "multiple" as *u8, T_F32, ws_bin(m, "*" as *u8, ws_bin(m, "*" as *u8, ws_f(m, "0.5" as *u8), ws_c1(m, "sqrt" as *u8, ws_id(m, "T" as *u8, T_F32), T_F32), T_F32), ws_c2(m, "cloud_phase" as *u8, ws_id(m, "mu" as *u8, T_F32), ws_bin(m, "*" as *u8, ws_f(m, "0.5" as *u8), ws_f(m, CB_PHASE_G), T_F32), T_F32), T_F32))) 47 ws_st(m, f, sir_let(m, "solarWeight" as *u8, T_F32, ws_bin(m, "*" as *u8, ws_bin(m, "*" as *u8, ws_bin(m, "*" as *u8, ws_f(m, "3.141592653589793" as *u8), ws_f(m, CB_DIRECT), T_F32), ws_id(m, "sun" as *u8, T_F32), T_F32), ws_bin(m, "+" as *u8, ws_id(m, "single" as *u8, T_F32), ws_id(m, "multiple" as *u8, T_F32), T_F32), T_F32))) 48 ws_st(m, f, ws_ret(m, ws_bin(m, "+" as *u8, ws_id(m, "ambientL" as *u8, T_V3F), ws_bin(m, "*" as *u8, ws_id(m, "solarL" as *u8, T_V3F), ws_id(m, "solarWeight" as *u8, T_F32), T_V3F), T_V3F))) 49 return f 50} 51 52func ws_fn_cld3_transport_t155(m: *i64) -> i64 { 53 let f: i64 = sir_func(m, "cld3" as *u8, T_V3F) 54 sir_param(m, f, "rd" as *u8, T_V3F) 55 sir_param(m, f, "s0" as *u8, T_V3F) 56 ws_st(m, f, ws_if(m, ws_cmp(m, "<=" as *u8, ws_id(m, "cld" as *u8, T_F32), ws_f(m, "0.0" as *u8)), ws_ret(m, ws_id(m, "s0" as *u8, T_V3F)), 0)) 57 ws_st(m, f, sir_let(m, "dy" as *u8, T_F32, ws_sx(m, "rd" as *u8, T_V3F, "y" as *u8, T_F32))) 58 ws_st(m, f, ws_if(m, ws_cmp(m, "==" as *u8, ws_id(m, "dy" as *u8, T_F32), ws_f(m, "0.0" as *u8)), ws_ret(m, ws_id(m, "s0" as *u8, T_V3F)), 0)) 59 ws_st(m, f, sir_let(m, "a" as *u8, T_F32, ws_bin(m, "/" as *u8, ws_bin(m, "-" as *u8, ws_f(m, CB_BASE), ws_sx(m, "cam" as *u8, T_V3F, "y" as *u8, T_F32), T_F32), ws_id(m, "dy" as *u8, T_F32), T_F32))) 60 ws_st(m, f, sir_let(m, "b" as *u8, T_F32, ws_bin(m, "/" as *u8, ws_bin(m, "-" as *u8, ws_f(m, CB_TOP), ws_sx(m, "cam" as *u8, T_V3F, "y" as *u8, T_F32), T_F32), ws_id(m, "dy" as *u8, T_F32), T_F32))) 61 ws_st(m, f, sir_let(m, "t0" as *u8, T_F32, ws_c2(m, "max" as *u8, ws_c2(m, "min" as *u8, ws_id(m, "a" as *u8, T_F32), ws_id(m, "b" as *u8, T_F32), T_F32), ws_f(m, "0.0" as *u8), T_F32))) 62 ws_st(m, f, sir_let(m, "t1" as *u8, T_F32, ws_c2(m, "min" as *u8, ws_c2(m, "max" as *u8, ws_id(m, "a" as *u8, T_F32), ws_id(m, "b" as *u8, T_F32), T_F32), ws_f(m, CB_VIEW_DISTANCE), T_F32))) 63 ws_st(m, f, ws_if(m, ws_cmp(m, "<=" as *u8, ws_id(m, "t1" as *u8, T_F32), ws_id(m, "t0" as *u8, T_F32)), ws_ret(m, ws_id(m, "s0" as *u8, T_V3F)), 0)) 64 ws_st(m, f, sir_let(m, "dt" as *u8, T_F32, ws_bin(m, "/" as *u8, ws_bin(m, "-" as *u8, ws_id(m, "t1" as *u8, T_F32), ws_id(m, "t0" as *u8, T_F32), T_F32), ws_f(m, CB_STEPS_F), T_F32))) 65 ws_st(m, f, sir_var(m, "tr" as *u8, T_F32, ws_f(m, "1.0" as *u8))) 66 ws_st(m, f, sir_var(m, "acc" as *u8, T_V3F, ws_v1(m, T_V3F, ws_f(m, "0.0" as *u8)))) 67 ws_st(m, f, sir_let(m, "mu" as *u8, T_F32, ws_c3(m, "clamp" as *u8, ws_c2(m, "dot" as *u8, ws_id(m, "rd" as *u8, T_V3F), ws_id(m, "sund" as *u8, T_V3F), T_F32), ws_f(m, "-1.0" as *u8), ws_f(m, "1.0" as *u8), T_F32))) 68 let p0: i64 = sir_let(m, "p" as *u8, T_V3F, ws_bin(m, "+" as *u8, ws_id(m, "cam" as *u8, T_V3F), ws_bin(m, "*" as *u8, ws_id(m, "rd" as *u8, T_V3F), ws_bin(m, "+" as *u8, ws_id(m, "t0" as *u8, T_F32), ws_bin(m, "*" as *u8, ws_bin(m, "+" as *u8, ws_fi(m, "i" as *u8), ws_f(m, "0.5" as *u8), T_F32), ws_id(m, "dt" as *u8, T_F32), T_F32), T_F32), T_V3F), T_V3F)) 69 let d0: i64 = sir_let(m, "density" as *u8, T_F32, ws_c1(m, "cvol" as *u8, ws_id(m, "p" as *u8, T_V3F), T_F32)) 70 let a0: i64 = sir_let(m, "alpha" as *u8, T_F32, ws_bin(m, "-" as *u8, ws_f(m, "1.0" as *u8), ws_c1(m, "exp" as *u8, ws_bin(m, "-" as *u8, ws_f(m, "0.0" as *u8), ws_bin(m, "*" as *u8, ws_bin(m, "*" as *u8, ws_id(m, "density" as *u8, T_F32), ws_id(m, "dt" as *u8, T_F32), T_F32), ws_f(m, CB_SIGMA), T_F32), T_F32), T_F32), T_F32)) 71 let l0: i64 = sir_let(m, "light" as *u8, T_V3F, ws_c2(m, "cloud_incident" as *u8, ws_id(m, "p" as *u8, T_V3F), ws_id(m, "mu" as *u8, T_F32), T_V3F)) 72 let c0: i64 = ws_op(m, "acc" as *u8, T_V3F, "+" as *u8, ws_bin(m, "*" as *u8, ws_id(m, "light" as *u8, T_V3F), ws_bin(m, "*" as *u8, ws_id(m, "tr" as *u8, T_F32), ws_id(m, "alpha" as *u8, T_F32), T_F32), T_V3F)) 73 let t0s: i64 = ws_op(m, "tr" as *u8, T_F32, "*" as *u8, ws_bin(m, "-" as *u8, ws_f(m, "1.0" as *u8), ws_id(m, "alpha" as *u8, T_F32), T_F32)) 74 let body: i64 = ws_q2(m, ws_q3(m, p0, d0, a0), ws_if(m, ws_cmp(m, ">" as *u8, ws_id(m, "density" as *u8, T_F32), ws_f(m, "0.0" as *u8)), ws_q3(m, l0, c0, t0s), 0)) 75 sir_for_until(m, f, sir_var(m, "i" as *u8, T_I32, ws_i(m, "0" as *u8)), ws_cmp(m, ">=" as *u8, ws_id(m, "i" as *u8, T_I32), ws_i(m, CB_STEPS)), ws_op(m, "i" as *u8, T_I32, "+" as *u8, ws_i(m, "1" as *u8)), body) 76 let fog: i64 = ws_c3(m, "smoothstep" as *u8, ws_f(m, "0.0" as *u8), ws_f(m, CB_VIEW_DISTANCE), ws_id(m, "t0" as *u8, T_F32), T_F32) 77 let clearL: i64 = ws_c1(m, "cloud_decode" as *u8, ws_id(m, "s0" as *u8, T_V3F), T_V3F) 78 let composite: i64 = ws_bin(m, "+" as *u8, ws_bin(m, "*" as *u8, clearL, ws_id(m, "tr" as *u8, T_F32), T_V3F), ws_id(m, "acc" as *u8, T_V3F), T_V3F) 79 let clearFogL: i64 = ws_c1(m, "cloud_decode" as *u8, ws_id(m, "s0" as *u8, T_V3F), T_V3F) 80 ws_st(m, f, ws_ret(m, ws_c1(m, "cloud_encode" as *u8, ws_c3(m, "mix" as *u8, composite, clearFogL, fog, T_V3F), T_V3F))) 81 return f 82} 83func shsrc_world_transport_t155(m: *i64) -> i64 { 84 ws_world_uniforms_raw(m) 85 ws_world_privates(m) 86 sir_texture(m, "tV" as *u8, T_TEX3U) 87 sir_texture(m, "tH" as *u8, T_TEX2F) // GE53: the surface field, one f32 height per column (r32float 128x128), uploaded from the sim's hq block 88 let hty: i64 = sir_struct_ty(ws_struct_hit(m)) 89 ws_fn_rgb9(m) 90 ws_fn_upk(m) 91 ws_fn_vx(m) 92 ws_fn_h21(m) 93 ws_fn_h31(m) 94 ws_fn_vn3(m) // PG22: the cloud volume's noise, density and march -- after h31, before sky which calls cld3 95 ws_fn_cvol(m) 96 ws_fn_csun(m) 97 ws_fn_cloud_decode_t155(m) 98 ws_fn_cloud_encode_t155(m) 99 ws_fn_cloud_phase_t155(m) 100 ws_fn_cloud_incident_t155(m) 101 ws_fn_cld3_transport_t155(m) 102 ws_fn_pal9(m) 103 ws_fn_sky(m) 104 ws_fn_hq(m) 105 ws_fn_surf(m) 106 ws_fn_terrain(m) 107 ws_fn_smarch(m) 108 ws_fn_gnd(m) 109 ws_fn_sand(m) // GR27: after surf, h21, vx and gnd (GLSL declares before use), before shade which calls it 110 ws_fn_march(m, hty) 111 ws_fn_scene_hit(m, hty) 112 ws_fn_shade(m, hty) 113 return ws_fn_fs(m, hty) 114}