frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Perfecting anti-aliasing on signed distance functions

https://blog.pkh.me/p/44-perfecting-anti-aliasing-on-signed-distance-functions.html
64•ibobev•4h ago

Comments

mxfh•3h ago
The minute black area on the inner part of the sector getting perceptually boosted with the same ramp width like the outer area is effectively how an outline on a shape would behave, not two shapes with no stroke width. I would expect the output brightness should scale with the volume/depth under a pixel in the 3d visualization.

Is this intentional? To me this is an opiniated (aka artistic preference) feature preserving method not the perfect one.

Btw the common visualization has a source and an author:

https://iquilezles.org/articles/distfunctions2d/ https://www.shadertoy.com/playlist/MXdSRf

Retr0id•3h ago
> The minute black area on the inner part of the sector

I'm not grasping what you're referring to here.

mxfh•1h ago
That Pac-Man “mouth” is collapsing to a constant width line like halfway in for the last for examples for me.

Having some weird mid-length discontinuity in the edge direction for me. Not just perceptually.

Maybe I’m misunderstanding something here or have a different idea what the goal of that exercise is, but I would expect some pixels to turn near white near the center towards that gap sector.

NohatCoder•3h ago
Reminds me that I found an alternative way of sampling an SDF:

First take a sample in each corner of the pixel to be rendered (s1 s2 s3 s4), then compute:

    coverage=0.5 + (s1+s2+s3+s4)/(abs(s1)+abs(s2)+abs(s3)+abs(s4))/2
It is a good approximation, and it keeps on working no matter how you scale and stretch the field.

Relative to the standard method it is expensive to calculate. But for a modern GPU it is still a very light workload to do this once per screen pixel.

brookman64k•2h ago
Would that be done in two passes? 1. Render the image shifted by 0.5 pixels in both directions (plus one additional row & column). 2. Apply above formula to each pixel (4 reads, 1 write).
NohatCoder•2h ago
You certainly could imagine doing that, but as long as the initial evaluation is fairly cheap (say a texture lookup), I don't see the extra pass being worth it.
ralferoo•2h ago
That'd be one way of doing it.

You don't technically need 4 reads per pixel either, for instance you can process a 7x7 group with a 64-count thread group. Each thread does 1 read, and then fetches the other 3 values from its neighbours and calculates the average. Then the 7x7 subset of the 8x8 write their values.

You could integrate this into the first pass too, but then there would be duplication on the overlapped areas of each block. Depending on the complexity of the first pass, it still might be more efficient to do that than an extra pass.

Knowing that it's only the edges that are shared between threads, you could expand the work of each thread to do multiple pixels so that each thread group covers more pixels the reduce the number of pixels sampled multiple times. How much you do this by depends on register pressure, it's probably not worth doing more than 4 pixels per thread but YMMV.

shiandow•2h ago
Technically that only requires calculating one extra row and column of pixels.

It is indeed scale invariant but I think you can do better, you should have enough to make it invariant to any linear transformation. The calculation will be more complex but that is nothing compared to evaluating the SDF

NohatCoder•1h ago
I do believe that it is already invariant to linear transformations the way you want, i.e. we can evaluate the corners of an arbitrary parallelogram instead of a square and get a similar coverage estimate.
talkingtab•2h ago
A very good example of SDF thinking, using signed distance fields in shaders. Both shaders and SDF are new to me and very interesting. Another example of what is being done is MSDF here: https://github.com/Chlumsky/msdfgen.
WithinReason•1h ago
Instead of OKLAB isn't it simpler to just use a linear color space and only do gamma correction at the very end?
badlibrarian•30m ago
Simpler and worse in this application.
Const-me•1h ago
Good article, but I believe it lacks information what specifically these magical dFdx, dFdy, and fwidth = abs(dFdx) + abs(dFdy) functions are computing.

The following stackexchange answer addresses that question rather well: https://gamedev.stackexchange.com/a/130933/3355 As you see, dFdx and dFdx are not exactly derivatives, these are discrete screen-space approximations of these derivativities. Very cheap to compute due to the weird execution model of pixel shaders running in hardware GPUs.

mananaysiempre•36m ago
If you’ve ever sampled a texture in a shader, then you know what those are, so it’s probably fair to include them in the prerequisites for the article. But yes, those are intended to be approximate screen-space derivatives of whatever quantity you plug into them, and (I believe) on basically any hardware the approximation in question is a single-sided first difference, because the particular fragment (single-pixel contribution) you’re computing always exists in a 2×2 group of screen-space neighbours executing in lockstep.
david-gpu•52m ago
This looks a lot like some line anti aliasing I had to hack together many years ago when a customer started complaining loudly about the lack of hardware support for it. I think I had something like a week to put together three different alternatives for them to pick from, and this was the winner. It looked the best by far.

Years later my boss was telling me how satisfied he was that he could throw any problem in my general direction and it would be gone in no time. There is nothing like the risk of losing his work permit to motivate a young guy to work himself down to a crisp, all for peanuts.

jeremyscanvic•45m ago
Really interesting write-up! I'm not very familiar with signed distance functions but aliasing is a major part of my PhD and this is really insightful to me!

Part 1: A Deep Dive into Rust and C Memory Interoperability

https://notashes.me/blog/part-1-memory-management/
31•hyperbrainer•39m ago•12 comments

Perplexity is using stealth, undeclared crawlers to evade no-crawl directives

https://blog.cloudflare.com/perplexity-is-using-stealth-undeclared-crawlers-to-evade-website-no-crawl-directives/
363•rrampage•2h ago•165 comments

Century-Old Stone “Tsunami Stones” Dot Japan's Coastline (2015)

https://www.smithsonianmag.com/smart-news/century-old-warnings-against-tsunamis-dot-japans-coastline-180956448/
76•deegles•3h ago•17 comments

Open IP Camera Firmware

https://openipc.org/à
40•zakki•3d ago•17 comments

My Ideal Array Language

https://www.ashermancinelli.com/csblog/2025-7-20-Ideal-Array-Language.html
45•bobajeff•2h ago•11 comments

Scientists shine a laser through a human head

https://spectrum.ieee.org/optical-brain-imaging
47•sohkamyung•2h ago•19 comments

GHz spiking neuromorphic photonic chip with in-situ training

https://arxiv.org/abs/2506.14272
85•juanviera23•4h ago•9 comments

Job-seekers are dodging AI interviewers

https://fortune.com/2025/08/03/ai-interviewers-job-seekers-unemployment-hiring-hr-teams/
203•robtherobber•7h ago•304 comments

Show HN: Tiny logic and number games I built for my kids

https://quizmathgenius.com/
5•min2bro•26m ago•2 comments

The Toyota Corolla of programming

https://deprogrammaticaipsum.com/the-toyota-corolla-of-programming/
78•secstate•2h ago•57 comments

Perfecting anti-aliasing on signed distance functions

https://blog.pkh.me/p/44-perfecting-anti-aliasing-on-signed-distance-functions.html
64•ibobev•4h ago•16 comments

Do LLMs identify fonts?

https://maxhalford.github.io/blog/llm-font-identification/
28•alexmolas•4d ago•12 comments

Mozilla Firefox's extension store being flooded with malware

https://www.theregister.com/2025/08/04/mozilla_add_on_phishing/
36•lknik•1h ago•9 comments

Genetic correlates of social stratification in Great Britain (2019) [pdf]

https://research.vu.nl/ws/portalfiles/portal/127420931/Genetic_correlates_of_social_stratification_in_Great_Britain.pdf
41•djoldman•3h ago•31 comments

ScreenCoder: An intelligent UI-to-code generation system

https://github.com/leigest519/ScreenCoder
13•Dowwie•2h ago•5 comments

Mastercard deflects blame for NSFW games being taken down

https://www.pcgamer.com/games/mastercard-deflects-blame-for-nsfw-games-being-taken-down-but-valve-says-payment-processors-specifically-cited-a-mastercard-rule-about-damaging-the-brand/
382•croes•6h ago•364 comments

Modern Node.js Patterns

https://kashw1n.com/blog/nodejs-2025/
776•eustoria•20h ago•358 comments

New quantum state of matter found at interface of exotic materials

https://phys.org/news/2025-07-quantum-state-interface-exotic-materials.html
124•janandonly•3d ago•19 comments

So you want to parse a PDF?

https://eliot-jones.com/2025/8/pdf-parsing-xref
346•UglyToad•17h ago•193 comments

Writing a good design document

https://grantslatton.com/how-to-design-document
472•kiyanwang•19h ago•123 comments

How we built Bluey’s world

https://www.itsnicethat.com/features/how-we-built-bluey-s-world-cartoon-background-scenery-art-director-catriona-drummond-animation-090725
139•skrebbel•3d ago•78 comments

Read your code

https://etsd.tech/posts/rtfc/
99•noeclement•2h ago•62 comments

Every Visual Workflow Tool Is Just Excel for Developers Who Gave Up

https://medium.com/@mohamedalibenothmen1/every-visual-workflow-tool-is-just-excel-for-developers-who-gave-up-f7261090fbc8
9•dalibenothmen•22m ago•1 comments

Objects should shut the fuck up

https://dustri.org/b/objects-should-shut-the-fuck-up.html
125•gm678•1h ago•84 comments

Persona vectors: Monitoring and controlling character traits in language models

https://www.anthropic.com/research/persona-vectors
385•itchyjunk•23h ago•126 comments

KDE Plasma prepares crackdown on focus-stealing window behavior under Wayland

https://www.neowin.net/news/kde-plasma-prepares-crackdown-on-focus-stealing-window-behavior-under-wayland/
77•bundie•4h ago•35 comments

Why doctors hate their computers (2018)

https://www.newyorker.com/magazine/2018/11/12/why-doctors-hate-their-computers
102•mitchbob•15h ago•156 comments

Life, Work, Death and the Peasant: Family Formation

https://acoup.blog/2025/08/01/collections-life-work-death-and-the-peasant-part-iiia-family-formation/
197•Khaine•2d ago•65 comments

How to grow almost anything

https://howtogrowalmostanything.notion.site/htgaa25
188•car•16h ago•55 comments

Converge (YC S23) well-capitalized New York startup seeks product developers

https://www.runconverge.com/careers
1•thomashlvt•22h ago