High performance rendering of implicit surfaces presented in blobtree view. Use Vulkan(NVVK) as backend.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

57 lines
2.9 KiB

#include <iostream>
#include <random>
#include <nvmath.h>
int main(int argc, char** argv)
{
nvmath::vec3f eye = { .0f, .0f, -8.f }, center = { .0f, .0f, -1.f }, up = { .0f, 1.f, .0f };
uint32_t width = 1024, height = 1024;
float fov = 60.f;
nvmath::vec2f clipPlanes = {.001f, 64.f};
auto matrixView = nvmath::look_at(eye, center, up);
auto matrixProj = nvmath::perspectiveVK(fov, (float)height / width, clipPlanes.x, clipPlanes.y);
/* {
float aspectRatio = static_cast<float>(height) / static_cast<float>(width);
float invTanHalfFOV = 1.f / tanf(fov * nv_to_rad * .5f);
matrixProj = {aspectRatio * invTanHalfFOV, .0f, .0f, .0f,
.0f, -invTanHalfFOV, .0f, .0f,
.0f, .0f, -clipPlanes.y / (clipPlanes.y - clipPlanes.x), -1.f,
.0f, .0f, -clipPlanes.x * clipPlanes.y / (clipPlanes.y - clipPlanes.x), .0f};
} */
nvmath::vec2f coords = {1.f, .0f};
auto cameraWorldPos = nvmath::inverse(matrixView) * nvmath::vec4f(.0f, .0f, .0f, 1.f);
auto targetWorldPos = nvmath::inverse(matrixProj * matrixView) * nvmath::vec4f(coords * 2.f - 1.f, .0f, 1.f);
targetWorldPos /= targetWorldPos.w;
auto rayOrigin = cameraWorldPos;
auto rayDirection = nvmath::normalize(targetWorldPos - cameraWorldPos);
std::cout << "Current ray has origin (" << rayOrigin.x << ", " << rayOrigin.y << ", " << rayOrigin.z << ") and direction ("
<< rayDirection.x << ", " << rayDirection.y << ", " << rayDirection.z << ")" << std::endl;
/* std::mt19937 randomEngine(time(nullptr));
std::uniform_real_distribution<float> tGenerator(clipPlanes.x, clipPlanes.y * .25f);
float t = tGenerator(randomEngine);
auto pos = rayOrigin + rayDirection * clipPlanes.y;
std::cout << "Generated t = " << t << std::endl;
std::cout << "Generated position (" << pos.x << ", " << pos.y << ", " << pos.z << ", " << pos.w << ")" << std::endl;;
pos = matrixProj * matrixView * pos;
std::cout << "Transformed position (" << pos.x << ", " << pos.y << ", " << pos.z << ", " << pos.w << ")" << std::endl;;
pos /= pos.w;
std::cout << "Projected position (" << pos.x << ", " << pos.y << ", " << pos.z << ")" << std::endl; */
for(int i = 0; i < 8; ++i)
{
float t = i * (clipPlanes.y - clipPlanes.x) / 8 + clipPlanes.x;
auto pos = rayOrigin + t * rayDirection;
std::cout << "Generated position (" << pos.x << ", " << pos.y << ", " << pos.z << ", " << pos.w << ")" << std::endl;
pos = matrixView * pos;
std::cout << "Transformed position (" << pos.x << ", " << pos.y << ", " << pos.z << ", " << pos.w << ")" << std::endl;
pos = matrixProj * pos;
std::cout << "Transformed position (" << pos.x << ", " << pos.y << ", " << pos.z << ", " << pos.w << ")" << std::endl;
pos /= pos.w;
std::cout << "Projected position (" << pos.x << ", " << pos.y << ", " << pos.z << ")" << std::endl;
}
return 0;
}