Overlay Engine: Wireframe: Remove geometry shader and fragment discard
This Simplify and should also speedup the drawing a tiny bit. We now discard the edges in the vertex shader by setting one of the verts at vec4(0,0,0,0) to not produce any fragment
This commit is contained in:
parent
0f521ca4d9
commit
3e241af3ae
|
@ -380,7 +380,6 @@ data_to_c_simple(engines/overlay/shaders/particle_frag.glsl SRC)
|
|||
data_to_c_simple(engines/overlay/shaders/sculpt_mask_vert.glsl SRC)
|
||||
data_to_c_simple(engines/overlay/shaders/volume_velocity_vert.glsl SRC)
|
||||
data_to_c_simple(engines/overlay/shaders/wireframe_vert.glsl SRC)
|
||||
data_to_c_simple(engines/overlay/shaders/wireframe_geom.glsl SRC)
|
||||
data_to_c_simple(engines/overlay/shaders/wireframe_frag.glsl SRC)
|
||||
|
||||
list(APPEND INC
|
||||
|
|
|
@ -100,7 +100,6 @@ extern char datatoc_particle_frag_glsl[];
|
|||
extern char datatoc_sculpt_mask_vert_glsl[];
|
||||
extern char datatoc_volume_velocity_vert_glsl[];
|
||||
extern char datatoc_wireframe_vert_glsl[];
|
||||
extern char datatoc_wireframe_geom_glsl[];
|
||||
extern char datatoc_wireframe_frag_glsl[];
|
||||
|
||||
extern char datatoc_gpu_shader_depth_only_frag_glsl[];
|
||||
|
@ -1216,10 +1215,6 @@ GPUShader *OVERLAY_shader_wireframe_select(void)
|
|||
datatoc_gpu_shader_common_obinfos_lib_glsl,
|
||||
datatoc_wireframe_vert_glsl,
|
||||
NULL},
|
||||
.geom = (const char *[]){sh_cfg->lib,
|
||||
datatoc_common_globals_lib_glsl,
|
||||
datatoc_wireframe_geom_glsl,
|
||||
NULL},
|
||||
.frag = (const char *[]){datatoc_gpu_shader_depth_only_frag_glsl, NULL},
|
||||
.defs = (const char *[]){sh_cfg->def, "#define SELECT_EDGES\n", NULL},
|
||||
});
|
||||
|
@ -1234,23 +1229,14 @@ GPUShader *OVERLAY_shader_wireframe(void)
|
|||
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
|
||||
if (!sh_data->wireframe) {
|
||||
sh_data->wireframe = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg->lib,
|
||||
datatoc_common_view_lib_glsl,
|
||||
datatoc_common_globals_lib_glsl,
|
||||
datatoc_gpu_shader_common_obinfos_lib_glsl,
|
||||
datatoc_wireframe_vert_glsl,
|
||||
NULL},
|
||||
.frag = (const char *[]){datatoc_common_view_lib_glsl, datatoc_wireframe_frag_glsl, NULL},
|
||||
/* Apple drivers does not support wide wires. Use geometry shader as a workaround. */
|
||||
#if USE_GEOM_SHADER_WORKAROUND
|
||||
.geom = (const char *[]){sh_cfg->lib,
|
||||
datatoc_common_globals_lib_glsl,
|
||||
datatoc_wireframe_geom_glsl,
|
||||
NULL},
|
||||
.defs = (const char *[]){sh_cfg->def, "#define USE_GEOM\n", NULL},
|
||||
#else
|
||||
.defs = (const char *[]){sh_cfg->def, NULL},
|
||||
#endif
|
||||
.vert = (const char *[]){sh_cfg->lib,
|
||||
datatoc_common_view_lib_glsl,
|
||||
datatoc_common_globals_lib_glsl,
|
||||
datatoc_gpu_shader_common_obinfos_lib_glsl,
|
||||
datatoc_wireframe_vert_glsl,
|
||||
NULL},
|
||||
.frag = (const char *[]){datatoc_common_view_lib_glsl, datatoc_wireframe_frag_glsl, NULL},
|
||||
.defs = (const char *[]){sh_cfg->def, NULL},
|
||||
});
|
||||
}
|
||||
return sh_data->wireframe;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
in vec3 finalColor;
|
||||
flat in float edgeSharpness;
|
||||
|
||||
flat in vec2 edgeStart;
|
||||
noperspective in vec2 edgePos;
|
||||
|
||||
|
@ -10,10 +8,6 @@ layout(location = 1) out vec4 lineOutput;
|
|||
|
||||
void main()
|
||||
{
|
||||
if (edgeSharpness < 0.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
lineOutput = pack_line_data(gl_FragCoord.xy, edgeStart, edgePos);
|
||||
fragColor.rgb = finalColor;
|
||||
fragColor.a = 1.0;
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
|
||||
/* This shader is only used for edge selection and OSX workaround for large wires. */
|
||||
|
||||
layout(lines) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
|
||||
in vec3 finalColor_g[];
|
||||
in float edgeSharpness_g[];
|
||||
|
||||
#ifndef SELECT_EDGES
|
||||
out vec3 finalColor;
|
||||
flat out float edgeSharpness;
|
||||
|
||||
flat out vec2 edgeStart;
|
||||
noperspective out vec2 edgePos;
|
||||
#endif
|
||||
|
||||
void do_vertex(const int i, float coord, vec2 offset)
|
||||
{
|
||||
#ifndef SELECT_EDGES
|
||||
/* TODO */
|
||||
edgePos = edgeStart = vec2(0);
|
||||
edgeSharpness = edgeSharpness_g[i];
|
||||
finalColor = finalColor_g[i];
|
||||
#endif
|
||||
gl_Position = gl_in[i].gl_Position;
|
||||
/* Multiply offset by 2 because gl_Position range is [-1..1]. */
|
||||
gl_Position.xy += offset * 2.0 * gl_Position.w;
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
world_clip_planes_set_clip_distance(gl_in[i].gl_ClipDistance);
|
||||
#endif
|
||||
EmitVertex();
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 ss_pos[2];
|
||||
ss_pos[0] = gl_in[0].gl_Position.xy / gl_in[0].gl_Position.w;
|
||||
ss_pos[1] = gl_in[1].gl_Position.xy / gl_in[1].gl_Position.w;
|
||||
|
||||
vec2 line = ss_pos[0] - ss_pos[1];
|
||||
line = abs(line) * sizeViewport.xy;
|
||||
|
||||
float half_size = sizePixel * 0.5;
|
||||
|
||||
vec3 edge_ofs = vec3(half_size * sizeViewportInv.xy, 0.0);
|
||||
|
||||
bool horizontal = line.x > line.y;
|
||||
edge_ofs = (horizontal) ? edge_ofs.zyz : edge_ofs.xzz;
|
||||
|
||||
if (edgeSharpness_g[0] < 0.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
do_vertex(0, half_size, edge_ofs.xy);
|
||||
do_vertex(0, -half_size, -edge_ofs.xy);
|
||||
do_vertex(1, half_size, edge_ofs.xy);
|
||||
do_vertex(1, -half_size, -edge_ofs.xy);
|
||||
|
||||
EndPrimitive();
|
||||
}
|
|
@ -1,37 +1,25 @@
|
|||
|
||||
uniform float wireStepParam;
|
||||
uniform bool useColoring;
|
||||
uniform bool isTransform;
|
||||
uniform bool isObjectColor;
|
||||
uniform bool isRandomColor;
|
||||
|
||||
in vec3 pos;
|
||||
in vec3 nor;
|
||||
in float wd; /* wiredata */
|
||||
|
||||
#ifndef SELECT_EDGES
|
||||
out vec3 finalColor;
|
||||
flat out vec2 edgeStart;
|
||||
noperspective out vec2 edgePos;
|
||||
#endif
|
||||
|
||||
float get_edge_sharpness(float wd)
|
||||
{
|
||||
return ((wd == 0.0) ? -1.5 : wd) + wireStepParam;
|
||||
}
|
||||
|
||||
/* Geometry shader version */
|
||||
#if defined(SELECT_EDGES) || defined(USE_GEOM)
|
||||
out vec3 finalColor_g;
|
||||
out float edgeSharpness_g;
|
||||
|
||||
#else /* USE_GEOM */
|
||||
|
||||
flat out vec2 edgeStart;
|
||||
noperspective out vec2 edgePos;
|
||||
|
||||
out vec3 finalColor;
|
||||
flat out float edgeSharpness;
|
||||
# define finalColor_g finalColor
|
||||
# define edgeSharpness_g edgeSharpness
|
||||
|
||||
#endif /* SELECT_EDGES */
|
||||
|
||||
uniform bool useColoring;
|
||||
uniform bool isTransform;
|
||||
uniform bool isObjectColor;
|
||||
uniform bool isRandomColor;
|
||||
|
||||
void wire_color_get(out vec3 rim_col, out vec3 wire_col)
|
||||
{
|
||||
int flag = int(abs(ObjectInfo.w));
|
||||
|
@ -115,12 +103,14 @@ void main()
|
|||
vec3 wpos = point_object_to_world(pos);
|
||||
gl_Position = point_world_to_ndc(wpos);
|
||||
|
||||
#if !(defined(SELECT_EDGES) || defined(USE_GEOM))
|
||||
if (get_edge_sharpness(wd) < 0.0) {
|
||||
/* Discard primitive. */
|
||||
gl_Position = vec4(0.0);
|
||||
}
|
||||
|
||||
#ifndef SELECT_EDGES
|
||||
/* Convert to screen position [0..sizeVp]. */
|
||||
edgePos = edgeStart = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy;
|
||||
#endif
|
||||
|
||||
edgeSharpness_g = get_edge_sharpness(wd);
|
||||
|
||||
vec3 rim_col, wire_col;
|
||||
if (isObjectColor || isRandomColor) {
|
||||
|
@ -136,7 +126,8 @@ void main()
|
|||
|
||||
vec3 final_front_col = mix(rim_col, wire_col, 0.4);
|
||||
vec3 final_rim_col = mix(rim_col, wire_col, 0.1);
|
||||
finalColor_g = mix(final_rim_col, final_front_col, facing);
|
||||
finalColor = mix(final_rim_col, final_front_col, facing);
|
||||
#endif
|
||||
|
||||
#ifdef USE_WORLD_CLIP_PLANES
|
||||
world_clip_planes_calc_clip_distance(wpos);
|
||||
|
|
Loading…
Reference in New Issue