Rename some material parameters, look up the true material density, and add some more function types.

fixes #1074
This commit is contained in:
IntegratedQuantum 2025-02-20 20:42:26 +01:00
parent 894a8bd93a
commit feff96b3f3
22 changed files with 201 additions and 120 deletions

View File

@ -3,10 +3,12 @@
.blockHealth = 6, .blockHealth = 6,
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.0, .density = 0.45,
.resistance = 1.0, .strength = 1.0,
.power = 0.2, .elasticity = 1.2,
.roughness = 0.7, .grip = 1.5,
.hardness = 1.9,
.textureRoughness = 0.7,
.colors = .{ .colors = .{
0xff8c6f59, 0xffa07f66, 0xffb8917b, 0xffd7b194, 0xffe4c29f, 0xff8c6f59, 0xffa07f66, 0xffb8917b, 0xffd7b194, 0xffe4c29f,
}, },

View File

@ -6,10 +6,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 0.7, .density = 3.0,
.resistance = 1.3, .strength = 1.3,
.power = 0.3, .elasticity = 2.5,
.roughness = 2.5, .grip = 0.4,
.hardness = 6.0,
.textureRoughness = 2.5,
.colors = .{ .colors = .{
0xff282328, 0xff353135, 0xff434041, 0xff4A4849, 0xff605E5F, 0xff282328, 0xff353135, 0xff434041, 0xff4A4849, 0xff605E5F,
}, },

View File

