Logo Defold Shaders Editing

Defold Shaders Editing

Tổ chức
indiesoftby
defold-shaders-editing

Tạo và chỉnh sửa tệp shader Defold (.vp, .fp, .glsl). Dùng khi được yêu cầu tạo, sửa đổi hoặc cấu hình shader đỉnh, shader mảnh hoặc tệp include GLSL của Defold.

Add to TypingMind

Tổng quan

Nhà phát hànhindiesoftby
Kho mãdefold-agent-config
Tên kỹ năngdefold-shaders-editing
Sao
104
Bản fork
10
Tệp đi kèm
Chỉ có hướng dẫn
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được indiesoftby công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Defold Shaders Editing trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/indiesoftby/defold-agent-config/tree/main/.agents/skills/defold-shaders-editing
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/indiesoftby/defold-agent-config.git /tmp/defold-agent-config
mkdir -p .claude/skills
cp -r /tmp/defold-agent-config/.agents/skills/defold-shaders-editing .claude/skills/defold-shaders-editing
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Defold Shaders Editing trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Defold Shaders Editing ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Defold Shaders Editing với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Editing Defold Shaders

Creates and edits Defold shader files: vertex programs (.vp), fragment programs (.fp), and GLSL include snippets (.glsl).

When to use

This skill covers GLSL shader files used in Defold's rendering pipeline. It does NOT cover .material files — for those, use the defold-proto-file-editing skill (see references/material.md).

Shader pipeline and GLSL version

