载入中...
搜索中...
未找到
WeatherWgsl.h
浏览该文件的文档.
1#pragma once
2
4
5inline constexpr const char *kWeatherVertWgsl = R"wgsl(
6struct Light3D { posRadius: vec4f, color: vec4f };
7struct Frame { mvp:mat4x4f,model:mat4x4f,lightDir:vec4f,lightColor:vec4f,tint:vec4f,cameraPos:vec4f,ambient:vec4f,lights:array<Light3D,8>,texBomb:vec4f,parallax:vec4f,surface:vec4f,view:mat4x4f,clipInfo:vec4f,cloud:vec4f,cloudWind:vec4f };
8struct Params { data: array<vec4f,8> }; struct In{@location(0) pos:vec3f,@location(1) normal:vec3f,@location(2) uv:vec2f};
9struct Out{@builtin(position) pos:vec4f,@location(0) normal:vec3f,@location(1) uv:vec2f,@location(2) tint:vec4f,@location(3) world:vec3f,@location(4) camera:vec3f,@location(5) view:vec3f,@location(6) particle:f32};
10@group(0) @binding(0) var<uniform> frame:Frame; @group(0) @binding(15) var<uniform> params:Params;
11fn p(i:u32)->f32{return params.data[i/4u][i%4u];}
12fn hash12(q:vec2f)->f32{var v=fract(vec3f(q.x,q.y,q.x)*0.1031);v+=dot(v,v.yzx+vec3f(33.33));return fract((v.x+v.y)*v.z);}
13@vertex fn vs_main(i:In)->Out {
14 let kind=p(12u);
15 let phase=hash12(i.pos.xz*0.5+vec2f(floor(i.pos.y*0.7),13.0));
16 let speed=p(3u)*i.normal.z;
17 let velocity=vec3f(p(1u),-speed,p(2u));
18 var base=i.pos+vec3f(p(13u),-speed*p(0u),p(14u));
19 if(kind>1.5) { base=i.pos; }
20 let relative=base-frame.cameraPos.xyz+vec3f(26.0,10.0,26.0);
21 base=relative-floor(relative/vec3f(52.0,20.0,52.0))*vec3f(52.0,20.0,52.0)-vec3f(26.0,10.0,26.0)+frame.cameraPos.xyz;
22 if(kind>0.5 && kind<1.5) {
23 let flutter=p(0u)*1.7+phase*6.283185;
24 base.x+=sin(flutter)*0.32;
25 base.z+=cos(flutter*0.73)*0.24;
26 }
27 let cameraRight=vec3f(frame.view[0][0],frame.view[1][0],frame.view[2][0]);
28 let cameraUp=vec3f(frame.view[0][1],frame.view[1][1],frame.view[2][1]);
29 var up=-normalize(velocity);
30 let sight=frame.cameraPos.xyz-base;
31 let side=cross(up,sight);
32 var right=cameraRight;
33 if(dot(side,side)>0.0001) { right=normalize(side); }
34 var widthScale=i.normal.y;
35 if(kind>0.5 && kind<1.5) {
36 let angle=phase*6.283185+p(0u)*0.35;
37 right=cameraRight*cos(angle)+cameraUp*sin(angle);
38 up=-cameraRight*sin(angle)+cameraUp*cos(angle);
39 widthScale=i.normal.x;
40 }
41 let position=base+right*i.uv.x*p(5u)*widthScale+up*(i.uv.y-0.5)*p(4u)*i.normal.x;
42 let world=frame.model*vec4f(position,1);
43 var o:Out;
44 o.pos=frame.mvp*vec4f(position,1); o.pos.y=-o.pos.y;
45 o.normal=i.normal; o.uv=vec2f(i.uv.x+0.5,i.uv.y); o.tint=frame.tint;
46 let distanceFade=smoothstep(1.0,3.0,length(sight));
47 let edgeFade=1.0-smoothstep(20.0,26.0,max(abs(base.x-frame.cameraPos.x),abs(base.z-frame.cameraPos.z)));
48 o.tint.a*=distanceFade*edgeFade;
49 o.world=world.xyz; o.camera=frame.cameraPos.xyz;
50 o.view=(frame.view*world).xyz; o.particle=phase; return o;
51}
52)wgsl";
53
54inline constexpr const char *kWeatherFragWgsl = R"wgsl(
55struct Params{data:array<vec4f,8>};struct In{@builtin(position) pos:vec4f,@location(1) uv:vec2f,@location(2) tint:vec4f,@location(3) world:vec3f,@location(4) camera:vec3f,@location(5) view:vec3f,@location(6) particle:f32};
56@group(0) @binding(1) var albedo:texture_2d<f32>;@group(0) @binding(7) var samp:sampler;@group(0) @binding(15) var<uniform> params:Params;fn p(i:u32)->f32{return params.data[i/4u][i%4u];}
57@fragment fn fs_main(i:In)->@location(0) vec4f {
58 var tex=textureSample(albedo,samp,i.uv)*i.tint;
59 // Evaluate derivatives before particle discard for uniform control flow.
60 let t=i.uv.y;
61 let center=0.5+(0.045+i.particle*0.035)*sin(t*3.141593);
62 let taper=smoothstep(0.0,0.08,t)*(1.0-smoothstep(0.92,1.0,t));
63 let head=fract(p(0u)*0.22+i.particle*7.13)*1.5-0.25;
64 let along=1.0-t;
65 let light=smoothstep(head-0.32,head-0.12,along)*(1.0-smoothstep(head-0.035,head+0.025,along));
66 let halfWidth=0.006;
67 let aa=max(fwidth(i.uv.x-center),0.001);
68 if(p(12u)>1.5) {
69 let ribbon=1.0-smoothstep(max(halfWidth-aa,0.0),halfWidth+aa,abs(i.uv.x-center));
70 tex=vec4f(vec3f(0.94,0.98,1.0)*i.tint.rgb,ribbon*taper*light*i.tint.a*0.16);
71 }
72 if(p(6u)<=0.0 || i.particle>=p(6u)){discard;}
73 let coverage=sqrt(max(tex.a,0.0))*select(0.95,0.88,p(12u)>1.5);
74 let threshold=fract(52.9829189*fract(dot(floor(i.pos.xy),vec2f(0.06711056,0.00583715))));
75 if(coverage<=threshold){discard;}
76 let fog=clamp(1.0-exp(-length(i.view)*p(10u)),0.0,1.0);
77 let glint=0.72+0.28*pow(max(0.0,1.0-abs(i.uv.x-0.5)*2.0),2.0);
78 return vec4f(mix(tex.rgb*glint,vec3f(p(7u),p(8u),p(9u)),fog),1);
79}
80)wgsl";
81
82inline constexpr const char *kBoltVertWgsl = R"wgsl(
83struct Light3D{posRadius:vec4f,color:vec4f};struct Frame{mvp:mat4x4f,model:mat4x4f,lightDir:vec4f,lightColor:vec4f,tint:vec4f,cameraPos:vec4f,ambient:vec4f,lights:array<Light3D,8>,texBomb:vec4f,parallax:vec4f,surface:vec4f,view:mat4x4f,clipInfo:vec4f,cloud:vec4f,cloudWind:vec4f};struct In{@location(0) pos:vec3f,@location(1) normal:vec3f,@location(2) uv:vec2f};struct Out{@builtin(position) pos:vec4f,@location(0) normal:vec3f,@location(1) uv:vec2f,@location(2) tint:vec4f,@location(3) world:vec3f,@location(4) camera:vec3f,@location(5) view:vec3f};@group(0) @binding(0) var<uniform> frame:Frame;@vertex fn vs_main(i:In)->Out{let w=frame.model*vec4f(i.pos,1);var o:Out;o.pos=frame.mvp*vec4f(i.pos,1);o.pos.y=-o.pos.y;o.normal=i.normal;o.uv=i.uv;o.tint=frame.tint;o.world=w.xyz;o.camera=frame.cameraPos.xyz;o.view=(frame.view*w).xyz;return o;}
84)wgsl";
85
86inline constexpr const char *kBoltFragWgsl = R"wgsl(
87struct Params{data:array<vec4f,8>};struct In{@builtin(position) pos:vec4f,@location(1) uv:vec2f,@location(2) tint:vec4f,@location(3) world:vec3f,@location(5) view:vec3f};@group(0) @binding(15) var<uniform> params:Params;fn p(i:u32)->f32{return params.data[i/4u][i%4u];}
88@fragment fn fs_main(i:In)->@location(0) vec4f{let flash=clamp(p(11u),0.0,1.0);if(flash<=0.01){discard;}let across=abs(i.uv.x);let core=1.0-smoothstep(0.08,0.34,across);let halo=pow(max(0.0,1.0-across),2.2)*flash;let bayer=array<f32,16>(0.0,0.5,0.125,0.625,0.75,0.25,0.875,0.375,0.1875,0.6875,0.0625,0.5625,0.9375,0.4375,0.8125,0.3125);let q=vec2u(i.pos.xy)%vec2u(4);if(max(core,halo*0.72)<=bayer[q.y*4u+q.x]){discard;}let color=mix(vec3f(0.20,0.38,0.95),vec3f(0.92,0.97,1.0),core)*(0.55+0.85*flash);let fog=clamp(1.0-exp(-length(i.view)*p(10u)),0.0,1.0);return vec4f(mix(color,vec3f(p(7u),p(8u),p(9u)),fog*0.6),1);}
89)wgsl";
90
91} // namespace eve::weather::shaders
constexpr const char * kWeatherFragWgsl
Definition WeatherWgsl.h:54
constexpr const char * kWeatherVertWgsl
Definition WeatherWgsl.h:5
constexpr const char * kBoltFragWgsl
Definition WeatherWgsl.h:86
constexpr const char * kBoltVertWgsl
Definition WeatherWgsl.h:82