You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
3.1 KiB
161 lines
3.1 KiB
|
|
|
|
// NOTE: default shader |
|
|
|
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 world_transform; |
|
uniform mat4 model; |
|
uniform mat4 view; |
|
uniform mat4 projection; |
|
|
|
|
|
void main() |
|
{ |
|
fragNormal = vec4(world_transform * vec4(normal, 1)).xyz; |
|
fragVertex = vertexPosition_modelspace; |
|
fragUV = texCoord.st; |
|
gl_Position = projection * view * |
|
world_transform * model * vec4(vertexPosition_modelspace, 1); |
|
} |
|
)VS"; |
|
|
|
// TODO: there's a bug here with the array size of 'lights' |
|
// with intel opengl, size can be >1000 |
|
// but with nvidea opengl size of >200 gives the following error: |
|
// error C6020: Constant register limit exceeded at sampler; |
|
// more than 1024 registers needed to compile program |
|
const char* DEFAULT_FRAGMENT_SHADER = R"FS( |
|
#version 330 core |
|
|
|
in vec3 fragVertex; |
|
in vec3 fragNormal; |
|
in vec2 fragUV; |
|
|
|
out vec4 color; |
|
|
|
uniform mat4 model; |
|
uniform mat3 normal_matrix; |
|
uniform sampler2D sampler; |
|
uniform uint num_lights = 0u; |
|
|
|
struct point_light { |
|
uint light_ID; |
|
vec3 position; |
|
vec3 color; |
|
float intensity; |
|
}; |
|
|
|
uniform point_light lights[200]; |
|
|
|
|
|
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)); |
|
float brightness = dot(normal, surfaceToLight) / length(surfaceToLight); |
|
totalBrightness += brightness; |
|
} |
|
|
|
color = clamp(totalBrightness, 0, 1) * texture(sampler, fragUV.st); |
|
} |
|
)FS"; |
|
|
|
|
|
// NOTE: debug shader |
|
|
|
const char* DEBUG_VERTEX_SHADER = R"DVS( |
|
#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; |
|
|
|
uniform mat4 world_transform; |
|
uniform mat4 model; |
|
uniform mat4 view; |
|
uniform mat4 projection; |
|
uniform mat3 normal_matrix; |
|
|
|
|
|
void main() |
|
{ |
|
fragNormal = vec4(world_transform * vec4(normal, 1)).xyz; |
|
fragVertex = vertexPosition_modelspace; |
|
gl_Position = projection * view * |
|
world_transform * model * vec4(vertexPosition_modelspace, 1); |
|
} |
|
)DVS"; |
|
|
|
const char* DEBUG_FRAGMENT_SHADER = R"DFS( |
|
#version 330 core |
|
|
|
in vec3 fragVertex; |
|
in vec3 fragNormal; |
|
|
|
out vec4 color; |
|
|
|
uniform mat4 model; |
|
uniform mat3 normal_matrix; |
|
|
|
|
|
void main() |
|
{ |
|
color = vec4(0.5 * normalize(fragNormal) + 0.5, 1.0); |
|
//color = vec4(1.0, 0.8, 0.8, 1.0); |
|
} |
|
)DFS"; |
|
|
|
|
|
// NOTE: simple shader |
|
|
|
const char* SIMPLE_VERTEX_SHADER = R"SVS( |
|
#version 330 core |
|
|
|
layout (location = 0) in vec3 position; |
|
layout (location = 1) in vec3 color; |
|
|
|
out vec3 frag_color; |
|
|
|
uniform mat4 world_transform; |
|
uniform mat4 MVP; |
|
|
|
|
|
void main() |
|
{ |
|
frag_color = color; |
|
gl_Position = MVP * world_transform * vec4(position, 1); |
|
} |
|
)SVS"; |
|
|
|
const char* SIMPLE_FRAGMENT_SHADER = R"SFS( |
|
#version 330 core |
|
|
|
in vec3 frag_color; |
|
|
|
out vec4 color; |
|
|
|
|
|
void main() |
|
{ |
|
color = vec4(frag_color.rgb, 1); |
|
} |
|
)SFS"; |
|
|
|
|