pre facing switch
This commit is contained in:
parent
3f4656939c
commit
dd568a75e3
5 changed files with 117 additions and 33 deletions
Binary file not shown.
|
@ -133,8 +133,8 @@ vec3 get_light_position(uint light_index) {
|
||||||
return vec3(float(scene_info.infos[light_index]), float(scene_info.infos[light_index + 1]), float(scene_info.infos[light_index + 2]));
|
return vec3(float(scene_info.infos[light_index]), float(scene_info.infos[light_index + 1]), float(scene_info.infos[light_index + 2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 get_light_color(uint light_index) {
|
vec3 get_light_color(uint light_index) {
|
||||||
return vec4(float(scene_info.infos[light_index + 3]) / 255.0, float(scene_info.infos[light_index + 4]) / 255.0, float(scene_info.infos[light_index + 5]) / 255.0, 1.0);
|
return vec3(float(scene_info.infos[light_index + 3]) / 255.0, float(scene_info.infos[light_index + 4]) / 255.0, float(scene_info.infos[light_index + 5]) / 255.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -147,22 +147,29 @@ void main() {
|
||||||
uint max_light_num = scene_info.infos[0];
|
uint max_light_num = scene_info.infos[0];
|
||||||
uint light_num = 0;
|
uint light_num = 0;
|
||||||
uint volume_index = fragVolumeStart;
|
uint volume_index = fragVolumeStart;
|
||||||
uint light_index = scene_info.infos[fragVolumeStart + 3];
|
uint volume_pos_x = scene_info.infos[volume_index + 0];
|
||||||
|
uint volume_pos_y = scene_info.infos[volume_index + 1];
|
||||||
|
uint volume_pos_z = scene_info.infos[volume_index + 2];
|
||||||
|
uint light_index = scene_info.infos[volume_index + 6];
|
||||||
vec3 light_direction = get_light_position(light_index) - origPosition;
|
vec3 light_direction = get_light_position(light_index) - origPosition;
|
||||||
vec4 light_color = get_light_color(light_index);
|
vec3 light_color = get_light_color(light_index);
|
||||||
|
|
||||||
bool x_pos = light_direction.x > 0.0;
|
bool x_pos = light_direction.x > 0.0;
|
||||||
bool x_null = light_direction.x == 0.0;
|
bool x_null = (light_direction.x == 0.0);
|
||||||
bool y_pos = light_direction.y > 0.0;
|
bool y_pos = light_direction.y > 0.0;
|
||||||
bool y_null = light_direction.y == 0.0;
|
bool y_null = (light_direction.y == 0.0);
|
||||||
bool z_pos = light_direction.z > 0.0;
|
bool z_pos = light_direction.z > 0.0;
|
||||||
bool z_null = light_direction.z == 0.0;
|
bool z_null = (light_direction.z == 0.0);
|
||||||
|
|
||||||
uint max_iterations = max_light_num * 20;
|
vec3 color_sum = vec3(0.0, 0.0, 0.0) + (color_sample.xyz * 0.01);
|
||||||
|
|
||||||
|
uint max_iterations = 2; //max_light_num * 20;
|
||||||
for (int i = 0; i < max_iterations; i++) {
|
for (int i = 0; i < max_iterations; i++) {
|
||||||
float x_border = float(scene_info.infos[volume_index + 0] + scene_info.infos[volume_index + 3] * uint(x_pos));
|
float x_border = float(volume_pos_x + (scene_info.infos[volume_index + 3]) * uint(x_pos)) - 0.5;
|
||||||
float y_border = float(scene_info.infos[volume_index + 1] + scene_info.infos[volume_index + 4] * uint(y_pos));
|
float y_border = float(volume_pos_y + (scene_info.infos[volume_index + 4]) * uint(y_pos)) - 0.5;
|
||||||
float z_border = float(scene_info.infos[volume_index + 2] + scene_info.infos[volume_index + 5] * uint(z_pos));
|
float z_border = float(volume_pos_z + (scene_info.infos[volume_index + 5]) * uint(z_pos)) - 0.5;
|
||||||
|
|
||||||
|
bool needs_next_light = false;
|
||||||
|
|
||||||
// 2 is way behind the light position and should result in no collision being detected
|
// 2 is way behind the light position and should result in no collision being detected
|
||||||
float x_factor = 2.0;
|
float x_factor = 2.0;
|
||||||
|
@ -172,17 +179,84 @@ void main() {
|
||||||
x_factor = (x_border - origPosition.x) / light_direction.x;
|
x_factor = (x_border - origPosition.x) / light_direction.x;
|
||||||
}
|
}
|
||||||
if (!y_null) {
|
if (!y_null) {
|
||||||
float y_factor = (y_border - origPosition.y) / light_direction.y;
|
y_factor = (y_border - origPosition.y) / light_direction.y;
|
||||||
}
|
}
|
||||||
if (!z_null) {
|
if (!z_null) {
|
||||||
float z_factor = (z_border - origPosition.z) / light_direction.z;
|
z_factor = (z_border - origPosition.z) / light_direction.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((x_factor >= 0.999 && y_factor >= 0.999 && z_factor >= 0.999)) {
|
||||||
|
// no hit, add light color result
|
||||||
|
color_sum += (color_sample.xyz * light_color) / (0.01 * light_direction.length() * light_direction.length() + 1.0);
|
||||||
|
needs_next_light = true;
|
||||||
|
} else {
|
||||||
|
// if there is a border hit before reaching the light
|
||||||
|
// change to the relevant next volume
|
||||||
|
// Todo: look into removing ifs from this
|
||||||
|
uint hit_facing = 0;
|
||||||
|
uint u = 0;
|
||||||
|
uint v = 0;
|
||||||
|
if (x_factor <= y_factor && x_factor <= z_factor) {
|
||||||
|
if (x_pos) {
|
||||||
|
hit_facing = 3;
|
||||||
|
} else {
|
||||||
|
hit_facing = 2;
|
||||||
|
}
|
||||||
|
vec3 intersection_pos = origPosition + x_factor * light_direction;
|
||||||
|
u = uint(ceil(intersection_pos.y)) - volume_pos_y;
|
||||||
|
v = uint(ceil(intersection_pos.z)) - volume_pos_z;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y_factor <= x_factor && y_factor <= z_factor) {
|
||||||
|
if (y_pos) {
|
||||||
|
hit_facing = 5;
|
||||||
|
} else {
|
||||||
|
hit_facing = 4;
|
||||||
|
}
|
||||||
|
vec3 intersection_pos = origPosition + y_factor * light_direction;
|
||||||
|
u = uint(ceil(intersection_pos.x)) - volume_pos_x;
|
||||||
|
v = uint(ceil(intersection_pos.z)) - volume_pos_z;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (z_factor <= x_factor && z_factor <= y_factor) {
|
||||||
|
if (y_pos) {
|
||||||
|
hit_facing = 0;
|
||||||
|
} else {
|
||||||
|
hit_facing = 1;
|
||||||
|
}
|
||||||
|
vec3 intersection_pos = origPosition + z_factor * light_direction;
|
||||||
|
u = uint(ceil(intersection_pos.x)) - volume_pos_x;
|
||||||
|
v = uint(ceil(intersection_pos.y)) - volume_pos_y;
|
||||||
|
}
|
||||||
|
uint next_neighbor = sample_neighbor_from_scene_info(volume_index, uvec2(u, v), hit_facing);
|
||||||
|
uvec4 color_sample = sample_color_from_scene_info(volume_index, uvec2(u, v), hit_facing);
|
||||||
|
|
||||||
|
if (color_sample == uvec4(0, 0, 0, 0)) {
|
||||||
|
// not a color hit, so check neighbor
|
||||||
|
if (next_neighbor != 0) {
|
||||||
|
color_sum = vec3(1.0, 0.0, 0.0);
|
||||||
|
volume_index = next_neighbor;
|
||||||
|
uint volume_pos_x = scene_info.infos[volume_index + 0];
|
||||||
|
uint volume_pos_y = scene_info.infos[volume_index + 1];
|
||||||
|
uint volume_pos_z = scene_info.infos[volume_index + 2];
|
||||||
|
} else {
|
||||||
|
color_sum = vec3(0.0, 0.0, 1.0);
|
||||||
|
// neightbor miss, shouldn't happen with a light inside of a volume. Might happen with ambient light. For now move on to next light.
|
||||||
|
needs_next_light = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
color_sum = vec3(1.0, 0.0, 1.0);
|
||||||
|
// color hit, move on to next light (may change once transparents are implemnted)
|
||||||
|
needs_next_light = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needs_next_light) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo light color memory index does not contain the expected values -> check
|
||||||
outColor = color_sample;
|
outColor = vec4(color_sum, 1.0);
|
||||||
|
|
||||||
/*if (scene_info.infos[1] == 16) {
|
/*if (scene_info.infos[1] == 16) {
|
||||||
outColor = vec4(0, 1, 0, 1);
|
outColor = vec4(0, 1, 0, 1);
|
||||||
|
|
|
@ -216,8 +216,8 @@ impl EmptyVolume {
|
||||||
bottom_roughness.push(128);
|
bottom_roughness.push(128);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bottom_colors.push(Vector3 { x: 255, y: 255, z: 255 });
|
bottom_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||||
bottom_roughness.push(255);
|
bottom_roughness.push(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,8 +242,8 @@ impl EmptyVolume {
|
||||||
top_roughness.push(128);
|
top_roughness.push(128);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
top_colors.push(Vector3 { x: 255, y: 255, z: 255 });
|
top_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||||
top_roughness.push(255);
|
top_roughness.push(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,8 +269,8 @@ impl EmptyVolume {
|
||||||
back_roughness.push(128);
|
back_roughness.push(128);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
back_colors.push(Vector3 { x: 255, y: 255, z: 255 });
|
back_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||||
back_roughness.push(255);
|
back_roughness.push(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,8 +296,8 @@ impl EmptyVolume {
|
||||||
front_roughness.push(128);
|
front_roughness.push(128);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
front_colors.push(Vector3 { x: 255, y: 255, z: 255 });
|
front_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||||
front_roughness.push(255);
|
front_roughness.push(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,8 +323,8 @@ impl EmptyVolume {
|
||||||
left_roughness.push(128);
|
left_roughness.push(128);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
left_colors.push(Vector3 { x: 255, y: 255, z: 255 });
|
left_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||||
left_roughness.push(255);
|
left_roughness.push(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,8 +350,8 @@ impl EmptyVolume {
|
||||||
right_roughness.push(128);
|
right_roughness.push(128);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
right_colors.push(Vector3 { x: 255, y: 255, z: 255 });
|
right_colors.push(Vector3 { x: 0, y: 0, z: 0 });
|
||||||
right_roughness.push(255);
|
right_roughness.push(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct PointLight{
|
||||||
|
|
||||||
impl PointLight {
|
impl PointLight {
|
||||||
pub fn get_buffer_mem_size(&self) -> u32 {
|
pub fn get_buffer_mem_size(&self) -> u32 {
|
||||||
4 * 3 + 4 * 3
|
3 + 3
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_into_memory(&self, mut v: Vec<u32>) -> Vec<u32> {
|
pub fn insert_into_memory(&self, mut v: Vec<u32>) -> Vec<u32> {
|
||||||
|
@ -19,9 +19,9 @@ impl PointLight {
|
||||||
v[self.memory_start + 1] = self.pos.y as u32;
|
v[self.memory_start + 1] = self.pos.y as u32;
|
||||||
v[self.memory_start + 2] = self.pos.z as u32;
|
v[self.memory_start + 2] = self.pos.z as u32;
|
||||||
|
|
||||||
v[self.memory_start + 3] = self.color.x as u32;
|
v[self.memory_start + 3] = (self.color.x * 255.0) as u32;
|
||||||
v[self.memory_start + 4] = self.color.y as u32;
|
v[self.memory_start + 4] = (self.color.y * 255.0) as u32;
|
||||||
v[self.memory_start + 5] = self.color.z as u32;
|
v[self.memory_start + 5] = (self.color.z * 255.0) as u32;
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use anyhow::Ok;
|
||||||
use vulkanalia::prelude::v1_0::*;
|
use vulkanalia::prelude::v1_0::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use cgmath::{vec2, vec3};
|
use cgmath::{vec2, vec3, Vector3};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -14,6 +14,7 @@ use std::rc::Rc;
|
||||||
use crate::app_data;
|
use crate::app_data;
|
||||||
use crate::app_data::AppData;
|
use crate::app_data::AppData;
|
||||||
use crate::buffer;
|
use crate::buffer;
|
||||||
|
use crate::primitives::rec_cuboid::Cuboid;
|
||||||
use crate::vertex;
|
use crate::vertex;
|
||||||
use crate::primitives::cube::Cube;
|
use crate::primitives::cube::Cube;
|
||||||
use crate::primitives::drawable::Drawable;
|
use crate::primitives::drawable::Drawable;
|
||||||
|
@ -118,6 +119,15 @@ impl Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cube = Cuboid {
|
||||||
|
pos: vec3(11.0, 11.0, 11.0),
|
||||||
|
color: vec3(shade, 1.0, shade),
|
||||||
|
tex_coord: vec2(0.0, 0.0),
|
||||||
|
size: Vector3 {x: 0.5, y: 0.5, z: 0.5}
|
||||||
|
};
|
||||||
|
let index = self.sized_vertices.len();
|
||||||
|
cube.draw(&data.topology, index, self);
|
||||||
|
|
||||||
let mut memory_index = 1; // zero should be the location for the overall length (also will be the invalid memory allocation for pointing to a nonexistant neighbor)
|
let mut memory_index = 1; // zero should be the location for the overall length (also will be the invalid memory allocation for pointing to a nonexistant neighbor)
|
||||||
for light in &mut self.point_lights {
|
for light in &mut self.point_lights {
|
||||||
light.memory_start = memory_index;
|
light.memory_start = memory_index;
|
||||||
|
|
Loading…
Add table
Reference in a new issue