Cheaper and less broken material reflection/glow

This commit is contained in:
Joshua Barretto 2021-03-11 13:56:11 +00:00
parent d1b58ebb36
commit 6e0807f3f5
4 changed files with 18 additions and 5 deletions

View File

@ -163,8 +163,12 @@ void main() {
vec3 k_d = vec3(1.0);
vec3 k_s = vec3(R_s);
// This is a silly hack. It's not true reflectance (see below for that), but gives the desired
// effect without breaking the entire lighting model until we come up with a better way of doing
// reflectivity that accounts for physical surroundings like the ground
if ((material & (1u << 1u)) > 0u) {
k_s = vec3(10.0);
vec3 reflect_ray_dir = reflect(cam_to_frag, f_norm);
surf_color *= dot(vec3(1.0) - abs(fract(reflect_ray_dir * 3.5) * 2.0 - 1.0) * 0.85, vec3(1));
}
vec3 emitted_light, reflected_light;
@ -190,8 +194,10 @@ void main() {
float ao = f_ao * sqrt(f_ao);//0.25 + f_ao * 0.75; ///*pow(f_ao, 0.5)*/f_ao * 0.85 + 0.15;
// For now, just make glowing material light be the same colour as the surface
// TODO: Add a way to control this better outside the shaders
if ((material & (1u << 0u)) > 0u) {
emitted_light *= 1000;
emitted_light += 1000 * surf_color;
}
float glow_mag = length(model_glow.xyz);
@ -217,14 +223,18 @@ void main() {
// diffuse_light += point_light;
// reflected_light += point_light;
// vec3 surf_color = illuminate(srgb_to_linear(highlight_col.rgb * f_col), light, diffuse_light, ambient_light);
float reflectance = 0.0;
// TODO: Do reflectance properly like this later
vec3 reflect_color = vec3(0);
if ((material & (1u << 1u)) > 0u) {
/*
if ((material & (1u << 1u)) > 0u && false) {
vec3 reflect_ray_dir = reflect(cam_to_frag, f_norm);
reflect_color = get_sky_color(reflect_ray_dir, time_of_day.x, f_pos, vec3(-100000), 0.125, true);
reflect_color = get_cloud_color(reflect_color, reflect_ray_dir, cam_pos.xyz, time_of_day.x, 100000.0, 0.25);
reflectance = 1.0;
}
*/
surf_color = illuminate(max_light, view_dir, mix(surf_color * emitted_light, reflect_color, reflectance), mix(surf_color * reflected_light, reflect_color, reflectance)) * highlight_col.rgb;

View File

@ -5,6 +5,7 @@ pub(super) const GLOWY: u8 = 1 << 0;
pub(super) const SHINY: u8 = 1 << 1;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(packed)]
pub struct CellData {
pub col: Rgb<u8>,
pub attr: u8, // 0 = glowy, 1 = shiny

View File

@ -192,6 +192,7 @@ impl MatSegment {
})
}
#[allow(clippy::identity_op)]
pub fn from_vox(dot_vox_data: &DotVoxData, flipped: bool) -> Self {
if let Some(model) = dot_vox_data.models.get(0) {
let palette = dot_vox_data
@ -224,8 +225,8 @@ impl MatSegment {
MatCell::Normal(CellData {
col: color,
attr: 0
| (13..16).contains(&index) as u8 * GLOWY
| (8..13).contains(&index) as u8 * SHINY,
| ((13..16).contains(&index) as u8 * GLOWY)
| ((8..13).contains(&index) as u8 * SHINY),
})
},
};

View File

@ -134,6 +134,7 @@ impl Vertex {
]
}
#[allow(clippy::identity_op)]
pub fn make_col_light_figure(
// 0 to 31
light: u8,