Move PVM matrix multiplication from vertex to tessellation eval shader
This commit is contained in:
parent
b2450d4ca5
commit
136b5cab9c
|
@ -2,6 +2,14 @@
|
||||||
|
|
||||||
layout(quads, equal_spacing, ccw) in; // Define the type of patch (e.g., quads)
|
layout(quads, equal_spacing, ccw) in; // Define the type of patch (e.g., quads)
|
||||||
|
|
||||||
|
layout(location = 0) uniform mat4 M;
|
||||||
|
|
||||||
|
layout(std140, binding = 0) uniform SceneUniforms
|
||||||
|
{
|
||||||
|
mat4 PV; //camera projection * view matrix
|
||||||
|
vec4 eye_w; //world-space eye position
|
||||||
|
};
|
||||||
|
|
||||||
out vec3 frag_position; // Ensure this matches the input in fragment.glsl
|
out vec3 frag_position; // Ensure this matches the input in fragment.glsl
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
@ -13,5 +21,5 @@ void main()
|
||||||
|
|
||||||
frag_position = pos;
|
frag_position = pos;
|
||||||
|
|
||||||
gl_Position = vec4(pos, 1.0);
|
gl_Position = PV*M*vec4(pos, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
#version 430
|
#version 430
|
||||||
|
layout(location = 0) uniform mat4 M;
|
||||||
|
|
||||||
|
layout(std140, binding = 0) uniform SceneUniforms
|
||||||
|
{
|
||||||
|
mat4 PV; //camera projection * view matrix
|
||||||
|
vec4 eye_w; //world-space eye position
|
||||||
|
};
|
||||||
|
|
||||||
layout(location = 0) in vec3 pos_attrib;
|
layout(location = 0) in vec3 pos_attrib;
|
||||||
layout(location = 1) in vec2 tex_coord_attrib;
|
layout(location = 1) in vec2 tex_coord_attrib;
|
||||||
|
|
|
@ -41,10 +41,11 @@ Scene::Scene(int width, int height)
|
||||||
quad_shader_program_(-1),
|
quad_shader_program_(-1),
|
||||||
vao_(-1),
|
vao_(-1),
|
||||||
quad_vao_(-1),
|
quad_vao_(-1),
|
||||||
angle_(0.0f),
|
angle_(-glm::pi<float>() / 2.0f),
|
||||||
scale_(1.0f),
|
scale_(1.0f),
|
||||||
aspect_(static_cast<float>(width) / static_cast<float>(height)),
|
aspect_(static_cast<float>(width) / static_cast<float>(height)),
|
||||||
near_z_(0.1f), far_z_(100.0f),
|
near_z_(0.01f),
|
||||||
|
far_z_(100.0f),
|
||||||
fov_(glm::pi<float>() / 4.0f)
|
fov_(glm::pi<float>() / 4.0f)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -80,11 +81,19 @@ void Scene::Init() {
|
||||||
void Scene::InitBuffers() {
|
void Scene::InitBuffers() {
|
||||||
GLuint patch_vbo;
|
GLuint patch_vbo;
|
||||||
// Quad vertices in 3D space
|
// Quad vertices in 3D space
|
||||||
|
// float patchVertices[] = {
|
||||||
|
// -0.5f, 0.0f, -0.5f, // Bottom-left
|
||||||
|
// 0.5f, 0.0f, -0.5f, // Bottom-right
|
||||||
|
// 0.5f, 0.0f, 0.5f, // Top-right
|
||||||
|
// -0.5f, 0.0f, 0.5f // Top-left
|
||||||
|
|
||||||
|
// };
|
||||||
|
|
||||||
float patchVertices[] = {
|
float patchVertices[] = {
|
||||||
-0.5f, -0.5f, 0.0f, // Bottom-left
|
-0.5f, -0.5f, 0.0f, // Bottom-left
|
||||||
0.5f, -0.5f, 0.0f, // Bottom-right
|
0.5f, -0.5f, 0.0f, // Bottom-right
|
||||||
0.5f, 0.5f, 0.0f, // Top-right
|
0.5f, 0.5f, 0.0f, // Top-right
|
||||||
-0.5f, 0.5f, 0.0f // Top-left
|
-0.5f, 0.5f, 0.0f // Top-left
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,20 +161,20 @@ void Scene::Display(GLFWwindow* window) {
|
||||||
|
|
||||||
glUseProgram(shader_program_);
|
glUseProgram(shader_program_);
|
||||||
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
|
||||||
view_matrix_ = glm::lookAt(glm::vec3(Uniforms::SceneData.eye_w), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
view_matrix_ = glm::lookAt(glm::vec3(0.0f, 2.0f, 3.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
Uniforms::SceneData.PV = projection_matrix_ * view_matrix_; // Projection-View matrix
|
Uniforms::SceneData.PV = projection_matrix_ * view_matrix_; // Projection-View matrix
|
||||||
Uniforms::BufferSceneData();
|
Uniforms::BufferSceneData();
|
||||||
|
|
||||||
glm::mat4 model_matrix = glm::rotate(angle_, glm::vec3(0.0f, 1.0f, 0.0f)) * glm::scale(glm::vec3(scale_));
|
glm::mat4 model_matrix = glm::rotate(angle_, glm::vec3(1.0f, 0.0f, 0.0f)) * glm::scale(glm::vec3(scale_));
|
||||||
glUniformMatrix4fv(Uniforms::UniformLocs::M, 1, false, glm::value_ptr(model_matrix));
|
glUniformMatrix4fv(Uniforms::UniformLocs::M, 1, false, glm::value_ptr(model_matrix));
|
||||||
|
|
||||||
glBindVertexArray(vao_);
|
glBindVertexArray(vao_);
|
||||||
glPatchParameteri(GL_PATCH_VERTICES, 4);
|
glPatchParameteri(GL_PATCH_VERTICES, 4);
|
||||||
glDrawArrays(GL_PATCHES, 0, 4);
|
glDrawArrays(GL_PATCHES, 0, 4);
|
||||||
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|
||||||
fbo_.Unbind();
|
fbo_.Unbind();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue