- OBJ file reading
- VBO memory management - Lighting
This commit is contained in:
@@ -3,9 +3,14 @@
|
||||
uniform sampler2D texBase;
|
||||
|
||||
in vec2 fragTC;
|
||||
//in vec3 fragNorm;
|
||||
//in vec3 light0Vect;
|
||||
in vec3 light;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
void main(void) {
|
||||
color = texture(texBase, fragTC);
|
||||
vec4 texColor = texture(texBase, fragTC);
|
||||
|
||||
color = texColor*vec4(light, 1.0)+texColor*0.05;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
#version 330 core
|
||||
#extension GL_ARB_shading_language_420pack : enable
|
||||
|
||||
uniform mat4 projection_matrix;
|
||||
uniform mat4 modelview_matrix;
|
||||
uniform mat4 view_matrix;
|
||||
uniform mat4 model_matrix;
|
||||
|
||||
in vec3 vertex;
|
||||
in vec2 vertexTC;
|
||||
const uint lights = 2u;
|
||||
|
||||
const vec3 lightPos[lights] = {vec3(2.0, -2.0, 10.0),
|
||||
vec3(2.0, 2.0, 10.0)};
|
||||
const vec3 lightColor[lights] = {vec3(1.0, 0.9, 0.8),
|
||||
vec3(0.0, 1.0, 0.0)};
|
||||
const float lightIntensity[lights] = {75.0, 25.0};
|
||||
|
||||
|
||||
layout(location = 0) in vec3 vertex;
|
||||
layout(location = 1) in vec2 vertexTC;
|
||||
layout(location = 2) in vec3 vertexNorm;
|
||||
|
||||
out vec2 fragTC;
|
||||
out vec3 light;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = projection_matrix * modelview_matrix * vec4(vertex, 1.0);
|
||||
vec4 vertex_Pos = model_matrix * vec4(vertex, 1.0);
|
||||
gl_Position = projection_matrix * view_matrix * vertex_Pos;
|
||||
|
||||
fragTC = vertexTC;
|
||||
|
||||
vec3 vertexNorm_trans = (model_matrix*vec4(vertexNorm, 0.0)).xyz;
|
||||
light = vec3(0.0, 0.0, 0.0);
|
||||
for (uint i = 0u;i < lights;++i) {
|
||||
vec3 lightVec = lightPos[i]-vertex_Pos.xyz;
|
||||
vec3 lightNorm = normalize(lightVec);
|
||||
float lightDist = length(lightVec);
|
||||
light += lightColor[i]*clamp(dot(vertexNorm_trans, lightNorm), 0.0, 1.0)*
|
||||
clamp(lightIntensity[i]/(lightDist*lightDist), 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user