Lots of little tweaks as I figure out the octree. Fixed bug regarding the selects in the kernel dictating material texturing

master
MitchellHansen 7 years ago
parent 4642ab8f0b
commit 9f764f4cbd

@ -208,13 +208,16 @@ __kernel void raycaster(
// traverse an integer split
float3 delta_t = fabs(1.0f / ray_dir);
// offset is how far we are into a voxel, enables sub voxel movement
// Intersection T is the collection of the next intersection points
// for all 3 axis XYZ.
// delta_t * offset = intersection_t
float3 intersection_t = delta_t * ((*cam_pos) - floor(*cam_pos)) * convert_float3(voxel_step);
// for negative values, wrap around the delta_t
// for all 3 axis XYZ. We take the full positive cardinality when
// subtracting the floor, so we must transfer the sign over from
// the voxel step
float3 intersection_t = delta_t * ((*cam_pos) - ceil(*cam_pos)) * convert_float3(voxel_step);
// When we transfer the sign over, we get the correct direction of
// the offset, but we merely transposed over the value instead of mirroring
// it over the axis like we want. So here, isless returns a boolean if intersection_t
// is less than 0 which dictates whether or not we subtract the delta which in effect
// mirrors the offset
intersection_t -= delta_t * convert_float3(isless(intersection_t, 0));
int dist = 0;
@ -258,6 +261,10 @@ __kernel void raycaster(
if (face_mask.x == -1) {
sign.x *= -1.0;
// the next intersection for this plane - the last intersection of the passed plane / delta of this plane
// basically finds how far in on the other 2 axis we are when the ray traversed the plane
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;
@ -332,18 +339,25 @@ __kernel void raycaster(
// }
// Now either use the face position to retrieve a texture sample, or
// just a plain color for the voxel color
voxel_color = select((float4)voxel_color,
(float4)(0.0f, 0.239f, 0.419f, 0.0f),
(int4)(voxel_data == 6));
// just a plain color for the voxel color. Notice the JANK -1 after the
// conditionals in the select statement. That's because select works on negs
// and pos's. So a false equality will still eval as true as it is technically
// a positive result (0)
voxel_color = select(
(float4)(0.25f, 0.64f, 0.87f, 0.0f),
(float4)voxel_color,
(int4)((voxel_data == 5) - 1)
);
voxel_color = select((float4)read_imagef(
voxel_color = select(
(float4)(0.0f, 0.239f, 0.419f, 0.0f),
(float4)read_imagef(
texture_atlas,
convert_int2(tile_face_position * convert_float2(*atlas_dim / *tile_dim)) +
convert_int2((float2)(0, 0) * convert_float2(*atlas_dim / *tile_dim))
convert_int2((float2)(3, 0) * convert_float2(*atlas_dim / *tile_dim))
),
(float4)(0.0f, 0.239f, 0.419f, 0.0f),
(int4)(voxel_data == 5));
(int4)((voxel_data == 6) - 1)
);
voxel_color.w = 0.0f;

@ -130,7 +130,7 @@ int main() {
LightPrototype prototype(
sf::Vector3f(100.0f, 100.0f, 75.0f),
sf::Vector3f(-1.0f, -1.0f, -1.5f),
sf::Vector4f(0.2f, 0.9f, 0.0f, 1.0f)
sf::Vector4f(0.4f, 0.4f, 0.4f, 1.0f)
);
std::shared_ptr<LightHandle> handle(light_controller.create_light(prototype));

@ -157,7 +157,7 @@ std::vector<std::tuple<sf::Vector3i, char>> Map::CastRayOctree(
sf::Vector3i voxel(*cam_pos);
// THIS DOES NOT HAVE TO RETURN TRUE ON FOUND
// This function when passed a "air" voxel will return as far down
// This function when passed an "air" voxel will return as far down
// the IDX stack as it could go. We use this oct-level to determine
// our first position and jump. Updating it as we go
OctState traversal_state = octree->GetVoxel(voxel);
@ -210,21 +210,28 @@ std::vector<std::tuple<sf::Vector3i, char>> Map::CastRayOctree(
delta_t *= static_cast<float>(jump_power);
// offset is how far we are into a voxel, enables sub voxel movement
// Intersection T is the collection of the next intersection points
// for all 3 axis XYZ.
// TODO: start here
// Whats the issue?
// Using traversal_scale
// set intersection t to the current hierarchy level each time we change levels
// and use that to step
// Intersection T is the collection of the next intersection points
// for all 3 axis XYZ. We take the full positive cardinality when
// subtracting the floor, so we must transfer the sign over from
// the voxel step
sf::Vector3f intersection_t(
delta_t.x * (cam_pos->y - floor(cam_pos->x)) * voxel_step.x,
delta_t.y * (cam_pos->x - floor(cam_pos->y)) * voxel_step.y,
delta_t.z * (cam_pos->z - floor(cam_pos->z)) * voxel_step.z
);
// for negative values, wrap around the delta_t
// When we transfer the sign over, we get the correct direction of
// the offset, but we merely transposed over the value instead of mirroring
// it over the axis like we want. So here, isless returns a boolean if intersection_t
// is less than 0 which dictates whether or not we subtract the delta which in effect
// mirrors the offset
intersection_t.x -= delta_t.x * (std::isless(intersection_t.x, 0.0f));
intersection_t.y -= delta_t.y * (std::isless(intersection_t.y, 0.0f));
intersection_t.z -= delta_t.z * (std::isless(intersection_t.z, 0.0f));
@ -273,7 +280,7 @@ std::vector<std::tuple<sf::Vector3i, char>> Map::CastRayOctree(
// If we hit a voxel
//voxel_data = map[voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z))];
voxel_data = getVoxel(voxel);
// voxel_data = getVoxel(voxel);
travel_path.push_back(std::make_tuple(voxel, voxel_data));
if (voxel_data != 0)

@ -234,7 +234,7 @@ void Old_Map::generate_terrain() {
for (int y = 0; y < dimensions.y; y++) {
// for (int z = 0; z < dimensions.z; z++) {
//if (rand() % 1000 < 1)
voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 5;
voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6;
// }
}
}

Loading…
Cancel
Save