Skip to content

Commit ce700fb

Browse files
committed
broken something?
1 parent 1af8216 commit ce700fb

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

shaders/geometry.glsl

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,65 @@
11
#shader vertex
22
#version 430 core
33
layout(location = 0) in vec4 a_position;
4+
layout(location = 1) in vec4 a_normal;
45
layout(location = 2) in vec2 a_texCoord;
56

67
uniform mat4 u_modelMat;
78
uniform mat4 u_viewMat;
9+
uniform mat4 u_normalMat;
810
uniform mat4 u_projectionMat;
911

10-
1112
out VS_OUT {
1213
vec2 v_texCoord;
14+
vec3 v_normal;
1315
};
1416

1517
void main() {
1618
gl_Position = u_projectionMat * u_viewMat * u_modelMat * a_position;
1719
v_texCoord = a_texCoord;
20+
v_normal = vec3(normalize(a_normal));
1821
}
1922

2023
#shader geometry
2124
#version 430 core
2225

2326
in VS_OUT {
2427
vec2 v_texCoord;
28+
vec3 v_normal;
2529
} gs_in[];
2630
out GS_OUT {
2731
vec2 v_texCoord;
2832
};
2933

34+
uniform float u_timepoint;
35+
3036
layout (triangles) in;
3137
layout (triangle_strip, max_vertices=3) out;
38+
vec4 explode(vec4 position, vec3 normal)
39+
{
40+
float magnitude = 2.0;
41+
vec3 direction = normal * ((sin(u_timepoint) + 1.0) / 2) * magnitude;
42+
return position + vec4(direction, 0.0);
43+
}
44+
45+
vec3 GetNormal()
46+
{
47+
vec3 a = vec3(gl_in[0].gl_Position) - vec3(gl_in[1].gl_Position);
48+
vec3 b = vec3(gl_in[2].gl_Position) - vec3(gl_in[1].gl_Position);
49+
return normalize(cross(a, b));
50+
}
3251
void main() {
52+
vec3 normal = GetNormal(); // FIXME: gs_in[0].v_normal is wrong
53+
54+
gl_Position = explode(gl_in[0].gl_Position, normal);
3355
v_texCoord = gs_in[0].v_texCoord;
34-
gl_Position = gl_in[0].gl_Position;
3556
EmitVertex();
36-
57+
gl_Position = explode(gl_in[1].gl_Position, normal);
3758
v_texCoord = gs_in[1].v_texCoord;
38-
gl_Position = gl_in[1].gl_Position;
3959
EmitVertex();
40-
60+
gl_Position = explode(gl_in[2].gl_Position, normal);
4161
v_texCoord = gs_in[2].v_texCoord;
42-
gl_Position = gl_in[2].gl_Position;
4362
EmitVertex();
44-
4563
EndPrimitive();
4664
}
4765

@@ -59,6 +77,6 @@ in GS_OUT {
5977
uniform Material u_material;
6078

6179
void main() {
62-
// o_color = texture(u_material.diffuse, v_texCoord);
63-
o_color = vec4(1);
80+
o_color = texture(u_material.diffuse, v_texCoord);
81+
// o_color = vec4(1);
6482
}

src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ if(!fastLoad) {
123123
glCullFace(GL_BACK);
124124
glFrontFace(GL_CCW);
125125

126+
glDisable(GL_CULL_FACE);
127+
128+
126129
glfwSwapInterval(0);
127130
glfwSetInputMode(window, GLFW_CURSOR, camera.locked ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
128131
glfwSetWindowUserPointer(window, &camera);
@@ -154,7 +157,7 @@ if(!fastLoad) {
154157
app.models[app.currentModelIndex].rotate(app.models[app.currentModelIndex].m_rotation);
155158
app.models[app.currentModelIndex].scale(app.models[app.currentModelIndex].m_scale);
156159

157-
glUniform1f(currentShader.getUniform("u_timepoint"), start.time_since_epoch().count());
160+
glUniform1f(currentShader.getUniform("u_timepoint"), glfwGetTime());
158161
glUniform1i(currentShader.getUniform("u_skybox"), 1);
159162
app.textures[app.currentTextureIndex].bind();
160163
renderer.drawLighting(app.models[app.currentModelIndex], currentShader, camera);

src/utils/Model.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ Mesh Model::processMesh(aiMesh *aimesh, bool flipTextures) {
9393
}
9494

9595
VertexBufferLayout layout;
96-
layout.push(3, GL_FLOAT, 0);
97-
layout.push(3, GL_FLOAT, positions.size() * sizeof(positions[0]));
98-
layout.push(2, GL_FLOAT, positions.size() * sizeof(positions[0]) + normals.size() * sizeof(normals[0]));
96+
/* positions */ layout.push(3, GL_FLOAT, 0);
97+
/* normals */ layout.push(3, GL_FLOAT, positions.size() * sizeof(positions[0]));
98+
/* tex coords */ layout.push(2, GL_FLOAT, positions.size() * sizeof(positions[0]) + normals.size() * sizeof(normals[0]));
9999

100100
mesh.va.bind();
101101
mesh.ib = IndexBuffer {indices.data(), indices.size() * sizeof(unsigned)};

0 commit comments

Comments
 (0)