Finally converted the camera lens to a proper frustrum, no more fish eye

master
mitchellhansen 7 years ago
parent cc0b078e17
commit c698711fdf

@ -41,9 +41,10 @@ class CLCaster;
class Application {
public:
static const int WINDOW_X = 1600;
static const int WINDOW_Y = 900;
static const int WINDOW_X = 1366;
static const int WINDOW_Y = 768;
// static const int WINDOW_X = 1920;
// static const int WINDOW_Y = 1080;
static const int MAP_X;
static const int MAP_Y;
static const int MAP_Z;

@ -113,11 +113,13 @@ public:
// Creates a texture to send to the GPU via height and width
// Creates a viewport vector array via vertical and horizontal fov
bool create_viewport(int width, int height, float v_fov, float h_fov) ;
bool release_viewport();
// Light controllers own the copy of the PackedData array.
// We receive a pointer to the array and USE_HOST_POINTER to map the memory to the GPU
bool assign_lights(std::vector<PackedData> *data) ;
// TODO: Double maps??
// We take a ptr to the map and create the map, and map_dimensions buffer for the GPU
bool assign_map(std::shared_ptr<Map> map);
bool release_map();

@ -11,6 +11,7 @@
#include <SFML/Graphics/Texture.hpp>
#include <algorithm>
#include <tuple>
#include "Vector4.hpp"
const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f;
@ -108,7 +109,6 @@ inline sf::Vector3f Normalize(sf::Vector3f in) {
return r;
}
inline float DotProduct(sf::Vector3f a, sf::Vector3f b){
return a.x * b.x + a.y * b.y + a.z * b.z;
}

@ -16,7 +16,7 @@ __constant int2 zeroed_int2 = {0, 0};
__constant const uchar idx_set_x_mask = 0x1;
__constant const uchar idx_set_y_mask = 0x2;
__constant const uchar idx_set_z_mask = 0x4;
__constant const uchar idx_set_mask = {0x1, 0x2, 0x4};
__constant const uchar3 idx_set_mask = {0x1, 0x2, 0x4};
__constant const uchar mask_8[8] = {
0x1, 0x2, 0x4, 0x8,
@ -50,15 +50,6 @@ constant float4 overshoot_color_2 = { 0.00f, 0.00f, 0.00f, 0.00f };
// =========================================================================
// ========================= HELPER FUNCTIONS ==============================
float DistanceBetweenPoints(float3 a, float3 b) {
return fast_distance(a, b);
}
float Distance(float3 a) {
return fast_length(a);
}
// Phong + diffuse lighting function for g
// 0 1 2 3 4 5 6 7 8 9
// {r, g, b, i, x, y, z, x', y', z'}
@ -68,7 +59,7 @@ float4 view_light(float4 in_color, float3 light, float4 light_color, float3 view
if (all(light == zeroed_float3))
return zeroed_float4;
float d = Distance(light) / 120.0f;
float d = fast_length(light) * 0.01f;
d *= d;
float diffuse = max(dot(normalize(convert_float3(mask)), normalize(light)), 0.1f);
@ -474,8 +465,8 @@ __kernel void raycaster(
constant int vox_dim = OCTDIM;
// If we hit a voxel
if (voxel.x < vox_dim && voxel.y < vox_dim && voxel.z < vox_dim){
// If we hit a voxel
if (voxel.x < (*map_dim).x && voxel.y < (*map_dim).x && voxel.z < (*map_dim).x){
if (get_oct_vox(
voxel,
octree_descriptor_buffer,
@ -570,7 +561,7 @@ __kernel void raycaster(
voxel_color.xyz += (float3)read_imagef(
texture_atlas,
convert_int2(tile_face_position * convert_float2(*atlas_dim / *tile_dim)) +
convert_int2((float2)(3, 0) * convert_float2(*atlas_dim / *tile_dim))
convert_int2((float2)(5, 0) * convert_float2(*atlas_dim / *tile_dim))
).xyz/2;
color_accumulator = view_light(
@ -582,7 +573,7 @@ __kernel void raycaster(
);
fog_distance = distance_traveled;
max_distance = distance_traveled + DistanceBetweenPoints(convert_float3(voxel), (float3)(lights[4], lights[5], lights[6]));
max_distance = distance_traveled + fast_distance(convert_float3(voxel), (float3)(lights[4], lights[5], lights[6]));
float3 hit_pos = convert_float3(voxel) + face_position;
ray_dir = normalize((float3)(lights[4], lights[5], lights[6]) - hit_pos);

@ -40,8 +40,8 @@ bool Application::init_clcaster() {
// Create a new camera with (starting position, direction)
camera = std::make_shared<Camera>(
sf::Vector3f(0.5f, 0.5f, 0.5f),
sf::Vector2f(1.45f, 0.3f),
sf::Vector3f(3.5f, 3.5f, 3.5f),
sf::Vector2f(1.57f, 0.0f),
window.get()
);

@ -2,8 +2,18 @@
CLCaster::CLCaster() {}
CLCaster::~CLCaster() {
// Causes sigabrt??
//release_map();
//release_camera();
//release_octree();
release_viewport();
delete[] viewport_matrix;
delete[] viewport_image;
camera.reset();
map.reset();
}
bool CLCaster::init() {
@ -222,7 +232,6 @@ bool CLCaster::compute() {
// There is a possibility that I would want to move this over to be all inside it's own
// container to make it so it can be changed via CL_MEM_USE_HOST_PTR. But I doubt it
// would ever be called enough to warrant that
// TODO : Move CL interaction into the CLCaster?
bool CLCaster::create_viewport(int width, int height, float v_fov, float h_fov) {
// CL needs the screen resolution
@ -235,46 +244,34 @@ bool CLCaster::create_viewport(int width, int height, float v_fov, float h_fov)
// This could be modified to make some odd looking camera lenses
double y_increment_radians = DegreesToRadians(v_fov / view_res.y);
double x_increment_radians = DegreesToRadians(h_fov / view_res.x);
viewport_matrix = new sf::Vector4f[width * height * 4];
for (int y = -view_res.y / 2; y < view_res.y / 2; y++) {
for (int x = -view_res.x / 2; x < view_res.x / 2; x++) {
// The base ray direction to slew from
sf::Vector3f ray(1, 0, 0);
// Y axis, pitch
ray = sf::Vector3f(
static_cast<float>(ray.z * sin(y_increment_radians * y) + ray.x * cos(y_increment_radians * y)),
static_cast<float>(ray.y),
static_cast<float>(ray.z * cos(y_increment_radians * y) - ray.x * sin(y_increment_radians * y))
);
// Z axis, yaw
ray = sf::Vector3f(
static_cast<float>(ray.x * cos(x_increment_radians * x) - ray.y * sin(x_increment_radians * x)),
static_cast<float>(ray.x * sin(x_increment_radians * x) + ray.y * cos(x_increment_radians * x)),
static_cast<float>(ray.z)
);
sf::Vector3f ray(-800, x, y);
// correct for the base ray pointing to (1, 0, 0) as (0, 0). Should equal (1.57, 0)
ray = sf::Vector3f(
static_cast<float>(ray.z * sin(-1.57) + ray.x * cos(-1.57)),
static_cast<float>(ray.z * sin(1.57) + ray.x * cos(1.57)),
static_cast<float>(ray.y),
static_cast<float>(ray.z * cos(-1.57) - ray.x * sin(-1.57))
static_cast<float>(ray.z * cos(1.57) - ray.x * sin(1.57))
);
int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2);
ray.y += (rand() % 1000) / 100000.0;
ray.x += (rand() % 1000) / 100000.0;
ray.z += (rand() % 1000) / 100000.0;
ray = Normalize(ray);
int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2);
viewport_matrix[index] = sf::Vector4f(
ray.x,
ray.y,
ray.z,
0
ray.x,
ray.y,
ray.z,
0
);
}
}
@ -306,6 +303,18 @@ bool CLCaster::create_viewport(int width, int height, float v_fov, float h_fov)
}
bool CLCaster::release_viewport() {
bool success = true;
if (!release_buffer("viewport_resolution"))
success = false;
if (!release_buffer("viewport_matrix"))
success = false;
if (!release_buffer("image"))
success = false;
return success;
}
bool CLCaster::assign_lights(std::vector<PackedData> *data) {
// Get a pointer to the packed light data
@ -855,6 +864,7 @@ bool CLCaster::release_buffer(std::string buffer_name) {
if (buffer_map.count(buffer_name) > 0) {
clFinish(command_queue);
int error = clReleaseMemObject(buffer_map.at(buffer_name));
if (cl_assert(error)) {
@ -1160,6 +1170,7 @@ std::string CLCaster::cl_err_lookup(int error_code) {
}
CLCaster::device::device(cl_device_id device_id, cl_platform_id platform_id) {
this->device_id = device_id;

@ -16,7 +16,7 @@ ArrayMap::ArrayMap(sf::Vector3i dimensions) {
for (int x = 0; x < dimensions.x; x++) {
for (int y = 0; y < dimensions.y; y++) {
setVoxel(sf::Vector3i(x, y, 0), 1);
setVoxel(sf::Vector3i(x, y, 0), 5);
}
}
}

@ -336,11 +336,13 @@ bool Octree::Validate(char* data, sf::Vector3i dimensions){
char arr_val = get1DIndexedVoxel(data, dimensions, pos);
char oct_val = GetVoxel(pos).found;
if (arr_val != oct_val) {
if (arr_val != oct_val && (oct_val == 0 || arr_val == 0)) {
std::cout << "X: " << pos.x << " Y: " << pos.y << " Z: " << pos.z << " ";
std::cout << (int)arr_val << " : " << (int)oct_val << std::endl;
//return false;
}
}
}
}

Loading…
Cancel
Save