[Bf-blender-cvs] [8dcf7a46a28] blender2.8: OpenGL: fix GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR
Mike Erwin
noreply at git.blender.org
Sun Apr 16 21:13:08 CEST 2017
Commit: 8dcf7a46a28dd291680873f78a8a5259d065ee2f
Author: Mike Erwin
Date: Sun Apr 16 15:04:07 2017 -0400
Branches: blender2.8
https://developer.blender.org/rB8dcf7a46a28dd291680873f78a8a5259d065ee2f
OpenGL: fix GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR
The fragment shader expects a normal, but the vertex shader was not providing one.
Fix: added a new vertex shader that has normals + smooth color interpolation.
I also split gpu_shader_3D_vert in two:
- one with just position
- one with position + normal
For each of the builtin shaders, we should be able to look at the GLSL and tell exactly what it's doing. Using #defines and #ifdefs for rendering options makes the shaders hard to read and easy to break.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/intern/gpu_shader.c
A source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
A source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
M source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index f2b13d860dd..8d1d45d34cc 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -147,8 +147,10 @@ data_to_c_simple(shaders/gpu_shader_image_depth_linear_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_image_interlace_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_normal_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_normal_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_3D_passthrough_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl SRC)
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index a3668eb156b..737d186c950 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -70,8 +70,10 @@ extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[];
extern char datatoc_gpu_shader_image_rect_modulate_alpha_frag_glsl[];
extern char datatoc_gpu_shader_image_depth_linear_frag_glsl[];
extern char datatoc_gpu_shader_3D_vert_glsl[];
+extern char datatoc_gpu_shader_3D_normal_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_normal_smooth_color_vert_glsl[];
extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
extern char datatoc_gpu_shader_3D_passthrough_vert_glsl[];
extern char datatoc_gpu_shader_3D_clipped_uniform_color_vert_glsl[];
@@ -661,8 +663,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
[GPU_SHADER_EDGES_OVERLAY] = { datatoc_gpu_shader_edges_overlay_vert_glsl,
datatoc_gpu_shader_edges_overlay_frag_glsl,
datatoc_gpu_shader_edges_overlay_geom_glsl },
- [GPU_SHADER_SIMPLE_LIGHTING] = { datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_simple_lighting_frag_glsl },
- [GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR] = { datatoc_gpu_shader_3D_smooth_color_vert_glsl, datatoc_gpu_shader_simple_lighting_smooth_color_frag_glsl },
+ [GPU_SHADER_SIMPLE_LIGHTING] = { datatoc_gpu_shader_3D_normal_vert_glsl, datatoc_gpu_shader_simple_lighting_frag_glsl },
+ [GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR] = { datatoc_gpu_shader_3D_normal_smooth_color_vert_glsl, datatoc_gpu_shader_simple_lighting_smooth_color_frag_glsl },
[GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_image_vert_glsl,
datatoc_gpu_shader_image_mask_uniform_color_frag_glsl },
@@ -767,7 +769,6 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
if (builtin_shaders[shader] == NULL) {
/* just a few special cases */
const char *defines = (shader == GPU_SHADER_SMOKE_COBA) ? "#define USE_COBA;\n" :
- (shader == GPU_SHADER_SIMPLE_LIGHTING) ? "#define USE_NORMALS;\n" :
(shader == GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE) ? "#define UNIFORM_SCALE;\n" :
(shader == GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS) ? "#define AXIS_NAME;\n" :
(shader == GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR) ? "#define USE_INSTANCE_COLOR;\n" : NULL;
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
similarity index 74%
copy from source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
copy to source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
index 58150c004e5..9eacd10d69e 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
@@ -1,27 +1,26 @@
uniform mat4 ModelViewProjectionMatrix;
-#ifdef USE_NORMALS
uniform mat3 NormalMatrix;
-#endif
#if __VERSION__ == 120
attribute vec3 pos;
-#ifdef USE_NORMALS
attribute vec3 nor;
+ attribute vec4 color;
+
+ varying vec4 finalColor;
varying vec3 normal;
-#endif
#else
in vec3 pos;
-#ifdef USE_NORMALS
in vec3 nor;
+ in vec4 color;
+
out vec3 normal;
-#endif
+ out vec4 finalColor;
#endif
void main()
{
-#ifdef USE_NORMALS
normal = normalize(NormalMatrix * nor);
-#endif
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
similarity index 76%
copy from source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
copy to source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
index 58150c004e5..5084e438d40 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
@@ -1,27 +1,19 @@
uniform mat4 ModelViewProjectionMatrix;
-#ifdef USE_NORMALS
uniform mat3 NormalMatrix;
-#endif
#if __VERSION__ == 120
attribute vec3 pos;
-#ifdef USE_NORMALS
attribute vec3 nor;
varying vec3 normal;
-#endif
#else
in vec3 pos;
-#ifdef USE_NORMALS
in vec3 nor;
out vec3 normal;
#endif
-#endif
void main()
{
-#ifdef USE_NORMALS
normal = normalize(NormalMatrix * nor);
-#endif
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
index 58150c004e5..32da3a99c63 100644
--- a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
@@ -1,27 +1,13 @@
uniform mat4 ModelViewProjectionMatrix;
-#ifdef USE_NORMALS
-uniform mat3 NormalMatrix;
-#endif
#if __VERSION__ == 120
attribute vec3 pos;
-#ifdef USE_NORMALS
- attribute vec3 nor;
- varying vec3 normal;
-#endif
#else
in vec3 pos;
-#ifdef USE_NORMALS
- in vec3 nor;
- out vec3 normal;
-#endif
#endif
void main()
{
-#ifdef USE_NORMALS
- normal = normalize(NormalMatrix * nor);
-#endif
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
}
More information about the Bf-blender-cvs
mailing list