Added new screenshots to show off imgui. As well as a quick delve into the blinn function to add the inverse square law
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 380 KiB After Width: | Height: | Size: 1.7 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 839 KiB After Width: | Height: | Size: 1.4 MiB |
@@ -1,4 +1,12 @@
|
|||||||
|
|
||||||
|
float DistanceBetweenPoints(float3 a, float3 b) {
|
||||||
|
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2) + pow(a.z - b.z, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
float Distance(float3 a) {
|
||||||
|
return sqrt(pow(a.x, 2) + pow(a.y, 2) + pow(a.z, 2));
|
||||||
|
}
|
||||||
|
|
||||||
// Naive incident ray light
|
// Naive incident ray light
|
||||||
float4 white_light(float4 input, float3 light, int3 mask) {
|
float4 white_light(float4 input, float3 light, int3 mask) {
|
||||||
|
|
||||||
@@ -22,17 +30,19 @@ float4 white_light(float4 input, float3 light, int3 mask) {
|
|||||||
|
|
||||||
float4 view_light(float4 in_color, float3 light, float4 light_color, float3 view, int3 mask) {
|
float4 view_light(float4 in_color, float3 light, float4 light_color, float3 view, int3 mask) {
|
||||||
|
|
||||||
|
float d = Distance(light) / 100.0f;
|
||||||
|
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);
|
||||||
in_color += diffuse * 0.2f * light_color; //(float4)(1.0f, 1.0f, 0.0f, 1.0f);
|
in_color += diffuse * light_color * 0.5f / d;
|
||||||
|
|
||||||
if (dot(light, normalize(convert_float3(mask))) > 0.0f)
|
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.5f * light_color;//(float4)(1.0f, 1.0f, 0.0f, 0.0f);
|
in_color += pow(specTmp, 8.0f) * light_color * 0.5f / d;
|
||||||
}
|
}
|
||||||
|
|
||||||
//in_color += 0.02;
|
|
||||||
return in_color;
|
return in_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,9 +56,7 @@ int rand(int* seed) // 1 <= *seed < m
|
|||||||
return(*seed);
|
return(*seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
float DistanceBetweenPoints(float3 a, float3 b) {
|
|
||||||
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2) + pow(a.z - b.z, 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
// =================================== Boolean ray intersection ============================
|
// =================================== Boolean ray intersection ============================
|
||||||
// =========================================================================================
|
// =========================================================================================
|
||||||
@@ -230,6 +238,8 @@ __kernel void raycaster(
|
|||||||
// If we hit a voxel
|
// If we hit a voxel
|
||||||
int index = voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z));
|
int index = voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * (voxel.z));
|
||||||
int voxel_data = map[index];
|
int voxel_data = map[index];
|
||||||
|
if (all(voxel == convert_int3((float3)(lights[4], lights[5], lights[6]-3))))
|
||||||
|
voxel_data = 1;
|
||||||
|
|
||||||
if (voxel_data != 0) {
|
if (voxel_data != 0) {
|
||||||
|
|
||||||
@@ -307,16 +317,16 @@ __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.0f, 0.239f, 0.419f, 0.3f);
|
voxel_color = (float4)(0.0f, 0.239f, 0.419f, 0.0f);
|
||||||
}
|
}
|
||||||
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.w = 0.0f;
|
||||||
//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.929f, 0.957f, 0.027f, 0.3f);
|
voxel_color = (float4)(0.929f, 0.957f, 0.027f, 0.0f);
|
||||||
}
|
}
|
||||||
//else {
|
//else {
|
||||||
// voxel_color = (float4)(1.0f, 0.0f, 0.0f, 0.0f);
|
// voxel_color = (float4)(1.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ int main() {
|
|||||||
fps_counter fps;
|
fps_counter fps;
|
||||||
|
|
||||||
float light_color[4] = { 0, 0, 0, 0 };
|
float light_color[4] = { 0, 0, 0, 0 };
|
||||||
|
float light_pos[4] = { 100, 100, 30 };
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
|
|
||||||
@@ -263,6 +264,10 @@ int main() {
|
|||||||
handle->set_rgbi(light);
|
handle->set_rgbi(light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::SliderFloat4("Position", light_pos, 0, MAP_X)) {
|
||||||
|
sf::Vector3f light(light_pos[0], light_pos[1], light_pos[2]);
|
||||||
|
handle->set_position(light);
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user