Removed the demo movement, added fog, correctly this time!
This commit is contained in:
@@ -38,8 +38,8 @@
|
|||||||
class Application {
|
class Application {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const int WINDOW_X = 1536;
|
const int WINDOW_X = 1600;
|
||||||
const int WINDOW_Y = 1024;
|
const int WINDOW_Y = 900;
|
||||||
|
|
||||||
const int MAP_X = 256;
|
const int MAP_X = 256;
|
||||||
const int MAP_Y = 256;
|
const int MAP_Y = 256;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ __constant const ulong contour_mask = 0xFF00000000000000;
|
|||||||
// =========================================================================
|
// =========================================================================
|
||||||
// ========================= RAYCASTER CONSTANTS ===========================
|
// ========================= RAYCASTER CONSTANTS ===========================
|
||||||
|
|
||||||
constant float4 fog_color = { 0.73f, 0.81f, 0.89f, 0.8f };
|
constant float4 fog_color = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
constant float4 overshoot_color = { 0.00f, 0.00f, 0.00f, 0.00f };
|
constant float4 overshoot_color = { 0.00f, 0.00f, 0.00f, 0.00f };
|
||||||
constant float4 overshoot_color_2 = { 0.00f, 0.00f, 0.00f, 0.00f };
|
constant float4 overshoot_color_2 = { 0.00f, 0.00f, 0.00f, 0.00f };
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ float4 view_light(float4 in_color, float3 light, float4 light_color, float3 view
|
|||||||
if (all(light == zeroed_float3))
|
if (all(light == zeroed_float3))
|
||||||
return zeroed_float4;
|
return zeroed_float4;
|
||||||
|
|
||||||
float d = Distance(light) / 140.0f;
|
float d = Distance(light) / 280.0f;
|
||||||
d *= d;
|
d *= d;
|
||||||
|
|
||||||
float diffuse = max(dot(normalize(convert_float3(mask)), normalize(light)), 0.0f);
|
float diffuse = max(dot(normalize(convert_float3(mask)), normalize(light)), 0.0f);
|
||||||
@@ -296,6 +296,7 @@ __kernel void raycaster(
|
|||||||
float2 tile_face_position = zeroed_float2;
|
float2 tile_face_position = zeroed_float2;
|
||||||
float3 sign = zeroed_float3;
|
float3 sign = zeroed_float3;
|
||||||
float4 color_accumulator = zeroed_float4;
|
float4 color_accumulator = zeroed_float4;
|
||||||
|
float fog_distance = 0.0f;
|
||||||
|
|
||||||
bool shadow_ray = false;
|
bool shadow_ray = false;
|
||||||
|
|
||||||
@@ -404,7 +405,7 @@ __kernel void raycaster(
|
|||||||
// Now we detect what type of of voxel we intersected and decide whether
|
// Now we detect what type of of voxel we intersected and decide whether
|
||||||
// to bend the ray, send out a light intersection ray, or add texture color
|
// to bend the ray, send out a light intersection ray, or add texture color
|
||||||
|
|
||||||
// SHADOWING
|
// TEXTURE HIT + SHADOW REDIRECTION
|
||||||
if (voxel_data == 5 && !shadow_ray){
|
if (voxel_data == 5 && !shadow_ray){
|
||||||
|
|
||||||
shadow_ray = true;
|
shadow_ray = true;
|
||||||
@@ -422,9 +423,9 @@ __kernel void raycaster(
|
|||||||
face_mask * voxel_step
|
face_mask * voxel_step
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fog_distance = distance_traveled;
|
||||||
|
max_distance = distance_traveled + DistanceBetweenPoints(convert_float3(voxel), (float3)(lights[4], lights[5], lights[6]));
|
||||||
|
|
||||||
max_distance = DistanceBetweenPoints(convert_float3(voxel), (float3)(lights[4], lights[5], lights[6]));
|
|
||||||
distance_traveled = 0;
|
|
||||||
|
|
||||||
float3 hit_pos = convert_float3(voxel) + face_position;
|
float3 hit_pos = convert_float3(voxel) + face_position;
|
||||||
ray_dir = normalize((float3)(lights[4], lights[5], lights[6]) - hit_pos);
|
ray_dir = normalize((float3)(lights[4], lights[5], lights[6]) - hit_pos);
|
||||||
@@ -448,8 +449,8 @@ __kernel void raycaster(
|
|||||||
).xyz/4;
|
).xyz/4;
|
||||||
|
|
||||||
voxel_color.w -= 0.0f;
|
voxel_color.w -= 0.0f;
|
||||||
max_distance = 700;
|
//max_distance += 200;
|
||||||
distance_traveled = 0;
|
|
||||||
|
|
||||||
float3 hit_pos = convert_float3(voxel) + face_position;
|
float3 hit_pos = convert_float3(voxel) + face_position;
|
||||||
ray_dir *= sign;
|
ray_dir *= sign;
|
||||||
@@ -478,6 +479,7 @@ __kernel void raycaster(
|
|||||||
// At the bottom of the while loop, add one to the distance ticker
|
// At the bottom of the while loop, add one to the distance ticker
|
||||||
distance_traveled++;
|
distance_traveled++;
|
||||||
}
|
}
|
||||||
|
color_accumulator = mix(fog_color, color_accumulator, 1.0f - max(fog_distance / 700.0f, 0.0f));
|
||||||
write_imagef(
|
write_imagef(
|
||||||
image,
|
image,
|
||||||
pixel,
|
pixel,
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ bool Application::init_events() {
|
|||||||
window_handler->subscribe_to_publisher(&input_handler, vr::Event::EventType::Closed);
|
window_handler->subscribe_to_publisher(&input_handler, vr::Event::EventType::Closed);
|
||||||
window_handler->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed);
|
window_handler->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed);
|
||||||
|
|
||||||
raycaster->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed);
|
//raycaster->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed);
|
||||||
//camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::JoystickMoved);
|
//camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::JoystickMoved);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -118,14 +118,6 @@ bool Application::game_loop() {
|
|||||||
while ((accumulator_time - step_size) >= step_size) {
|
while ((accumulator_time - step_size) >= step_size) {
|
||||||
accumulator_time -= step_size;
|
accumulator_time -= step_size;
|
||||||
|
|
||||||
sf::Vector3f light_pos = light_handle->get_position();
|
|
||||||
light_pos.x = sin(elapsed_time / 2) * 100 + 100;
|
|
||||||
light_handle->set_position(light_pos);
|
|
||||||
|
|
||||||
sf::Vector3f cam_pos = camera->get_position();
|
|
||||||
cam_pos.x = sin(elapsed_time / 2 + 3.141f) * 50 + 125;
|
|
||||||
camera->set_position(cam_pos);
|
|
||||||
|
|
||||||
// ==== DELTA TIME LOCKED ====
|
// ==== DELTA TIME LOCKED ====
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,20 +147,6 @@ bool Application::game_loop() {
|
|||||||
|
|
||||||
Gui::do_render();
|
Gui::do_render();
|
||||||
|
|
||||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar;
|
|
||||||
bool window_show = true;
|
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::BeginMenuBar())
|
|
||||||
{
|
|
||||||
if (ImGui::BeginMenu("Menu"))
|
|
||||||
{
|
|
||||||
ImGui::Button("asdoifjasodif");
|
|
||||||
ImGui::EndMenu();
|
|
||||||
}
|
|
||||||
ImGui::EndMenuBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::Begin("Window");
|
ImGui::Begin("Window");
|
||||||
ImGui::InputText("filename", screenshot_buf, 128);
|
ImGui::InputText("filename", screenshot_buf, 128);
|
||||||
if (ImGui::Button("Take Screen shot")) {
|
if (ImGui::Button("Take Screen shot")) {
|
||||||
@@ -201,45 +179,6 @@ bool Application::game_loop() {
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
ImGui::Begin("Controller debugger");
|
|
||||||
|
|
||||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
|
||||||
static ImVec4 col = ImVec4(1.0f, 0.0f, 1.0f, 1.0f);
|
|
||||||
const ImVec2 p = ImGui::GetCursorScreenPos();
|
|
||||||
const ImU32 col32 = ImColor(col);
|
|
||||||
|
|
||||||
std::vector<float> axis_values = {
|
|
||||||
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::X) / 2,
|
|
||||||
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Y) / 2,
|
|
||||||
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::U) / 2,
|
|
||||||
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::R) / 2,
|
|
||||||
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Z) / 2,
|
|
||||||
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::V) / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
ImGui::Columns(3, "Axis's"); // 4-ways, with border
|
|
||||||
ImGui::Separator();
|
|
||||||
ImGui::Text("X Y"); ImGui::NextColumn();
|
|
||||||
ImGui::Text("U R"); ImGui::NextColumn();
|
|
||||||
ImGui::Text("Z V"); ImGui::NextColumn();
|
|
||||||
ImGui::Separator();
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
|
|
||||||
|
|
||||||
float offset = ImGui::GetColumnWidth(i);
|
|
||||||
|
|
||||||
draw_list->AddLine(ImVec2(p.x + 0 + offset * i, p.y + 50), ImVec2(p.x + 100 + offset * i, p.y + 50), col32, 1.0);
|
|
||||||
draw_list->AddLine(ImVec2(p.x + 50 + offset * i, p.y + 0), ImVec2(p.x + 50 + offset * i, p.y + 100), col32, 1.0);
|
|
||||||
draw_list->AddCircleFilled(ImVec2(p.x + axis_values[2 * i] + 50 + offset * i, p.y + axis_values[2 * i + 1] + 50), 6, col32, 32);
|
|
||||||
|
|
||||||
ImGui::Dummy(ImVec2(100, 100));
|
|
||||||
ImGui::NextColumn();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
//ImGui::ShowTestWindow();
|
//ImGui::ShowTestWindow();
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|||||||
Reference in New Issue
Block a user