Added color to lights, added a gui slider to control the single light color
This commit is contained in:
@@ -41,6 +41,11 @@ struct device {
|
|||||||
bool cl_gl_sharing = false;
|
bool cl_gl_sharing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct raycaster_settings {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct PackedData;
|
struct PackedData;
|
||||||
|
|
||||||
class Hardware_Caster : public RayCaster
|
class Hardware_Caster : public RayCaster
|
||||||
|
|||||||
@@ -20,16 +20,16 @@ float4 white_light(float4 input, float3 light, int3 mask) {
|
|||||||
// {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, float4 light_color, 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);
|
||||||
in_color += diffuse * 0.2;
|
in_color += diffuse * 0.2f * light_color; //(float4)(1.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
if (dot(light, normalize(convert_float3(mask))) > 0.0)
|
if (dot(light, normalize(convert_float3(mask))) > 0.0f)
|
||||||
{
|
{
|
||||||
float3 halfwayVector = normalize(normalize(light) + normalize(view));
|
float3 halfwayVector = normalize(normalize(light) + normalize(view));
|
||||||
float specTmp = max(dot(normalize(convert_float3(mask)), halfwayVector), 0.0f);
|
float specTmp = max(dot(normalize(convert_float3(mask)), halfwayVector), 0.0f);
|
||||||
in_color += pow(specTmp, 1.0f) * 0.5;
|
in_color += pow(specTmp, 1.0f) * 0.5f * light_color;//(float4)(1.0f, 1.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//in_color += 0.02;
|
//in_color += 0.02;
|
||||||
@@ -200,10 +200,10 @@ __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.73f, 0.81f, 0.89f, 0.8f };
|
||||||
float4 voxel_color = (float4)(0.50, 0.0, 0.50, 0.1);
|
float4 voxel_color = (float4)(0.50f, 0.0f, 0.50f, 0.1f);
|
||||||
float4 overshoot_color = { 0.25, 0.48, 0.52, 0.8 };
|
float4 overshoot_color = { 0.25f, 0.48f, 0.52f, 0.8f };
|
||||||
float4 overshoot_color_2 = { 0.25, 0.1, 0.52, 0.8 };
|
float4 overshoot_color_2 = { 0.25f, 0.1f, 0.52f, 0.8f };
|
||||||
|
|
||||||
|
|
||||||
// Andrew Woo's raycasting algo
|
// Andrew Woo's raycasting algo
|
||||||
@@ -307,17 +307,20 @@ __kernel void raycaster(
|
|||||||
// just a plain color for the voxel color
|
// just a plain color for the voxel color
|
||||||
|
|
||||||
if (voxel_data == 6) {
|
if (voxel_data == 6) {
|
||||||
voxel_color = (float4)(0.0, 0.239, 0.419, 0.3);
|
voxel_color = (float4)(0.0f, 0.239f, 0.419f, 0.3f);
|
||||||
}
|
}
|
||||||
else if (voxel_data == 5) {
|
else if (voxel_data == 5) {
|
||||||
float2 tile_size = convert_float2(*atlas_dim / *tile_dim);
|
float2 tile_size = convert_float2(*atlas_dim / *tile_dim);
|
||||||
voxel_color = read_imagef(texture_atlas, convert_int2(tile_face_position * tile_size) + convert_int2((float2)(3, 0) * tile_size));
|
voxel_color = read_imagef(texture_atlas, convert_int2(tile_face_position * tile_size) + convert_int2((float2)(3, 0) * tile_size));
|
||||||
|
voxel_color.w = 0.3f;
|
||||||
//voxel_color = (float4)(0.25, 0.52, 0.30, 0.1);
|
//voxel_color = (float4)(0.25, 0.52, 0.30, 0.1);
|
||||||
}
|
}
|
||||||
else if (voxel_data == 1) {
|
else if (voxel_data == 1) {
|
||||||
voxel_color = (float4)(0.929, 0.957, 0.027, 0.7);
|
voxel_color = (float4)(0.929f, 0.957f, 0.027f, 0.3f);
|
||||||
}
|
}
|
||||||
|
//else {
|
||||||
|
// voxel_color = (float4)(1.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
//}
|
||||||
//
|
//
|
||||||
|
|
||||||
if (cast_light_intersection_ray(
|
if (cast_light_intersection_ray(
|
||||||
@@ -329,6 +332,7 @@ __kernel void raycaster(
|
|||||||
light_count
|
light_count
|
||||||
)) {
|
)) {
|
||||||
|
|
||||||
|
// If the light ray intersected an object on the way to the light point
|
||||||
float4 ambient_color = white_light(voxel_color, (float3)(lights[4], lights[5], lights[6]), face_mask);
|
float4 ambient_color = white_light(voxel_color, (float3)(lights[4], lights[5], lights[6]), face_mask);
|
||||||
write_imagef(image, pixel, ambient_color);
|
write_imagef(image, pixel, ambient_color);
|
||||||
return;
|
return;
|
||||||
@@ -343,6 +347,7 @@ __kernel void raycaster(
|
|||||||
view_light(
|
view_light(
|
||||||
voxel_color,
|
voxel_color,
|
||||||
(convert_float3(voxel) + face_position) - (float3)(lights[4], lights[5], lights[6]),
|
(convert_float3(voxel) + face_position) - (float3)(lights[4], lights[5], lights[6]),
|
||||||
|
(float4)(lights[0], lights[1], lights[2], lights[3]),
|
||||||
(convert_float3(voxel) + face_position) - (*cam_pos),
|
(convert_float3(voxel) + face_position) - (*cam_pos),
|
||||||
face_mask * voxel_step
|
face_mask * voxel_step
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ void LightHandle::add_movement(sf::Vector3f movement)
|
|||||||
|
|
||||||
void LightHandle::set_position(sf::Vector3f position)
|
void LightHandle::set_position(sf::Vector3f position)
|
||||||
{
|
{
|
||||||
|
data_reference->position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightHandle::set_direction(sf::Vector3f direction)
|
void LightHandle::set_direction(sf::Vector3f direction)
|
||||||
@@ -60,7 +60,7 @@ void LightHandle::set_direction(sf::Vector3f direction)
|
|||||||
|
|
||||||
void LightHandle::set_rgbi(sf::Vector4f rgbi)
|
void LightHandle::set_rgbi(sf::Vector4f rgbi)
|
||||||
{
|
{
|
||||||
|
data_reference->rgbi = rgbi;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightHandle::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Event> event)
|
void LightHandle::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Event> event)
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ void Old_Map::generate_terrain() {
|
|||||||
|
|
||||||
int z = static_cast<int>(height_map[x + y * dimensions.x]);
|
int z = static_cast<int>(height_map[x + y * dimensions.x]);
|
||||||
|
|
||||||
while (z > 0) {
|
while (z > 0 && z < dimensions.z) {
|
||||||
voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 5;
|
voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 5;
|
||||||
z--;
|
z--;
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/main.cpp
15
src/main.cpp
@@ -143,7 +143,7 @@ int main() {
|
|||||||
LightPrototype prototype(
|
LightPrototype prototype(
|
||||||
sf::Vector3f(100.0f, 100.0f, 30.0f),
|
sf::Vector3f(100.0f, 100.0f, 30.0f),
|
||||||
sf::Vector3f(-1.0f, -1.0f, -1.5f),
|
sf::Vector3f(-1.0f, -1.0f, -1.5f),
|
||||||
sf::Vector4f(1.0f, 1.0f, 1.0f, 1.0f)
|
sf::Vector4f(0.2f, 0.9f, 0.0f, 1.0f)
|
||||||
);
|
);
|
||||||
|
|
||||||
std::shared_ptr<LightHandle> handle(light_controller.create_light(prototype));
|
std::shared_ptr<LightHandle> handle(light_controller.create_light(prototype));
|
||||||
@@ -178,6 +178,8 @@ int main() {
|
|||||||
sf::Clock sf_delta_clock;
|
sf::Clock sf_delta_clock;
|
||||||
fps_counter fps;
|
fps_counter fps;
|
||||||
|
|
||||||
|
float light_color[4] = { 0, 0, 0, 0 };
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
|
|
||||||
input_handler.consume_sf_events(&window);
|
input_handler.consume_sf_events(&window);
|
||||||
@@ -254,6 +256,17 @@ int main() {
|
|||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
ImGui::Begin("Lights");
|
||||||
|
|
||||||
|
if (ImGui::SliderFloat4("Color", light_color, 0, 1)) {
|
||||||
|
sf::Vector4f light(light_color[0], light_color[1], light_color[2], light_color[3]);
|
||||||
|
handle->set_rgbi(light);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ int Hardware_Caster::debug_quick_recompile()
|
|||||||
}
|
}
|
||||||
validate();
|
validate();
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hardware_Caster::test_edit_viewport(int width, int height, float v_fov, float h_fov)
|
void Hardware_Caster::test_edit_viewport(int width, int height, float v_fov, float h_fov)
|
||||||
@@ -377,6 +377,11 @@ int Hardware_Caster::acquire_platform_and_device() {
|
|||||||
current_best_device = device;
|
current_best_device = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if (device.type == CL_DEVICE_TYPE_CPU &&
|
||||||
|
// current_best_device.type != CL_DEVICE_TYPE_CPU) {
|
||||||
|
// current_best_device = device;
|
||||||
|
//}
|
||||||
|
|
||||||
// Get the unit with the higher compute units
|
// Get the unit with the higher compute units
|
||||||
if (device.comp_units > current_best_device.comp_units) {
|
if (device.comp_units > current_best_device.comp_units) {
|
||||||
current_best_device = device;
|
current_best_device = device;
|
||||||
@@ -390,6 +395,7 @@ int Hardware_Caster::acquire_platform_and_device() {
|
|||||||
if (current_best_device.cl_gl_sharing == false && device.cl_gl_sharing == true) {
|
if (current_best_device.cl_gl_sharing == false && device.cl_gl_sharing == true) {
|
||||||
current_best_device = device;
|
current_best_device = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,6 +406,7 @@ int Hardware_Caster::acquire_platform_and_device() {
|
|||||||
std::cout << "Selected Platform : " << platform_id << std::endl;
|
std::cout << "Selected Platform : " << platform_id << std::endl;
|
||||||
std::cout << "Selected Device : " << device_id << std::endl;
|
std::cout << "Selected Device : " << device_id << std::endl;
|
||||||
std::cout << "Selected Name : " << current_best_device.name << std::endl;
|
std::cout << "Selected Name : " << current_best_device.name << std::endl;
|
||||||
|
std::cout << "Selected Version : " << current_best_device.version << std::endl;
|
||||||
|
|
||||||
if (current_best_device.cl_gl_sharing == false) {
|
if (current_best_device.cl_gl_sharing == false) {
|
||||||
std::cout << "This device does not support the cl_khr_gl_sharing extension" << std::endl;
|
std::cout << "This device does not support the cl_khr_gl_sharing extension" << std::endl;
|
||||||
@@ -538,7 +545,7 @@ int Hardware_Caster::compile_kernel(std::string kernel_source, bool is_path, std
|
|||||||
kernel_map[kernel_name] = kernel;
|
kernel_map[kernel_name] = kernel;
|
||||||
//kernel_map.emplace(std::make_pair(kernel_name, kernel));
|
//kernel_map.emplace(std::make_pair(kernel_name, kernel));
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Hardware_Caster::set_kernel_arg(
|
int Hardware_Caster::set_kernel_arg(
|
||||||
|
|||||||
Reference in New Issue
Block a user