Tweaked indexing, there is a discrepancy at z_max values that I need to

sort out. Added some 2d optimization functions for fun, currently doing a
class involving them
master
MitchellHansen 8 years ago
parent 582e37f540
commit 0b3557cd5e

@ -6,6 +6,9 @@
#include <iostream>
#include <functional>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include <deque>
class Map {
@ -57,30 +60,85 @@ public:
//generate_octree();
//return;
dimensions = dim;
std::mt19937 gen;
std::uniform_real_distribution<double> dis(-1.0, 1.0);
auto f_rand = std::bind(dis, gen);
list = new char[dim.x * dim.y * dim.z];
height_map = new double[dim.x * dim.y];
for (int i = 0; i < dim.x * dim.y * dim.z; i++) {
list[i] = 0;
}
//for (int x = -dim.x / 2; x < dim.x/2; x++) {
// for (int y = -dim.y / 2; y < dim.y/2; y++) {
//
// double height = 20;
// height += std::pow(x / 50.0, 2) - 10 * std::cos(2 * 3.1415926 * x / 50.0);
// height += std::pow(y / 50.0, 2) - 10 * std::cos(2 * 3.1415926 * y / 50.0);
//
// list[(x + dim.x/2) + dim.x * ((y +dim.y/2) + dim.z * (int)height)] = 5;
// }
//}
int xx = 0;
int yy = 0;
for (int x = -dim.x / 2; x < dim.x / 2; x++) {
for (int y = -dim.y / 2; y < dim.y / 2; y++) {
double z = 150;
//for (int x = 0; x < dim.x; x++) {
// for (int y = 0; y < dim.y; y++) {
double height = 0;
z += -x*2 * std::sin(std::sqrt(abs(x*2 - y*2 - 47))) -
(y*2 + 47) * std::sin(std::sqrt(std::abs(y*2 + 47 + x*2 / 2)));
//z += x * std::sin(std::sqrt(std::abs(y - x + 1))) *
// std::cos(std::sqrt(std::abs(y + x + 1))) +
// (y + 1) *
// std::cos(std::sqrt(std::abs(y - x + 1))) *
// std::sin(std::sqrt(std::abs(y + x + 1)));
// Pathological
//z += 0.5 +
// (std::pow(std::sin(std::sqrt(100 * std::pow(x/20, 2) + std::pow(y/20, 2))), 2) - 0.5) /
// (1 + 0.001 * std::pow(std::pow(x/20, 2) - 2 * x/20 * y/20 + std::pow(y/20, 2), 2));
// Ackleys
//z += 20 + M_E -
// (20 / (std::pow(M_E, 0.2) * std::sqrt((std::pow(x / 16.0, 2) + std::pow(y / 16.0, 2) + 1) / 2))) -
// std::pow(M_E, 0.5 * std::cos(2 * M_PI * x / 16.0) + cos(2 * M_PI * y / 16.0));
//
//z += -20 * std::pow(M_E, -0.2 * sqrt(0.5 * std::pow(x/64.0, 2) + std::pow(y/64.0, 2))) - std::pow(M_E, 0.5 * (cos(2 * M_PI * x/64.0) + (cos(2 * M_PI * y/64.0)))) + 20 + M_E;
//list[x + dim.x * (y + dim.z * (int)height)] = 5;
double m = 0.7;
while ((z*m) > 0){
list[xx + dim.x * (yy + dim.z * (int)(z*m))] = 5;
z -= 1/m;
}
yy++;
dimensions = dim;
std::mt19937 gen;
std::uniform_real_distribution<double> dis(-1.0, 1.0);
auto f_rand = std::bind(dis, gen);
}
yy = 0;
xx++;
}
list = new char[dim.x * dim.y * dim.z];
return;
height_map = new double[dim.x * dim.y];
for (int i = 0; i < dim.x * dim.y; i++) {
height_map[i] = 0;
}
//int featuresize = 2;
@ -109,7 +167,7 @@ public:
//value 2^n+1
int DATA_SIZE = dim.x + 1;
//an initial seed value for the corners of the data
double SEED = 50;
double SEED = rand() % 25 + 25;
//seed the data
setSample(0, 0, SEED);

@ -13,7 +13,12 @@ float4 white_light(float4 input, float3 light, int3 mask) {
}
// {r, g, b, i, x, y, z, x', y', z'}
float4 cast_light_rays(float3 ray_origin, global float* lights, global int* light_count) {
}
__kernel void min_kern(
global char* map,
@ -81,7 +86,7 @@ __kernel void min_kern(
uint t = seed ^ (seed << 11);
uint result = randoms.y ^ (randoms.y >> 19) ^ (t ^ (t >> 8));
int max_dist = 500 + result % 50;
int max_dist = 800 + result % 50;
int dist = 0;
int3 mask = { 0, 0, 0 };
@ -90,7 +95,6 @@ __kernel void min_kern(
do {
mask = intersection_t.xyz <= min(intersection_t.yzx, intersection_t.zxy);
intersection_t += delta_t * fabs(convert_float3(mask.xyz));
voxel.xyz += voxel_step.xyz * mask.xyz;
@ -108,7 +112,9 @@ __kernel void min_kern(
}
// If we hit a voxel
int index = voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * voxel.z);
//int index = voxel.x * (*map_dim).y * (*map_dim).z + voxel.z * (*map_dim).z + voxel.y;
// Why the off by one on voxel.y?
int index = voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z-1));
int voxel_data = map[index];
if (voxel_data != 0) {
@ -127,11 +133,15 @@ __kernel void min_kern(
return;
case 5:
//write_imagef(image, pixel, (float4)(.25, .00, .25, 1.00));
write_imagef(image, pixel, white_light((float4)(.25, .32, .14, 0.2), (float3)(lights[7], lights[8], lights[9]), mask));
write_imagef(image, pixel, white_light((float4)(.25, .32, .14, 0.2), (float3)(lights[7], lights[8], lights[9]), mask));
//cast_light_rays(voxel, lights, light_count)
return;
case 6:
write_imagef(image, pixel, (float4)(.30, .80, .10, 1.00));
return;
default:
write_imagef(image, pixel, (float4)(.30, .80, .10, 1.00));
return;
}
}

@ -38,9 +38,9 @@ const int WINDOW_X = 1000;
const int WINDOW_Y = 1000;
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
const int MAP_X = 1024;
const int MAP_Y = 1024;
const int MAP_Z = 256;
const int MAP_X = 512;
const int MAP_Y = 512;
const int MAP_Z = 512;
float elap_time(){
static std::chrono::time_point<std::chrono::system_clock> start;
@ -135,7 +135,7 @@ int main() {
c.create_buffer("view_matrix_buffer", sizeof(float) * 4 * view_res.x * view_res.y, view_matrix);
Camera camera(
sf::Vector3f(55, 50, 50),
sf::Vector3f(256, 256, 256),
sf::Vector2f(0.0f, 1.00f)
);

Loading…
Cancel
Save