41 lines
2.1 KiB
Plaintext
41 lines
2.1 KiB
Plaintext
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||
|
|
||
|
#include <metal_stdlib>
|
||
|
#include <simd/simd.h>
|
||
|
|
||
|
using namespace metal;
|
||
|
|
||
|
constant uint3 gl_WorkGroupSize = uint3(8u, 8u, 1u);
|
||
|
|
||
|
struct UBO
|
||
|
{
|
||
|
float4 uInvSize;
|
||
|
float4 uScale;
|
||
|
};
|
||
|
|
||
|
float jacobian(thread const float2& dDdx, thread const float2& dDdy)
|
||
|
{
|
||
|
return ((1.0 + dDdx.x) * (1.0 + dDdy.y)) - (dDdx.y * dDdy.x);
|
||
|
}
|
||
|
|
||
|
kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], constant UBO& _46 [[buffer(0)]], texture2d<float> uHeight [[texture(0)]], sampler uHeightSmplr [[sampler(0)]], texture2d<float> uDisplacement [[texture(1)]], sampler uDisplacementSmplr [[sampler(1)]], texture2d<float, access::write> iHeightDisplacement [[texture(2)]], texture2d<float, access::write> iGradJacobian [[texture(3)]])
|
||
|
{
|
||
|
float4 uv = (float2(gl_GlobalInvocationID.xy) * _46.uInvSize.xy).xyxy + (_46.uInvSize * 0.5);
|
||
|
float h = uHeight.sample(uHeightSmplr, uv.xy, level(0.0)).x;
|
||
|
float x0 = uHeight.sample(uHeightSmplr, uv.xy, level(0.0), int2(-1, 0)).x;
|
||
|
float x1 = uHeight.sample(uHeightSmplr, uv.xy, level(0.0), int2(1, 0)).x;
|
||
|
float y0 = uHeight.sample(uHeightSmplr, uv.xy, level(0.0), int2(0, -1)).x;
|
||
|
float y1 = uHeight.sample(uHeightSmplr, uv.xy, level(0.0), int2(0, 1)).x;
|
||
|
float2 grad = (_46.uScale.xy * 0.5) * float2(x1 - x0, y1 - y0);
|
||
|
float2 displacement = uDisplacement.sample(uDisplacementSmplr, uv.zw, level(0.0)).xy * 1.2000000476837158203125;
|
||
|
float2 dDdx = (uDisplacement.sample(uDisplacementSmplr, uv.zw, level(0.0), int2(1, 0)).xy - uDisplacement.sample(uDisplacementSmplr, uv.zw, level(0.0), int2(-1, 0)).xy) * 0.60000002384185791015625;
|
||
|
float2 dDdy = (uDisplacement.sample(uDisplacementSmplr, uv.zw, level(0.0), int2(0, 1)).xy - uDisplacement.sample(uDisplacementSmplr, uv.zw, level(0.0), int2(0, -1)).xy) * 0.60000002384185791015625;
|
||
|
float2 param = dDdx * _46.uScale.z;
|
||
|
float2 param_1 = dDdy * _46.uScale.z;
|
||
|
float j = jacobian(param, param_1);
|
||
|
displacement = float2(0.0);
|
||
|
iHeightDisplacement.write(float4(h, displacement, 0.0), uint2(int2(gl_GlobalInvocationID.xy)));
|
||
|
iGradJacobian.write(float4(grad, j, 0.0), uint2(int2(gl_GlobalInvocationID.xy)));
|
||
|
}
|
||
|
|