Commit: fcb4aaf7a9b08b4123a17846c02a9da40c274874
Author: Clément Foucault
Date:   Fri Apr 6 14:22:20 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBfcb4aaf7a9b08b4123a17846c02a9da40c274874

GPUShader: Add GPU_SHADER_2D_WIDGET_BASE_INST shader.

This will let us draw multiple widget base at once.

===================================================================

M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/intern/gpu_shader.c
M       source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl

===================================================================

diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 8051855ffbe..b33df9fdb20 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -173,6 +173,7 @@ typedef enum GPUBuiltinShader {
        GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR,
        /* specialized for UI drawing */
        GPU_SHADER_2D_WIDGET_BASE,
+       GPU_SHADER_2D_WIDGET_BASE_INST,
        GPU_SHADER_2D_WIDGET_SHADOW,
        GPU_SHADER_2D_NODELINK,
        GPU_SHADER_2D_NODELINK_INST,
diff --git a/source/blender/gpu/intern/gpu_shader.c 
b/source/blender/gpu/intern/gpu_shader.c
index 08a2c0c2c09..7c7297e90fb 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -803,6 +803,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
 
                [GPU_SHADER_2D_WIDGET_BASE] = { 
datatoc_gpu_shader_2D_widget_base_vert_glsl,
                                                
datatoc_gpu_shader_2D_smooth_color_frag_glsl},
+               [GPU_SHADER_2D_WIDGET_BASE_INST] = { 
datatoc_gpu_shader_2D_widget_base_vert_glsl,
+                                                    
datatoc_gpu_shader_2D_smooth_color_frag_glsl},
                [GPU_SHADER_2D_WIDGET_SHADOW] = { 
datatoc_gpu_shader_2D_widget_shadow_vert_glsl,
                                                  
datatoc_gpu_shader_2D_widget_shadow_frag_glsl },
                [GPU_SHADER_2D_NODELINK] = { 
datatoc_gpu_shader_2D_nodelink_vert_glsl,
@@ -823,6 +825,7 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
                /* just a few special cases */
                const char *defines = NULL;
                switch (shader) {
+                       case GPU_SHADER_2D_WIDGET_BASE_INST:
                        case GPU_SHADER_2D_NODELINK_INST:
                                defines = "#define USE_INSTANCE;\n";
                                break;
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl 
b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
index 2686f443c87..f4dafd7de16 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
@@ -71,24 +71,30 @@ const vec2 triavec[34] = vec2[34](
 
 uniform mat4 ModelViewProjectionMatrix;
 
+#ifdef USE_INSTANCE
+#define MAX_INSTANCE 6
+uniform vec4 parameters[11 * MAX_INSTANCE];
+#else
 uniform vec4 parameters[11];
-/* radi and rad per corner */
-#define recti        parameters[0]
-#define rect         parameters[1]
-#define radsi        parameters[2].x
-#define rads         parameters[2].y
-#define faci         parameters[2].zw
-#define roundCorners parameters[3]
-#define colorInner1  parameters[4]
-#define colorInner2  parameters[5]
-#define colorEdge    parameters[6]
-#define colorEmboss  parameters[7]
-#define colorTria    parameters[8]
-#define tria1Center  parameters[9].xy
-#define tria2Center  parameters[9].zw
-#define tria1Size    parameters[10].x
-#define tria2Size    parameters[10].y
-#define shadeDir     parameters[10].z
+#endif
+
+/* gl_InstanceID is 0 if not drawing instances. */
+#define recti        parameters[gl_InstanceID * 11 + 0]
+#define rect         parameters[gl_InstanceID * 11 + 1]
+#define radsi        parameters[gl_InstanceID * 11 + 2].x
+#define rads         parameters[gl_InstanceID * 11 + 2].y
+#define faci         parameters[gl_InstanceID * 11 + 2].zw
+#define roundCorners parameters[gl_InstanceID * 11 + 3]
+#define colorInner1  parameters[gl_InstanceID * 11 + 4]
+#define colorInner2  parameters[gl_InstanceID * 11 + 5]
+#define colorEdge    parameters[gl_InstanceID * 11 + 6]
+#define colorEmboss  parameters[gl_InstanceID * 11 + 7]
+#define colorTria    parameters[gl_InstanceID * 11 + 8]
+#define tria1Center  parameters[gl_InstanceID * 11 + 9].xy
+#define tria2Center  parameters[gl_InstanceID * 11 + 9].zw
+#define tria1Size    parameters[gl_InstanceID * 11 + 10].x
+#define tria2Size    parameters[gl_InstanceID * 11 + 10].y
+#define shadeDir     parameters[gl_InstanceID * 11 + 10].z
 
 in uint vflag;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to