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.
This commit is contained in:
parent
6a2c82332b
commit
8dcf7a46a2
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
uniform mat3 NormalMatrix;
|
||||
|
||||
#if __VERSION__ == 120
|
||||
attribute vec3 pos;
|
||||
attribute vec3 nor;
|
||||
attribute vec4 color;
|
||||
|
||||
varying vec4 finalColor;
|
||||
varying vec3 normal;
|
||||
#else
|
||||
in vec3 pos;
|
||||
in vec3 nor;
|
||||
in vec4 color;
|
||||
|
||||
out vec3 normal;
|
||||
out vec4 finalColor;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
normal = normalize(NormalMatrix * nor);
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
finalColor = color;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
uniform mat3 NormalMatrix;
|
||||
|
||||
#if __VERSION__ == 120
|
||||
attribute vec3 pos;
|
||||
attribute vec3 nor;
|
||||
varying vec3 normal;
|
||||
#else
|
||||
in vec3 pos;
|
||||
in vec3 nor;
|
||||
out vec3 normal;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
normal = normalize(NormalMatrix * nor);
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue