added light controls

master
MitchellHansen 8 years ago
parent 26bc8bff70
commit 86f342432a

Binary file not shown.

Before

Width:  |  Height:  |  Size: 369 KiB

After

Width:  |  Height:  |  Size: 380 KiB

@ -7,7 +7,7 @@ float4 white_light(float4 input, float3 light, int3 mask) {
normalize(light), normalize(light),
normalize(convert_float3(mask * (-mask))) normalize(convert_float3(mask * (-mask)))
) )
) / 2; ) / 8;
return input; return input;
@ -19,6 +19,7 @@ float4 white_light(float4 input, float3 light, int3 mask) {
// 0 1 2 3 4 5 6 7 8 9 // 0 1 2 3 4 5 6 7 8 9
// {r, g, b, i, x, y, z, x', y', z'} // {r, g, b, i, x, y, z, x', y', z'}
float4 view_light(float4 in_color, float3 light, float3 view, int3 mask) { float4 view_light(float4 in_color, float3 light, float3 view, int3 mask) {
float diffuse = max(dot(normalize(convert_float3(mask)), normalize(light)), 0.0f); float diffuse = max(dot(normalize(convert_float3(mask)), normalize(light)), 0.0f);
@ -31,8 +32,6 @@ float4 view_light(float4 in_color, float3 light, float3 view, int3 mask) {
in_color += pow(specTmp, 1.0f) * 0.1; in_color += pow(specTmp, 1.0f) * 0.1;
} }
//float3 halfwayDir = normalize(normalize(view) + normalize(light));
//float spec = pow(max(dot(normalize(convert_float3(mask)), halfwayDir), 0.0f), 32.0f);
in_color += 0.02; in_color += 0.02;
return in_color; return in_color;
} }
@ -334,22 +333,13 @@ __kernel void raycaster(
if (face_mask.x == -1) { if (face_mask.x == -1) {
//float z_percent = ((intersection_t.z - delta_t.z) - intersection_t.x) / delta_t.z;
//float y_percent = ((intersection_t.y - delta_t.y) - intersection_t.x) / delta_t.y;
float z_percent = (intersection_t.z - (intersection_t.x - delta_t.x)) / delta_t.z; float z_percent = (intersection_t.z - (intersection_t.x - delta_t.x)) / delta_t.z;
float y_percent = (intersection_t.y - (intersection_t.x - delta_t.x)) / delta_t.y; float y_percent = (intersection_t.y - (intersection_t.x - delta_t.x)) / delta_t.y;
//if (z_percent > 0 && z_percent > 1)
// face_position = (float3)(-1.0f, 1-y_percent, 1-z_percent);
face_position = (float3)(1.001f, y_percent, z_percent); face_position = (float3)(1.001f, y_percent, z_percent);
} }
else if (face_mask.y == -1) { else if (face_mask.y == -1) {
//float x_percent = ((intersection_t.x - delta_t.x) - intersection_t.y) / delta_t.x;
//float z_percent = ((intersection_t.z - delta_t.z) - intersection_t.y) / delta_t.z;
float x_percent = (intersection_t.x - (intersection_t.y - delta_t.y)) / delta_t.x; float x_percent = (intersection_t.x - (intersection_t.y - delta_t.y)) / delta_t.x;
float z_percent = (intersection_t.z - (intersection_t.y - delta_t.y)) / delta_t.z; float z_percent = (intersection_t.z - (intersection_t.y - delta_t.y)) / delta_t.z;
@ -359,9 +349,6 @@ __kernel void raycaster(
else if (face_mask.z == -1) { else if (face_mask.z == -1) {
//float x_percent = ((intersection_t.x - delta_t.x) - intersection_t.z) / delta_t.x;
//float y_percent = ((intersection_t.y - delta_t.y) - intersection_t.z) / delta_t.y;
float x_percent = (intersection_t.x - (intersection_t.z - delta_t.z)) / delta_t.x; float x_percent = (intersection_t.x - (intersection_t.z - delta_t.z)) / delta_t.x;
float y_percent = (intersection_t.y - (intersection_t.z - delta_t.z)) / delta_t.y; float y_percent = (intersection_t.y - (intersection_t.z - delta_t.z)) / delta_t.y;
@ -397,9 +384,9 @@ __kernel void raycaster(
lights, lights,
light_count light_count
)) { )) {
write_imagef(image, pixel, voxel_color); float4 ambient_color = white_light(voxel_color, (float3)(lights[4], lights[5], lights[6]), face_mask);
//write_imagef(image, pixel, voxel_color); write_imagef(image, pixel, ambient_color);
return; return;
} }

@ -38,7 +38,7 @@ void Old_Map::generate_terrain() {
int DATA_SIZE = dimensions.x + 1; int DATA_SIZE = dimensions.x + 1;
//an initial seed value for the corners of the data //an initial seed value for the corners of the data
//srand(f_rand()); //srand(f_rand());
double SEED = rand() % 5 + 10; double SEED = rand() % 10 + 40;
//seed the data //seed the data
set_sample(0, 0, SEED); set_sample(0, 0, SEED);
@ -46,7 +46,7 @@ void Old_Map::generate_terrain() {
set_sample(dimensions.x, 0, SEED); set_sample(dimensions.x, 0, SEED);
set_sample(dimensions.x, dimensions.y, SEED); set_sample(dimensions.x, dimensions.y, SEED);
double h = 5.0;//the range (-h -> +h) for the average offset double h = 40.0;//the range (-h -> +h) for the average offset
//for the new value in range of h //for the new value in range of h
//side length is distance of a single square side //side length is distance of a single square side
//or distance of diagonal in diamond //or distance of diagonal in diamond

@ -40,9 +40,9 @@ const int WINDOW_X = 1000;
const int WINDOW_Y = 1000; const int WINDOW_Y = 1000;
const int WORK_SIZE = WINDOW_X * WINDOW_Y; const int WORK_SIZE = WINDOW_X * WINDOW_Y;
const int MAP_X = 128; const int MAP_X = 256;
const int MAP_Y = 128; const int MAP_Y = 256;
const int MAP_Z = 128; const int MAP_Z = 256;
float elap_time(){ float elap_time(){
static std::chrono::time_point<std::chrono::system_clock> start; static std::chrono::time_point<std::chrono::system_clock> start;
@ -186,12 +186,33 @@ int main() {
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Dash)) { //if (sf::Keyboard::isKeyPressed(sf::Keyboard::Dash)) {
// raycaster->test_edit_viewport(WINDOW_X, WINDOW_Y, w -= 5, h -= 5); // raycaster->test_edit_viewport(WINDOW_X, WINDOW_Y, w -= 5, h -= 5);
//} //}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
light_vec.at(0).position.x -= delta_time * 10;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
light_vec.at(0).position.x += delta_time * 10;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
light_vec.at(0).position.y += delta_time * 10;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
light_vec.at(0).position.y -= delta_time * 10;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Home)) {
light_vec.at(0).position.z += delta_time * 10;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) {
light_vec.at(0).position.z -= delta_time * 10;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) {
light_vec.at(0).position = camera->get_position(); light_vec.at(0).position = camera->get_position();
light_vec.at(0).direction_cartesian = SphereToCart(camera->get_direction()); light_vec.at(0).direction_cartesian = SphereToCart(camera->get_direction());
} }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::O)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::O)) {
light_vec.at(0).orbit_around_center(timer_accumulator += delta_time); light_vec.at(0).orbit_around_center(fmod(timer_accumulator += delta_time, 3));
} }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::M)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::M)) {

Loading…
Cancel
Save