百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

Planet-LOD

> 编程语言
开源

行星渲染:基于三角形细分的自适应球面细节级别

340 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

行星渲染:基于三角形细分的自适应球面细节级别

Planet-LOD - Spherical Level-of-Detail

License : MIT

http://opensource.org/licenses/MIT

Summary

This is a simple tutorial of how to render planet using a triangle subdivision approach. The source is optimized for compactness and to make the algorithm easy to understand. The algorithm renders an icosahedron with 12 triangles, each of which is being sub-divided using a recursive function.

If you would render the planet in a game engine, you would have to render a triangle patch for NxN triangles with a VBO inside the draw_triangle function, rather than a single triangle with gl immediate mode. The center of detail is where the camera would be in the game. The camera in the demo is above for demonstration purpose.

What the code is :

  • A simple demo to show how a planet rendering with LOD works
  • As short as possible so you can experiment with the algorithm
  • Easy to understand

What the code is not:

  • A ready to use planet rendering library with shaders frustum culling etc
  • A way to render a planet with best performance
  • A demonstration of modern high performance gl rendering

Discussion Forum

http://www.gamedev.net/topic/677700-planet-rendering-spherical-level-of-detail-in-less-than-100-lines-of-c/ https://www.reddit.com/r/gamedev/comments/4d2oez/planet_rendering_spherical_levelofdetail_in_less/

Screenshot

struct World
{
	static void draw_triangle(vec3f p1, vec3f p2, vec3f p3)
	{
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glBegin(GL_TRIANGLES);
		glVertex3f(p1.x, p1.y, p1.z);
		glVertex3f(p2.x, p2.y, p2.z);
		glVertex3f(p3.x, p3.y, p3.z);
		glEnd();
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	}
	static void draw_recursive(vec3f p1,vec3f p2,vec3f p3, vec3f center , float size=1)
	{
		float ratio = gui.screen[0].slider["lod.ratio"].val; // default : 1
		float minsize = gui.screen[0].slider["detail"].val;  // default : 0.01

		double dot = double(((p1+p2+p3)/3).dot(center));
		double dist = acos(clamp(dot, -1, 1)) / M_PI;

		if (dist > 0.5) return;//culling

		if (dist > double(ratio)*double(size) || size  p({ 
			{ -1, t, 0 }, { 1, t, 0 }, { -1, -t, 0 }, { 1, -t, 0 },
			{ 0, -1, t }, { 0, 1, t }, { 0, -1, -t }, { 0, 1, -t },
			{ t, 0, -1 }, { t, 0, 1 }, { -t, 0, -1 }, { -t, 0, 1 },
		});
		std::vector idx({ 
			0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
			1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 10, 7, 6, 7, 1, 8,
			3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
			4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
		});

		loopi(0, idx.size() / 3)
		{
			draw_recursive(
				p[idx[i * 3 + 0]].norm(), // triangle point 1
				p[idx[i * 3 + 1]].norm(), // triangle point 2
				p[idx[i * 3 + 2]].norm(), // triangle point 3
				center);
		}
	}
};

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言