GifproGifpro

Draw Your First WebGPU Shader Triangle: Prompt Example

CODE PREVIEW

エディタを読み込み中…
P

Prompt

Create an interactive WebGPU shader playground that renders a simple triangle using a vertex shader and a fragment shader. Include a canvas, a log panel showing shader source code, and a button to recompile. Use CDN for WebGPU polyfill if needed. Keep it beginner-friendly with comments in code.

このWebGPUチュートリアルでは、頂点シェーダーとフラグメントシェーダーを使って初めての三角形を描画します。シェーダーモジュールの作成、頂点位置をハードコードしたレンダーパイプラインの構築、キャンバスへの描画という最小限のGPUパイプライン設定を示します。余計な複雑さなしにWebGPUの核となる概念を理解するのに最適です。

Prompt Overview

This prompt asks an AI coding assistant to scaffold a complete, self-contained WebGPU demo that draws the classic first triangle — the "Hello, World" of GPU programming. The generated output includes an HTML canvas wired to a WebGPU render pipeline, commented vertex and fragment shader source written in WGSL, a live log panel that surfaces the shader code, and a recompile button so learners can edit and hot-reload without a build tool. A CDN polyfill reference keeps the demo runnable in browsers that are still catching up on native WebGPU support.

This kind of prompt is ideal for educators building workshop starter kits, frontend developers taking their first steps into GPU rendering, or technical bloggers who want a reproducible, copy-paste-ready code example alongside an explainer article. It works best with models strong in code generation — GPT-4o, Claude 3.5 Sonnet, or Gemini 1.5 Pro are solid choices. Variations worth trying include swapping the static triangle for an animated rotating shape, adding a color uniform controlled by a slider, or splitting the output into separate HTML, JS, and WGSL files for a cleaner project structure.

Was this prompt helpful?

Comments

Comments appear after moderation

この記事が役に立ったら投げ銭で応援

Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済

開発者が選ぶ最強ツール集

運営者が毎日使っているツール・ガジェット 6選

見る
Homeヘルプ