Add 3D version of dashed line shader.
This is actually nearly same code as 2D version, maybe we can deduplicate that later?
This commit is contained in:
parent
224f148e22
commit
bb43dff935
|
@ -150,6 +150,8 @@ data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC)
|
|||
data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_normal_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_line_dashed_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_line_dashed_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_normal_smooth_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_smooth_color_frag.glsl SRC)
|
||||
|
|
|
@ -143,6 +143,7 @@ typedef enum GPUBuiltinShader {
|
|||
GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
|
||||
/* lines */
|
||||
GPU_SHADER_2D_LINE_DASHED_COLOR,
|
||||
GPU_SHADER_3D_LINE_DASHED_COLOR,
|
||||
/* lamp drawing */
|
||||
GPU_SHADER_3D_GROUNDPOINT,
|
||||
GPU_SHADER_3D_GROUNDLINE,
|
||||
|
|
|
@ -109,6 +109,8 @@ extern char datatoc_gpu_shader_2D_point_uniform_size_varying_color_outline_aa_ve
|
|||
|
||||
extern char datatoc_gpu_shader_2D_line_dashed_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_line_dashed_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_line_dashed_frag_glsl[];
|
||||
|
||||
extern char datatoc_gpu_shader_edges_front_back_persp_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_edges_front_back_persp_geom_glsl[];
|
||||
|
@ -709,6 +711,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
|||
|
||||
[GPU_SHADER_2D_LINE_DASHED_COLOR] = { datatoc_gpu_shader_2D_line_dashed_vert_glsl,
|
||||
datatoc_gpu_shader_2D_line_dashed_frag_glsl },
|
||||
[GPU_SHADER_3D_LINE_DASHED_COLOR] = { datatoc_gpu_shader_3D_line_dashed_vert_glsl,
|
||||
datatoc_gpu_shader_3D_line_dashed_frag_glsl },
|
||||
|
||||
[GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR] =
|
||||
{ datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl,
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
/* Same code as 2D version actually, maybe we should deduplicate that? */
|
||||
|
||||
#if __VERSION__ == 120
|
||||
noperspective varying float distance_along_line;
|
||||
#define fragColor gl_FragColor
|
||||
#else
|
||||
noperspective in float distance_along_line;
|
||||
out vec4 fragColor;
|
||||
#endif
|
||||
|
||||
uniform float dash_width;
|
||||
uniform float dash_width_on;
|
||||
uniform vec4 color1;
|
||||
uniform vec4 color2;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (mod(distance_along_line, dash_width) <= dash_width_on) {
|
||||
fragColor = color1;
|
||||
} else {
|
||||
fragColor = color2;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
/* Note: nearly the same code as for 2D version... Maybe we could deduplicate? */
|
||||
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
uniform vec2 viewport_size;
|
||||
|
||||
#if __VERSION__ == 120
|
||||
attribute vec3 pos;
|
||||
attribute vec3 line_origin; // = pos for one vertex of the line
|
||||
noperspective varying float distance_along_line;
|
||||
#else
|
||||
in vec3 pos;
|
||||
in vec3 line_origin;
|
||||
noperspective out float distance_along_line;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
|
||||
vec4 point = ModelViewProjectionMatrix * vec4(line_origin, 1.0);
|
||||
vec2 ref_point = (point.xy / point.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
|
||||
ref_point = ref_point * viewport_size; // <- fragment coordinates.
|
||||
|
||||
vec2 curr_point = (gl_Position.xy / gl_Position.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
|
||||
curr_point = curr_point * viewport_size; // <- fragment coordinates.
|
||||
|
||||
distance_along_line = distance(ref_point, curr_point);
|
||||
|
||||
/* Note: we could also use similar approach as diag_stripes_frag, but this would give us dashed 'anchored'
|
||||
* to the screen, and not to one end of the line... */
|
||||
}
|
Loading…
Reference in New Issue