diff options
Diffstat (limited to 'engine/src/renderer/opengl')
-rw-r--r-- | engine/src/renderer/opengl/glsl/light.glsl | 4 | ||||
-rw-r--r-- | engine/src/renderer/opengl/vertex.rs | 64 |
2 files changed, 66 insertions, 2 deletions
diff --git a/engine/src/renderer/opengl/glsl/light.glsl b/engine/src/renderer/opengl/glsl/light.glsl index 1bc23a4..f12b5fe 100644 --- a/engine/src/renderer/opengl/glsl/light.glsl +++ b/engine/src/renderer/opengl/glsl/light.glsl @@ -80,10 +80,10 @@ vec3 calc_specular_light( { vec3 view_direction = normalize(view_pos - frag_pos); - vec3 reflect_direction = reflect(-light_dir, norm); + vec3 halfway_direction = normalize(light_dir + view_direction); float spec = - pow(max(dot(view_direction, reflect_direction), 0.0), material.shininess); + pow(max(dot(norm, halfway_direction), 0.0), material.shininess); return light_phong.specular * ( spec * (vec3(texture(material.specular_map, texture_coords)) * material.specular) diff --git a/engine/src/renderer/opengl/vertex.rs b/engine/src/renderer/opengl/vertex.rs new file mode 100644 index 0000000..499b94b --- /dev/null +++ b/engine/src/renderer/opengl/vertex.rs @@ -0,0 +1,64 @@ +use crate::vector::{Vec2, Vec3}; + +#[derive(Debug, Clone)] +#[repr(C)] +pub struct Vertex +{ + pub pos: Vec3<f32>, + pub texture_coords: Vec2<f32>, + pub normal: Vec3<f32>, +} + +impl Vertex +{ + pub fn attrs() -> &'static [Attribute] + { + #[allow(clippy::cast_possible_truncation)] + &[ + Attribute { + index: 0, + component_type: AttributeComponentType::Float, + component_cnt: AttributeComponentCnt::Three, + component_size: size_of::<f32>() as u32, + }, + Attribute { + index: 1, + component_type: AttributeComponentType::Float, + component_cnt: AttributeComponentCnt::Two, + component_size: size_of::<f32>() as u32, + }, + Attribute { + index: 2, + component_type: AttributeComponentType::Float, + component_cnt: AttributeComponentCnt::Three, + component_size: size_of::<f32>() as u32, + }, + ] + } +} + +#[derive(Debug)] +pub struct Attribute +{ + pub index: u32, + pub component_type: AttributeComponentType, + pub component_cnt: AttributeComponentCnt, + pub component_size: u32, +} + +#[derive(Debug)] +pub enum AttributeComponentType +{ + Float, +} + +#[derive(Debug, Clone, Copy)] +#[repr(u32)] +#[allow(dead_code)] +pub enum AttributeComponentCnt +{ + One = 1, + Two = 2, + Three = 3, + Four = 4, +} |