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:
2017-04-16 15:04:07 -04:00
parent 6a2c82332b
commit 8dcf7a46a2
5 changed files with 51 additions and 17 deletions

View File

@@ -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;
}

View 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);
}

View File

@@ -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);
}