Skip to content

Commit

Permalink
Some procedural modeling
Browse files Browse the repository at this point in the history
  • Loading branch information
markusmoenig committed Jun 30, 2024
1 parent 69d6486 commit 69ea010
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion StarterProject.eldiron

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion shared/src/geofxnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ impl GeoFXNode {
match self.role {
Ground => {
if let Some(hit) = hit {
let value = noise2d(&coll, &hit.uv);
let value = if hit.two_d {
noise2d(&coll, &hit.global_uv)
} else {
noise2d(&coll, &hit.uv)
};
hit.albedo = vec3f(value, value, value);
hit.value = value;
}
Expand Down
2 changes: 2 additions & 0 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub struct Hit {
pub hit_point: Vec3f,
pub normal: Vec3f,
pub uv: Vec2f,
pub global_uv: Vec2f,
pub face: HitFace,

pub pattern_pos: Vec2f,
Expand Down Expand Up @@ -192,6 +193,7 @@ impl Hit {
hit_point: Vec3f::zero(),
normal: Vec3f::zero(),
uv: Vec2f::zero(),
global_uv: Vec2f::zero(),
face: HitFace::XFace,

pattern_pos: Vec2f::zero(),
Expand Down
12 changes: 8 additions & 4 deletions shared/src/materialfxnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ impl MaterialFXNode {

if let Some(texture_id) = &self.texture_id {
if let Some(texture) = textures.get(texture_id) {
if let Some(color) = texture.buffer[0].at_f_vec4f(vec2f(hit.uv.x, hit.uv.y))
{
if let Some(color) = texture.buffer[0].at_f_vec4f(hit.uv) {
hit.albedo.x = color.x;
hit.albedo.y = color.y;
hit.albedo.z = color.z;
Expand Down Expand Up @@ -388,7 +387,12 @@ impl MaterialFXNode {
Noise2D => {
let collection = self.collection();
hit.noise_scale = collection.get_f32_default("Out Scale", 1.0);
hit.noise = Some(noise2d(&collection, &hit.uv));
let value = if hit.two_d {
noise2d(&collection, &hit.global_uv)
} else {
noise2d(&collection, &hit.uv)
};
hit.noise = Some(value);
hit.albedo = vec3f(hit.value, hit.value, hit.value);
Some(0)
}
Expand All @@ -401,7 +405,7 @@ impl MaterialFXNode {
}
Brick => {
let collection = self.collection();
let (_, terminal) = bricks(&collection, hit.uv, hit);
let (_, terminal) = bricks(&collection, hit.global_uv, hit);
Some(terminal)
}
UVSplitter => {
Expand Down
2 changes: 2 additions & 0 deletions shared/src/materialfxobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ impl MaterialFXObject {
..Default::default()
};

hit.global_uv = hit.uv;

noise2d.compute(&mut hit, palette, textures, vec![]);
self.get_distance(&time, hit.uv, &mut hit, &geo_object, 1.0);
self.compute(&mut hit, palette, textures);
Expand Down
1 change: 1 addition & 0 deletions shared/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ impl Renderer {

if let Some(material) = material {
hit.uv = self.get_uv_face(hit.normal, hit.hit_point).0;
hit.global_uv = hit.uv;
material.compute(&mut hit, palette, &self.textures);
}
has_hit = true;
Expand Down
8 changes: 6 additions & 2 deletions shared/src/tiledrawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,13 @@ impl TileDrawer {

let p = vec2f(x as f32, y as f32);
let mut hit = Hit {
global_uv: vec2f(
tile_x as f32 + xx as f32 / region.grid_size as f32,
tile_y as f32 + yy as f32 / region.grid_size as f32,
),
uv: vec2f(
/*tile_x as f32 +*/ xx as f32 / region.grid_size as f32,
/*tile_y as f32 +*/ yy as f32 / region.grid_size as f32,
xx as f32 / region.grid_size as f32,
yy as f32 / region.grid_size as f32,
),
two_d: true,
..Default::default()
Expand Down

0 comments on commit 69ea010

Please sign in to comment.