完成坐标和法线对齐

test-headless
ink-soul 2024-04-23 16:56:42 +08:00
parent d0ae241479
commit a438e685f3
9 changed files with 113 additions and 36 deletions

View File

@ -29,12 +29,8 @@ const std::string getAssetPath()
}
else
{
std::filesystem::path currentPath = std::filesystem::current_path();
dataFilePath = VK_EXAMPLE_DATA_DIR;
dataFilePath = dataFilePath.lexically_relative(currentPath);
dataFile = dataFilePath.generic_string();
return dataFile;
return VK_EXAMPLE_DATA_DIR;
}
#endif

View File

@ -26,9 +26,10 @@ void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string
std::string cY = toml::find<std::string>(camera, "cY");
std::vector<float> bottomCenter = toml::find<std::vector<float>>(camera, "bottomCenter");
std::vector<float> bottomNormal = toml::find<std::vector<float>>(camera, "bottomNormal");
std::vector<float> cameraFixation = toml::find<std::vector<float>>(camera, "center");
std::vector<std::vector<float>> cameraTracks = toml::find<std::vector<std::vector<float>>>(camera, "cameraTracks");
std::vector<std::vector<std::vector<float>>> cameraAngle = toml::find<std::vector<std::vector<std::vector<float>>>>(camera, "cameraAngle");
auto& debug = toml::find(tomlSettings, "debug");
settings.validation = toml::find<bool>(debug, "validation");
settings.vsync = toml::find<bool>(debug, "vsync");
@ -38,8 +39,9 @@ void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string
//settings.cleanUpImageSequece = toml::find_or<bool>(debug, "cleanUpImageSequece");
/*
conversion
conversion: type and coordinate system(rotation had been converted)
*/
size_t sz;
settings.fX = std::stof(fX, &sz);
settings.fY = std::stof(fY, &sz);
@ -47,6 +49,7 @@ void PlumageConfig::PlumageConfiguration::readConfigurationFromToml(std::string
settings.cY = std::stof(cY, &sz);
settings.bottomCenter = glm::vec3(bottomCenter[0], -bottomCenter[1], -bottomCenter[2]);
settings.bottomNormal = glm::vec3(bottomNormal[0], -bottomNormal[1], -bottomNormal[2]);
settings.cameraFixation = glm::vec3(cameraFixation[0], -cameraFixation[1], -cameraFixation[2]);
auto cameraTracksAndAngleSize = std::min(cameraTracks.size(), cameraAngle.size());
settings.cameraTracks.resize(cameraTracksAndAngleSize);
settings.cameraAngle.resize(cameraTracksAndAngleSize);

View File

@ -51,6 +51,7 @@ namespace PlumageConfig
glm::vec3 bottomCenter = { 0.f,0.f,-6.f };
//std::vector<float> bottomCenter = { 0.f,0.f,-6.f };
glm::vec3 bottomNormal = { 0.f,1.0f,0.f };
glm::vec3 cameraFixation = { -0.5f,1.5f,1.79f };
std::vector<glm::vec3> cameraTracks = { {0.f,0.f,-6.f},{1.f,0.f,-3.f} };
std::vector<glm::mat3> cameraAngle = { {{0.f,0.f,0.f},{45.f,0.f,0.f},{0.f,0.f,0.f}},{{0.f,0.f,0.f},{45.f,0.f,0.f},{0.f,0.f,0.f}} };
@ -106,7 +107,7 @@ namespace PlumageConfig
std::string brdfVertShaderPath = getAssetPath() + "shaders/genbrdflut.vert.spv";
std::string brdfFragShaderPath = getAssetPath() + "shaders/genbrdflut.frag.spv";
// environment map texture
std::string envMapFilePath = getAssetPath() + "environments/brown_photostudio_02_4k_hdr16f_cube.ktx";
std::string envMapFilePath = getAssetPath() + "environments/metro_noord_4k_hdr16f_cube.ktx";
std::string emptyEnvmapFilePath = getAssetPath() + "textures/empty.ktx";
// pbr shader
std::string pbrVertShaderPath = getAssetPath() + "shaders/pbr.vert.spv";
@ -130,7 +131,7 @@ namespace PlumageConfig
std::string hdr2ktxShFilePath = getAssetPath() + "script/hdr2ktxShFilePath.sh";
// 配置文件路径,命令行传入后保存在这
//std::string configFilePath = getAssetPath() + "config/guanzi.toml";
std::string configFilePath = getAssetPath() + "config/yukino_traj1_matrix.toml";
std::string configFilePath = getAssetPath() + "config/yukino_flat.toml";
} filePath;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1283,4 +1283,12 @@
return nodeFound;
}
void glTFModel::Model::setModelPosition(glm::vec3 position)
{
this->position = position;
}

