Skip to content

Commit 4662144

Browse files
committed
rearchitecting for port
1 parent 23e58cc commit 4662144

3 files changed

Lines changed: 179 additions & 133 deletions

File tree

public/shader.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#version 300 es
22
precision highp float;
33

4-
in vec3 vBarycentric;
5-
in vec3 vColor;
4+
in vec3 v_barycentric;
5+
in vec3 v_color;
66

77
out vec4 fragColor;
88

99
// Controls how thick the wireframe edges are
10-
uniform float uLineWidth; // e.g. 0.05
10+
uniform float u_lineWidth; // e.g. 0.05
1111

1212
// Helper: find min distance to an edge
1313
float edgeFactor() {
14-
vec3 d = fwidth(vBarycentric);
15-
vec3 a3 = smoothstep(vec3(0.0), d * uLineWidth, vBarycentric);
14+
vec3 d = fwidth(v_barycentric);
15+
vec3 a3 = smoothstep(vec3(0.0), d * u_lineWidth, v_barycentric);
1616
return min(min(a3.x, a3.y), a3.z);
1717
}
1818

@@ -21,7 +21,7 @@ void main() {
2121

2222
// edge ~ 0 near edges, ~1 inside face
2323
if (edge < 0.5) {
24-
fragColor = vec4(vColor, 1.0); // draw edge
24+
fragColor = vec4(v_color, 1.0); // draw edge
2525
} else {
2626
discard; // transparent background
2727
}

public/shader.vs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
precision highp float;
33

44
// Cube vertex position (object space)
5-
in vec3 aPosition;
5+
in vec3 a_position;
66

77
// Barycentric coordinates for wireframe effect
8-
in vec3 aBarycentric;
8+
in vec3 a_barycentric;
99

1010
// Instance attributes
11-
uniform mat4 uProjection;
12-
uniform mat4 uView;
13-
uniform mat4 uModel; // base model transform for cube
14-
uniform vec3 uCubeOffset; // per-instance offset (grid position)
15-
uniform float uCubeScale; // per-instance scale
16-
uniform vec3 uCubeColor; // per-instance color
11+
uniform mat4 u_projection;
12+
uniform mat4 u_view;
13+
uniform mat4 u_model; // base model transform for cube
14+
uniform vec3 u_cubeOffset; // per-instance offset (grid position)
15+
uniform float u_cubeScale; // per-instance scale
16+
uniform vec3 u_cubeColor; // per-instance color
1717

1818
// Pass to fragment shader
19-
out vec3 vBarycentric;
20-
out vec3 vColor;
19+
out vec3 v_barycentric;
20+
out vec3 v_color;
2121

2222
void main() {
2323
// Apply scale and offset
24-
vec3 pos = aPosition * uCubeScale + uCubeOffset;
24+
vec3 pos = a_position * u_cubeScale + u_cubeOffset;
2525

26-
gl_Position = uProjection * uView * uModel * vec4(pos, 1.0);
26+
gl_Position = u_projection * u_view * u_model * vec4(pos, 1.0);
2727

28-
vBarycentric = aBarycentric;
29-
vColor = uCubeColor;
28+
v_barycentric = a_barycentric;
29+
v_color = u_cubeColor;
3030
}

0 commit comments

Comments
 (0)