1
+ #include "gsplatCommonVS"
2
+
3
+ varying mediump vec2 gaussianUV;
4
+ varying mediump vec4 gaussianColor;
5
+
6
+ #ifndef DITHER_NONE
7
+ varying float id;
8
+ #endif
9
+
10
+ mediump vec4 discardVec = vec4 (0.0 , 0.0 , 2.0 , 1.0 );
11
+
1
12
uniform float uTime;
2
- varying float height;
3
13
4
- void animate( inout vec3 center) {
14
+ vec3 animatePosition( vec3 center) {
5
15
// modify center
6
16
float heightIntensity = center.y * 0.2 ;
7
17
center.x += sin (uTime * 5.0 + center.y) * 0.3 * heightIntensity;
8
18
9
19
// output y-coordinate
10
- height = center.y ;
20
+ return center;
11
21
}
12
22
13
- uniform vec3 view_position;
14
-
15
- uniform sampler2D splatColor;
16
-
17
- varying mediump vec2 texCoord;
18
- varying mediump vec4 color;
23
+ vec4 animateColor(float height, vec4 clr) {
24
+ float sineValue = abs (sin (uTime * 5.0 + height));
25
+
26
+ #ifdef CUTOUT
27
+ // in cutout mode, remove pixels along the wave
28
+ if (sineValue < 0.5 ) {
29
+ clr.a = 0.0 ;
30
+ }
31
+ #else
32
+ // in non-cutout mode, add a golden tint to the wave
33
+ vec3 gold = vec3 (1.0 , 0.85 , 0.0 );
34
+ float blend = smoothstep (0.9 , 1.0 , sineValue);
35
+ clr.xyz = mix (clr.xyz, gold, blend);
36
+ #endif
19
37
20
- mediump vec4 discardVec = vec4 (0.0 , 0.0 , 2.0 , 1.0 );
38
+ return clr;
39
+ }
21
40
22
- void main(void )
23
- {
24
- // calculate splat uv
25
- if (! calcSplatUV( )) {
41
+ void main(void ) {
42
+ // read gaussian center
43
+ SplatState state;
44
+ if (! readCenter(state )) {
26
45
gl_Position = discardVec;
27
46
return ;
28
47
}
29
48
30
- // get center
31
- vec3 center = getCenter();
32
-
33
- animate(center);
49
+ state.center = animatePosition(state.center);
34
50
35
- // handle transforms
36
- mat4 model_view = matrix_view * matrix_model;
37
- vec4 splat_cam = model_view * vec4 (center, 1.0 );
38
- vec4 splat_proj = matrix_projection * splat_cam;
39
-
40
- // cull behind camera
41
- if (splat_proj.z < - splat_proj.w) {
51
+ // project center to screen space
52
+ ProjectedState projState;
53
+ if (! projectCenter(state, projState)) {
42
54
gl_Position = discardVec;
43
55
return ;
44
56
}
45
57
46
- // get covariance
47
- vec3 covA, covB;
48
- getCovariance(covA, covB);
49
-
50
- vec4 v1v2 = calcV1V2(splat_cam.xyz, covA, covB, transpose (mat3 (model_view)));
51
-
52
- // get color
53
- color = texelFetch(splatColor, splatUV, 0 );
58
+ // read color
59
+ vec4 clr = readColor(state);
54
60
55
- // calculate scale based on alpha
56
- float scale = min (1.0 , sqrt (- log (1.0 / 255.0 / color.a)) / 2.0 );
57
-
58
- v1v2 *= scale;
59
-
60
- // early out tiny splats
61
- if (dot (v1v2.xy, v1v2.xy) < 4.0 && dot (v1v2.zw, v1v2.zw) < 4.0 ) {
62
- gl_Position = discardVec;
63
- return ;
64
- }
61
+ // evaluate spherical harmonics
62
+ #if SH_BANDS > 0
63
+ clr.xyz = max (clr.xyz + evalSH(state, projState), 0.0 );
64
+ #endif
65
65
66
- gl_Position = splat_proj + vec4 ((vertex_position.x * v1v2.xy + vertex_position.y * v1v2.zw) / viewport * splat_proj.w, 0 , 0 );
66
+ clr = animateColor(state.center.y, clr );
67
67
68
- texCoord = vertex_position.xy * scale / 2.0 ;
68
+ applyClipping(projState, clr.w) ;
69
69
70
- #ifdef USE_SH1
71
- vec4 worldCenter = matrix_model * vec4 (center, 1.0 );
72
- vec3 viewDir = normalize ((worldCenter.xyz / worldCenter.w - view_position) * mat3 (matrix_model));
73
- color.xyz = max (color.xyz + evalSH(viewDir), 0.0 );
74
- #endif
70
+ // write output
71
+ gl_Position = projState.cornerProj;
72
+ gaussianUV = projState.cornerUV;
73
+ gaussianColor = vec4 (prepareOutputFromGamma(clr.xyz), clr.w);
75
74
76
75
#ifndef DITHER_NONE
77
- id = float (splatId );
76
+ id = float (state.id );
78
77
#endif
79
- }
78
+ }
0 commit comments