2
0

tools.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <!DOCTYPE html>
  2. <html class="writer-html5" lang="en" data-content_root="./">
  3. <head>
  4. <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Tools &mdash; bgfx 1.136.9083 documentation</title>
  7. <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
  8. <link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />
  9. <script src="_static/jquery.js?v=5d32c60e"></script>
  10. <script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
  11. <script src="_static/documentation_options.js?v=f601d78d"></script>
  12. <script src="_static/doctools.js?v=9bcbadda"></script>
  13. <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
  14. <script src="_static/js/theme.js"></script>
  15. <link rel="index" title="Index" href="genindex.html" />
  16. <link rel="search" title="Search" href="search.html" />
  17. <link rel="next" title="Internals" href="internals.html" />
  18. <link rel="prev" title="API Reference" href="bgfx.html" />
  19. </head>
  20. <body class="wy-body-for-nav">
  21. <div class="wy-grid-for-nav">
  22. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  23. <div class="wy-side-scroll">
  24. <div class="wy-side-nav-search" >
  25. <a href="index.html" class="icon icon-home">
  26. bgfx
  27. </a>
  28. <div role="search">
  29. <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
  30. <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
  31. <input type="hidden" name="check_keywords" value="yes" />
  32. <input type="hidden" name="area" value="default" />
  33. </form>
  34. </div>
  35. </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
  36. <ul class="current">
  37. <li class="toctree-l1"><a class="reference internal" href="overview.html">Overview</a></li>
  38. <li class="toctree-l1"><a class="reference internal" href="build.html">Building</a></li>
  39. <li class="toctree-l1"><a class="reference internal" href="examples.html">Examples</a></li>
  40. <li class="toctree-l1"><a class="reference internal" href="bgfx.html">API Reference</a></li>
  41. <li class="toctree-l1 current"><a class="current reference internal" href="#">Tools</a><ul>
  42. <li class="toctree-l2"><a class="reference internal" href="#geometry-compiler-geometryc">Geometry Compiler (geometryc)</a></li>
  43. <li class="toctree-l2"><a class="reference internal" href="#geometry-viewer-geometryv">Geometry Viewer (geometryv)</a></li>
  44. <li class="toctree-l2"><a class="reference internal" href="#shader-compiler-shaderc">Shader Compiler (shaderc)</a><ul>
  45. <li class="toctree-l3"><a class="reference internal" href="#defines">Defines</a></li>
  46. <li class="toctree-l3"><a class="reference internal" href="#predefined-uniforms">Predefined Uniforms</a></li>
  47. <li class="toctree-l3"><a class="reference internal" href="#vertex-shader-attributes">Vertex Shader Attributes</a></li>
  48. <li class="toctree-l3"><a class="reference internal" href="#options">Options</a></li>
  49. <li class="toctree-l3"><a class="reference internal" href="#building-shaders">Building shaders</a></li>
  50. </ul>
  51. </li>
  52. <li class="toctree-l2"><a class="reference internal" href="#texture-compiler-texturec">Texture Compiler (texturec)</a></li>
  53. <li class="toctree-l2"><a class="reference internal" href="#texture-viewer-texturev">Texture Viewer (texturev)</a></li>
  54. </ul>
  55. </li>
  56. <li class="toctree-l1"><a class="reference internal" href="internals.html">Internals</a></li>
  57. <li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
  58. </ul>
  59. </div>
  60. </div>
  61. </nav>
  62. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
  63. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  64. <a href="index.html">bgfx</a>
  65. </nav>
  66. <div class="wy-nav-content">
  67. <div class="rst-content">
  68. <div role="navigation" aria-label="Page navigation">
  69. <ul class="wy-breadcrumbs">
  70. <li><a href="index.html" class="icon icon-home" aria-label="Home"></a></li>
  71. <li class="breadcrumb-item active">Tools</li>
  72. <li class="wy-breadcrumbs-aside">
  73. </li>
  74. </ul>
  75. <hr/>
  76. </div>
  77. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  78. <div itemprop="articleBody">
  79. <section id="tools">
  80. <h1>Tools<a class="headerlink" href="#tools" title="Link to this heading"></a></h1>
  81. <section id="geometry-compiler-geometryc">
  82. <h2>Geometry Compiler (geometryc)<a class="headerlink" href="#geometry-compiler-geometryc" title="Link to this heading"></a></h2>
  83. <p>Converts Wavefront .obj, or glTF 2.0 mesh files to a format which is optimized for use with bgfx.</p>
  84. <p>Usage:</p>
  85. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">geometryc</span> <span class="o">-</span><span class="n">f</span> <span class="o">&lt;</span><span class="ow">in</span><span class="o">&gt;</span> <span class="o">-</span><span class="n">o</span> <span class="o">&lt;</span><span class="n">out</span><span class="o">&gt;</span>
  86. </pre></div>
  87. </div>
  88. <p>Supported input file formats:</p>
  89. <blockquote>
  90. <div><table class="docutils align-default">
  91. <thead>
  92. <tr class="row-odd"><th class="head"><p>Format</p></th>
  93. <th class="head"><p>Description</p></th>
  94. </tr>
  95. </thead>
  96. <tbody>
  97. <tr class="row-even"><td><p>.obj</p></td>
  98. <td><p>Wavefront</p></td>
  99. </tr>
  100. <tr class="row-odd"><td><p>.gltf</p></td>
  101. <td><p>glTF 2.0</p></td>
  102. </tr>
  103. <tr class="row-even"><td><p>.glb</p></td>
  104. <td><p>glTF 2.0</p></td>
  105. </tr>
  106. </tbody>
  107. </table>
  108. </div></blockquote>
  109. <p>Options:</p>
  110. <blockquote>
  111. <div><dl class="option-list">
  112. <dt><kbd><span class="option">-h</span>, <span class="option">--help</span></kbd></dt>
  113. <dd><p>Display this help and exit.</p>
  114. </dd>
  115. <dt><kbd><span class="option">-v</span>, <span class="option">--version</span></kbd></dt>
  116. <dd><p>Output version information and exit.</p>
  117. </dd>
  118. <dt><kbd><span class="option">-f <var>&lt;file path&gt;</var></span></kbd></dt>
  119. <dd><p>Input’s file path.</p>
  120. </dd>
  121. <dt><kbd><span class="option">-o <var>&lt;file path&gt;</var></span></kbd></dt>
  122. <dd><p>Output’s file path.</p>
  123. </dd>
  124. <dt><kbd><span class="option">-s</span>, <span class="option">--scale <var>&lt;num&gt;</var></span></kbd></dt>
  125. <dd><p>Scale factor.</p>
  126. <dl class="option-list">
  127. <dt><kbd><span class="option">--ccw</span></kbd></dt>
  128. <dd><p>Front face is counter-clockwise winding order.</p>
  129. </dd>
  130. <dt><kbd><span class="option">--flipv</span></kbd></dt>
  131. <dd><p>Flip texture coordinate V.</p>
  132. </dd>
  133. <dt><kbd><span class="option">--obb <var>&lt;num&gt;</var></span></kbd></dt>
  134. <dd><div class="line-block">
  135. <div class="line">Number of steps for calculating oriented bounding box.</div>
  136. <div class="line">Defaults to 17.</div>
  137. <div class="line">Less steps = less precise OBB.</div>
  138. <div class="line">More steps = slower calculation.</div>
  139. </div>
  140. </dd>
  141. <dt><kbd><span class="option">--packnormal <var>&lt;num&gt;</var></span></kbd></dt>
  142. <dd><div class="line-block">
  143. <div class="line">Normal packing.</div>
  144. <div class="line">0 - unpacked 12 bytes. (default)</div>
  145. <div class="line">1 - packed 4 bytes.</div>
  146. </div>
  147. </dd>
  148. <dt><kbd><span class="option">--packuv <var>&lt;num&gt;</var></span></kbd></dt>
  149. <dd><div class="line-block">
  150. <div class="line">Texture coordinate packing.</div>
  151. <div class="line">0 - unpacked 8 bytes. (default)</div>
  152. <div class="line">1 - packed 4 bytes.</div>
  153. </div>
  154. </dd>
  155. <dt><kbd><span class="option">--tangent</span></kbd></dt>
  156. <dd><p>Calculate tangent vectors. (packing mode is the same as normal)</p>
  157. </dd>
  158. <dt><kbd><span class="option">--barycentric</span></kbd></dt>
  159. <dd><p>Adds barycentric vertex attribute. (Packed in bgfx::Attrib::Color1)</p>
  160. </dd>
  161. </dl>
  162. </dd>
  163. <dt><kbd><span class="option">-c</span>, <span class="option">--compress</span></kbd></dt>
  164. <dd><p>Compress indices.</p>
  165. <p>–[l/r]h-up+[y/z] Coordinate system. Defaults to ‘–lh-up+y’ — Left-Handed +Y is up.</p>
  166. </dd>
  167. </dl>
  168. </div></blockquote>
  169. </section>
  170. <section id="geometry-viewer-geometryv">
  171. <h2>Geometry Viewer (geometryv)<a class="headerlink" href="#geometry-viewer-geometryv" title="Link to this heading"></a></h2>
  172. <p>A geometry viewer.</p>
  173. </section>
  174. <section id="shader-compiler-shaderc">
  175. <h2>Shader Compiler (shaderc)<a class="headerlink" href="#shader-compiler-shaderc" title="Link to this heading"></a></h2>
  176. <p>Shader Compiler is used to compile bgfx’s cross-platform shader language, which based on GLSL.
  177. It uses an ANSI C pre-processor to transform the GLSL-like language into HLSL.
  178. This method has certain drawbacks,
  179. but overall it’s simple and allows for quick authoring of cross-platform shaders.</p>
  180. <p>Some differences between bgfx’s shaderc flavor of GLSL and vanilla GLSL:</p>
  181. <ul class="simple">
  182. <li><p><code class="docutils literal notranslate"><span class="pre">bool/int</span></code> uniforms are not allowed; all uniforms must be <code class="docutils literal notranslate"><span class="pre">float</span></code>.</p></li>
  183. <li><p>Attributes and varyings can only be accessed from <code class="docutils literal notranslate"><span class="pre">main()</span></code>.</p></li>
  184. <li><p><code class="docutils literal notranslate"><span class="pre">SAMPLER2D/3D/CUBE/etc.</span></code> macros replace the <code class="docutils literal notranslate"><span class="pre">sampler2D/3D/Cube/etc.</span></code> tokens.</p></li>
  185. <li><p><code class="docutils literal notranslate"><span class="pre">vec2/3/4_splat(&lt;value&gt;)</span></code> replaces the <code class="docutils literal notranslate"><span class="pre">vec2/3/4(&lt;value&gt;)</span></code> constructor.
  186. <code class="docutils literal notranslate"><span class="pre">vec2/3/4</span></code> constructors with multiple values are still valid.</p></li>
  187. <li><p><code class="docutils literal notranslate"><span class="pre">mtxFromCols/mtxFromRows</span></code> must be used for constructing matrices.</p></li>
  188. <li><p><code class="docutils literal notranslate"><span class="pre">mul(x,</span> <span class="pre">y)</span></code> must be used when multiplying vectors with matrices.</p></li>
  189. <li><p>A <code class="docutils literal notranslate"><span class="pre">varying.def.sc</span></code> file must be used to define input/output semantics and types,
  190. instead of using <code class="docutils literal notranslate"><span class="pre">attribute/in</span></code> and <code class="docutils literal notranslate"><span class="pre">varying/in/out</span></code>.
  191. This file cannot include comments, and typically only one is necessary.</p></li>
  192. <li><p><code class="docutils literal notranslate"><span class="pre">$input/$output</span></code> tokens corresponding to inputs and outputs defined in
  193. <code class="docutils literal notranslate"><span class="pre">varying.def.sc</span></code> must be used at the beginning of shader.</p></li>
  194. </ul>
  195. <section id="defines">
  196. <h3>Defines<a class="headerlink" href="#defines" title="Link to this heading"></a></h3>
  197. <p>Shader Compiler also has the following default defines (default value is set to 0):</p>
  198. <blockquote>
  199. <div><table class="docutils align-default">
  200. <thead>
  201. <tr class="row-odd"><th class="head"><p>Define symbol</p></th>
  202. <th class="head"><p>Description</p></th>
  203. <th class="head"><p>Option</p></th>
  204. </tr>
  205. </thead>
  206. <tbody>
  207. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BX_PLATFORM_ANDROID</span></code></p></td>
  208. <td><p>Android platform</p></td>
  209. <td><p><code class="docutils literal notranslate"><span class="pre">--platform</span> <span class="pre">android</span></code></p></td>
  210. </tr>
  211. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BX_PLATFORM_EMSCRIPTEN</span></code></p></td>
  212. <td><p>Emscripten platform</p></td>
  213. <td><p><code class="docutils literal notranslate"><span class="pre">--platform</span> <span class="pre">asm.js</span></code></p></td>
  214. </tr>
  215. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BX_PLATFORM_IOS</span></code></p></td>
  216. <td><p>iOS platform</p></td>
  217. <td><p><code class="docutils literal notranslate"><span class="pre">--platform</span> <span class="pre">ios</span></code></p></td>
  218. </tr>
  219. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BX_PLATFORM_LINUX</span></code></p></td>
  220. <td><p>Linux platform</p></td>
  221. <td><p><code class="docutils literal notranslate"><span class="pre">--platform</span> <span class="pre">linux</span></code></p></td>
  222. </tr>
  223. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BX_PLATFORM_OSX</span></code></p></td>
  224. <td><p>macOS platform</p></td>
  225. <td><p><code class="docutils literal notranslate"><span class="pre">--platform</span> <span class="pre">osx</span></code></p></td>
  226. </tr>
  227. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BX_PLATFORM_PS4</span></code></p></td>
  228. <td><p>PlayStation 4 platform</p></td>
  229. <td><p><code class="docutils literal notranslate"><span class="pre">--platform</span> <span class="pre">orbis</span></code></p></td>
  230. </tr>
  231. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BX_PLATFORM_WINDOWS</span></code></p></td>
  232. <td><p>Windows platform</p></td>
  233. <td><p><code class="docutils literal notranslate"><span class="pre">--platform</span> <span class="pre">windows</span></code></p></td>
  234. </tr>
  235. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BX_PLATFORM_XBOXONE</span></code></p></td>
  236. <td><p><em>Not implemented</em></p></td>
  237. <td></td>
  238. </tr>
  239. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BGFX_SHADER_LANGUAGE_GLSL</span></code></p></td>
  240. <td><p>GLSL profile</p></td>
  241. <td><p><code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">NNN</span></code> and <code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">NNN_es</span></code></p></td>
  242. </tr>
  243. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BGFX_SHADER_LANGUAGE_HLSL</span></code></p></td>
  244. <td><p>HLSL profile</p></td>
  245. <td><p><code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">s_N_N</span></code></p></td>
  246. </tr>
  247. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BGFX_SHADER_LANGUAGE_METAL</span></code></p></td>
  248. <td><p>Metal profile</p></td>
  249. <td><p><code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">metal</span></code></p></td>
  250. </tr>
  251. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BGFX_SHADER_LANGUAGE_PSSL</span></code></p></td>
  252. <td><p>PSSL profile</p></td>
  253. <td><p><code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">pssl</span></code></p></td>
  254. </tr>
  255. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BGFX_SHADER_LANGUAGE_SPIRV</span></code></p></td>
  256. <td><p>SPIR-V profile</p></td>
  257. <td><p><code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">spirv</span></code> and <code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">spirvNN-NN</span></code></p></td>
  258. </tr>
  259. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BGFX_SHADER_TYPE_COMPUTE</span></code></p></td>
  260. <td><p>Compute shader</p></td>
  261. <td><p><code class="docutils literal notranslate"><span class="pre">--type</span> <span class="pre">compute</span></code> or <code class="docutils literal notranslate"><span class="pre">--type</span> <span class="pre">c</span></code></p></td>
  262. </tr>
  263. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">BGFX_SHADER_TYPE_FRAGMENT</span></code></p></td>
  264. <td><p>Fragment shader</p></td>
  265. <td><p><code class="docutils literal notranslate"><span class="pre">--type</span> <span class="pre">fragment</span></code> or <code class="docutils literal notranslate"><span class="pre">--type</span> <span class="pre">f</span></code></p></td>
  266. </tr>
  267. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">BGFX_SHADER_TYPE_VERTEX</span></code></p></td>
  268. <td><p>Vertex shader</p></td>
  269. <td><p><code class="docutils literal notranslate"><span class="pre">--type</span> <span class="pre">vertex</span></code> or <code class="docutils literal notranslate"><span class="pre">--type</span> <span class="pre">v</span></code></p></td>
  270. </tr>
  271. </tbody>
  272. </table>
  273. </div></blockquote>
  274. </section>
  275. <section id="predefined-uniforms">
  276. <h3>Predefined Uniforms<a class="headerlink" href="#predefined-uniforms" title="Link to this heading"></a></h3>
  277. <blockquote>
  278. <div><table class="docutils align-default">
  279. <thead>
  280. <tr class="row-odd"><th class="head"><p>Type</p></th>
  281. <th class="head"><p>Name</p></th>
  282. <th class="head"><p>Description</p></th>
  283. </tr>
  284. </thead>
  285. <tbody>
  286. <tr class="row-even"><td><p>vec4</p></td>
  287. <td><p>u_viewRect</p></td>
  288. <td><div class="line-block">
  289. <div class="line">View rectangle.</div>
  290. <div class="line"><code class="docutils literal notranslate"><span class="pre">u_viewRect.xy</span></code> - xy offset in screen space.</div>
  291. <div class="line"><code class="docutils literal notranslate"><span class="pre">u_viewRect.zw</span></code> - width/height size in screen space.</div>
  292. </div>
  293. </td>
  294. </tr>
  295. <tr class="row-odd"><td><p>vec4</p></td>
  296. <td><p>u_viewTexel</p></td>
  297. <td><div class="line-block">
  298. <div class="line">Screen-to-texel space conversion.</div>
  299. <div class="line"><code class="docutils literal notranslate"><span class="pre">u_viewTexel.xy</span> <span class="pre">=</span> <span class="pre">1.0/u_viewRect.zw;</span></code></div>
  300. </div>
  301. </td>
  302. </tr>
  303. <tr class="row-even"><td><p>mat4</p></td>
  304. <td><p>u_view</p></td>
  305. <td><p>Transform world-to-view space.</p></td>
  306. </tr>
  307. <tr class="row-odd"><td><p>mat4</p></td>
  308. <td><p>u_invView</p></td>
  309. <td><p>Transform view-to-world space.</p></td>
  310. </tr>
  311. <tr class="row-even"><td><p>mat4</p></td>
  312. <td><p>u_proj</p></td>
  313. <td><p>Transform view-to-clip space.</p></td>
  314. </tr>
  315. <tr class="row-odd"><td><p>mat4</p></td>
  316. <td><p>u_invProj</p></td>
  317. <td><p>Transform clip-to-view space.</p></td>
  318. </tr>
  319. <tr class="row-even"><td><p>mat4</p></td>
  320. <td><p>u_viewProj</p></td>
  321. <td><p>Transform world-to-clip space.</p></td>
  322. </tr>
  323. <tr class="row-odd"><td><p>mat4</p></td>
  324. <td><p>u_invViewProj</p></td>
  325. <td><p>Transform clip-to-world space.</p></td>
  326. </tr>
  327. <tr class="row-even"><td><p>mat4[N]</p></td>
  328. <td><p>u_model</p></td>
  329. <td><p>Transform local-to-world space array.</p></td>
  330. </tr>
  331. <tr class="row-odd"><td><p>mat4</p></td>
  332. <td><p>u_modelView</p></td>
  333. <td><p>Transform local-to-view space.</p></td>
  334. </tr>
  335. <tr class="row-even"><td><p>mat4</p></td>
  336. <td><p>u_invModelView</p></td>
  337. <td><p>Transform view-to-local space.</p></td>
  338. </tr>
  339. <tr class="row-odd"><td><p>mat4</p></td>
  340. <td><p>u_modelViewProj</p></td>
  341. <td><p>Transform local-to-clip space.</p></td>
  342. </tr>
  343. <tr class="row-even"><td><p>float</p></td>
  344. <td><p>u_alphaRef</p></td>
  345. <td><div class="line-block">
  346. <div class="line">The reference value to which incoming alpha</div>
  347. <div class="line">values are compared.</div>
  348. </div>
  349. </td>
  350. </tr>
  351. </tbody>
  352. </table>
  353. </div></blockquote>
  354. <p>For more info, see the <a class="reference external" href="https://github.com/bkaradzic/bgfx/blob/master/src/bgfx_shader.sh">shader helper macros</a>.</p>
  355. </section>
  356. <section id="vertex-shader-attributes">
  357. <h3>Vertex Shader Attributes<a class="headerlink" href="#vertex-shader-attributes" title="Link to this heading"></a></h3>
  358. <p><code class="docutils literal notranslate"><span class="pre">$input</span></code> tokens for vertex shader can be only following:</p>
  359. <blockquote>
  360. <div><table class="docutils align-default">
  361. <thead>
  362. <tr class="row-odd"><th class="head"><p>Attribute</p></th>
  363. <th class="head"><p>bgfx::Attrib::Enum</p></th>
  364. </tr>
  365. </thead>
  366. <tbody>
  367. <tr class="row-even"><td><p>a_position</p></td>
  368. <td><p>Position</p></td>
  369. </tr>
  370. <tr class="row-odd"><td><p>a_normal</p></td>
  371. <td><p>Normal</p></td>
  372. </tr>
  373. <tr class="row-even"><td><p>a_tangent</p></td>
  374. <td><p>Tangent</p></td>
  375. </tr>
  376. <tr class="row-odd"><td><p>a_bitangent</p></td>
  377. <td><p>Bitangent</p></td>
  378. </tr>
  379. <tr class="row-even"><td><p>a_color0</p></td>
  380. <td><p>Color0</p></td>
  381. </tr>
  382. <tr class="row-odd"><td><p>a_color1</p></td>
  383. <td><p>Color1</p></td>
  384. </tr>
  385. <tr class="row-even"><td><p>a_color2</p></td>
  386. <td><p>Color2</p></td>
  387. </tr>
  388. <tr class="row-odd"><td><p>a_color3</p></td>
  389. <td><p>Color3</p></td>
  390. </tr>
  391. <tr class="row-even"><td><p>a_indices</p></td>
  392. <td><p>Indices</p></td>
  393. </tr>
  394. <tr class="row-odd"><td><p>a_weight</p></td>
  395. <td><p>Weight</p></td>
  396. </tr>
  397. <tr class="row-even"><td><p>a_texcoord0</p></td>
  398. <td><p>TexCoord0</p></td>
  399. </tr>
  400. <tr class="row-odd"><td><p>a_texcoord1</p></td>
  401. <td><p>TexCoord1</p></td>
  402. </tr>
  403. <tr class="row-even"><td><p>a_texcoord2</p></td>
  404. <td><p>TexCoord2</p></td>
  405. </tr>
  406. <tr class="row-odd"><td><p>a_texcoord3</p></td>
  407. <td><p>TexCoord3</p></td>
  408. </tr>
  409. <tr class="row-even"><td><p>a_texcoord4</p></td>
  410. <td><p>TexCoord4</p></td>
  411. </tr>
  412. <tr class="row-odd"><td><p>a_texcoord5</p></td>
  413. <td><p>TexCoord5</p></td>
  414. </tr>
  415. <tr class="row-even"><td><p>a_texcoord6</p></td>
  416. <td><p>TexCoord6</p></td>
  417. </tr>
  418. <tr class="row-odd"><td><p>a_texcoord7</p></td>
  419. <td><p>TexCoord7</p></td>
  420. </tr>
  421. </tbody>
  422. </table>
  423. </div></blockquote>
  424. <p>In <code class="docutils literal notranslate"><span class="pre">varying.def.sc</span></code>, instance buffer input must use <code class="docutils literal notranslate"><span class="pre">i_dataN</span></code> as identifier where <code class="docutils literal notranslate"><span class="pre">N</span></code> is the index
  425. of the attribute in the buffer. Type must be <code class="docutils literal notranslate"><span class="pre">vec4</span></code>, and the stride must be multiple of 16.
  426. The semantic must be <code class="docutils literal notranslate"><span class="pre">TEXCOORDN</span></code> with a decreasing index starting from <code class="docutils literal notranslate"><span class="pre">TEXCOORD7</span></code>.</p>
  427. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">vec4</span> <span class="n">i_data0</span> <span class="p">:</span> <span class="n">TEXCOORD7</span><span class="p">;</span>
  428. <span class="n">vec4</span> <span class="n">i_data1</span> <span class="p">:</span> <span class="n">TEXCOORD6</span><span class="p">;</span>
  429. <span class="n">vec4</span> <span class="n">i_data2</span> <span class="p">:</span> <span class="n">TEXCOORD5</span><span class="p">;</span>
  430. <span class="n">vec4</span> <span class="n">i_data3</span> <span class="p">:</span> <span class="n">TEXCOORD4</span><span class="p">;</span>
  431. <span class="n">vec4</span> <span class="n">i_data4</span> <span class="p">:</span> <span class="n">TEXCOORD3</span><span class="p">;</span>
  432. </pre></div>
  433. </div>
  434. </section>
  435. <section id="options">
  436. <h3>Options<a class="headerlink" href="#options" title="Link to this heading"></a></h3>
  437. <p>Options:</p>
  438. <blockquote>
  439. <div><dl class="option-list">
  440. <dt><kbd><span class="option">-h</span>, <span class="option">--help</span></kbd></dt>
  441. <dd><p>Display this help and exit.</p>
  442. </dd>
  443. <dt><kbd><span class="option">-v</span>, <span class="option">--version</span></kbd></dt>
  444. <dd><p>Output version information and exit.</p>
  445. </dd>
  446. <dt><kbd><span class="option">-f <var>&lt;file path&gt;</var></span></kbd></dt>
  447. <dd><p>Input’s file path.</p>
  448. </dd>
  449. <dt><kbd><span class="option">-i <var>&lt;include path&gt;</var></span></kbd></dt>
  450. <dd><p>Include path. (for multiple paths use -i multiple times)</p>
  451. </dd>
  452. <dt><kbd><span class="option">-o <var>&lt;file path&gt;</var></span></kbd></dt>
  453. <dd><p>Output’s file path.</p>
  454. </dd>
  455. <dt><kbd><span class="option">--bin2c <var>&lt;array name&gt;</var></span></kbd></dt>
  456. <dd><p>Generate C header file. If array name is not specified base file name will be used as name.</p>
  457. </dd>
  458. <dt><kbd><span class="option">--depends</span></kbd></dt>
  459. <dd><p>Generate makefile style depends file.</p>
  460. </dd>
  461. <dt><kbd><span class="option">--platform <var>&lt;platform&gt;</var></span></kbd></dt>
  462. <dd><p>Target platform.</p>
  463. </dd>
  464. <dt><kbd><span class="option">-p</span>, <span class="option">--profile <var>&lt;profile&gt;</var></span></kbd></dt>
  465. <dd><p>Shader model.
  466. Defaults to GLSL.</p>
  467. </dd>
  468. <dt><kbd><span class="option">--preprocess</span></kbd></dt>
  469. <dd><p>Only pre-process.</p>
  470. </dd>
  471. <dt><kbd><span class="option">--define <var>&lt;defines&gt;</var></span></kbd></dt>
  472. <dd><p>Add defines to preprocessor. (semicolon separated)</p>
  473. </dd>
  474. <dt><kbd><span class="option">--raw</span></kbd></dt>
  475. <dd><p>Do not process shader. No preprocessor, and no glsl-optimizer. (GLSL only)</p>
  476. </dd>
  477. <dt><kbd><span class="option">--type <var>&lt;type&gt;</var></span></kbd></dt>
  478. <dd><p>Shader type.
  479. Can be ‘vertex’, ‘fragment, or ‘compute’.</p>
  480. </dd>
  481. <dt><kbd><span class="option">--varyingdef <var>&lt;file path&gt;</var></span></kbd></dt>
  482. <dd><p>A varying.def.sc’s file path.</p>
  483. </dd>
  484. <dt><kbd><span class="option">--verbose</span></kbd></dt>
  485. <dd><p>Be verbose.</p>
  486. </dd>
  487. </dl>
  488. </div></blockquote>
  489. <p>(Vulkan, DirectX and Metal):</p>
  490. <blockquote>
  491. <div><dl class="option-list">
  492. <dt><kbd><span class="option">--debug</span></kbd></dt>
  493. <dd><p>Debug information.</p>
  494. </dd>
  495. </dl>
  496. </div></blockquote>
  497. <p>(DirectX only):</p>
  498. <blockquote>
  499. <div><dl class="option-list">
  500. <dt><kbd><span class="option">--disasm</span></kbd></dt>
  501. <dd><p>Disassemble a compiled shader.</p>
  502. </dd>
  503. <dt><kbd><span class="option">-O <var>&lt;level&gt;</var></span></kbd></dt>
  504. <dd><p>Set optimization level.
  505. Can be 0–3.</p>
  506. </dd>
  507. <dt><kbd><span class="option">--Werror</span></kbd></dt>
  508. <dd><p>Treat warnings as errors.</p>
  509. </dd>
  510. </dl>
  511. </div></blockquote>
  512. </section>
  513. <section id="building-shaders">
  514. <h3>Building shaders<a class="headerlink" href="#building-shaders" title="Link to this heading"></a></h3>
  515. <p>Shaders can be compiled for all renderers by using the <code class="docutils literal notranslate"><span class="pre">shaderc</span></code> tool.
  516. A Makefile to simplify building shaders is provided in the <a class="reference external" href="https://github.com/bkaradzic/bgfx/tree/master/examples">bgfx examples</a>.
  517. D3D shaders can be only compiled on Windows.</p>
  518. </section>
  519. </section>
  520. <section id="texture-compiler-texturec">
  521. <h2>Texture Compiler (texturec)<a class="headerlink" href="#texture-compiler-texturec" title="Link to this heading"></a></h2>
  522. <p>Convert PNG, TGA, DDS, KTX, and PVR textures into bgfx-supported texture formats.</p>
  523. <p>Usage:</p>
  524. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">texturec</span> <span class="o">-</span><span class="n">f</span> <span class="o">&lt;</span><span class="ow">in</span><span class="o">&gt;</span> <span class="o">-</span><span class="n">o</span> <span class="o">&lt;</span><span class="n">out</span><span class="o">&gt;</span> <span class="p">[</span><span class="o">-</span><span class="n">t</span> <span class="o">&lt;</span><span class="n">texture</span> <span class="nb">format</span><span class="o">&gt;</span><span class="p">]</span>
  525. </pre></div>
  526. </div>
  527. <p>Supported file formats:</p>
  528. <blockquote>
  529. <div><table class="docutils align-default">
  530. <thead>
  531. <tr class="row-odd"><th class="head"><p>Format</p></th>
  532. <th class="head"><p>In/Out</p></th>
  533. <th class="head"><p>Description</p></th>
  534. </tr>
  535. </thead>
  536. <tbody>
  537. <tr class="row-even"><td><p>.bmp</p></td>
  538. <td><p>(input)</p></td>
  539. <td><p>Windows Bitmap.</p></td>
  540. </tr>
  541. <tr class="row-odd"><td><p>.dds</p></td>
  542. <td><p>(input, output)</p></td>
  543. <td><p>Direct Draw Surface.</p></td>
  544. </tr>
  545. <tr class="row-even"><td><p>.exr</p></td>
  546. <td><p>(input, output)</p></td>
  547. <td><p>OpenEXR.</p></td>
  548. </tr>
  549. <tr class="row-odd"><td><p>.gif</p></td>
  550. <td><p>(input)</p></td>
  551. <td><p>Graphics Interchange Format.</p></td>
  552. </tr>
  553. <tr class="row-even"><td><p>.jpg</p></td>
  554. <td><p>(input)</p></td>
  555. <td><p>JPEG Interchange Format.</p></td>
  556. </tr>
  557. <tr class="row-odd"><td><p>.hdr</p></td>
  558. <td><p>(input, output)</p></td>
  559. <td><p>Radiance RGBE.</p></td>
  560. </tr>
  561. <tr class="row-even"><td><p>.ktx</p></td>
  562. <td><p>(input, output)</p></td>
  563. <td><p>Khronos Texture.</p></td>
  564. </tr>
  565. <tr class="row-odd"><td><p>.png</p></td>
  566. <td><p>(input, output)</p></td>
  567. <td><p>Portable Network Graphics.</p></td>
  568. </tr>
  569. <tr class="row-even"><td><p>.psd</p></td>
  570. <td><p>(input)</p></td>
  571. <td><p>Photoshop Document.</p></td>
  572. </tr>
  573. <tr class="row-odd"><td><p>.pvr</p></td>
  574. <td><p>(input)</p></td>
  575. <td><p>PowerVR.</p></td>
  576. </tr>
  577. <tr class="row-even"><td><p>.tga</p></td>
  578. <td><p>(input)</p></td>
  579. <td><p>Truevision TGA.</p></td>
  580. </tr>
  581. </tbody>
  582. </table>
  583. </div></blockquote>
  584. <p>Options:</p>
  585. <dl>
  586. <dt>Options:</dt><dd><dl class="option-list">
  587. <dt><kbd><span class="option">-h</span>, <span class="option">--help</span></kbd></dt>
  588. <dd><p>Help.</p>
  589. </dd>
  590. <dt><kbd><span class="option">-v</span>, <span class="option">--version</span></kbd></dt>
  591. <dd><p>Version information only.</p>
  592. </dd>
  593. <dt><kbd><span class="option">-f <var>&lt;file path&gt;</var></span></kbd></dt>
  594. <dd><p>Input file path.</p>
  595. </dd>
  596. <dt><kbd><span class="option">-o <var>&lt;file path&gt;</var></span></kbd></dt>
  597. <dd><p>Output file path.</p>
  598. </dd>
  599. <dt><kbd><span class="option">-t <var>&lt;format&gt;</var></span></kbd></dt>
  600. <dd><p>Output format type (BC1/2/3/4/5, ETC1, PVR14, etc.).</p>
  601. </dd>
  602. <dt><kbd><span class="option">-q <var>&lt;quality&gt;</var></span></kbd></dt>
  603. <dd><p>Encoding quality (default, fastest, highest).</p>
  604. </dd>
  605. <dt><kbd><span class="option">-m</span>, <span class="option">--mips</span></kbd></dt>
  606. <dd><p>Generate mip-maps.
  607. –mipskip &lt;N&gt; Skip &lt;N&gt; number of mips.</p>
  608. </dd>
  609. <dt><kbd><span class="option">-n</span>, <span class="option">--normalmap</span></kbd></dt>
  610. <dd><p>Input texture is normal map. (Implies –linear)</p>
  611. <dl class="option-list">
  612. <dt><kbd><span class="option">--equirect</span></kbd></dt>
  613. <dd><p>Input texture is equirectangular projection of cubemap.</p>
  614. </dd>
  615. <dt><kbd><span class="option">--strip</span></kbd></dt>
  616. <dd><p>Input texture is horizontal or vertical strip of cubemap.</p>
  617. </dd>
  618. <dt><kbd><span class="option">--sdf</span></kbd></dt>
  619. <dd><p>Compute SDF texture.</p>
  620. </dd>
  621. <dt><kbd><span class="option">--ref <var>&lt;alpha&gt;</var></span></kbd></dt>
  622. <dd><p>Alpha reference value.</p>
  623. </dd>
  624. <dt><kbd><span class="option">--iqa</span></kbd></dt>
  625. <dd><p>Image Quality Assessment</p>
  626. </dd>
  627. <dt><kbd><span class="option">--pma</span></kbd></dt>
  628. <dd><p>Premultiply alpha into RGB channel.</p>
  629. </dd>
  630. <dt><kbd><span class="option">--linear</span></kbd></dt>
  631. <dd><p>Input and output texture is linear color space (gamma correction won’t be applied).</p>
  632. </dd>
  633. <dt><kbd><span class="option">--max <var>&lt;max size&gt;</var></span></kbd></dt>
  634. <dd><p>Maximum width/height (image will be scaled down and
  635. aspect ratio will be preserved)</p>
  636. </dd>
  637. <dt><kbd><span class="option">--radiance <var>&lt;model&gt;</var></span></kbd></dt>
  638. <dd><p>Radiance cubemap filter. (Lighting model: Phong, PhongBrdf, Blinn, BlinnBrdf, GGX)</p>
  639. </dd>
  640. <dt><kbd><span class="option">--as <var>&lt;extension&gt;</var></span></kbd></dt>
  641. <dd><p>Save as.</p>
  642. </dd>
  643. <dt><kbd><span class="option">--formats</span></kbd></dt>
  644. <dd><p>List all supported formats.</p>
  645. </dd>
  646. <dt><kbd><span class="option">--validate</span></kbd></dt>
  647. <dd><p><strong>DEBUG</strong> Validate that output image produced matches after loading.</p>
  648. </dd>
  649. </dl>
  650. </dd>
  651. </dl>
  652. </dd>
  653. </dl>
  654. </section>
  655. <section id="texture-viewer-texturev">
  656. <h2>Texture Viewer (texturev)<a class="headerlink" href="#texture-viewer-texturev" title="Link to this heading"></a></h2>
  657. <p>A texture viewer.</p>
  658. </section>
  659. </section>
  660. </div>
  661. </div>
  662. <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
  663. <a href="bgfx.html" class="btn btn-neutral float-left" title="API Reference" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
  664. <a href="internals.html" class="btn btn-neutral float-right" title="Internals" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
  665. </div>
  666. <hr/>
  667. <div role="contentinfo">
  668. <p>&#169; Copyright 2010-2025, Branimir Karadžić.</p>
  669. </div>
  670. </footer>
  671. </div>
  672. </div>
  673. </section>
  674. </div>
  675. <script>
  676. jQuery(function () {
  677. SphinxRtdTheme.Navigation.enable(true);
  678. });
  679. </script>
  680. </body>
  681. </html>