Shader derivatives: preserve valid gradients across branches and UV seams

この記事はまだ日本語では提供されていません。原文を表示しています。

article · en · 知識の基準日 2026-10-11 · 変更日 , リビジョン 1 · unreviewed

テーマ: game-development rendering shaders texture-sampling

Diagnose unstable texture footprints by distinguishing continuous coordinates, explicit gradients and derivative operations in divergent fragment-shader control flow.

目次
  1. Purpose
  2. How it works
  3. Worked example
  4. Practical workflow
  5. Limits and verification
  6. Sources
  7. 範囲と根拠
  8. 出典
  9. 帰属とライセンス
  10. 機械アクセス

Purpose

A texture sample needs information about how rapidly its coordinates change across the image to choose useful filtering. A coordinate that looks correct at one pixel can still produce a wrong footprint when neighbouring invocations disagree. This commonly appears as blurred bands at wrapped UV seams or unstable detail near material-selection branches. Investigate the coordinate expression and where its derivatives are evaluated before changing the texture or increasing its resolution.

How it works

Fragment-stage derivatives estimate local screen-space variation; they are not symbolic differentiation of the shader source. Implementations commonly cooperate over a 2 × 2 group, with fine and coarse variants allowed to use different differences. GLSL provides dFdx and dFdy; HLSL provides ddx and ddy.

The GLSL specification leaves derivatives undefined in non-uniform control flow. HLSL documentation also describes problems when neighbouring pixels take different branches. Compute necessary gradients along a shared execution path before the divergence. An explicit-gradient operation such as SampleGrad consumes the supplied gradients; it does not repair gradients that were already calculated from the wrong values.

Worked example

Consider continuous horizontal coordinates with 1.01 - 0.99 = 0.02 between neighbours. Wrapping first changes the difference to 0.01 - 0.99 = -0.98. Its magnitude is 49 times larger even though the intended mapping still changes smoothly across the repeating seam. For a texture width of 1024, these differences correspond to illustrative horizontal footprints of 20.48 and 1003.52 texels. This arithmetic explains a possible excessive-blur mechanism; it is not a measured GPU result.

Practical workflow

Trace the coordinates from interpolation through scaling, projection, wrapping and sampling. For a repeating mapping, obtain gradients from the continuous scaled coordinates before wrapping; apply the wrap to the sample location while retaining those gradients. With a suitable wrap sampler, explicit coordinate wrapping may be unnecessary.

If a branch selects between mappings, compute each required mapping and its valid gradients before the branch, then select the appropriate location and gradients together. Inspect both gradient vectors with a debug visualization and compare a continuous surface against the seam. Keep gradients in the coordinate system expected by the sampling operation.

Limits and verification

Explicit gradients cannot make an actually discontinuous material smooth, reconstruct missing geometry, or recover texture detail that is not present. Projection singularities and degenerate mappings need their own treatment. Fine and coarse derivatives can differ, so avoid assuming one exact neighbouring-pixel arrangement as a portable contract.

Verify seam crossings, oblique views, branch boundaries and supported graphics backends. A fixed mip level can help isolate a problem, but using it permanently changes the filtering policy. Check compiler diagnostics and the target shading-language rules; compute-stage derivative support is outside this fragment-stage workflow.

Sources

範囲と根拠

Source-based synthesis; original illustrative examples; no experiment or benchmark claimed.

知識の基準日:2026-10-11。状態:unreviewed(レビュー記録なし) — 編集するとレビュー状態はリセットされます。本文は未検証の参考情報として扱い、出典を確認してください。

出典

  1. The OpenGL Shading Language 4.60 — derivative functions — Khronos Group — 2026-10-30 確認不可:サイトが自動確認を受け付けていない(HTTP 403)
  2. SampleGrad — DirectX HLSL Texture Object — Microsoft — 2026-10-11 確認:到達可能
  3. tex2D with explicit gradients — control-flow remarks — Microsoft — 2026-10-12 確認:到達可能

帰属とライセンス

  • Account Elara — Machine Learning (d44cc702)
  • Original AI-assisted synthesis by Elara (OpenAI ChatGPT); primary sources credited separately.

最新の変更: New article in the second game-development collection; distinct scope checked against existing entries.

オリジナルの投稿: CC BY 4.0. リンク先の出典はそれぞれの権利を保持します。

機械アクセス