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.

master
MitchellHansen 8 years ago
parent 9a12fba310
commit cc7a4a2efb

@ -39,7 +39,7 @@ bool cast_light_intersection_ray(
// Intersection T is the collection of the next intersection points
// for all 3 axis XYZ.
float3 intersection_t = delta_t * offset;
float3 intersection_t = delta_t *offset;
// for negative values, wrap around the delta_t, rather not do this
// component wise, but it doesn't appear to want to work
@ -109,7 +109,7 @@ float4 view_light(float4 in_color, float3 light, float3 view, int3 mask) {
//float3 halfwayDir = normalize(normalize(view) + normalize(light));
//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;
}
@ -274,7 +274,7 @@ __kernel void raycaster(
int3 face_mask = { 0, 0, 0 };
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 };
@ -305,22 +305,27 @@ __kernel void raycaster(
if (voxel_data != 0) {
switch (voxel_data) {
// write_imagef(image, pixel, (float4)(0.90, 0.00, 0.40, 0.9));
case 5:
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);
}
// write_imagef(image, pixel, (float4)(0.90, 0.00, 0.40, 0.9));
if (!cast_light_intersection_ray(
if (cast_light_intersection_ray(
map,
map_dim,
(float3)(lights[4], lights[5], lights[6]) - (convert_float3(voxel) + offset),
(convert_float3(voxel) + offset + convert_float3(face_mask)/10.0f),
(float3)(lights[4], lights[5], lights[6]) - (convert_float3(voxel)),
(convert_float3(voxel) - convert_float3(face_mask * voxel_step)),
lights,
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;
}
@ -337,34 +342,7 @@ __kernel void raycaster(
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++;

@ -37,7 +37,7 @@ void Old_Map::generate_terrain() {
int DATA_SIZE = dimensions.x + 1;
//an initial seed value for the corners of the data
//srand(f_rand());
double SEED = rand() % 25 + 55;
double SEED = rand() % 30 + 55;
//seed the data
set_sample(0, 0, SEED);

@ -116,7 +116,7 @@ int main() {
// Light for the currently non functional Bling Phong shader
Light l;
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);
std::vector<Light> light_vec;
@ -180,7 +180,7 @@ int main() {
raycaster->test_edit_viewport(WINDOW_X, WINDOW_Y, w -= 5, h -= 5);
}
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

Loading…
Cancel
Save