Skip to content

Instantly share code, notes, and snippets.

@kunofellasleep
Last active October 16, 2018 21:23
Show Gist options
  • Select an option

  • Save kunofellasleep/2b9d685345c66171caf43d99ce6dbd87 to your computer and use it in GitHub Desktop.

Select an option

Save kunofellasleep/2b9d685345c66171caf43d99ce6dbd87 to your computer and use it in GitHub Desktop.
kernel void chromaticAberration(
texture2d<float, access::write> outTex [[texture(0)]],
texture2d<float, access::read> inTex [[texture(1)]],
uint2 gid [[thread_position_in_grid]]) {
float filterLevel = 3.5;
float4 c = float4(0.0, 0.0, 0.0, 1.0);
//収差に使用するレイヤーの色味
float3 weight[4] = {
float3(0.0f, 0.0f, 0.5f),
float3(0.0f, 0.5f, 0.5f),
float3(0.5f, 0.5f, 0.0f),
float3(0.5f, 0.0f, 0.0f)
}
//正規化
float nx = ((float)(gid.x)/(outTex.get_width()/2.0) - 1.0);
float ny = ((float)(gid.y)/(outTex.get_height()/2.0) - 1.0);
for (int i=0; i<4; i++) {
unsigned int xo = (int)((float)(gid.x) - nx * filterLevel * i);
unsigned int yo = (int)((float)(gid.y) - ny * filterLevel * i);
float3 split = weight[i];
float3 src = inTex.read(uint2(xo, yo)).rgb;
c.rgb += src.rgb * split;
}
outTex.write(c.rgba, gid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment