diff options
Diffstat (limited to 'src/render/shaders/gl3')
-rw-r--r-- | src/render/shaders/gl3/pervertexcolor.frag | 29 | ||||
-rw-r--r-- | src/render/shaders/gl3/pervertexcolor.vert | 22 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/render/shaders/gl3/pervertexcolor.frag b/src/render/shaders/gl3/pervertexcolor.frag new file mode 100644 index 000000000..a636781c4 --- /dev/null +++ b/src/render/shaders/gl3/pervertexcolor.frag @@ -0,0 +1,29 @@ +#version 150 core + +// TODO: Replace with a uniform block +uniform vec4 lightPosition; +uniform vec3 lightIntensity; + +in vec3 position; +in vec3 normal; +in vec3 color; + +out vec4 fragColor; + +vec3 adModel( const in vec3 pos, const in vec3 n, const in vec3 col ) +{ + // Calculate the vector from the light to the fragment + vec3 s = normalize( vec3( lightPosition ) - pos ); + + // Calculate the diffuse component + float diffuse = max( dot( s, n ), 0.0 ); + + // Combine the ambient and diffuse contributions + return lightIntensity * ( col + col * diffuse ); +} + +void main() +{ + fragColor = vec4( adModel( position, normalize( normal ), color ), 1.0 ); +} + diff --git a/src/render/shaders/gl3/pervertexcolor.vert b/src/render/shaders/gl3/pervertexcolor.vert new file mode 100644 index 000000000..b6b1a5da7 --- /dev/null +++ b/src/render/shaders/gl3/pervertexcolor.vert @@ -0,0 +1,22 @@ +#version 150 core + +in vec3 vertexPosition; +in vec3 vertexNormal; +in vec3 vertexColor; + +out vec3 position; +out vec3 normal; +out vec3 color; + +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform mat4 mvp; + +void main() +{ + normal = normalize( modelViewNormal * vertexNormal ); + position = vec3( modelView * vec4( vertexPosition, 1.0 ) ); + color = vertexColor; + + gl_Position = mvp * vec4( vertexPosition, 1.0 ); +} |