{
 "id": "contrast-adaptive-sharpening",
 "title": "Contrast Adaptive Sharpening",
 "aliases": [
  "CAS"
 ],
 "domain": "post",
 "subdomain": "sharpening",
 "stage": "post",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal"
 ],
 "year_introduced": 2019,
 "inputs": [
  "ldr-image"
 ],
 "outputs": [
  "ldr-image"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "A cheap sharpening filter that scales its strength per pixel by local contrast, so already-crisp edges are not over-sharpened while soft areas are lifted, avoiding most of the halos of a plain unsharp mask.",
 "how_it_works": "CAS reads a plus-shaped neighbourhood of five pixels. It computes the per-channel min and max of the neighbourhood and derives a sharpening amount inversely related to the headroom between those extremes and the representable range: a pixel with plenty of headroom sharpens more, a pixel near 0 or 1 sharpens less. This amount sets a negative lobe weight for the four neighbours, and the output is the normalised weighted sum of the centre and neighbours, clamped to the neighbourhood range. Because the weight adapts to local contrast, the filter stays stable in high-contrast regions where a fixed kernel would ring. It operates on LDR display-referred values and can be fused with upscaling.",
 "when_to_use": "Choose it as a final pass after TAA or an upscaler to restore crispness lost to history blur.\n\nPrefer built-in sharpening inside `fidelityfx-super-resolution` or `dlss` when those already apply one, to avoid double sharpening. Prefer no sharpening for stylized flat-shaded content.",
 "cost": {
  "class": "cheap",
  "notes": "One full-screen pass with five fetches; negligible next to TAA."
 },
 "failure_modes": [
  "Amplifies noise and film grain if applied after grain",
  "Halos remain around very high-contrast edges at high strength",
  "Sharpening after tonemapping clips highlights in already bright regions",
  "Exaggerates aliasing in unfiltered scenes"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "gh:gpuopen-effects/fidelityfx-cas",
   "type": "code",
   "title": "GPUOpen-Effects/FidelityFX-CAS",
   "description": "Contrast Adaptive Sharpening (CAS)",
   "authors": [
    "GPUOpen-Effects"
   ],
   "year": 2020,
   "venue": "GitHub",
   "url": "https://github.com/GPUOpen-Effects/FidelityFX-CAS",
   "ids": {
    "repo": "GPUOpen-Effects/FidelityFX-CAS"
   },
   "license": "MIT",
   "extra": {
    "stars": 234,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2021-07-15T14:30:39Z",
    "language": "C",
    "homepage": "https://gpuopen.com/fidelityfx-cas/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/GPUOpen-Effects/FidelityFX-CAS",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/GPUOpen-Effects/FidelityFX-CAS",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/GPUOpen-Effects/FidelityFX-CAS",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/GPUOpen-Effects/FidelityFX-CAS",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/GPUOpen-Effects/FidelityFX-CAS",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/GPUOpen-Effects/FidelityFX-CAS",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "gpuopeneffects2020gpuopen"
  },
  {
   "role": "tutorial",
   "key": "url:https://gpuopen.com/fidelityfx-cas",
   "type": "tutorial",
   "title": "FidelityFX Contrast Adaptive Sharpening",
   "authors": [
    "AMD GPUOpen"
   ],
   "year": null,
   "venue": "gpuopen.com",
   "url": "https://gpuopen.com/fidelityfx-cas",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": null,
    "page_title": "AMD FidelityFX™ Contrast Adaptive Sharpening (CAS)",
    "host": "gpuopen.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://gpuopen.com/fidelityfx-cas → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://gpuopen.com/fidelityfx-cas → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://gpuopen.com/fidelityfx-cas → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.6,
   "__bib": "gpuopenfidelityfx"
  }
 ],
 "presets": [
  {
   "id": "contrast-adaptive-sharpening-specimen",
   "title": "Left: softened image. Right: CAS, a 5-tap cross whose strength is scaled by local min/max contrast",
   "runtime": "glsl-fragment",
   "params": {
    "SHARP": 1
   },
   "code": "float hash(vec2 c){uvec2 u=uvec2(ivec2(floor(c)));uint h=u.x*1597334673u^u.y*3812015801u;h^=h>>15;h*=2246822519u;h^=h>>13;h*=3266489917u;h^=h>>16;return float(h)*(1./4294967296.);}\nfloat lum(vec3 c){return dot(c,vec3(.2126,.7152,.0722));}\nvec3 gam(vec3 c){return pow(clamp(c,0.,1.),vec3(1./2.2));}\nvec3 img(vec2 p){\n  vec3 c=mix(vec3(.12,.18,.34),vec3(.95,.72,.45),clamp(p.y+.5,0.,1.));\n  vec2 q=p-vec2(-.03,.14); float rr=.16; float d=length(q)-rr;\n  vec3 n=normalize(vec3(q/rr,sqrt(max(1.-dot(q,q)/(rr*rr),0.))));\n  float l=clamp(dot(n,normalize(vec3(-.5,.6,.6))),0.,1.);\n  c=mix(c,vec3(.85,.26,.2)*(.18+.9*l),smoothstep(.002,-.002,d));\n  vec2 r=p-vec2(0.,-.2);\n  if(abs(r.x)<.2&&abs(r.y)<.09) c=mix(vec3(.1,.35,.3),vec3(.93,.92,.85),smoothstep(-.3,.3,sin(r.x*340.+r.y*90.)));\n  if(p.y<-.34&&p.y>-.42){ vec3 h=.5+.5*cos(6.2832*((p.x+.25)*2.+vec3(0.,.33,.67))); c=h; }\n  c=mix(c,vec3(.97,.85,.2),smoothstep(.003,-.003,abs(p.x-.17)-.025)*step(.0,p.y)*step(p.y,.4));\n  return c;\n}\n\nconst float SHARP=1.0; // P\nvec3 soft(vec2 p){float e=2.2/512.;return .25*(img(p+vec2(e,e))+img(p+vec2(-e,e))+img(p+vec2(e,-e))+img(p+vec2(-e,-e)));}\nvoid mainImage(out vec4 fragColor,in vec2 fragCoord){\n  vec2 uv=(fragCoord-.5*iResolution.xy)/iResolution.y;bool R=uv.x>0.;vec2 q=vec2(uv.x+(R?-.25:.25),uv.y);\n  vec3 col=soft(q);\n  if(R){float e=1./512.;\n    vec3 b=soft(q+vec2(0.,e)),d=soft(q-vec2(e,0.)),f=soft(q+vec2(e,0.)),h=soft(q-vec2(0.,e)),c=col;\n    vec3 mn=min(min(min(d,c),min(f,b)),h),mx=max(max(max(d,c),max(f,b)),h);\n    vec3 amp=sqrt(clamp(min(mn,1.-mx)/max(mx,1e-3),0.,1.));\n    vec3 w=-amp/mix(8.,5.,SHARP);\n    col=(w*(b+d+f+h)+c)/(1.+4.*w);}\n  if(abs(uv.x)<.0015)col=vec3(1.);fragColor=vec4(clamp(col,0.,1.),1.);\n}",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "contrast-adaptive-sharpening",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4818,
      "std": 0.2052,
      "unique_colors": 572
     },
     "image": "/specimens/contrast-adaptive-sharpening-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "temporal-anti-aliasing",
  "fidelityfx-super-resolution"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "temporal-anti-aliasing",
   "why": "Run after the TAA resolve to counter its blur."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/post/contrast-adaptive-sharpening.json"
 },
 "solves": [
  "image looks soft after upscaling or taa",
  "sharpen the frame without halos or noise boosting",
  "cheap sharpening pass that avoids ringing on edges",
  "taa blur makes the image mushy"
 ],
 "authority": "GPUOpen-Effects, 2020",
 "url": "https://texelatlas.vercel.app/t/contrast-adaptive-sharpening/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 14.58,
  "tier": "moderate",
  "p50_ms": 0.4796,
  "p95_ms": 0.4924,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "contrast-adaptive-sharpening-specimen",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 11.23,
   "tier": "moderate",
   "p50_ms": 0.1785,
   "p95_ms": 0.1803,
   "speedup_x": 2.69,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 9.21,
   "tier": "moderate",
   "p50_ms": 0.2653,
   "p95_ms": 0.2664,
   "speedup_x": 1.81,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}