惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog RSS Feed
U
Unit 42
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
雷峰网
雷峰网
罗磊的独立博客
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
P
Proofpoint News Feed
The Cloudflare Blog
D
Docker
大猫的无限游戏
大猫的无限游戏

Red Blob Games: latest blog posts

Red Blob Games: Differential heuristics Red Blob Games: Responsive design calculator Red Blob Games: Academic citations Red Blob Games: Highlighting interactive code blocks Red Blob Games: Optimizing page size Red Blob Games: Writing a guide to SDF fonts Red Blob Games: URLs with trailing punctuation Red Blob Games: What I did in 2025 Red Blob Games: Goodbye Sass Goodbye Sass Red Blob Games: RotMG map seeds Red Blob Games: Mapgen4 Mapgen4's use of WebGL2 Red Blob Games: Mapgen4 river shader Red Blob Games: Harnessing ChatGPT hallucinations Red Blob Games: Let Let's write a search engine, part 2 of 2 Red Blob Games: Let Let's write a search engine, part 1 of 2 Red Blob Games: Hexagon conversions Red Blob Games: Mapgen4 trade routes Red Blob Games: De-optimizing mapgen4 Red Blob Games: Hexagon spiral coordinates Red Blob Games: Thoughts on Flash Red Blob Games: What I did in 2024 Red Blob Games: Hexagon page animations Red Blob Games: SDF Halos SDF Halos Red Blob Games: SDF headless tests, part 2 Red Blob Games: SDF headless tests, part 1
Red Blob Games: Mapgen4 renderer
2025-09-30 · via Red Blob Games: latest blog posts
Blog post: 29 Sep 2025

It’s been a while since I’ve worked on mapgen4 features. In 2018 I declared it finished[1]. I then put it away and worked on other projects. Over the years I have updated the code (es6 modules, typescript, pointer events, boundary points, pnpm) without adding any features. I had been leaving all feature updates for a future map generator.

Last year I decided it was time to start thinking about new features. I started experimenting with some prototypes. That made me realize there are many improvements I’d like to make to mapgen4 before getting into big features.

Mapgen4 debug view

I made a list. One of the projects on the list is rewriting the renderer. But why?

  1. Migrate to WebGL2. I started mapgen4 in 2017. WebGL2 wasn’t widely available until 2021[2]. I’d like to use it both for features[3] and performance. I’m using a WebGL1 library, Regl.js[4], which does not support WebGL2[5].
  2. Reduce load time. Regl.js almost doubles the JS size of mapgen4. I would be able to shrink mapgen4 significantly by switching away from it.

Rewriting the renderer was not something I was looking forward to. It’s work that has to be done in “one shot”, where the intermediate steps aren’t testable. I decided to use an LLM to help me. I rarely use LLMs for coding and learned a lot.

  1. In this project I used the LLM for translating existing working code from Regl.js to WebGL1. This felt different from having it write new code.
  2. The resulting code had some subtle bugs. I was able to track some of them down by comparing the output of the original mapgen4 renderer with the rewritten renderer. Having a previous working version was important.
  3. It got me out of my analysis paralysis. Having something that runs rather than a blank editor window was a huge win.
  4. I didn’t like the structure of the code it generated. It triggered XKCD 386[6] for me. I ended up replacing all of its code, bit by bit, testing after each change.

Along the way I re-evaluated some of how the renderer worked. For example, I’m using nearest neighbor filtering in many places, even though linear might be better.

GL_NEAREST vs GL_LINEAR filtering

Look at how much smoother the ocean colors are with linear filtering! But there are blue splotches near rivers. I decided to keep nearest neighbor filtering for now.

I also discovered some bugs, like this one where one edge of the map is jagged, but only noticeable when the camera is rotated and zoomed in:

Bug: jagged edge

Overall, I don’t think the LLM saved me any time. I didn’t end up keeping the code it gave me. But it got me unstuck, and that meant I actually made progress.

The main benefit of the rewrite was output size:

File Size before Size after
_worker.js 18543 18579
_bundle.js 150672 69469
(total) 169215 88048

But the source code did get bigger, from 600 lines to 750 lines (to avoid 9500 lines of Regl.js).

The secondary benefits are that I got to revisit some of the decisions I made, I found some bugs, and I got unstuck. I didn’t stop at the main renderer. I also rewrote the river renderer, which saved another 8666 bytes. That’s for the next blog post.