@ -3,10 +3,12 @@
.blockHealth = 6, .blockHealth = 6,
.item = .{ .item = .{
.material = .{ .material = .{
.density = 0.6, .density = 0.59,
.resistance = 0.8, .strength = 0.8,
.power = 0.2, .elasticity = 0.7,
.roughness = 0.7, .grip = 1.0,
.hardness = 2.0,
.textureRoughness = 0.7,
.colors = .{ .colors = .{
0xff9b7a5b, 0xffbf9872, 0xffdeb287, 0xfff2c89c, 0xffffdfb7, 0xff9b7a5b, 0xffbf9872, 0xffdeb287, 0xfff2c89c, 0xffffdfb7,
}, },

View File

@ -6,10 +6,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.0, .density = 2.4,
.resistance = 1.0, .strength = 1.0,
.power = 0.4, .elasticity = 2.0,
.roughness = 1.0, .grip = 0.4,
.hardness = 7.0,
.textureRoughness = 1.0,
.colors = .{ .colors = .{
0xff3d3d3d, 0xff535353, 0xff6b6b6b, 0xff81807e, 0xff9c9996, 0xff3d3d3d, 0xff535353, 0xff6b6b6b, 0xff81807e, 0xff9c9996,
}, },

View File

@ -7,10 +7,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 0.9, .density = 2.6,
.resistance = 1.1, .strength = 1.1,
.power = 0.35, .elasticity = 2.0,
.roughness = 0.5, .grip = 0.3,
.hardness = 5.5,
.textureRoughness = 0.5,
.colors = .{ .colors = .{
0xff72403C, 0xff905B57, 0xffB77966, 0xffC2846A, 0xffC49B77, 0xff72403C, 0xff905B57, 0xffB77966, 0xffC2846A, 0xffC49B77,
}, },

View File

@ -7,10 +7,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 0.8, .density = 2.8,
.resistance = 1.6, .strength = 1.6,
.power = 0.4, .elasticity = 3.5,
.roughness = 1.5, .grip = 0.4,
.hardness = 7.5,
.textureRoughness = 1.5,
.colors = .{ .colors = .{
0xff6E757F, 0xff86898E, 0xffA4A7AA, 0xffB9BCBF, 0xffCACCCE, 0xff6E757F, 0xff86898E, 0xffA4A7AA, 0xffB9BCBF, 0xffCACCCE,
}, },

View File

@ -7,10 +7,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.25, .density = 2.1,
.resistance = 0.9, .strength = 0.9,
.power = 0.35, .elasticity = 1.5,
.roughness = 0.9, .grip = 0.5,
.hardness = 4.5,
.textureRoughness = 0.9,
.colors = .{ .colors = .{
0xff70583E, 0xff886D52, 0xffAB8D6A, 0xffC09B6E, 0xffCCA780, 0xff70583E, 0xff886D52, 0xffAB8D6A, 0xffC09B6E, 0xffCCA780,
}, },

View File

@ -3,10 +3,12 @@
.blockHealth = 6, .blockHealth = 6,
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.0, .density = 0.55,
.resistance = 1.2, .strength = 1.2,
.power = 0.3, .elasticity = 1.0,
.roughness = 0.7, .grip = 1.2,
.hardness = 2.1,
.textureRoughness = 0.7,
.colors = .{ .colors = .{
0xff734c2f, 0xff8e5d38, 0xffa26a3f, 0xffbd7e48, 0xffcf9459, 0xff734c2f, 0xff8e5d38, 0xffa26a3f, 0xffbd7e48, 0xffcf9459,
}, },

View File

@ -6,10 +6,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.25, .density = 2.7,
.resistance = 1.4, .strength = 1.4,
.power = 0.5, .elasticity = 2.8,
.roughness = 0.5, .grip = 0.5,
.hardness = 4.0,
.textureRoughness = 0.5,
.colors = .{ .colors = .{
0xffA89B94, 0xffC9C0BB, 0xffECE9E3, 0xffFBF8F1, 0xffECE9E3, 0xffA89B94, 0xffC9C0BB, 0xffECE9E3, 0xffFBF8F1, 0xffECE9E3,
}, },

View File

@ -3,10 +3,12 @@
.blockHealth = 6, .blockHealth = 6,
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.0, .density = 0.64,
.resistance = 1.0, .strength = 1.0,
.power = 0.2, .elasticity = 0.9,
.roughness = 0.7, .grip = 1.0,
.hardness = 2.0,
.textureRoughness = 0.7,
.colors = .{ .colors = .{
0xff835e37, 0xffa37543, 0xffbd8a4f, 0xffd3a164, 0xffe5b570, 0xff835e37, 0xffa37543, 0xffbd8a4f, 0xffd3a164, 0xffe5b570,
}, },

View File

@ -7,10 +7,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 0.5, .density = 2.5,
.resistance = 2.0, .strength = 0.5,
.power = 0.5, .elasticity = 7.0,
.roughness = 0.1, .grip = 0.3,
.hardness = 6.0,
.textureRoughness = 0.1,
.colors = .{ .colors = .{
0xff0F0811, 0xff19121C, 0xff312436, 0xff69486B, 0xff462F47, 0xff0F0811, 0xff19121C, 0xff312436, 0xff69486B, 0xff462F47,
}, },

View File

@ -3,10 +3,12 @@
.blockHealth = 6, .blockHealth = 6,
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.5, .density = 0.5,
.resistance = 1.2, .strength = 1.2,
.power = 0.2, .elasticity = 1.1,
.roughness = 0.7, .grip = 1.0,
.hardness = 2.0,
.textureRoughness = 0.7,
.colors = .{ .colors = .{
0xff533f27, 0xff664c2e, 0xff795a37, 0xff8c6b41, 0xffa37b46, 0xff533f27, 0xff664c2e, 0xff795a37, 0xff8c6b41, 0xffa37b46,
}, },

View File

@ -6,10 +6,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 0.25, .density = 1.9,
.resistance = 0.25, .strength = -0.5,
.power = 0.25, .elasticity = 0.1,
.roughness = 3.0, .grip = 0.7,
.hardness = 5.0,
.textureRoughness = 3.0,
.colors = .{ .colors = .{
0xffAF8354, 0xffC89965, 0xffE6B776, 0xffEEC589, 0xffEDD0AD, 0xffAF8354, 0xffC89965, 0xffE6B776, 0xffEEC589, 0xffEDD0AD,
}, },

View File

@ -7,10 +7,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.0, .density = 2.4,
.resistance = 1.5, .strength = 1.0,
.power = 0.4, .elasticity = 2.0,
.roughness = 1.0, .grip = 0.4,
.hardness = 7.0,
.textureRoughness = 1.0,
.colors = .{ .colors = .{
0xff444444, 0xff626262, 0xff7A7876, 0xff878583, 0xff9c9996, 0xff444444, 0xff626262, 0xff7A7876, 0xff878583, 0xff9c9996,
}, },

View File

@ -7,10 +7,12 @@
}, },
.item = .{ .item = .{
.material = .{ .material = .{
.density = 2.0, .density = 3.5,
.resistance = 3.0, .strength = 3.0,
.power = 0.8, .elasticity = 7.0,
.roughness = 2.0, .grip = 0.1,
.hardness = 8.5,
.textureRoughness = 2.0,
.colors = .{ .colors = .{
0xff030308, 0xff0D0C11, 0xff151420, 0xff1C1A2B, 0xff28253D, 0xff030308, 0xff0D0C11, 0xff151420, 0xff1C1A2B, 0xff28253D,
}, },

View File

@ -3,10 +3,12 @@
.blockHealth = 6, .blockHealth = 6,
.item = .{ .item = .{
.material = .{ .material = .{
.density = 1.0, .density = 0.39,
.resistance = 1.0, .strength = 1.0,
.power = 0.2, .elasticity = 0.9,
.roughness = 0.7, .grip = 0.9,
.hardness = 2.5,
.textureRoughness = 0.7,
.colors = .{ .colors = .{
0xff35281b, 0xff493523, 0xff60462e, 0xff6f5133, 0xff815d39, 0xff35281b, 0xff493523, 0xff60462e, 0xff6f5133, 0xff815d39,
}, },

View File

@ -1,10 +1,12 @@
.{ .{
.texture = "diamond.png", .texture = "diamond.png",
.material = .{ .material = .{
.density = 1.0, .density = 3.5,
.resistance = -5.0, .strength = -5.0,
.power = 20.0, .elasticity = 10.0,
.roughness = 0.1, .grip = 0.1,
.hardness = 10.0,
.textureRoughness = 0.1,
.colors = .{ .colors = .{
0xff847bce, 0xff8b9fe0, 0xff94c6ea, 0xffb0eaf6, 0xffffffff, 0xff847bce, 0xff8b9fe0, 0xff94c6ea, 0xffb0eaf6, 0xffffffff,
}, },

View File

@ -1,10 +1,12 @@
.{ .{
.texture = "iron_ingot.png", .texture = "iron_ingot.png",
.material = .{ .material = .{
.density = 1.5, .density = 7.874,
.resistance = 2.5, .strength = 5.0,
.power = 5.0, .elasticity = 10.0,
.roughness = 0.1, .grip = 0.1,
.hardness = 4.0,
.textureRoughness = 0.1,
.colors = .{ .colors = .{
0xff69696b, 0xff878484, 0xffa3a3a3, 0xffc2c2c2, 0xffe9e9e9, 0xff69696b, 0xff878484, 0xffa3a3a3, 0xffc2c2c2, 0xffe9e9e9,
}, },

View File

@ -5,7 +5,7 @@
.name = .handle, .name = .handle,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },
@ -14,13 +14,19 @@
.destination = .swingTime, .destination = .swingTime,
.factor = 0.1, .factor = 0.1,
}, },
.{
.source = .grip,
.destination = .swingTime,
.functionType = .inverse,
.factor = 0.05,
},
}, },
}, },
.{ .{
.name = .center, .name = .center,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 50, .factor = 50,
}, },
@ -35,7 +41,7 @@
.factor = 0.2, .factor = 0.2,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.functionType = .squareRoot, .functionType = .squareRoot,
.factor = 0.1, .factor = 0.1,
@ -46,7 +52,7 @@
.name = .blade, .name = .blade,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },
@ -61,7 +67,7 @@
.factor = 0.2, .factor = 0.2,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.factor = 0.7, .factor = 0.7,
}, },
@ -72,7 +78,7 @@
.optional = true, .optional = true,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 2, .factor = 2,
}, },
@ -88,7 +94,7 @@
.optional = true, .optional = true,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 2, .factor = 2,
}, },
@ -104,7 +110,7 @@
.optional = true, .optional = true,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },

View File

@ -5,7 +5,7 @@
.name = .handle, .name = .handle,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },
@ -14,13 +14,19 @@
.destination = .swingTime, .destination = .swingTime,
.factor = 0.1, .factor = 0.1,
}, },
.{
.source = .grip,
.destination = .swingTime,
.functionType = .inverse,
.factor = 0.05,
},
}, },
}, },
.{ .{
.name = .center, .name = .center,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 50, .factor = 50,
}, },
@ -29,13 +35,19 @@
.destination = .swingTime, .destination = .swingTime,
.factor = 0.02, .factor = 0.02,
}, },
.{
.source = .elasticity,
.destination = .swingTime,
.functionType = .inverseSquare,
.factor = 0.1,
},
.{ .{
.source = .density, .source = .density,
.destination = .power, .destination = .power,
.factor = 0.2, .factor = 0.2,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.functionType = .squareRoot, .functionType = .squareRoot,
.factor = 0.1, .factor = 0.1,
@ -46,7 +58,7 @@
.name = .bridge, .name = .bridge,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 10, .factor = 10,
}, },
@ -55,13 +67,19 @@
.destination = .swingTime, .destination = .swingTime,
.factor = 0.02, .factor = 0.02,
}, },
.{
.source = .elasticity,
.destination = .swingTime,
.functionType = .inverseSquare,
.factor = 0.1,
},
.{ .{
.source = .density, .source = .density,
.destination = .power, .destination = .power,
.factor = 0.2, .factor = 0.2,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.functionType = .squareRoot, .functionType = .squareRoot,
.factor = 0.1, .factor = 0.1,
@ -72,7 +90,7 @@
.name = .tip, .name = .tip,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },
@ -81,13 +99,19 @@
.destination = .swingTime, .destination = .swingTime,
.factor = 0.02, .factor = 0.02,
}, },
.{
.source = .elasticity,
.destination = .swingTime,
.functionType = .inverseSquare,
.factor = 0.1,
},
.{ .{
.source = .density, .source = .density,
.destination = .power, .destination = .power,
.factor = 0.2, .factor = 0.2,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.factor = 0.7, .factor = 0.7,
}, },
@ -98,7 +122,7 @@
.optional = true, .optional = true,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 2, .factor = 2,
}, },
@ -114,7 +138,7 @@
.optional = true, .optional = true,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },

