Skip to content

Commit d4a48c2

Browse files
committed
sokol: 3d pipelines for 3d layouts only
previous change was rushed, do not violate feierabend for this. node orientation is borked.
1 parent d20f458 commit d4a48c2

File tree

5 files changed

+1859
-415
lines changed

5 files changed

+1859
-415
lines changed

draw/drw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum{
2929
DFmsaa = 1<<5,
3030
DFhidpi = 1<<6,
3131
DFnope = 1<<7,
32+
DF3d = 1<<8,
3233
};
3334
struct Drawing{
3435
int flags;

glsl/node.glsl

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,97 @@ in vec4 col;
1515
in float len;
1616
out vec4 c;
1717

18+
vec2 rotatez(vec2 v, float c, float s){
19+
return mat2(c, s, -s, c) * v;
20+
}
21+
22+
void main(){
23+
vec2 g = geom * vec2(len, 1.0);
24+
vec3 r = vec3(rotatez(g, dir.x, dir.y), 0.0);
25+
gl_Position = mvp * vec4(r + pos, 1.0);
26+
c = col;
27+
}
28+
@end
29+
30+
@fs fs
31+
precision mediump float;
32+
33+
in vec4 c;
34+
out vec4 fc;
35+
36+
void main(){
37+
fc = c;
38+
}
39+
@end
40+
41+
@vs vsoff
42+
@glsl_options fixup_clipspace
43+
44+
precision mediump float;
45+
46+
layout(binding=0) uniform Vparam {
47+
mat4 mvp;
48+
};
49+
in vec2 geom;
50+
in vec3 pos;
51+
in vec3 dir;
52+
in float len;
53+
flat out uint idx;
54+
55+
vec2 rotatez(vec2 v, float c, float s){
56+
return mat2(c, s, -s, c) * v;
57+
}
58+
59+
void main(){
60+
vec2 g = geom * vec2(len, 1.0);
61+
vec3 r = vec3(rotatez(g, dir.x, dir.y), 0.0);
62+
gl_Position = mvp * vec4(r + pos, 1.0);
63+
idx = gl_InstanceIndex + 1;
64+
}
65+
@end
66+
67+
@fs fsoff
68+
precision mediump float;
69+
70+
flat in uint idx;
71+
out uint fc;
72+
73+
void main(){
74+
fc = idx;
75+
}
76+
@end
77+
78+
@vs vs3d
79+
@glsl_options fixup_clipspace
80+
81+
precision mediump float;
82+
83+
layout(binding=0) uniform Vparam {
84+
mat4 mvp;
85+
};
86+
in vec3 geom;
87+
in vec3 pos;
88+
in vec3 dir;
89+
in vec4 col;
90+
in float len;
91+
out vec4 c;
92+
1893
vec3 rotate(vec3 v, float c, float s){
19-
float w = 1.0 - c;
2094
return mat3(c, s, 0, -s, c, 0, 0, 0, 1)
2195
* mat3(c, 0, s, 0, 1, 0, -s, 0, c)
2296
* mat3(1, 0, 0, 0, c, s, 0, -s, c)
2397
* v;
2498
}
2599

26100
void main(){
27-
vec3 g = vec3(geom * vec2(len, 1.0), 0.0);
101+
vec3 g = geom * vec3(len, 1.0, 1.0);
28102
vec3 r = rotate(g, dir.x, dir.y);
29103
gl_Position = mvp * vec4(r + pos, 1.0);
30104
c = col;
31105
}
32106
@end
33107

34-
@fs fs
108+
@fs fs3d
35109
precision mediump float;
36110

37111
in vec4 c;
@@ -42,37 +116,36 @@ void main(){
42116
}
43117
@end
44118

45-
@vs vsoff
119+
@vs vsoff3d
46120
@glsl_options fixup_clipspace
47121

48122
precision mediump float;
49123

50124
layout(binding=0) uniform Vparam {
51125
mat4 mvp;
52126
};
53-
in vec2 geom;
127+
in vec3 geom;
54128
in vec3 pos;
55129
in vec3 dir;
56130
in float len;
57131
flat out uint idx;
58132

59133
vec3 rotate(vec3 v, float c, float s){
60-
float w = 1.0 - c;
61134
return mat3(c, s, 0, -s, c, 0, 0, 0, 1)
62135
* mat3(c, 0, s, 0, 1, 0, -s, 0, c)
63136
* mat3(1, 0, 0, 0, c, s, 0, -s, c)
64137
* v;
65138
}
66139

67140
void main(){
68-
vec3 g = vec3(geom * vec2(len, 1.0), 0.0);
141+
vec3 g = geom * vec3(len, 1.0, 1.0);
69142
vec3 r = rotate(g, dir.x, dir.y);
70143
gl_Position = mvp * vec4(r + pos, 1.0);
71144
idx = gl_InstanceIndex + 1;
72145
}
73146
@end
74147

75-
@fs fsoff
148+
@fs fsoff3d
76149
precision mediump float;
77150

78151
flat in uint idx;
@@ -85,3 +158,5 @@ void main(){
85158

86159
@program idx vsoff fsoff
87160
@program s vs fs
161+
@program idx3d vsoff3d fsoff3d
162+
@program s3d vs3d fs3d

0 commit comments

Comments
 (0)