[Bf-blender-cvs] [b8f27b2] blender2.8: OpenGL: shaders for simple 3D drawing
Mike Erwin
noreply at git.blender.org
Tue Aug 16 20:59:21 CEST 2016
Commit: b8f27b25145b23ebaa402aa6873ebfcbadc3491f
Author: Mike Erwin
Date: Tue Aug 16 14:58:53 2016 -0400
Branches: blender2.8
https://developer.blender.org/rBb8f27b25145b23ebaa402aa6873ebfcbadc3491f
OpenGL: shaders for simple 3D drawing
These are intended for very simple drawing. No lighting etc.
Shares some fragment code with the 2D shaders.
Similar to their 2D counterparts, but are not combined because of
future plans for separate 2D & 3D matrix stacks.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_shader.h
M source/blender/gpu/intern/gpu_shader.c
A source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
A source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
A source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl
A source/blender/gpu/shaders/gpu_shader_3D_uniform_color_vert.glsl
R100 source/blender/gpu/shaders/gpu_shader_2D_flat_color_frag.glsl source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
R100 source/blender/gpu/shaders/gpu_shader_2D_uniform_color_frag.glsl source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 467b76a..27643ff 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -100,12 +100,16 @@ set(SRC
intern/gpu_private.h
)
+data_to_c_simple(shaders/gpu_shader_uniform_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_flat_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_uniform_color_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_2D_uniform_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_flat_color_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_2D_flat_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_uniform_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_smooth_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_geometry.glsl SRC)
data_to_c_simple(shaders/gpu_shader_smoke_frag.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index ebc90df..367e134 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -90,10 +90,14 @@ typedef enum GPUBuiltinShader {
GPU_SHADER_SMOKE = 2,
GPU_SHADER_SMOKE_FIRE = 3,
- /* for simple drawing */
+ /* for simple 2D drawing */
GPU_SHADER_2D_UNIFORM_COLOR,
GPU_SHADER_2D_FLAT_COLOR,
GPU_SHADER_2D_SMOOTH_COLOR,
+ /* for simple 3D drawing */
+ GPU_SHADER_3D_UNIFORM_COLOR,
+ GPU_SHADER_3D_FLAT_COLOR,
+ GPU_SHADER_3D_SMOOTH_COLOR,
} GPUBuiltinShader;
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 1b3392e..fc387b7 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -46,12 +46,16 @@
#define MAX_EXT_DEFINE_LENGTH 1024
/* Non-generated shaders */
+extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
+extern char datatoc_gpu_shader_flat_color_frag_glsl[];
extern char datatoc_gpu_shader_2D_uniform_color_vert_glsl[];
-extern char datatoc_gpu_shader_2D_uniform_color_frag_glsl[];
extern char datatoc_gpu_shader_2D_flat_color_vert_glsl[];
-extern char datatoc_gpu_shader_2D_flat_color_frag_glsl[];
extern char datatoc_gpu_shader_2D_smooth_color_vert_glsl[];
extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[];
+extern char datatoc_gpu_shader_3D_uniform_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
extern char datatoc_gpu_shader_smoke_vert_glsl[];
extern char datatoc_gpu_shader_smoke_frag_glsl[];
@@ -77,10 +81,14 @@ static struct GPUShadersGlobal {
GPUShader *smoke_fire;
/* cache for shader fx. Those can exist in combinations so store them here */
GPUShader *fx_shaders[MAX_FX_SHADERS * 2];
- /* for simple drawing */
+ /* for simple 2D drawing */
GPUShader *uniform_color_2D;
GPUShader *flat_color_2D;
GPUShader *smooth_color_2D;
+ /* for simple 3D drawing */
+ GPUShader *uniform_color_3D;
+ GPUShader *flat_color_3D;
+ GPUShader *smooth_color_3D;
} shaders;
} GG = {{NULL}};
@@ -637,7 +645,7 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
if (!GG.shaders.uniform_color_2D)
GG.shaders.uniform_color_2D = GPU_shader_create(
datatoc_gpu_shader_2D_uniform_color_vert_glsl,
- datatoc_gpu_shader_2D_uniform_color_frag_glsl,
+ datatoc_gpu_shader_uniform_color_frag_glsl,
NULL, NULL, NULL, 0, 0, 0);
retval = GG.shaders.uniform_color_2D;
break;
@@ -645,7 +653,7 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
if (!GG.shaders.flat_color_2D)
GG.shaders.flat_color_2D = GPU_shader_create(
datatoc_gpu_shader_2D_flat_color_vert_glsl,
- datatoc_gpu_shader_2D_flat_color_frag_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl,
NULL, NULL, NULL, 0, 0, 0);
retval = GG.shaders.flat_color_2D;
break;
@@ -657,6 +665,30 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
NULL, NULL, NULL, 0, 0, 0);
retval = GG.shaders.smooth_color_2D;
break;
+ case GPU_SHADER_3D_UNIFORM_COLOR:
+ if (!GG.shaders.uniform_color_3D)
+ GG.shaders.uniform_color_3D = GPU_shader_create(
+ datatoc_gpu_shader_3D_uniform_color_vert_glsl,
+ datatoc_gpu_shader_uniform_color_frag_glsl,
+ NULL, NULL, NULL, 0, 0, 0);
+ retval = GG.shaders.uniform_color_3D;
+ break;
+ case GPU_SHADER_3D_FLAT_COLOR:
+ if (!GG.shaders.flat_color_3D)
+ GG.shaders.flat_color_3D = GPU_shader_create(
+ datatoc_gpu_shader_3D_flat_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl,
+ NULL, NULL, NULL, 0, 0, 0);
+ retval = GG.shaders.flat_color_3D;
+ break;
+ case GPU_SHADER_3D_SMOOTH_COLOR:
+ if (!GG.shaders.smooth_color_3D)
+ GG.shaders.smooth_color_3D = GPU_shader_create(
+ datatoc_gpu_shader_3D_smooth_color_vert_glsl,
+ datatoc_gpu_shader_3D_smooth_color_frag_glsl,
+ NULL, NULL, NULL, 0, 0, 0);
+ retval = GG.shaders.smooth_color_3D;
+ break;
}
if (retval == NULL)
@@ -783,6 +815,21 @@ void GPU_shader_free_builtin_shaders(void)
GG.shaders.smooth_color_2D = NULL;
}
+ if (GG.shaders.uniform_color_3D) {
+ GPU_shader_free(GG.shaders.uniform_color_3D);
+ GG.shaders.uniform_color_3D = NULL;
+ }
+
+ if (GG.shaders.flat_color_3D) {
+ GPU_shader_free(GG.shaders.flat_color_3D);
+ GG.shaders.flat_color_3D = NULL;
+ }
+
+ if (GG.shaders.smooth_color_3D) {
+ GPU_shader_free(GG.shaders.smooth_color_3D);
+ GG.shaders.smooth_color_3D = NULL;
+ }
+
for (i = 0; i < 2 * MAX_FX_SHADERS; ++i) {
if (GG.shaders.fx_shaders[i]) {
GPU_shader_free(GG.shaders.fx_shaders[i]);
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
new file mode 100644
index 0000000..ec6037e
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
@@ -0,0 +1,18 @@
+
+#if __VERSION__ == 120
+ attribute vec3 pos;
+ attribute vec4 color;
+
+ flat varying vec4 finalColor;
+#else
+ in vec3 pos;
+ in vec4 color;
+
+ flat out vec4 finalColor;
+#endif
+
+void main()
+{
+ gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_flat_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
similarity index 69%
copy from source/blender/gpu/shaders/gpu_shader_2D_flat_color_frag.glsl
copy to source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
index 91097d2..955a49a 100644
--- a/source/blender/gpu/shaders/gpu_shader_2D_flat_color_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
@@ -1,9 +1,9 @@
#if __VERSION__ == 120
- flat varying vec4 finalColor;
+ varying vec4 finalColor;
#define fragColor gl_FragColor
#else
- flat in vec4 finalColor;
+ in vec4 finalColor;
out vec4 fragColor;
#endif
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl
new file mode 100644
index 0000000..9b766c0
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl
@@ -0,0 +1,18 @@
+
+#if __VERSION__ == 120
+ attribute vec3 pos;
+ attribute vec4 color;
+
+ varying vec4 finalColor;
+#else
+ in vec2 pos;
+ in vec4 color;
+
+ out vec4 finalColor;
+#endif
+
+void main()
+{
+ gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_uniform_color_vert.glsl
new file mode 100644
index 0000000..5d10eae
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_uniform_color_vert.glsl
@@ -0,0 +1,11 @@
+
+#if __VERSION__ == 120
+ attribute vec3 pos;
+#else
+ in vec3 pos;
+#endif
+
+void main()
+{
+ gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_flat_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
similarity index 100%
rename from source/blender/gpu/shaders/gpu_shader_2D_flat_color_frag.glsl
rename to source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
similarity index 100%
rename from source/blender/gpu/shaders/gpu_shader_2D_uniform_color_frag.glsl
rename to source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
More information about the Bf-blender-cvs
mailing list