View File

@ -5,7 +5,7 @@
.name = .handle, .name = .handle,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },
@ -14,13 +14,19 @@
.destination = .swingTime, .destination = .swingTime,
.factor = 0.1, .factor = 0.1,
}, },
.{
.source = .grip,
.destination = .swingTime,
.functionType = .inverse,
.factor = 0.05,
},
}, },
}, },
.{ .{
.name = .center, .name = .center,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 60, .factor = 60,
}, },
@ -30,7 +36,7 @@
.factor = 0.02, .factor = 0.02,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.functionType = .squareRoot, .functionType = .squareRoot,
.factor = 0.1, .factor = 0.1,
@ -41,7 +47,7 @@
.name = .blade, .name = .blade,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },
@ -51,7 +57,7 @@
.factor = 0.02, .factor = 0.02,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.factor = 0.3, .factor = 0.3,
}, },
@ -61,7 +67,7 @@
.name = .tip, .name = .tip,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 20, .factor = 20,
}, },
@ -71,7 +77,7 @@
.factor = 0.02, .factor = 0.02,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.factor = 0.6, .factor = 0.6,
}, },
@ -82,7 +88,7 @@
.optional = true, .optional = true,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 30, .factor = 30,
}, },
@ -92,7 +98,7 @@
.factor = 0.1, .factor = 0.1,
}, },
.{ .{
.source = .power, .source = .hardness,
.destination = .power, .destination = .power,
.factor = 0.7, .factor = 0.7,
}, },
@ -103,7 +109,7 @@
.optional = true, .optional = true,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 10, .factor = 10,
}, },
@ -119,7 +125,7 @@
.optional = true, .optional = true,
.parameterSets = .{ .parameterSets = .{
.{ .{
.source = .resistance, .source = .strength,
.destination = .maxDurability, .destination = .maxDurability,
.factor = 2, .factor = 2,
}, },

View File

@ -18,25 +18,23 @@ const NeverFailingAllocator = main.utils.NeverFailingAllocator;
pub const Inventory = @import("Inventory.zig"); pub const Inventory = @import("Inventory.zig");
/// Holds the basic properties of a tool crafting material.
const Material = struct { // MARK: Material const Material = struct { // MARK: Material
/// how much it weighs
density: f32 = undefined, density: f32 = undefined,
/// how long it takes until the tool breaks strength: f32 = undefined,
resistance: f32 = undefined, elasticity: f32 = undefined,
/// how useful it is for block breaking grip: f32 = undefined,
power: f32 = undefined, hardness: f32 = undefined,
/// How rough the texture should look. textureRoughness: f32 = undefined,
roughness: f32 = undefined,
/// The colors that are used to make tool textures.
colorPalette: []Color = undefined, colorPalette: []Color = undefined,
pub fn init(self: *Material, allocator: NeverFailingAllocator, zon: ZonElement) void { pub fn init(self: *Material, allocator: NeverFailingAllocator, zon: ZonElement) void {
self.density = zon.get(f32, "density", 1.0); self.density = zon.get(f32, "density", 1.0);
self.resistance = zon.get(f32, "resistance", 1.0); self.strength = zon.get(f32, "strength", 1.0);
self.power = zon.get(f32, "power", 1.0); self.elasticity = zon.get(f32, "elasticity", 1.0);
self.roughness = @max(0, zon.get(f32, "roughness", 1.0)); self.grip = zon.get(f32, "grip", 1.0);
self.hardness = zon.get(f32, "hardness", 1.0);
self.textureRoughness = @max(0, zon.get(f32, "textureRoughness", 1.0));
const colors = zon.getChild("colors"); const colors = zon.getChild("colors");
self.colorPalette = allocator.alloc(Color, colors.array.items.len); self.colorPalette = allocator.alloc(Color, colors.array.items.len);
for(colors.array.items, self.colorPalette) |item, *color| { for(colors.array.items, self.colorPalette) |item, *color| {
@ -52,9 +50,12 @@ const Material = struct { // MARK: Material
pub fn hashCode(self: Material) u32 { pub fn hashCode(self: Material) u32 {
var hash: u32 = @bitCast(self.density); var hash: u32 = @bitCast(self.density);
hash = 101*%hash +% @as(u32, @bitCast(self.resistance)); hash = 101*%hash +% @as(u32, @bitCast(self.density));
hash = 101*%hash +% @as(u32, @bitCast(self.power)); hash = 101*%hash +% @as(u32, @bitCast(self.strength));
hash = 101*%hash +% @as(u32, @bitCast(self.roughness)); hash = 101*%hash +% @as(u32, @bitCast(self.elasticity));
hash = 101*%hash +% @as(u32, @bitCast(self.grip));
hash = 101*%hash +% @as(u32, @bitCast(self.hardness));
hash = 101*%hash +% @as(u32, @bitCast(self.textureRoughness));
hash ^= hash >> 24; hash ^= hash >> 24;
return hash; return hash;
} }
@ -68,13 +69,15 @@ const Material = struct { // MARK: Material
const MaterialProperty = enum { const MaterialProperty = enum {
density, density,
resistance, strength,
power, elasticity,
grip,
hardness,
fn fromString(string: []const u8) MaterialProperty { fn fromString(string: []const u8) MaterialProperty {
return std.meta.stringToEnum(MaterialProperty, string) orelse { return std.meta.stringToEnum(MaterialProperty, string) orelse {
std.log.err("Couldn't find material property {s}. Replacing it with power", .{string}); std.log.err("Couldn't find material property {s}. Replacing it with strength", .{string});
return .power; return .strength;
}; };
} }
}; };
@ -178,7 +181,7 @@ const TextureGenerator = struct { // MARK: TextureGenerator
while(dy <= 0) : (dy += 1) { while(dy <= 0) : (dy += 1) {
if(y + dy < 0 or y + dy >= 16) continue; if(y + dy < 0 or y + dy >= 16) continue;
const otherItem = itemGrid[@intCast(x + dx)][@intCast(y + dy)]; const otherItem = itemGrid[@intCast(x + dx)][@intCast(y + dy)];
heightMap[x][y] = if(otherItem) |item| (if(item.material) |material| 1 + (4*random.nextFloat(seed) - 2)*material.roughness else 0) else 0; heightMap[x][y] = if(otherItem) |item| (if(item.material) |material| 1 + (4*random.nextFloat(seed) - 2)*material.textureRoughness else 0) else 0;
if(otherItem != oneItem) { if(otherItem != oneItem) {
hasDifferentItems = true; hasDifferentItems = true;
} }
@ -284,16 +287,22 @@ const ParameterSet = struct {
const FunctionType = enum { const FunctionType = enum {
linear, linear,
inverse,
square, square,
inverseSquare,
squareRoot, squareRoot,
inverseSquareRoot,
exp2, exp2,
log2, log2,
fn eval(self: FunctionType, val: f32) f32 { fn eval(self: FunctionType, val: f32) f32 {
switch(self) { switch(self) {
.linear => return val, .linear => return val,
.inverse => return 1.0/val,
.square => return val*val, .square => return val*val,
.inverseSquare => return 1.0/(val*val),
.squareRoot => return @sqrt(val), .squareRoot => return @sqrt(val),
.inverseSquareRoot => return 1.0/@sqrt(val),
.exp2 => return @exp2(val), .exp2 => return @exp2(val),
.log2 => return @log2(val), .log2 => return @log2(val),
} }