OpenGL: new built-in shader for smooth round 3D points w/ outline
This commit is contained in:
parent
36d2365ac3
commit
61ca73ea10
|
@ -149,6 +149,7 @@ data_to_c_simple(shaders/gpu_shader_point_varying_color_frag.glsl SRC)
|
|||
data_to_c_simple(shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_point_varying_size_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_3D_point_uniform_size_outline_smooth_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_smooth_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_outline_smooth_vert.glsl SRC)
|
||||
|
|
|
@ -112,6 +112,7 @@ typedef enum GPUBuiltinShader {
|
|||
GPU_SHADER_2D_POINT_VARYING_SIZE_VARYING_COLOR,
|
||||
GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR,
|
||||
GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR,
|
||||
GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_SMOOTH,
|
||||
GPU_SHADER_3D_POINT_VARYING_SIZE_UNIFORM_COLOR,
|
||||
GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
|
||||
} GPUBuiltinShader;
|
||||
|
|
|
@ -69,6 +69,7 @@ extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
|
|||
extern char datatoc_gpu_shader_3D_point_fixed_size_varying_color_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_point_varying_size_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_3D_point_uniform_size_outline_smooth_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_2D_point_varying_size_varying_color_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_2D_point_uniform_size_smooth_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_2D_point_uniform_size_outline_smooth_vert_glsl[];
|
||||
|
@ -126,6 +127,7 @@ static struct GPUShadersGlobal {
|
|||
GPUShader *point_fixed_size_varying_color_3D;
|
||||
GPUShader *point_varying_size_uniform_color_3D;
|
||||
GPUShader *point_varying_size_varying_color_3D;
|
||||
GPUShader *point_uniform_size_uniform_color_outline_smooth_3D;
|
||||
} shaders;
|
||||
} GG = {{NULL}};
|
||||
|
||||
|
@ -793,6 +795,14 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
|||
NULL, NULL, NULL, 0, 0, 0);
|
||||
retval = GG.shaders.point_varying_size_varying_color_3D;
|
||||
break;
|
||||
case GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_SMOOTH:
|
||||
if (!GG.shaders.point_uniform_size_uniform_color_outline_smooth_3D)
|
||||
GG.shaders.point_uniform_size_uniform_color_outline_smooth_3D = GPU_shader_create(
|
||||
datatoc_gpu_shader_3D_point_uniform_size_outline_smooth_vert_glsl,
|
||||
datatoc_gpu_shader_point_uniform_color_outline_smooth_frag_glsl,
|
||||
NULL, NULL, NULL, 0, 0, 0);
|
||||
retval = GG.shaders.point_uniform_size_uniform_color_outline_smooth_3D;
|
||||
break;
|
||||
}
|
||||
|
||||
if (retval == NULL)
|
||||
|
@ -992,6 +1002,11 @@ void GPU_shader_free_builtin_shaders(void)
|
|||
GG.shaders.point_varying_size_varying_color_3D = NULL;
|
||||
}
|
||||
|
||||
if (GG.shaders.point_uniform_size_uniform_color_outline_smooth_3D) {
|
||||
GPU_shader_free(GG.shaders.point_uniform_size_uniform_color_outline_smooth_3D);
|
||||
GG.shaders.point_uniform_size_uniform_color_outline_smooth_3D = NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2 * MAX_FX_SHADERS; ++i) {
|
||||
if (GG.shaders.fx_shaders[i]) {
|
||||
GPU_shader_free(GG.shaders.fx_shaders[i]);
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
uniform float size;
|
||||
uniform float outlineWidth;
|
||||
|
||||
#if __VERSION__ == 120
|
||||
attribute vec3 pos;
|
||||
varying vec4 radii;
|
||||
#else
|
||||
in vec3 pos;
|
||||
out vec4 radii;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
gl_PointSize = size;
|
||||
|
||||
// calculate concentric radii in pixels
|
||||
float radius = 0.5 * size;
|
||||
|
||||
// start at the outside and progress toward the center
|
||||
radii[0] = radius;
|
||||
radii[1] = radius - 1.0;
|
||||
radii[2] = radius - outlineWidth;
|
||||
radii[3] = radius - outlineWidth - 1.0;
|
||||
|
||||
// convert to PointCoord units
|
||||
radii /= size;
|
||||
}
|
Loading…
Reference in New Issue