View File

@ -236,6 +236,9 @@ namespace glTFModel
std::vector<Animation> animations;
std::vector<std::string> extensions;
glm::vec3 position = glm::vec3();
glm::vec3 rotation = glm::vec3();
struct Dimensions {
glm::vec3 min = glm::vec3(FLT_MAX);
glm::vec3 max = glm::vec3(-FLT_MAX);
@ -266,6 +269,8 @@ namespace glTFModel
void updateAnimation(uint32_t index, float time);
Node* findNode(Node* parent, uint32_t index);
Node* nodeFromIndex(uint32_t index);
void setModelPosition(glm::vec3 position);
void setModelRotation(glm::vec3 rotation);
};

View File

@ -1032,10 +1032,11 @@ PlumageRender::PlumageRender()
renderPassBeginInfo.pClearValues = clearValues;
std::vector<glm::mat4> matrices = {
// posi
glm::rotate(glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(0.0f, 1.0f, 0.0f)), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
glm::rotate(glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(0.0f, 1.0f, 0.0f)), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
glm::rotate(glm::mat4(1.0f), glm::radians(180.0f), glm::vec3(1.0f, 0.0f, 0.0f)),
glm::rotate(glm::mat4(1.0f), glm::radians(180.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
};
@ -1047,7 +1048,7 @@ PlumageRender::PlumageRender()
viewport.height = (float)dim;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
viewport.x = 0;
@ -1445,9 +1446,11 @@ PlumageRender::PlumageRender()
VkViewport viewport{};
viewport.width = (float)dim;
viewport.height = (float)dim;
viewport.height = -(float)dim;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
viewport.x = 0;
viewport.y = -viewport.height;
VkRect2D scissor{};
scissor.extent.width = dim;
@ -1497,24 +1500,35 @@ PlumageRender::PlumageRender()
float modelSize = std::max(models.scene.aabb[0][0], std::max(models.scene.aabb[1][1], models.scene.aabb[2][2]));
// Center and scale model
float scale = (1.0f / modelSize ) * 2.0f;
glm::vec3 translate = -glm::vec3(models.scene.aabb[3][0], models.scene.aabb[3][1], models.scene.aabb[3][2]);
translate += -2.0f * glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]);
translate += -2.0f * settings.bottomCenter;
float scale = (1.0f / modelSize ) * 5.0f;
//glm::vec3 translate = -glm::vec3(models.scene.aabb[3][0], models.scene.aabb[3][1], models.scene.aabb[3][2]);
//translate += -glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]);
//translate += -2.0f * settings.bottomCenter;
//camera.setPosition(glm::vec3(0, 0, -modelSize - 2));
shaderDataScene.model = glm::mat4(1.0f);
shaderDataScene.model[0][0] = scale;
shaderDataScene.model[1][1] = scale;
shaderDataScene.model[2][2] = scale;
glm::vec3 aabbMax = glm::vec3(models.scene.aabb[0][0], models.scene.aabb[1][1], models.scene.aabb[2][2]);
glm::vec3 aabbMin = glm::vec3(models.scene.aabb[3][0], models.scene.aabb[3][1], models.scene.aabb[3][2]);
glm::vec3 modelCenter = 0.5f * (aabbMin + aabbMax);
glm::vec3 translate = settings.cameraFixation - modelCenter;
//translate = modelCenter + translate ;
//shaderDataScene.model = glm::translate(glm::mat4(1.0f), translate);
//glm::vec3 translate = settings.cameraFixation;
shaderDataScene.model = glm::scale(glm::mat4(1.0f), glm::vec3(scale, scale, scale));
//glm::mat4 scaleModelMatrix = glm::scale(glm::mat4(1.0f),glm::vec3(scale,scale,scale));
//glm::mat4 translateMatrix = glm::translate(glm::mat4(1.0f), translate);
shaderDataScene.model = glm::translate(glm::mat4(1.0f), modelCenter);
shaderDataScene.model = glm::translate(shaderDataScene.model, translate);
if (settings.rotateModel)
{
shaderDataScene.model = glm::mat4(1.0f);
shaderDataScene.model = glm::rotate(shaderDataScene.model, glm::radians(modelrot), glm::vec3(0, 1, 0));
}
//shaderDataScene.model = glm::scale()
glm::mat4 rotationMatrix = glm::mat4(1.0f);
glm::vec4 topNormal = glm::vec4(0,1,0,0);
glm::vec4 modelTopNormal4 = glm::transpose(glm::inverse(shaderDataScene.model)) * topNormal;
glm::vec3 modelTopNormal3 = glm::vec3(modelTopNormal4[0], modelTopNormal4[1], modelTopNormal4[2]);
glm::vec3 rotationAxis = glm::normalize(glm::cross(settings.bottomNormal, modelTopNormal3));
float cosTheta = glm::dot(settings.bottomNormal, modelTopNormal3);
float angle = acos(cosTheta);
shaderDataScene.model = glm::rotate(glm::mat4(1.0f), angle, rotationAxis);
/*
shaderDataScene.camPos = glm::vec3(
-camera.position.z * sin(glm::radians(camera.rotation.y)) * cos(glm::radians(camera.rotation.x)),
@ -1522,9 +1536,19 @@ PlumageRender::PlumageRender()
camera.position.z * cos(glm::radians(camera.rotation.y)) * cos(glm::radians(camera.rotation.x))
);
*/
glm::mat4 selfRotationMatrix = glm::mat4(1.0f);
if (settings.rotateModel)
{
selfRotationMatrix = glm::rotate(shaderDataScene.model, glm::radians(modelrot), glm::vec3(0, 1, 0));
}
//shaderDataScene.model = translateMatrix * rotationMatrix * scaleModelMatrix
//shaderDataScene.model = rotationMatrix * scaleModelMatrix;
shaderDataScene.camPos = settings.cameraTracks[currentFrame];
shaderDataScene.model = selfRotationMatrix;
// Skybox
shaderDataSkybox.projection = camera.matrices.perspective;
shaderDataSkybox.view = camera.matrices.view;
@ -1552,7 +1576,7 @@ PlumageRender::PlumageRender()
camera.setProjectionMatrix(settings.fX,settings.fY,settings.cX,settings.cY,1.f, 256.f,settings.calibrationWidth,settings.calibrationHeight,false,true);
//camera.setPerspective(settings.fX, settings.fY, settings.cX, settings.cY, 1.0f, 256.0f);
camera.setTo(settings.bottomCenter);
camera.setTo(settings.cameraFixation);
camera.setUp(settings.bottomNormal);
camera.rotationSpeed = 0.25f;
camera.movementSpeed = 0.1f;
@ -1923,7 +1947,7 @@ PlumageRender::PlumageRender()
std::string commandLineFrameRate = std::to_string(settings.videoFrameRate);
std::filesystem::path image2videoBatFilePath = filePath.image2videoBatFilePath;
filePath.image2videoBatFilePath = image2videoBatFilePath.lexically_proximate(image2videoBatFilePath.root_path()).generic_string();
//filePath.image2videoBatFilePath = image2videoBatFilePath.lexically_proximate(image2videoBatFilePath.root_path()).generic_string();
#if defined(_WIN32)
std::string commandLine = filePath.image2videoBatFilePath + " " + commandLineFrameRate + " " + commandLineImageSequencePath + " " + resultVideoPath;
#else