Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. San Francisco Onion Futures Company(onionfutures.com ↗)
    17comments
  2. Android 17 is the first since 3.x to add new APIs without releasing to the AOSP(grapheneos.social ↗)
    336comments
  3. Science Is Open Software(jepedersen.dk ↗)
    15comments
  4. SDCC – Small Device C Compiler(sourceforge.net ↗)
    8comments
  5. Cloudflare Quick Tunnels(cloudflare.com ↗)
    268comments
  6. Show HN: Seal – Letters and passwords that open for your family after you die(github.com/jasonepage ↗)
    discuss
  7. How OpenAI Used Its Own LLMs to Design Its Jalapeño Chip(ieee.org ↗)
    69comments
  8. Saving another 100TB of RAM(cloudflare.com ↗)
    58comments
  9. Typesafe-computer-use drives a Mac toward a goal for 1/50th of a cent per step(github.com/awlevin ↗)
    2comments
  10. NASA-IBM Lunar Foundation open-Source Geospatial AI Model(usra.edu ↗)
    discuss
  11. How to Write with an LLM(sockpuppet.org ↗)
    305comments
  12. Why building a Rust LSP is hard(rust-glancer.github.io ↗)
    12comments
  13. Xcode 27.1 Beta Release Notes(developer.apple.com ↗)
    75comments
  14. The first new cat species discovered in 100 years(nationalgeographic.com ↗)
    81comments
  15. Show HN: Cactus Needle 3: 8-29MB automation models can match DeepSeek V4 Flash(cactuscompute.com ↗)
    81comments
  16. Photon-Emission-Guided Laser Fault Injection Enables RP2350 Secure Debug(ledger.com ↗)
    61comments
  17. OpenJev(openjev.com ↗)
    250comments
  18. Harm Laundering in GPT Models: Gender Discrimination Transformed Rather Than(arxiv.org ↗)
    discuss
  19. The Farnese letter(simonklee.dk ↗)
    5comments
  20. Cache-to-Cache: Direct Semantic Communication Between LLMs (2025)(arxiv.org ↗)
    12comments
  21. Goroutine Leak Profiles(go.dev ↗)
    1comments
  22. Minimal Phone 2(minimalcompany.com ↗)
    199comments
  23. Cyclomatic Complexity in C#(ndepend.com ↗)
    16comments
  24. Claude Code now reads AGENTS.md if there is no Claude.md(claude.com ↗)
    208comments
  25. LispBM is a concurrent Lisp for microcontrollers with message passing(lispbm.com ↗)
    3comments
  26. Alibaba open-sources AI model that can detect cancer and nearly 150 conditions(scmp.com ↗)
    10comments
  27. Show HN: LiveWorld – Every 24/7 YouTube live camera on one globe(liveworld.info ↗)
    32comments
  28. Flock Offers Employees Buyouts as Customers Flee(wired.com ↗)
    4comments
  29. Warez: The Infrastructure and Aesthetics of Piracy (2021)(archive.org ↗)
    40comments
  30. Inside ZCode: Silently uploading your Git history to the cloud(ferstar.org ↗)
    95comments

Rendering Worlds with Two Triangles on the GPU [pdf]

109 pointsby 12y agoiquilezles.org
25 comments
12y agoHN ↗

i just ran it on my mac successfully with wine..!

12y agoHN ↗

Thanks for the mirror.

Know of any novel techniques/rehashing of old techniques that have been developed since?

12y agoHN ↗

Well, for very small intros (4k/8k) distance fields are still hard to beat due to their compactness. A couple of examples not based on distfields, off the top of my head:

http://www.pouet.net/prod.php?which=62027 (No idea what this is, but it's great)

http://www.pouet.net/prod.php?which=62974 (reverse fluid simulation)

http://www.pouet.net/prod.php?which=59613 (particles)

For 64k intros and size unlimited demos the possibilities are too many to list. Procedural mesh generation is a classic approach which has found great modern use recently:

http://www.pouet.net/prod.php?which=61204 (if you follow 1 link in this comment make it this one)

12y agoHN ↗

Awesome, thanks!

What kind of mathemagical trickery is that reverse fluid simulation?!

12y agoHN ↗

It is disingenuous for the author to not cite Elevated.

12y agoHN ↗

This is a really impressive presentation -- after looking on from afar at the seemingly magical works of the demoscene, this finally helped me understand a little bit of how the magic happens. I've only got a bit of GLSL experience so far but now I want to learn a lot more.

