[Bf-blender-cvs] [f92e92b1c04] blender2.8: Object Mode: Outlines: Use textureGather extension if available.
Clément Foucault
noreply at git.blender.org
Mon Apr 16 22:48:24 CEST 2018
Commit: f92e92b1c041582f5d31620f734951daeee3d552
Author: Clément Foucault
Date: Mon Apr 16 22:53:44 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBf92e92b1c041582f5d31620f734951daeee3d552
Object Mode: Outlines: Use textureGather extension if available.
This has very little impact (only had 12.5% perf improvment on Nvidia for this specific pass).
But it's an improvement nontheless!
===================================================================
M source/blender/draw/modes/object_mode.c
M source/blender/draw/modes/shaders/object_outline_detect_frag.glsl
===================================================================
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
index 0d9e46d1268..4bdd1444898 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -346,7 +346,7 @@ static void OBJECT_engine_init(void *vedata)
datatoc_common_fullscreen_vert_glsl, NULL,
datatoc_object_outline_detect_frag_glsl,
datatoc_common_globals_lib_glsl,
- NULL);
+ "#extension GL_ARB_texture_gather : enable\n");
e_data.outline_fade_sh = DRW_shader_create_fullscreen(datatoc_object_outline_expand_frag_glsl, NULL);
diff --git a/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl
index 6b0f66d7c94..a7e68485b86 100644
--- a/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl
+++ b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl
@@ -34,25 +34,28 @@ vec4 convert_id_to_color(int id)
}
}
-const ivec2 ofs[4] = ivec2[4](
- ivec2( 1, 0), ivec2( 0, 1),
- ivec2(-1, 0), ivec2( 0, -1)
-);
-
void main()
{
ivec2 texel = ivec2(gl_FragCoord.xy);
- vec2 uv = gl_FragCoord.xy / vec2(textureSize(outlineId, 0).xy);
+#ifdef GL_ARB_texture_gather
+ vec2 texel_size = 1.0 / vec2(textureSize(outlineId, 0).xy);
+ vec2 uv1 = gl_FragCoord.xy * texel_size - texel_size;
+ vec2 uv2 = gl_FragCoord.xy * texel_size;
+
+ /* Samples order is CW starting from top left. */
+ uvec4 tmp1 = textureGather(outlineId, uv1);
+ uvec4 tmp2 = textureGather(outlineId, uv2);
+
+ uint ref_id = tmp1.y;
+ uvec4 id = uvec4(tmp1.xz, tmp2.xz);
+#else
uvec4 id;
uint ref_id = texelFetch(outlineId, texel, 0).r;
-#if 0 /* commented out until being tested */
- id = textureGatherOffsets(outlineId, uv, ofs);
-#else
- id.x = texelFetchOffset(outlineId, texel, 0, ofs[0]).r;
- id.y = texelFetchOffset(outlineId, texel, 0, ofs[1]).r;
- id.z = texelFetchOffset(outlineId, texel, 0, ofs[2]).r;
- id.w = texelFetchOffset(outlineId, texel, 0, ofs[3]).r;
+ id.x = texelFetchOffset(outlineId, texel, 0, ivec2( 1, 0)).r;
+ id.y = texelFetchOffset(outlineId, texel, 0, ivec2( 0, 1)).r;
+ id.z = texelFetchOffset(outlineId, texel, 0, ivec2(-1, 0)).r;
+ id.w = texelFetchOffset(outlineId, texel, 0, ivec2( 0, -1)).r;
#endif
float ref_depth = texelFetch(outlineDepth, texel, 0).r;
More information about the Bf-blender-cvs
mailing list