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:
@@ -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;
|
||||
}
|
||||
19
source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
Normal file
19
source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
Normal file
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user