12y agoHN ↗

Could someone explain to me what the "two triangles that cover the entire screen area" have to do with anything?

12y agoHN ↗

It basically means everything is happening in the shaders, not in geometry. There has to be some vertexes though, and the minimum you can have to cover the screen is two triangles.

12y agoHN ↗

That is incorrect. You can cover the screen with a single triangle ... just make it big enough. The corners get clipped and the middle region of the big triangle will cover the screen.

12y agoHN ↗

You can get around the clipping problem by displaying it on an old Interocitor.

12y agoHN ↗

True, both approaches are equally valid and being used. Every once in a while some gfx haxors also spend baffling amounts of effort on humorously "benchmarking" both approaches against each other.. ;)

12y agoHN ↗

Two triangles make a flat screen (a 'quad'), which is sized to fill your actual screen. When you run a pixel shader over the quad, it ends up running for every pixel on your screen. The result is you have the visual effect of the pixel shader giving a very detailed-looking scene, when the actual geometry is as simple as it gets.

Here's an old experiment I did where the pixel shader is running on the faces of a cube http://dgholz.github.io/GLSLSphere/ The cube edges are highlighted in red so you can see them. I like green.

12y agoHN ↗

Basically you draw a single quad (2 triangles) covering the entire screen using OpenGL (or DirectX).

A Pixel shader is run when rendering each pixel of the quad. It's only input is often `time` and `resolution`.

At least in GLSL there's a global variable, `gl_Fragcoord` and provides the integer position of the pixel currently being drawn. So for example the pixel at the bottom left is gl_Fragcoord = vec2(0,0). The one directly to the right of that is gl_Fragcoord = vec2(0,1)

Given you're also passed the resolution can get a value that goes from 0 to 1 over the screen with

   vec2 zeroToOne = gl_Fragcoord.xy / resolution;

If you were to dump that value directly do the screen you'd get a red gradient going black to red from left to right and a green gradient from black to green going from bottom to top. See http://glsl.heroku.com/e#18516.0

Now it's up to you to use more creative math that given just gl_Fragcoord, resolution, and time write a function that generates an image.

You can play with that in your browser here, http://glsl.heroku.com and here http://shadertoy.com

12y agoHN ↗

So the whole point of using a shader is that it's the GPU that's doing all the work?

12y agoHN ↗

Yes, that's what this trick is for.

In most standard 3D graphics, the CPU passes a description of the scene as polygons to the GPU, which then does two[1] shader steps - vertex and fragment[2] shading. The vertex shading works at the level of triangle vertices, effectively translating and and transforming the vertices, and then the fragment shader colors in each individual pixel.

So for a standard scene, the CPU tells the GPU: 'Right, we've got a room, with some pillars, and a monster, and a few lights, positioned like this', and then the CPU calculates what that looks like.

What Inigo is doing is that the CPU only knows there are two triangles - a quad covering the scene - so it just tells the GPU to draw a flat rectangle. The vertex shader does nothing but maintain the flat rectangle. However, because the fragment shader can be arbitrary logic, rather than just painting it with a solid color or even a texture, it is running its own simulation that involves drawing an entire scene.

----

[1] More these days with Geometry shaders, but that's another topic

[2] Sometimes called a pixel shader, although really that's incorrect - Fragment is a more accurate term

12y agoHN ↗

Wouldn't it be even easier to draw one triangle that extends beyond the screen so that it covers it entirely and let the pipeline clip it to the screen size?

12y agoHN ↗

I was working with distance fields back in 2008, and the idea of inverting the process blew my mind.

I had no idea Iñigo Quilez's image was produced this way and I'm so glad I had the chance to see how it was made.

Thanks for posting!!

12y agoHN ↗

I think the most elegant thing about this method is that it describes a scene in terms of its basic mathematical 3D objects and transformations on them (list here: http://www.iquilezles.org/www/articles/distfunctions/distfun... ) and then exploits the massive parallelism of the GPU for rendering all the pixels.

Here's a demo of someone playing around with it, complete with a Slisesix-inspired scene: http://www.rpenalva.com/blog/?p=254

This set of slides is also related: http://www.iquilezles.org/www/material/function2009/function...

12y agoHN ↗

Is the demoscene a good place to get into graphics programming? The prevalence of older methods leads me to believe one could learn in a similar progression to the graphics gurus of today, moving from simpler old methods with performance and size optimization to modern techniques?