Read texture data from the heights texture
This commit is contained in:
parent
753e8eb311
commit
4803620d4b
2 changed files with 13 additions and 7 deletions
|
@ -30,12 +30,17 @@ typedef struct
|
||||||
} ColorInOut;
|
} ColorInOut;
|
||||||
|
|
||||||
vertex ColorInOut vertexShader(Vertex in [[stage_in]],
|
vertex ColorInOut vertexShader(Vertex in [[stage_in]],
|
||||||
texture2d<half> heights [[ texture(1) ]],
|
texture2d<half> heights [[texture(0)]],
|
||||||
constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]])
|
constant Uniforms & uniforms [[buffer(BufferIndexUniforms)]])
|
||||||
{
|
{
|
||||||
|
constexpr sampler s(coord::pixel, address::clamp_to_zero, filter::linear);
|
||||||
|
|
||||||
ColorInOut out;
|
ColorInOut out;
|
||||||
|
|
||||||
float4 position = float4(in.position, 1.0);
|
uint2 gridCoord(in.texCoord.x * heights.get_width(), in.texCoord.y * heights.get_height());
|
||||||
|
half4 height = heights.read(gridCoord).rrrr;
|
||||||
|
|
||||||
|
float4 position(in.position.x, float(height.r), in.position.z, 1.0);
|
||||||
out.position = uniforms.projectionMatrix * uniforms.modelViewMatrix * position;
|
out.position = uniforms.projectionMatrix * uniforms.modelViewMatrix * position;
|
||||||
out.texCoord = in.texCoord;
|
out.texCoord = in.texCoord;
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,11 @@ class Terrain: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and condition mesh data to feed into a pipeline using the given vertex descriptor.
|
/// Create and condition mesh data to feed into a pipeline using the given vertex descriptor.
|
||||||
/// @param dimensions Coordinate dimensions of the plane
|
///
|
||||||
/// @param segments Number of segments to divide each dimension into
|
/// - parameter dimensions: Coordinate dimensions of the plane.
|
||||||
/// @param device Metal device
|
/// - parameter segments: Number of segments to divide each dimension into.
|
||||||
/// @param vertexDescriptor Description of how to lay out vertex data in GPU memory
|
/// - parameter device: Metal device.
|
||||||
|
/// - parameter vertexDescriptor: Description of how to lay out vertex data in GPU memory.
|
||||||
class func buildMesh(withDimensions dimensions: float2, segments: uint2, device: MTLDevice, vertexDescriptor: MTLVertexDescriptor) throws -> MTKMesh {
|
class func buildMesh(withDimensions dimensions: float2, segments: uint2, device: MTLDevice, vertexDescriptor: MTLVertexDescriptor) throws -> MTKMesh {
|
||||||
let metalAllocator = MTKMeshBufferAllocator(device: device)
|
let metalAllocator = MTKMeshBufferAllocator(device: device)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue