Skip to content

Commit e18fdd2

Browse files
committed
Formatting shaders
1 parent b830b7d commit e18fdd2

16 files changed

+199
-189
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BasedOnStyle: Microsoft

manim/renderer/shaders/default/frag.glsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
uniform vec4 u_color;
44
out vec4 frag_color;
55

6-
void main() {
7-
frag_color = u_color;
6+
void main()
7+
{
8+
frag_color = u_color;
89
}

manim/renderer/shaders/default/vert.glsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ uniform mat4 u_model_matrix;
55
uniform mat4 u_view_matrix;
66
uniform mat4 u_projection_matrix;
77

8-
void main() {
8+
void main()
9+
{
910
gl_Position = u_projection_matrix * u_view_matrix * u_model_matrix * vec4(in_vert, 1.0);
1011
}

manim/renderer/shaders/include/camera_uniform_declarations.glsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CAMERA_GLSL
22
#define CAMERA_GLSL
3-
layout (std140) uniform ubo_camera {
3+
layout(std140) uniform ubo_camera
4+
{
45
// mat4 u_projection_view_matrix; # TODO: convert to mat4 instead of the following...
56
vec2 frame_shape;
67
vec3 camera_center;

manim/renderer/shaders/include/finalize_color.glsl

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
#ifndef FINALIZE_COLOR_GLSL
22
#define FINALIZE_COLOR_GLSL
33

4-
vec3 float_to_color(float value, float min_val, float max_val, vec3[9] colormap_data){
4+
vec3 float_to_color(float value, float min_val, float max_val, vec3[9] colormap_data)
5+
{
56
float alpha = clamp((value - min_val) / (max_val - min_val), 0.0, 1.0);
67
int disc_alpha = min(int(alpha * 8), 7);
7-
return mix(
8-
colormap_data[disc_alpha],
9-
colormap_data[disc_alpha + 1],
10-
8.0 * alpha - disc_alpha
11-
);
8+
return mix(colormap_data[disc_alpha], colormap_data[disc_alpha + 1], 8.0 * alpha - disc_alpha);
129
}
1310

14-
15-
vec4 add_light(vec4 color,
16-
vec3 point,
17-
vec3 unit_normal,
18-
vec3 light_coords,
19-
float gloss,
20-
float shadow){
11+
vec4 add_light(vec4 color, vec3 point, vec3 unit_normal, vec3 light_coords, float gloss, float shadow)
12+
{
2113
if (gloss == 0.0 && shadow == 0.0 && reflectiveness == 0.0)
2214
return color;
2315

2416
// TODO, do we actually want this? It effectively treats surfaces as two-sided
25-
if(unit_normal.z < 0){
26-
unit_normal *= -1;
17+
if (unit_normal.z < 0)
18+
{
19+
unit_normal *= -1;
2720
}
2821

2922
// TODO, read this in as a uniform?
@@ -36,18 +29,11 @@ vec4 add_light(vec4 color,
3629
float shine = gloss * exp(-3 * pow(1 - dot_prod, 2));
3730
float dp2 = dot(normalize(to_light), unit_normal);
3831
float darkening = mix(1, max(dp2, 0), shadow);
39-
return vec4(
40-
darkening * mix(color.rgb, vec3(1.0), shine),
41-
color.a
42-
);
32+
return vec4(darkening * mix(color.rgb, vec3(1.0), shine), color.a);
4333
}
4434

45-
vec4 finalize_color(vec4 color,
46-
vec3 point,
47-
vec3 unit_normal,
48-
vec3 light_coords,
49-
float gloss,
50-
float shadow){
35+
vec4 finalize_color(vec4 color, vec3 point, vec3 unit_normal, vec3 light_coords, float gloss, float shadow)
36+
{
5137
///// INSERT COLOR FUNCTION HERE /////
5238
// The line above may be replaced by arbitrary code snippets, as per
5339
// the method Mobject.set_color_by_code

manim/renderer/shaders/include/get_gl_Position.glsl

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,35 @@
66

77
const vec2 DEFAULT_FRAME_SHAPE = vec2(8.0 * 16.0 / 9.0, 8.0);
88

9-
float perspective_scale_factor(float z, float focal_distance) {
10-
return max(0.0, focal_distance / (focal_distance - z));
9+
float perspective_scale_factor(float z, float focal_distance)
10+
{
11+
return max(0.0, focal_distance / (focal_distance - z));
1112
}
1213

13-
vec4 get_gl_Position(vec3 point) {
14-
vec4 result = vec4(point, 1.0);
15-
if (!bool(is_fixed_in_frame)) {
16-
result.x *= 2.0 / frame_shape.x;
17-
result.y *= 2.0 / frame_shape.y;
18-
float psf = perspective_scale_factor(result.z, focal_distance);
19-
if (psf > 0) {
20-
result.xy *= psf;
21-
// TODO, what's the better way to do this?
22-
// This is to keep vertices too far out of frame from getting cut.
23-
// TODO This will be done by the clipping plane in the future with the
24-
// transformation matrix result.z += z_shift;
25-
result.z *= (1.0 / 100.0);
14+
vec4 get_gl_Position(vec3 point)
15+
{
16+
vec4 result = vec4(point, 1.0);
17+
if (!bool(is_fixed_in_frame))
18+
{
19+
result.x *= 2.0 / frame_shape.x;
20+
result.y *= 2.0 / frame_shape.y;
21+
float psf = perspective_scale_factor(result.z, focal_distance);
22+
if (psf > 0)
23+
{
24+
result.xy *= psf;
25+
// TODO, what's the better way to do this?
26+
// This is to keep vertices too far out of frame from getting cut.
27+
// TODO This will be done by the clipping plane in the future with the
28+
// transformation matrix result.z += z_shift;
29+
result.z *= (1.0 / 100.0);
30+
}
2631
}
27-
} else {
28-
result.x *= 2.0 / DEFAULT_FRAME_SHAPE.x;
29-
result.y *= 2.0 / DEFAULT_FRAME_SHAPE.y;
30-
}
31-
result.z *= -1;
32-
return result;
32+
else
33+
{
34+
result.x *= 2.0 / DEFAULT_FRAME_SHAPE.x;
35+
result.y *= 2.0 / DEFAULT_FRAME_SHAPE.y;
36+
}
37+
result.z *= -1;
38+
return result;
3339
}
3440
#endif // GET_GL_POSITION_GLSL

manim/renderer/shaders/include/mobject_uniform_declarations.glsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#ifndef MOBJECT_GLSL
22
#define MOBJECT_GLSL
33

4-
layout (std140) uniform ubo_mobject {
4+
layout(std140) uniform ubo_mobject
5+
{
56
vec3 light_source_position;
67
float gloss;
78
float shadow;

manim/renderer/shaders/include/position_point_into_frame.glsl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
#include "./camera_uniform_declarations.glsl"
55
#include "./mobject_uniform_declarations.glsl"
66

7-
vec3 rotate_point_into_frame(vec3 point){
8-
if(bool(is_fixed_in_frame)){
7+
vec3 rotate_point_into_frame(vec3 point)
8+
{
9+
if (bool(is_fixed_in_frame))
10+
{
911
return point;
1012
}
1113
return camera_rotation * point;
1214
}
1315

14-
15-
vec3 position_point_into_frame(vec3 point){
16-
if(bool(is_fixed_in_frame)){
16+
vec3 position_point_into_frame(vec3 point)
17+
{
18+
if (bool(is_fixed_in_frame))
19+
{
1720
return point;
1821
}
19-
if(bool(is_fixed_orientation)){
22+
if (bool(is_fixed_orientation))
23+
{
2024
vec3 new_center = rotate_point_into_frame(fixed_orientation_center);
2125
return point + (new_center - fixed_orientation_center);
2226
}

manim/renderer/shaders/quadratic_bezier_fill/frag.glsl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ uniform vec2 pixel_shape;
55
uniform float index;
66

77
in vec4 color;
8-
in float fill_all; // Either 0 or 1e
8+
in float fill_all; // Either 0 or 1e
99

1010
in float orientation;
1111
in vec2 uv_coords;
@@ -18,8 +18,10 @@ layout(location = 1) out vec4 stencil_value;
1818

1919
#define ANTI_ALIASING
2020

21-
float sdf(){
22-
if(bezier_degree < 2){
21+
float sdf()
22+
{
23+
if (bezier_degree < 2)
24+
{
2325
return abs(uv_coords[1]);
2426
}
2527
vec2 p = uv_coords;
@@ -33,10 +35,11 @@ float sdf(){
3335
#endif
3436
}
3537

36-
37-
void main() {
38+
void main()
39+
{
3840
gl_FragDepth = gl_FragCoord.z;
39-
if (color.a == 0) discard;
41+
if (color.a == 0)
42+
discard;
4043

4144
float previous_index =
4245
texture2D(stencil_texture, vec2(gl_FragCoord.x / pixel_shape.x, gl_FragCoord.y / pixel_shape.y)).r;
@@ -55,7 +58,8 @@ void main() {
5558
stencil_value.rgb = vec3(index);
5659
stencil_value.a = 1.0;
5760
frag_color = color;
58-
if (fill_all == 1.0) return;
61+
if (fill_all == 1.0)
62+
return;
5963
#ifdef ANTI_ALIASING
6064
float fac = max(0.0, min(1.0, 0.5 - sdf()));
6165
frag_color.a *= fac; // Anti-aliasing

manim/renderer/shaders/quadratic_bezier_fill/geom.glsl

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

3-
layout (triangles) in;
4-
layout (triangle_strip, max_vertices = 5) out;
3+
layout(triangles) in;
4+
layout(triangle_strip, max_vertices = 5) out;
55

66
// Needed for get_gl_Position
77
// uniform vec2 frame_shape;
@@ -20,12 +20,12 @@ out vec2 uv_coords;
2020
out float bezier_degree;
2121

2222
// Analog of import for manim only
23-
#include "../include/mobject_uniform_declarations.glsl"
2423
#include "../include/camera_uniform_declarations.glsl"
25-
#include "../include/quadratic_bezier_geometry_functions.glsl"
24+
#include "../include/finalize_color.glsl"
2625
#include "../include/get_gl_Position.glsl"
2726
#include "../include/get_unit_normal.glsl"
28-
#include "../include/finalize_color.glsl"
27+
#include "../include/mobject_uniform_declarations.glsl"
28+
#include "../include/quadratic_bezier_geometry_functions.glsl"
2929

3030
const vec2 uv_coords_arr[3] = vec2[3](vec2(0, 0), vec2(0.5, 0), vec2(1, 1));
3131

@@ -39,21 +39,20 @@ void emit_vertex_wrapper(vec3 point, int index)
3939

4040
void emit_simple_triangle()
4141
{
42-
for(int i = 0; i < 3; i++)
42+
for (int i = 0; i < 3; i++)
4343
{
4444
emit_vertex_wrapper(bp[i], i);
4545
}
4646
EndPrimitive();
4747
}
4848

49-
void main(){
49+
void main()
50+
{
5051
// If vert indices are sequential, don't fill all
51-
fill_all = float(
52-
(v_vert_index[1] - v_vert_index[0]) != 1.0 ||
53-
(v_vert_index[2] - v_vert_index[1]) != 1.0
54-
);
52+
fill_all = float((v_vert_index[1] - v_vert_index[0]) != 1.0 || (v_vert_index[2] - v_vert_index[1]) != 1.0);
5553

56-
if(fill_all == 1.0){
54+
if (fill_all == 1.0)
55+
{
5756
emit_simple_triangle();
5857
return;
5958
}
@@ -63,7 +62,8 @@ void main(){
6362
vec3 local_unit_normal = get_unit_normal(new_bp);
6463
orientation = sign(dot(v_global_unit_normal[0], local_unit_normal));
6564

66-
if(bezier_degree >= 1){
65+
if (bezier_degree >= 1)
66+
{
6767
emit_simple_triangle();
6868
}
6969
// Don't emit any vertices for bezier_degree 0

manim/renderer/shaders/quadratic_bezier_fill/vert.glsl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "../include/camera_uniform_declarations.glsl"
44
#include "../include/mobject_uniform_declarations.glsl"
5+
#include "../include/position_point_into_frame.glsl"
56

67
in vec3 point;
78
in vec3 unit_normal;
@@ -13,10 +14,8 @@ out vec4 v_color;
1314
out float v_vert_index;
1415
out vec3 v_global_unit_normal;
1516

16-
// Analog of import for manim only
17-
#include "../include/position_point_into_frame.glsl"
18-
19-
void main(){
17+
void main()
18+
{
2019
bp = position_point_into_frame(point.xyz);
2120
v_global_unit_normal = rotate_point_into_frame(unit_normal);
2221
v_color = color;

0 commit comments

Comments
 (0)