Remove RandomGenerator

This commit is contained in:
Eryn Wells 2018-11-21 08:57:59 -07:00
parent 4e5dfcf20b
commit 261a768ae5
3 changed files with 7 additions and 49 deletions

View file

@ -104,42 +104,6 @@ class ZeroAlgorithm: Kernel, TerrainGenerator {
}
}
/// Randomly generate heights that are independent of all others.
class RandomAlgorithm: Kernel, TerrainGenerator {
let name = "Random"
let needsGPU: Bool = true
private var uniforms: UnsafeMutablePointer<RandomAlgorithmUniforms>
init?(device: MTLDevice, library: MTLLibrary) {
let bufferSize = (MemoryLayout<RandomAlgorithmUniforms>.stride & ~0xFF) + 0x100;
guard let buffer = device.makeBuffer(length: bufferSize, options: [.storageModeShared]) else {
print("Couldn't create uniform buffer")
return nil
}
uniforms = UnsafeMutableRawPointer(buffer.contents()).bindMemory(to: RandomAlgorithmUniforms.self, capacity:1)
do {
try super.init(device: device, library: library, functionName: "randomKernel", uniformBuffer: buffer)
} catch let e {
print("Couldn't create compute kernel. Error: \(e)")
return nil
}
updateUniforms()
}
func updateUniforms() {
RandomAlgorithmUniforms_refreshRandoms(uniforms)
}
func render(progress: Progress) -> [Float] {
return []
}
}
/// Implementation of the Diamond-Squares algorithm.
/// - https://en.wikipedia.org/wiki/Diamond-square_algorithm
public class DiamondSquareGenerator: TerrainGenerator {

View file

@ -66,8 +66,13 @@ typedef struct {
matrix_float4x4 projectionMatrix;
matrix_float4x4 modelViewMatrix;
matrix_float3x3 normalMatrix;
packed_float2 terrainDimensions;
packed_uint2 terrainSegments;
#ifdef __METAL_VERSION__
simd::packed_float2 terrainDimensions;
simd::packed_uint2 terrainSegments;
#else
simd_packed_float2 terrainDimensions;
simd_packed_uint2 terrainSegments;
#endif
} Uniforms;
#endif /* ShaderTypes_h */

View file

@ -93,14 +93,3 @@ kernel void zeroKernel(texture2d<float, access::write> outTexture [[texture(Gene
outTexture.write(0, tid);
}
#pragma mark - RandomGenerator
kernel void randomKernel(texture2d<float, access::write> outTexture [[texture(GeneratorTextureIndexOut)]],
constant RandomAlgorithmUniforms &uniforms [[buffer(0)]],
uint2 tid [[thread_position_in_grid]])
{
PRNG rng(uniforms.randoms[(tid.x * tid.y) % kRandomAlgorithmUniforms_RandomCount]);
uint r = rng.xorShift();
float x = float(r * (1.0 / float(UINT_MAX))) * 0.5f;
outTexture.write(x, tid);
}