Shadows now working, though they are still voxel based. Need to calculate where on the surface the ray hits, and then send the ray out from that point.

This commit is contained in:
MitchellHansen
2017-01-15 23:23:43 -08:00
parent 9a12fba310
commit cc7a4a2efb
3 changed files with 42 additions and 64 deletions

View File

@@ -109,7 +109,7 @@ float4 view_light(float4 in_color, float3 light, float3 view, int3 mask) {
//float3 halfwayDir = normalize(normalize(view) + normalize(light)); //float3 halfwayDir = normalize(normalize(view) + normalize(light));
//float spec = pow(max(dot(normalize(convert_float3(mask)), halfwayDir), 0.0f), 32.0f); //float spec = pow(max(dot(normalize(convert_float3(mask)), halfwayDir), 0.0f), 32.0f);
in_color.w += 0.2; in_color += 0.02;
return in_color; return in_color;
} }
@@ -274,7 +274,7 @@ __kernel void raycaster(
int3 face_mask = { 0, 0, 0 }; int3 face_mask = { 0, 0, 0 };
float4 fog_color = { 0.73, 0.81, 0.89, 0.8 }; float4 fog_color = { 0.73, 0.81, 0.89, 0.8 };
float4 voxel_color = (float4)(0.25, 0.52, 0.30, 0.1); float4 voxel_color = (float4)(0.50, 0.0, 0.50, 0.1);
float4 overshoot_color = { 0.25, 0.48, 0.52, 0.8 }; float4 overshoot_color = { 0.25, 0.48, 0.52, 0.8 };
@@ -305,22 +305,27 @@ __kernel void raycaster(
if (voxel_data != 0) { if (voxel_data != 0) {
switch (voxel_data) {
case 5:
// write_imagef(image, pixel, (float4)(0.90, 0.00, 0.40, 0.9)); // write_imagef(image, pixel, (float4)(0.90, 0.00, 0.40, 0.9));
if (!cast_light_intersection_ray( if (voxel_data == 6) {
voxel_color = (float4)(0.0, 0.239, 0.419, 0.3);
}
else if (voxel_data == 5) {
voxel_color = (float4)(0.25, 0.52, 0.30, 0.1);
}
if (cast_light_intersection_ray(
map, map,
map_dim, map_dim,
(float3)(lights[4], lights[5], lights[6]) - (convert_float3(voxel) + offset), (float3)(lights[4], lights[5], lights[6]) - (convert_float3(voxel)),
(convert_float3(voxel) + offset + convert_float3(face_mask)/10.0f), (convert_float3(voxel) - convert_float3(face_mask * voxel_step)),
lights, lights,
light_count light_count
)) { )) {
write_imagef(image, pixel, (float4)(0.90, 0.00, 0.40, 0.9)); write_imagef(image, pixel, voxel_color);
//write_imagef(image, pixel, voxel_color);
return; return;
} }
@@ -337,34 +342,7 @@ __kernel void raycaster(
return; return;
float3 vox = convert_float3(voxel);
float3 norm = normalize(convert_float3(face_mask) * convert_float3(voxel_step));
float4 color = (float4)(0.95, 0.00, 0.25, 1.00);
write_imagef(image, pixel,
cast_light_rays(
ray_dir,
vox,
color,
norm ,
lights,
light_count
));
return;
case 6:
write_imagef(image, pixel, view_light((float4)(0.0, 0.239, 0.419, 0.3), (convert_float3(voxel) + offset) - (float3)(lights[4], lights[5], lights[6]), (convert_float3(voxel) + offset) - (*cam_pos), face_mask * voxel_step));
//write_imagef(image, pixel, white_light(mix((float4)(0.73, 0.81, 0.89, 0.6), (float4)(0.0, 0.239, 0.419, 0.3), 1.0 - max((dist / 700.0f) - 0.3f, (float)0)), (float3)(lights[7], lights[8], lights[9]), face_mask));
return;
default:
write_imagef(image, pixel, (float4)(.30, .10, .10, 1.00));
continue;
}
} }
dist++; dist++;

View File

@@ -37,7 +37,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() % 25 + 55; double SEED = rand() % 30 + 55;
//seed the data //seed the data
set_sample(0, 0, SEED); set_sample(0, 0, SEED);

View File

@@ -116,7 +116,7 @@ int main() {
// Light for the currently non functional Bling Phong shader // Light for the currently non functional Bling Phong shader
Light l; Light l;
l.direction_cartesian = sf::Vector3f(-0.2f, -0.2f, -1.5f); l.direction_cartesian = sf::Vector3f(-0.2f, -0.2f, -1.5f);
l.position = sf::Vector3f(100.0f, 100.0f, 500.0f); l.position = sf::Vector3f(100.0f, 500.0f, 100.0f);
l.rgbi = sf::Vector4f(0.3f, 0.4f, 0.3f, 1.0f); l.rgbi = sf::Vector4f(0.3f, 0.4f, 0.3f, 1.0f);
std::vector<Light> light_vec; std::vector<Light> light_vec;
@@ -180,7 +180,7 @@ int main() {
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::L)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::L)) {
light_vec.at(0).position.y += 0.5; light_vec.at(0).position = camera->get_position();
} }
// Time keeping // Time keeping