Defold supports two shader pipelines:

  1. Legacy pipeline — shaders written in OpenGL ES 2.0 compatible GLSL (no #version directive). Deprecated since Defold 1.9.2.
  2. Modern pipeline — shaders written in SPIR-V compatible GLSL with #version 140 or higher. This is the current standard.

Always write shaders using #version 140 (OpenGL 3.1) at the top of the file. This directive selects the modern pipeline during the build process. If no #version is found, Defold falls back to the legacy pipeline.

glsl
#version 140

Cross-compilation and platform targets

Defold compiles shaders for multiple graphics APIs from a single GLSL source:

  • OpenGL 3.x / 4.x (desktop: Windows, macOS, Linux)
  • OpenGL ES 2.0 / 3.0 (mobile: Android, iOS)
  • WebGL 1.0 / 2.0 (HTML5)
  • SPIR-V (Vulkan on Android, desktop)
  • Metal (iOS, macOS — via SPIR-V cross-compilation)

Because of this cross-compilation, not all GLSL features are available everywhere. Some functions (e.g., dFdx, dFdy, fwidth) require extensions on ES 2.0 / WebGL 1.0 targets but are built-in on ES 3.0+ / desktop GL. Use #extension and preprocessor guards for conditional features:

glsl
#ifdef GL_OES_standard_derivatives
#extension GL_OES_standard_derivatives : enable
#endif

#if !defined(GL_ES) || __VERSION__ >= 300 || defined(GL_OES_standard_derivatives)
    // Use derivative functions
#else
    // Provide fallback
#endif

Key limitations to keep in mind:

  • Dynamic loops with variable bounds may not work on ES 2.0 / WebGL 1.0
  • Integer operations are limited on ES 2.0
  • sampler2DArray requires ES 3.0+ / WebGL 2.0+
  • Storage buffers and compute shaders require Vulkan / Metal

File types

Vertex program (.vp)

Runs once per vertex. Transforms vertex positions from model/world space to screen space. Outputs gl_Position and passes data to the fragment shader via out variables.

Fragment program (.fp)

Runs once per fragment (pixel). Computes the final color. Outputs to a user-defined out vec4 variable (not gl_FragColor, which is deprecated in #version 140).

GLSL include snippet (.glsl)

Reusable GLSL code included by .vp or .fp files via #include. Does not run standalone. Use header guards to prevent double-inclusion.

Modern GLSL syntax rules (#version 140)

Attributes → in

In vertex shaders, use in instead of attribute:

glsl
in highp vec4 position;
in mediump vec2 texcoord0;

Fragment shaders do NOT have vertex attributes.

Varyings → out / in

In vertex shaders, use out instead of varying. In fragment shaders, use in:

glsl
// vertex shader
out mediump vec2 var_texcoord0;

// fragment shader
in mediump vec2 var_texcoord0;

Fragment output → out vec4

Use a declared out variable instead of the deprecated gl_FragColor:

glsl
out vec4 out_fragColor;

void main()
{
    out_fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

Uniform blocks

Non-opaque uniforms (matrices, vectors, floats) must be placed in a uniform block. Use vs_uniforms for vertex shaders and fs_uniforms for fragment shaders (by convention):

glsl
uniform vs_uniforms
{
    highp mat4 view_proj;
};

Opaque uniforms (samplers, images) remain standalone:

glsl
uniform mediump sampler2D texture_sampler;

Members of the uniform block are accessed directly by name (no block prefix):

glsl
gl_Position = view_proj * vec4(position.xyz, 1.0);

Texture sampling → texture()

Use texture() instead of the deprecated texture2D() / texture2DArray():

glsl
vec4 color = texture(texture_sampler, var_texcoord0.xy);

Precision qualifiers

Explicit precision (lowp, mediump, highp) is optional in #version 140 — the pipeline sets precision automatically for platforms that need it. However, you may still use them for clarity or to match existing code style in the project. Follow the convention of surrounding files.

Editor-specific code (EDITOR define)

When shaders are rendered in the Defold Editor viewport, the preprocessor define EDITOR is available. Use #ifdef EDITOR to write code that behaves differently in the editor vs the game:

glsl
#ifdef EDITOR
    // Simplified rendering for editor preview
    out_fragColor = texture(texture_sampler, var_texcoord0.xy);
#else
    // Full rendering with effects for the game
    out_fragColor = apply_effects(texture(texture_sampler, var_texcoord0.xy));
#endif

Common use cases:

  • Disable expensive effects (RGSS, post-processing) in editor for performance
  • Show debug/fallback visuals for materials that don't preview well
  • Skip features that depend on runtime-only data (e.g., skinning)

Including snippets (#include)

Shader files can include .glsl snippets using #include with project-relative or file-relative paths:

glsl
// Absolute (project-relative) path
#include "/main/my-snippet.glsl"

// Relative to current file
#include "my-snippet.glsl"
#include "../shared/utils.glsl"

Rules:

  • Only .glsl files can be included
  • Paths must be within the project (or library dependencies)
  • Absolute paths start with /
  • #include cannot be used inline within a statement

Header guards

Use header guards in .glsl snippets to prevent double-inclusion:

glsl
#ifndef MY_SNIPPET_GLSL
#define MY_SNIPPET_GLSL

// ... snippet code ...

#endif // MY_SNIPPET_GLSL

Relationship with materials

Shaders and materials (.material) are tightly coupled. The material file defines what data the shader receives. For material file editing, use the defold-proto-file-editing skill (reference: references/material.md).

Constants (uniforms)

Constants declared in the material's vertex_constants / fragment_constants become uniform variables in the shader. Place them inside the uniform block:

Material constant typeShader uniform typeDescription
CONSTANT_TYPE_VIEWPROJmat4Combined view × projection matrix
CONSTANT_TYPE_WORLDmat4World transform matrix
CONSTANT_TYPE_VIEWmat4View (camera) matrix
CONSTANT_TYPE_PROJECTIONmat4Projection matrix
CONSTANT_TYPE_WORLDVIEWmat4World × view matrix
CONSTANT_TYPE_WORLDVIEWPROJmat4World × view × projection matrix
CONSTANT_TYPE_NORMALmat4Normal matrix — transpose(inverse(view * world)). Produces view-space normals, not world-space.
CONSTANT_TYPE_USERvec4Custom data, mutable via go.set() / go.animate()
CONSTANT_TYPE_USER_MATRIX4mat4Custom matrix data, mutable via go.set()

The name in the material must match the variable name in the uniform block.

Samplers

Samplers declared in the material's samplers section become sampler2D uniforms. The sampler name in the material must match the uniform name in the shader:

glsl
uniform mediump sampler2D texture_sampler;  // Matches samplers { name: "texture_sampler" ... }

For sprites, tilemaps, GUI, and particles — the first sampler2D is automatically bound to the component's image.

Vertex attributes

Attributes declared in the material's attributes section (or default attributes provided by the engine) become in variables in the vertex shader.

Default attributes by component type:

ComponentAttributes
Spriteposition, texcoord0
Tilemapposition, texcoord0
GUI nodeposition, texcoord0, color
ParticleFXposition, texcoord0, color
Modelposition, texcoord0, normal
Fontposition, texcoord0, face_color, outline_color, shadow_color

Vertex space

The material's vertex_space setting affects how position data arrives:

  • VERTEX_SPACE_WORLD (default) — positions are pre-transformed to world space. Used for 2D components (sprites, tilemaps). Use view_proj (or CONSTANT_TYPE_VIEWPROJ) to go directly to screen space.
  • VERTEX_SPACE_LOCAL — positions are in local/object space. Used for 3D models. You must transform through world → view → projection in the shader.

Instancing

For instanced rendering (Model components), declare mtx_world and mtx_normal as in attributes (not uniforms):

glsl
in mediump mat4 mtx_world;
in mediump mat4 mtx_normal;

The material must have vertex_space: VERTEX_SPACE_LOCAL. These attributes are automatically configured for per-instance step function.

Normal matrix (mtx_normal) — view-space vs world-space

The built-in CONSTANT_TYPE_NORMAL computes transpose(inverse(view * world)) on the CPU. This produces normals in view-space (camera-space), not world-space.

View-space normals are fine when:

  • All lighting calculations are done in view-space
  • Camera position is implicitly at origin (0,0,0) (simplifies specular)

World-space normals are needed for:

  • Cubemap reflections, environment mapping
  • World-space lighting, world-space effects

To get world-space normals, compute the normal matrix from mtx_world in the vertex shader using the adjugate matrix trick (cheaper than full inverse() — 3 cross products instead of cofactor expansion):

glsl
// transpose(adjugate(M)) for upper-left 3x3 of mat4.
// Equivalent to transpose(inverse(M)) up to a uniform scale factor,
// which is eliminated by normalize().
mat3 adjoint(mat4 m)
{
    return mat3(
        cross(m[1].xyz, m[2].xyz),
        cross(m[2].xyz, m[0].xyz),
        cross(m[0].xyz, m[1].xyz)
    );
}

Usage in vertex shader:

glsl
var_world_normal = normalize(adjoint(mtx_world) * normal.xyz);
GoalMethod
View-space normalsUse built-in mtx_normal (CONSTANT_TYPE_NORMAL)
World-space normalsCompute normalize(adjoint(mtx_world) * normal.xyz) in shader

Key rule: Never mix coordinate spaces — if light direction is in world-space, normals must also be in world-space.

Canonical examples

Builtin reference shaders

Use .deps/builtins/materials/ as reference for standard shaders:

  • sprite.vp / sprite.fp — 2D sprite (world space, view_proj, tint)
  • model.vp / model.fp — 3D model with lighting (local space, mtx_worldview, mtx_normal, light)
  • model_instanced.vp — 3D model with instancing (mtx_world, mtx_normal as in attributes)
  • gui.vp / gui.fp — GUI nodes (world space, color attribute, premultiplied alpha)
  • particlefx.vp / particlefx.fp — Particle effects
  • tile_map.vp / tile_map.fp — Tilemaps
  • skinning.glsl — Skeletal animation include (uses #ifdef EDITOR for fallback)

GLSL include snippet (with header guards and extension)

glsl
#ifndef MY_UTILS_GLSL
#define MY_UTILS_GLSL

#ifdef GL_OES_standard_derivatives
#extension GL_OES_standard_derivatives : enable
#endif

// Utility function available on platforms that support derivatives
#if !defined(GL_ES) || __VERSION__ >= 300 || defined(GL_OES_standard_derivatives)
mediump float edge_smoothing(mediump float dist)
{
    return smoothstep(0.0, fwidth(dist), dist);
}
#else
mediump float edge_smoothing(mediump float dist)
{
    return step(0.0, dist);
}
#endif

#endif // MY_UTILS_GLSL

Workflow

Creating a new shader pair (.vp + .fp)

  1. Determine the component type (sprite, model, GUI, etc.) to know which attributes and vertex space to use.
  2. Check the corresponding .material file (or plan one) to know which constants, samplers, and attributes the shader will receive. Use the defold-proto-file-editing skill for material editing.
  3. Start both files with #version 140.
  4. In the .vp: declare in attributes, out varyings, uniform block with constants, and compute gl_Position.
  5. In the .fp: declare in varyings, out vec4 for color output, samplers, uniform block, and compute the output color.
  6. Ensure uniform names match the material's constant names exactly.
  7. Ensure sampler names match the material's sampler names exactly.

Creating a GLSL include snippet

  1. Create a .glsl file.
  2. Add header guards (#ifndef / #define / #endif).
  3. Add #extension directives with preprocessor guards if using features not available on all targets.
  4. Write reusable functions or constants.

Editing an existing shader

  1. Read the current shader file and its corresponding .material file.
  2. Modify only the requested parts.
  3. Keep the existing code style (precision qualifiers, naming, spacing).
  4. Ensure any new uniforms are also added to the material file (use defold-proto-file-editing skill).
  5. Ensure any removed uniforms are also removed from the material file.

Câu hỏi thường gặp

Kỹ năng AI Defold Shaders Editing làm được gì?

Tạo và chỉnh sửa tệp shader Defold (.vp, .fp, .glsl). Dùng khi được yêu cầu tạo, sửa đổi hoặc cấu hình shader đỉnh, shader mảnh hoặc tệp include GLSL của Defold.

Vì sao nên dùng Defold Shaders Editing trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Defold Shaders Editing là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Defold Shaders Editing trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/indiesoftby/defold-agent-config/tree/main/.agents/skills/defold-shaders-editing. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Defold Shaders Editing?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Defold Shaders Editing với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Defold Shaders Editing với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Defold Shaders Editing có miễn phí không?

Kỹ năng này được indiesoftby phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