2 changed files with 68 additions and 24 deletions
@ -0,0 +1,66 @@ |
|||||||
|
const char* DEFAULT_VERTEX_SHADER = R"VS( |
||||||
|
#version 330 core |
||||||
|
|
||||||
|
layout (location = 0) in vec3 vertexPosition_modelspace; |
||||||
|
layout (location = 1) in vec3 normal; |
||||||
|
layout (location = 2) in vec3 texCoord; |
||||||
|
|
||||||
|
out vec3 fragVertex; |
||||||
|
out vec3 fragNormal; |
||||||
|
out vec2 fragUV; |
||||||
|
|
||||||
|
uniform mat4 model; |
||||||
|
uniform mat4 view; |
||||||
|
uniform mat4 projection; |
||||||
|
|
||||||
|
void main() |
||||||
|
{ |
||||||
|
fragNormal = normal; |
||||||
|
fragVertex = vertexPosition_modelspace; |
||||||
|
fragUV = texCoord.st; |
||||||
|
gl_Position = projection * view * model * vec4(vertexPosition_modelspace, 1); |
||||||
|
} |
||||||
|
)VS"; |
||||||
|
|
||||||
|
const char* DEFAULT_FRAGMENT_SHADER = R"FS( |
||||||
|
#version 330 core |
||||||
|
|
||||||
|
//in vec3 fragColor; // NOTE: removing this line fails to link program... somehow?
|
||||||
|
in vec3 fragVertex; |
||||||
|
in vec3 fragNormal; |
||||||
|
in vec2 fragUV; |
||||||
|
|
||||||
|
out vec4 color; |
||||||
|
|
||||||
|
uniform mat4 model; |
||||||
|
uniform mat3 normal_matrix; |
||||||
|
|
||||||
|
struct point_light { |
||||||
|
uint light_ID; |
||||||
|
vec3 position; |
||||||
|
vec3 color; |
||||||
|
float intensity; |
||||||
|
}; |
||||||
|
#define MAX_LIGHTS 10 |
||||||
|
uniform point_light lights[MAX_LIGHTS]; |
||||||
|
uniform uint num_lights = 0u; |
||||||
|
|
||||||
|
uniform sampler2D sampler; |
||||||
|
|
||||||
|
|
||||||
|
void main() |
||||||
|
{ |
||||||
|
vec3 normal = normalize(normal_matrix * fragNormal); |
||||||
|
vec3 fragPosition = vec3(model * vec4(fragVertex, 1)); |
||||||
|
float totalBrightness = 0; |
||||||
|
|
||||||
|
for (uint i = 0u; i < num_lights; i++) { |
||||||
|
vec3 surfaceToLight = lights[i].position - fragPosition; |
||||||
|
float brightness = dot(normal, surfaceToLight) / (length(surfaceToLight) * length(normal)); |
||||||
|
totalBrightness += brightness; |
||||||
|
} |
||||||
|
|
||||||
|
color = clamp(totalBrightness, 0, 1) * texture(sampler, fragUV.st); |
||||||
|
} |
||||||
|
)FS"; |
||||||
|
|
||||||
Loading…
Reference in new issue