49 lines
2.3 KiB
C
49 lines
2.3 KiB
C
#ifndef SHADERS_H
|
|
#define SHADERS_H
|
|
|
|
#define DEFAULT_VSHADER "#version 330 core\n" \
|
|
"layout (location = 0) in vec3 pos;\n" \
|
|
"layout (location = 1) in vec3 normal;\n" \
|
|
"\n" \
|
|
"uniform mat4 view;\n" \
|
|
"uniform mat4 projection;\n" \
|
|
"uniform mat4 translation;\n" \
|
|
"uniform mat4 rotation;\n" \
|
|
"uniform vec3 color;\n" \
|
|
"uniform float scale;\n" \
|
|
"\n" \
|
|
"out vec4 frag_pos;\n" \
|
|
"out vec4 frag_normal;\n" \
|
|
"out vec3 object_color;\n" \
|
|
"\n" \
|
|
"void main() {\n" \
|
|
" gl_Position = projection * view * translation * (vec4(pos.xyz, 1.0) * vec4(scale, scale, scale, 1.0));\n" \
|
|
" frag_pos = gl_Position;\n" \
|
|
" frag_normal = translation * vec4(normal.xyz, 1.0);\n" \
|
|
" object_color = color;\n" \
|
|
"}"
|
|
|
|
#define DEFAULT_FSHADER "#version 330 core\n" \
|
|
"in vec4 frag_pos;\n" \
|
|
"in vec4 frag_normal;\n" \
|
|
"in vec3 object_color;\n" \
|
|
"\n" \
|
|
"out vec4 outy;\n" \
|
|
"\n" \
|
|
"void main() {\n" \
|
|
" vec4 norm = normalize(frag_normal);\n" \
|
|
" vec4 ambient = vec4(0.7, 0.7788, 0.46, 1.0);\n" \
|
|
" vec4 light_color = vec4(0.7, 0.7, 0.7, 1.0);\n" \
|
|
" vec4 color = vec4(object_color.xyz, 1.0f);\n" \
|
|
"\n" \
|
|
" vec4 light_location = vec4(0.0, 100.0, 0.0, 1.0);\n" \
|
|
" vec4 light_direction = normalize(light_location - frag_pos);\n" \
|
|
" float diff = max(dot(norm.xyz, light_direction.xyz), 0.0);\n" \
|
|
"\n" \
|
|
" vec4 diffuse = diff * light_color;\n" \
|
|
"\n" \
|
|
" outy = color + diffuse;\n" \
|
|
"}"
|
|
|
|
#endif
|