Skip to content
This repository has been archived by the owner on Jun 19, 2021. It is now read-only.

One vertex buffer to rule them all #190

Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions base/src/math/axial_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,37 @@ impl AxialPoint {
/// system using `world::{HEX_INNER_RADIUS, HEX_OUTER_RADIUS}`.
pub fn to_real(&self) -> Point2f {
Point2f {
x: ((2 * self.q + self.r) as DefaultFloat) * HEX_INNER_RADIUS,
x: ((2 * self.q - self.r) as DefaultFloat) * HEX_INNER_RADIUS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, not even this was correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well... there are many "correct" versions. In the version of the axial coordinate system that I chose this was wrong, yes.

y: (self.r as DefaultFloat) * (3.0 / 2.0) * HEX_OUTER_RADIUS,
}
}

/// Return the `AxialPoint` from a `Point2f`
pub fn from_real(real: Point2f) -> Self {
let q: f32 = (real.x * ::math::SQRT_3 / 3.0 - real.y / 3.0) / HEX_OUTER_RADIUS;
let r: f32 = (real.y * 2.0 / 3.0) / HEX_OUTER_RADIUS;
let q = (real.x * ::math::SQRT_3 / 3.0 - real.y / 3.0) / HEX_OUTER_RADIUS;
let r = (real.y * 2.0 / 3.0) / HEX_OUTER_RADIUS;

let y: f32 = -q - r;
let s = -q - r;

// Rounding
let mut rx: i32 = q.round() as i32;
let ry: i32 = y.round() as i32;
let mut rz: i32 = r.round() as i32;
let rq = q.round();
let mut rr = r.round();
let mut rs = s.round();

// To test the right rounding
let x_diff = (rx as f32 - q).abs();
let y_diff = (ry as f32 - y).abs();
let z_diff = (rz as f32 - r).abs();
if x_diff > y_diff && x_diff > z_diff {
rx = -ry - rz;
} else if y_diff <= z_diff {
rz = -rx - ry;
let q_diff = (rq - q).abs();
let r_diff = (rr - r).abs();
let s_diff = (rs - s).abs();

if q_diff > r_diff && q_diff > s_diff {
// rq = -rr - rs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this stay or should this go?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I actually want this to stay, since it then represents the algorithm from redblobgames.com more closely. But I can add a comment. Will do it tomorrow when fixing the other stuff.

} else if s_diff > r_diff {
rr = -rq - rs;
} else {
rs = -rq - rr;
}

AxialPoint { q: rx, r: rz }
AxialPoint { q: -rs as AxialType, r: rr as AxialType}
}

/// Returns the `s` component of corresponding cube coordinates. In cube
Expand Down
2 changes: 1 addition & 1 deletion base/src/math/axial_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl AxialVector {
/// system using `world::{HEX_INNER_RADIUS, HEX_OUTER_RADIUS}`.
pub fn to_real(&self) -> Vector2f {
Vector2f {
x: ((2 * self.q + self.r) as DefaultFloat) * HEX_INNER_RADIUS,
x: ((2 * self.q - self.r) as DefaultFloat) * HEX_INNER_RADIUS,
y: (self.r as DefaultFloat) * (3.0 / 2.0) * HEX_OUTER_RADIUS,
}
}
Expand Down
10 changes: 5 additions & 5 deletions base/src/world/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ impl<'a> Iterator for ChunkPillars<'a> {

fn next(&mut self) -> Option<Self::Item> {
if self.i < CHUNK_SIZE * CHUNK_SIZE {
let axial = AxialVector::new((self.i / CHUNK_SIZE).into(),
(self.i % CHUNK_SIZE).into());
let axial = AxialVector::new((self.i % CHUNK_SIZE).into(),
(self.i / CHUNK_SIZE).into());
let item = (axial, &self.pillars[self.i as usize]);
self.i += 1;
Some(item)
Expand Down Expand Up @@ -97,9 +97,9 @@ impl Chunk {
let start_q = CHUNK_SIZE as i32 * chunk_index.0.q;
let start_r = CHUNK_SIZE as i32 * chunk_index.0.r;

for q in start_q..start_q + CHUNK_SIZE as i32 {
for r in start_r..start_r + CHUNK_SIZE as i32 {
let pos = AxialPoint::new(q.into(), r.into());
for r in start_r..start_r + CHUNK_SIZE as i32 {
for q in start_q..start_q + CHUNK_SIZE as i32 {
let pos = AxialPoint::new(q, r);
hec.push(func(pos));
}
}
Expand Down
15 changes: 14 additions & 1 deletion base/src/world/ground.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Clone, Debug)]
#[derive(Clone, Copy, Debug)]
pub enum GroundMaterial {
Dirt,
Grass,
Expand All @@ -24,4 +24,17 @@ impl GroundMaterial {
GroundMaterial::Debug => [1.0, 0.0, 0.0],
}
}

pub fn get_id(&self) -> i32 {
match *self {
GroundMaterial::Grass => 1,
GroundMaterial::Sand => 2,
GroundMaterial::Snow => 3,
GroundMaterial::Dirt => 4,
GroundMaterial::Stone => 5,
GroundMaterial::JungleGrass => 1,
GroundMaterial::Mulch => 7,
GroundMaterial::Debug => 8,
}
}
}
3 changes: 0 additions & 3 deletions base/src/world/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ impl World {
if inner_pos.r < 0 {
inner_pos.r += chunk_size;
}
if chunk_pos.q != chunk_pos.r {
::std::mem::swap(&mut inner_pos.r, &mut inner_pos.q);
}
&chunk[inner_pos]
});

Expand Down
10 changes: 2 additions & 8 deletions client/shader/chunk_shadow.vert
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
in vec3 position;
in vec3 normal;

// Per-instance attributes:
// Height in units, not world coordinates, since the "pillar prototype" has a
// height of one unit.
in float height;
in vec3 offset;
//in vec3 material_color;

uniform mat4 proj_matrix;
uniform mat4 view_matrix;
uniform vec2 offset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unused too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm... what about ...


void main() {
vec4 world_coords = vec4(
position.xy + offset.xy,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nevermind 😆

position.z * height + offset.z,
position.z,
1);
gl_Position = proj_matrix * view_matrix * world_coords;
}
4 changes: 3 additions & 1 deletion client/shader/chunk_std.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ uniform vec3 sun_dir;
uniform sampler2D shadow_map;
uniform vec3 sun_color;
uniform vec3 sky_light;
uniform vec3 cam_pos;

// Normals to bump mapping the textures
uniform sampler2D normal_sand;
Expand Down Expand Up @@ -165,7 +166,8 @@ void main() {
}

// apply fog to final color
float distance = (length(pos) / 130) * (length(pos) / 130);
vec3 player_to_frag = x_position - cam_pos;
float distance = pow(length(player_to_frag.xy) / 130, 2);
if (distance > 1) {
distance = 1;
}
Expand Down
21 changes: 3 additions & 18 deletions client/shader/chunk_std.vert
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ in vec3 position;
in vec3 normal;
in float radius;
in vec2 tex_coords;

// Per-instance attributes:
// Height in units, not world coordinates, since the "pillar prototype" has a
// height of one unit.
in float height;
in vec3 offset;
in vec3 material_color;
in int ground;

Expand All @@ -32,12 +26,12 @@ out vec3 pos;
uniform mat4 proj_matrix;
uniform mat4 view_matrix;
uniform mat4 depth_view_proj;
uniform vec3 cam_pos;
uniform vec2 offset;
Copy link
Contributor

@jonas-schievink jonas-schievink Aug 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unused? Nevermind


void main() {
vec4 world_coords = vec4(
position.xy + offset.xy,
position.z * height + offset.z,
position.z,
1);

gl_Position = proj_matrix * view_matrix * world_coords;
Expand All @@ -48,15 +42,6 @@ void main() {
x_radius = radius;
x_tex_coords = tex_coords;

// adjusting the height for the sides of each hexagon
if(tex_coords.y > 1.5){
x_tex_coords.y = height;
}

x_position = position;
x_position = world_coords.xyz;
x_ground = ground;

// position in relation to player ignoring hight, needed for fog
pos = vec3(offset - cam_pos);
pos = vec3(pos.x, pos.y, 0);
}
2 changes: 0 additions & 2 deletions client/shader/plants.tcs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ struct OutputPatch {

patch out OutputPatch oPatch;



vec3 ProjectToPlane(vec3 Point, vec3 PlanePoint, vec3 PlaneNormal)
{
vec3 v = Point - PlanePoint;
Expand Down
Loading