mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 02:59:37 +00:00 
			
		
		
		
	funny colours (world)
This commit is contained in:
		@ -9,6 +9,7 @@ add_executable(Voxelotl MACOSX_BUNDLE
 | 
			
		||||
 | 
			
		||||
  # Maths library
 | 
			
		||||
  Math/FloatExtensions.swift
 | 
			
		||||
  Math/IntegerExtensions.swift
 | 
			
		||||
  Math/VectorExtensions.swift
 | 
			
		||||
  Math/Matrix4x4.swift
 | 
			
		||||
  Math/Point.swift
 | 
			
		||||
 | 
			
		||||
@ -161,3 +161,37 @@ public extension SIMD4 {
 | 
			
		||||
    self = other.values
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension Color where T: FloatingPoint {
 | 
			
		||||
  init(hue: T, saturation: T, value: T) {
 | 
			
		||||
    if saturation == 0 {
 | 
			
		||||
      self.init(r: value, g: value, b: value, a: 1)
 | 
			
		||||
    } else {
 | 
			
		||||
      let hue = hue.floorMod(360)
 | 
			
		||||
 | 
			
		||||
      let rescale: T = 1 / 60
 | 
			
		||||
      let interp = (hue - floor(hue * rescale) * 60) * rescale
 | 
			
		||||
      let invInterp = (1 - interp)
 | 
			
		||||
 | 
			
		||||
      let base = 1 - saturation
 | 
			
		||||
 | 
			
		||||
      let dark = base * value
 | 
			
		||||
      let rise = value * interp + dark * invInterp
 | 
			
		||||
      let fall = dark * interp + value * invInterp
 | 
			
		||||
 | 
			
		||||
      if hue < 60 {
 | 
			
		||||
        self.init(r: value, g: rise, b: dark, a: 1)
 | 
			
		||||
      } else if hue < 120 {
 | 
			
		||||
        self.init(r: fall, g: value, b: dark, a: 1)
 | 
			
		||||
      } else if hue < 180 {
 | 
			
		||||
        self.init(r: dark, g: value, b: rise, a: 1)
 | 
			
		||||
      } else if hue < 240 {
 | 
			
		||||
        self.init(r: dark, g: fall, b: value, a: 1)
 | 
			
		||||
      } else if hue < 300 {
 | 
			
		||||
        self.init(r: rise, g: dark, b: value, a: 1)
 | 
			
		||||
      } else {
 | 
			
		||||
        self.init(r: value, g: dark, b: fall, a: 1)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -10,4 +10,13 @@ public extension FloatingPoint {
 | 
			
		||||
 | 
			
		||||
  @inline(__always) func smoothStep() -> Self { self * self * (3 - 2 * self) }
 | 
			
		||||
  @inline(__always) func smootherStep() -> Self { self * self * self * (self * (self * 6 - 15) + 10) }
 | 
			
		||||
 | 
			
		||||
  @inline(__always) func euclidianMod(_ divisor: Self) -> Self { self.floorMod(abs(divisor)) }
 | 
			
		||||
  @inline(__always) func floorMod(_ divisor: Self) -> Self {
 | 
			
		||||
    //fmod(fmod(self, divisor) + divisor, divisor)
 | 
			
		||||
    (self.truncateMod(divisor) + divisor).truncateMod(divisor)
 | 
			
		||||
  }
 | 
			
		||||
  @inline(__always) func truncateMod(_ divisor: Self) -> Self {
 | 
			
		||||
    self.truncatingRemainder(dividingBy: divisor)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								Sources/Voxelotl/Math/IntegerExtensions.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Sources/Voxelotl/Math/IntegerExtensions.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
public extension BinaryInteger {
 | 
			
		||||
  @inline(__always) func euclidianMod(_ divisor: Self) -> Self {
 | 
			
		||||
    self.floorMod(divisor < 0 ? divisor * -1 : divisor)
 | 
			
		||||
  }
 | 
			
		||||
  @inline(__always) func floorMod(_ divisor: Self) -> Self {
 | 
			
		||||
    //(self % divisor + divisor) % divisor
 | 
			
		||||
    (self.truncateMod(divisor) + divisor).truncateMod(divisor)
 | 
			
		||||
  }
 | 
			
		||||
  @inline(__always) func truncateMod(_ divisor: Self) -> Self {
 | 
			
		||||
    self.quotientAndRemainder(dividingBy: divisor).remainder
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -19,6 +19,7 @@ public class World {
 | 
			
		||||
 | 
			
		||||
  func generate(width: Int, height: Int, depth: Int, random: inout any RandomProvider) {
 | 
			
		||||
    let noise = ImprovedPerlin<Float>(random: &random)
 | 
			
		||||
    let noise2 = SimplexNoise<Float>(random: &random)
 | 
			
		||||
 | 
			
		||||
    for x in 0..<width {
 | 
			
		||||
      for y in 0..<height {
 | 
			
		||||
@ -30,12 +31,12 @@ public class World {
 | 
			
		||||
            let fpos = SIMD3<Float>(position)
 | 
			
		||||
            return if fpos.y / Float(Chunk.size)
 | 
			
		||||
                + noise.get(fpos * 0.05) * 1.1
 | 
			
		||||
                + noise.get(fpos * 0.1 + 500) * 0.5
 | 
			
		||||
                + noise.get(fpos * 0.3 + 100) * 0.23 < 0.6 {
 | 
			
		||||
                + noise.get(fpos * 0.10) * 0.5
 | 
			
		||||
                + noise.get(fpos * 0.30) * 0.23 < 0.6 {
 | 
			
		||||
              .solid(.init(
 | 
			
		||||
                r: Float16(noise.get(fpos * 0.1)),
 | 
			
		||||
                g: Float16(noise.get(fpos * 0.1 + 10)),
 | 
			
		||||
                b: Float16(noise.get(fpos * 0.1 + 100))).mix(.white, 0.6).linear)
 | 
			
		||||
                hue:        Float16(180 + noise2.get(fpos * 0.05) * 180),
 | 
			
		||||
                saturation: Float16(0.5 + noise2.get(SIMD4(fpos * 0.05, 4)) * 0.5),
 | 
			
		||||
                value:      Float16(0.5 + noise2.get(SIMD4(fpos * 0.05, 9)) * 0.5).lerp(0.5, 1)).linear)
 | 
			
		||||
            } else {
 | 
			
		||||
              .air
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user