mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Make TrueDot shading in 3d work
This commit is contained in:
parent
c372ef4aaa
commit
3f2d15986a
3 changed files with 58 additions and 21 deletions
|
@ -5,7 +5,11 @@ uniform mat4 perspective;
|
|||
|
||||
in vec4 color;
|
||||
in float scaled_aaw;
|
||||
in vec3 v_point;
|
||||
in vec3 point;
|
||||
in vec3 to_cam;
|
||||
in vec3 center;
|
||||
in float radius;
|
||||
in vec2 uv_coords;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
|
@ -13,9 +17,8 @@ out vec4 frag_color;
|
|||
#INSERT finalize_color.glsl
|
||||
|
||||
void main() {
|
||||
vec2 vect = 2.0 * gl_PointCoord.xy - vec2(1.0);
|
||||
float r = length(vect);
|
||||
if(r > 1.0 + scaled_aaw) discard;
|
||||
float r = length(uv_coords.xy);
|
||||
if(r > 1.0) discard;
|
||||
|
||||
frag_color = color;
|
||||
|
||||
|
@ -24,9 +27,9 @@ void main() {
|
|||
}
|
||||
|
||||
if(shading != vec3(0.0)){
|
||||
vec3 normal = vec3(vect, sqrt(1 - r * r));
|
||||
normal = (perspective * vec4(normal, 0.0)).xyz;
|
||||
frag_color = finalize_color(frag_color, v_point, normal);
|
||||
vec3 point_3d = point + radius * sqrt(1 - r * r) * to_cam;
|
||||
vec3 normal = normalize(point_3d - center);
|
||||
frag_color = finalize_color(frag_color, point_3d, normal);
|
||||
}
|
||||
|
||||
frag_color.a *= smoothstep(1.0, 1.0 - scaled_aaw, r);
|
||||
|
|
44
manimlib/shaders/true_dot/geom.glsl
Normal file
44
manimlib/shaders/true_dot/geom.glsl
Normal file
|
@ -0,0 +1,44 @@
|
|||
#version 330
|
||||
|
||||
layout (points) in;
|
||||
layout (triangle_strip, max_vertices = 4) out;
|
||||
|
||||
uniform float pixel_size;
|
||||
uniform float anti_alias_width;
|
||||
uniform float frame_scale;
|
||||
uniform vec3 camera_position;
|
||||
|
||||
in vec3 v_point[1];
|
||||
in float v_radius[1];
|
||||
in vec4 v_rgba[1];
|
||||
|
||||
out vec4 color;
|
||||
out float scaled_aaw;
|
||||
out vec3 point;
|
||||
out vec3 to_cam;
|
||||
out vec3 center;
|
||||
out float radius;
|
||||
out vec2 uv_coords;
|
||||
|
||||
#INSERT emit_gl_Position.glsl
|
||||
|
||||
void main(){
|
||||
color = v_rgba[0];
|
||||
radius = v_radius[0];
|
||||
center = v_point[0];
|
||||
scaled_aaw = (anti_alias_width * pixel_size) / v_radius[0];
|
||||
|
||||
to_cam = normalize(camera_position - v_point[0]);
|
||||
vec3 right = v_radius[0] * normalize(cross(vec3(0, 1, 1), to_cam));
|
||||
vec3 up = v_radius[0] * normalize(cross(to_cam, right));
|
||||
|
||||
for(int i = -1; i < 2; i += 2){
|
||||
for(int j = -1; j < 2; j += 2){
|
||||
point = v_point[0] + i * right + j * up;
|
||||
uv_coords = vec2(i, j);
|
||||
emit_gl_Position(point);
|
||||
EmitVertex();
|
||||
}
|
||||
}
|
||||
EndPrimitive();
|
||||
}
|
|
@ -1,26 +1,16 @@
|
|||
#version 330
|
||||
|
||||
uniform float pixel_size;
|
||||
uniform float anti_alias_width;
|
||||
|
||||
in vec3 point;
|
||||
in float radius;
|
||||
in vec4 rgba;
|
||||
|
||||
out vec4 color;
|
||||
out float scaled_aaw;
|
||||
out vec3 v_point;
|
||||
out vec3 light_pos;
|
||||
out float v_radius;
|
||||
out vec4 v_rgba;
|
||||
|
||||
#INSERT emit_gl_Position.glsl
|
||||
|
||||
void main(){
|
||||
v_point = point;
|
||||
color = rgba;
|
||||
scaled_aaw = (anti_alias_width * pixel_size) / radius;
|
||||
|
||||
emit_gl_Position(point);
|
||||
float z = -10 * gl_Position.z;
|
||||
float scaled_radius = radius * 1.0 / (1.0 - z);
|
||||
gl_PointSize = 2 * ((scaled_radius / pixel_size) + anti_alias_width);
|
||||
v_radius = radius;
|
||||
v_rgba = rgba;
|
||||
}
|
Loading…
Add table
Reference in a new issue