threejs-landscape
Skill này làm gì
Skill này tạo một nền ngoài trời 3D yên tĩnh, giúp chủ thể trông như đang ở một nơi có thật. Phù hợp với lập trình viên làm cảnh web 3D, sân khấu sản phẩm hoặc trò chơi cần một bối cảnh tự nhiên.
Khi nào nên dùng
- ✓Khi bạn cần một nền ngoài trời 3D phía sau một sản phẩm hoặc nhân vật trong cảnh Three.js.
- ✓Khi bạn muốn địa hình chi tiết gần camera và đơn giản hơn ở xa.
- ✓Khi bạn muốn thay đổi thời gian trong ngày mờ dần một cách mượt mà thay vì cắt đột ngột.
Liên kết skill
https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/threejs-landscape/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể xây một cảnh quan Three.js phía sau sản phẩm 3D của tôi, với cỏ, bầu trời và hoàng hôn mờ dần một cách mượt không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tạo một lưới địa hình theo cực quanh camera, nên chi tiết dày đặc gần người xem và thưa ở đường chân trời. Agent thêm cỏ instancing đung đưa trên card đồ họa, các viên đá rải rác, một vòm trời và hệ thống thay đổi thời gian trong ngày.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Three.js Landscape
A backdrop has one job: make the subject look like it is somewhere. Everything here is chosen so the landscape reads at a glance and then gets out of the way.
Reach for threejs-weather to put rain, storm or snow on top of it, and threejs-towers when the subject standing in it is architecture.
Ring the camera with a polar grid
Do not build a square heightfield. A long lens sees a narrow wedge, so a square grid spends most of its triangles behind the camera and still runs out of resolution at the horizon.
Sample on a polar grid centred under the camera, with radial rings that get further apart as they recede:
const AN = 900, RN = 52, R0 = 2.0, R1 = 700; // angular, radial, near, far
for (let r = 0; r <= RN; r++) {
const t = r / RN;
const rad = R0 + (R1 - R0) * Math.pow(t, 2.4); // dense near, sparse far
for (let a = 0; a < AN; a++) {
const th = a / AN * Math.PI * 2;
push(Math.cos(th) * rad, landH(x, z), Math.sin(th) * rad);
}
}
Two thousand triangles near the subject beat two hundred thousand spread evenly. pow(t, 2.4) is the whole trick: every ring covers roughly the same number of screen pixels.
Watch the winding. On a polar grid it is easy to wind every quad the wrong way and end up looking at the sky through the ground. Index as (a0, b1, b0, a0, a1, b1) and check by orbiting under the horizon once, deliberately, before you build anything else on top.
Warp the domain before you layer octaves
Plain fBm reads as crumpled paper. Warping the sample position with another noise field before you evaluate it is the single biggest step toward terrain that looks eroded:
function landH(x, z) {
const wx = x + fbm(x * 0.012, z * 0.012, 3) * 26; // domain warp
const wz = z + fbm(x * 0.012 + 41, z * 0.012 - 17, 3) * 26;
let h = fbm(wx * 0.0075, wz * 0.0075, 5) * 34; // broad landforms
h += ridged(wx * 0.021, wz * 0.021, 3) * 9; // ridge lines
return h;
}
Keep the analytic function separate from the mesh. Grass, stones, fog and anything else you scatter must sample the same landH, or they will float and sink.
Ridge layers have to scale with distance. A ridge amplitude that reads well at 40 units is invisible at 600, so the far rings need theirs multiplied up or the horizon goes flat.
Colour by what the ground is doing, not by a texture
A tiled ground texture always announces itself. Compute a vertex colour from the terrain's own properties instead:
const slope = 1 - normal.y; // steep = rock
const moist = smoothstep(-4, 6, -height); // low = wet, green
const c = rock.clone()
.lerp(grass, (1 - slope * 3.2) * (0.35 + moist * 0.65))
.lerp(sand, Math.max(0, 0.5 - moist) * 0.6);
You get cliffs that go stony, hollows that go green and ridges that go pale, for free, with no UVs and no seams. Keep a very low-frequency noise on top so the colour does not band.
Grass: one ribbon, shaped entirely in the vertex shader
100k blades is a single InstancedMesh of a five-segment ribbon. Every bend, lean, taper and gust happens in the vertex shader, so the wind costs nothing on the CPU:
const geo = new THREE.BufferGeometry(); // 11 verts: a strip + a tip
const mesh = new THREE.InstancedMesh(geo, mat, 104000);
mat.onBeforeCompile = sh => {
Object.assign(sh.uniforms, grassUni);
sh.vertexShader = `
uniform float uTime, uWindAmp; uniform vec2 uWind;
attribute vec4 aParams; // height, phase, tint, lean
varying float vT; varying float vTint;
` + sh.vertexShader.replace('#include <begin_vertex>', `
float gT = position.y; // 0 at root, 1 at tip
float gBend = uRestBend + sin(uTime * 1.7 + aParams.y) * uWindAmp;
vec2 gRib = ... ; // sweep the blade along an arc
vec3 transformed = vec3(gRib.x, gT * aParams.x, gRib.y);
`);
};
mat.customProgramCacheKey = () => 'grass'; // or every instance recompiles
Anchor the field to the camera. Keep a fixed grid of blades around the viewer and move the grid, snapping to cell size, rather than growing the field outward. The player never reaches the edge and you never pay for grass behind them.
Do not hard-code the blade colour in the fragment shader and then expect the material colour to change it. diffuseColor.rgb *= mix(base, tip, t) multiplies whatever the material gave you, so a white material times a green cons
Câu hỏi thường gặp
Vì sao dùng lưới cực?
Lưới vuông lãng phí chi tiết phía sau camera, còn lưới cực đặt độ phân giải nhiều hơn vào nơi người xem nhìn.
Cỏ có làm chậm trang không?
Skill nói gió chạy trên card đồ họa, nên tốn ít tài nguyên của bộ xử lý chính.
Có bao gồm hiệu ứng thời tiết không?
Đó là một skill riêng, mà skill cảnh quan chỉ đến khi cần mưa, tuyết và bão.
Chi tiết
Mô tả gốc của tác giả
Build a live Three.js landscape that stays quiet behind a subject — a noise heightfield on a polar grid so resolution follows the lens, ground coloured by slope and moisture rather than by texture, instanced GPU grass whose wind costs nothing on the CPU, scattered stones, a gradient sky dome, a star field you can actually see, and a time-of-day system that cross-fades instead of cutting. Use for hero backdrops, product stages, scroll worlds, or any scene where a building, object, or figure has to sit in a place rather than float on a gradient.
repo: MengTo/Skills
Độ phổ biến
- Sao GitHub
- 7.2k
- Vị trí xếp hạng
- #13475
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
3d-cloth-material
7.2kGiúp agent của bạn tạo vải dệt 3D trông thật trong Three.js, với sợi dệt, ánh bóng nhẹ, nếp gấp tự nhiên, viền gấu và đường may.
3d-falling-leaves
7.2kGiúp agent của bạn thêm lá rơi chân thực vào cảnh 3D, với lá xoay tròn, trôi theo gió và được tái sử dụng khi máy quay di chuyển.
3d-four-seasons
7.2kGiúp agent của bạn thêm diện mạo xuân, hạ, thu, đông vào cảnh 3D, thay đổi cây cối, ánh sáng, bầu trời và tuyết mà không cần dựng lại cảnh.
3d-high-poly-models
7.2kGiúp agent của bạn dựng mô hình 3D chi tiết với hình dạng mượt và cạnh trông thật, rồi tạo các phiên bản nhẹ hơn chạy tốt trên web.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.