diff options
-rw-r--r-- | data/simple.vert | 25 | ||||
-rw-r--r-- | src/main.cpp | 14 |
2 files changed, 30 insertions, 9 deletions
diff --git a/data/simple.vert b/data/simple.vert index 1850a67..6fdb13b 100644 --- a/data/simple.vert +++ b/data/simple.vert @@ -3,6 +3,7 @@ uniform mat4 mvp; uniform mat3 mv_normal; +uniform mat4x3 k_uniform[4]; layout(location = 0) in vec2 uv; @@ -14,15 +15,21 @@ out vec3 normal_cs; void main(void) { - /* Center the region at the origin. Assume that it's 7 units by 7 - * units. - */ - vec2 bias_uv = uv - 0.5; - vec4 position = vec4(bias_uv.x * 7., - 0.0, - bias_uv.y * 7., - 1.0); - gl_Position = mvp * position; + vec4 uhat = vec4((1 - uv.x) * (1 - uv.x) * (1 - uv.x), + 3. * uv.x * (1 - uv.x) * (1 - uv.x), + 3. * uv.x * uv.x * (1 - uv.x), + uv.x * uv.x * uv.x); + vec4 vhat = vec4((1 - uv.y) * (1 - uv.y) * (1 - uv.y), + 3. * uv.y * (1 - uv.y) * (1 - uv.y), + 3. * uv.y * uv.y * (1 - uv.y), + uv.y * uv.y * uv.y); + mat4x3 m; + m[0] = k_uniform[0] * uhat; + m[1] = k_uniform[1] * uhat; + m[2] = k_uniform[2] * uhat; + m[3] = k_uniform[3] * uhat; + + gl_Position = mvp * vec4(m * vhat, 1.0); /* Transform the normal by the inverse-transpose of the model-view * matrix. diff --git a/src/main.cpp b/src/main.cpp index 34d4959..126daef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,12 +68,15 @@ public: glGetUniformLocation(this->program, "mvp"); this->mv_normal_uniform = glGetUniformLocation(this->program, "mv_normal"); + this->k_uniform = + glGetUniformLocation(this->program, "k_uniform"); this->light_dir_cs_uniform = glGetUniformLocation(this->program, "light_dir_cs"); } GLint mvp_uniform; GLint mv_normal_uniform; + GLint k_uniform; GLint light_dir_cs_uniform; }; @@ -373,6 +376,17 @@ Redisplay(void) glUniformMatrix3fv(patch_program->mv_normal_uniform, 1, false, mv_normal); + float k_uniform[4][4][3]; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + for (int k = 0; k < 3; k++) { + k_uniform[i][j][k] = control_points[4 * i + j].values[k]; + } + } + } + glUniformMatrix4x3fv(patch_program->k_uniform, 4, false, + (const float *)k_uniform); + glDrawElements(mesh_sink->mode, mesh_sink->elt_count, GL_UNSIGNED_SHORT, |