|
1 |
| -struct VertexInput { |
2 |
| - @location(0) position: vec4<f32>, |
3 |
| - @location(1) tex_coord: vec2<f32>, |
4 |
| - @location(2) alpha: f32, |
5 |
| - @location(3) color: vec4<f32>, |
6 |
| - @location(4) fade_near_far: vec2<f32>, |
7 |
| -} |
8 |
| -struct VertexOutput { |
9 |
| - @location(0) tex_coord: vec2<f32>, |
10 |
| - @location(1) alpha: f32, |
11 |
| - @location(2) color: vec4<f32>, |
12 |
| - @builtin(position) position: vec4<f32>, |
13 |
| -}; |
14 |
| -struct UniformInput { |
15 |
| - transform: mat4x4<f32>, |
16 |
| - player_pos: vec3<f32>, |
17 |
| -} |
18 |
| - |
19 |
| -@group(0) |
20 |
| -@binding(0) |
21 |
| -var<uniform> uni: UniformInput; |
22 |
| - |
23 |
| -@vertex |
24 |
| -fn vs_main( |
25 |
| - vin: VertexInput |
26 |
| -) -> VertexOutput { |
27 |
| - var result: VertexOutput; |
28 |
| - result.alpha = vin.alpha; |
29 |
| - |
30 |
| - var dist = distance(uni.player_pos, vin.position.xyz); |
31 |
| - if vin.fade_near_far.x > 0.0 && dist >= vin.fade_near_far.x { |
32 |
| - // if distance is exactly fade_near, we will multiply with 1.0 |
33 |
| - // if its more, then we will multiply with how far we are in between fade_near and fade_far |
34 |
| - var ratio = 1.0 - (abs(dist - vin.fade_near_far.x) / abs(vin.fade_near_far.y - vin.fade_near_far.x)); |
35 |
| - // The actual alpha |
36 |
| - result.alpha *= ratio; |
37 |
| - } |
38 |
| - if vin.fade_near_far.y > 0.0 && dist >= vin.fade_near_far.y { |
39 |
| - result.alpha = 0.0; |
40 |
| - } |
41 |
| - result.tex_coord = vin.tex_coord; |
42 |
| - result.position = uni.transform * vin.position; |
43 |
| - result.color = vin.color; |
44 |
| - |
45 |
| - return result; |
46 |
| -} |
47 |
| - |
48 |
| -@group(1) @binding(0) var r_tex_color: texture_2d<f32>; |
49 |
| -@group(1) @binding(1) var r_tex_sampler: sampler; |
50 |
| - |
51 |
| -@fragment |
52 |
| -fn fs_main(vout: VertexOutput) -> @location(0) vec4<f32> { |
53 |
| - var color: vec4<f32> = textureSampleBias(r_tex_color, r_tex_sampler, vout.tex_coord, -2.0); |
54 |
| - color.a = color.a * vout.alpha; |
55 |
| - if color.a < 0.01 { |
56 |
| - discard; |
57 |
| - } |
58 |
| - return color; |
59 |
| -} |
60 |
| - |
0 commit comments