Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aeae877

Browse files
committed
2d scale rot
1 parent 7617ddb commit aeae877

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/shader/projection.comp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ layout(std430, set = 2, binding = 0) writeonly buffer DrawIndirect {
4848
};
4949

5050
layout(std430, set = 2, binding = 1) writeonly buffer Instances {
51-
vec4 instances[]; // (N, 12). 3 for ndc position, 1 padding, 4 for scale rot, 4 for color.
51+
vec4 instances[]; // (N, 12). 3 for ndc position, 1 padding, 4 for rot scale, 4 for color.
5252
};
5353

5454
layout(std430, set = 2, binding = 2) buffer VisiblePointCount {
@@ -130,10 +130,14 @@ void main() {
130130
float D = sqrt((a - b) * (a - b) + 4.f * c * c);
131131
float s0 = sqrt(0.5f * (a + b + D));
132132
float s1 = sqrt(0.5f * (a + b - D));
133-
// decompose to R^T S^2 R
133+
// decompose to R S^2 R^T
134134
float sin2t = 2.f * c / D;
135135
float cos2t = (a - b) / D;
136136
float theta = atan(sin2t, cos2t) / 2.f;
137+
float cos_theta = cos(theta);
138+
float sin_theta = sin(theta);
139+
// R*S
140+
mat2 rot_scale = mat2(s0 * cos_theta, s0 * sin_theta, -s1 * sin_theta, s1 * cos_theta);
137141

138142
pos = projection * pos;
139143
pos = pos / pos.w;
@@ -184,6 +188,6 @@ void main() {
184188
float opacity = gaussian_opacity[id];
185189

186190
instances[inverse_id * 3 + 0].xyz = pos.xyz;
187-
instances[inverse_id * 3 + 1] = vec4(s0, s1, cos(theta), sin(theta));
191+
instances[inverse_id * 3 + 1] = vec4(rot_scale[0], rot_scale[1]);
188192
instances[inverse_id * 3 + 2] = vec4(color, opacity);
189193
}

src/shader/splat.vert

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 460
22

33
layout (std430, set = 1, binding = 1) readonly buffer Instances {
4-
vec4 instances[]; // (N, 12). 3 for ndc position, 1 padding, 4 for scale rot, 4 for color.
4+
vec4 instances[]; // (N, 12). 3 for ndc position, 1 padding, 4 for rot scale, 4 for color.
55
};
66

77
layout (location = 0) out vec4 out_color;
@@ -11,19 +11,16 @@ void main() {
1111
// index [0,1,2,2,1,3], 4 vertices for a splat.
1212
int index = gl_VertexIndex / 4;
1313
vec3 ndc_position = instances[index * 3 + 0].xyz;
14-
vec2 scale = instances[index * 3 + 1].xy;
15-
vec2 rot = instances[index * 3 + 1].zw;
14+
mat2 rot_scale = mat2(instances[index * 3 + 1].xy, instances[index * 3 + 1].zw);
1615
vec4 color = instances[index * 3 + 2];
1716

1817
// quad positions (-1, -1), (-1, 1), (1, -1), (1, 1), ccw in screen space.
1918
int vert_index = gl_VertexIndex % 4;
2019
vec2 position = vec2(vert_index / 2, vert_index % 2) * 2.f - 1.f;
2120

22-
mat2 rot2d = mat2(rot.x, rot.y, -rot.y, rot.x);
23-
2421
float confidence_radius = 3.f;
2522

26-
gl_Position = vec4(ndc_position + vec3(rot2d * (scale * position) * confidence_radius, 0.f), 1.f);
23+
gl_Position = vec4(ndc_position + vec3(rot_scale * position * confidence_radius, 0.f), 1.f);
2724
out_color = color;
2825
out_position = position * confidence_radius;
2926
}

0 commit comments

Comments
 (0)