tools.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. Tools
  2. =====
  3. Geometry Compiler (geometryc)
  4. -----------------------------
  5. Converts Wavefront .obj, or glTF 2.0 mesh files to a format which is optimized for use with bgfx.
  6. Usage::
  7. geometryc -f <in> -o <out>
  8. Supported input file formats:
  9. ====== ============================
  10. Format Description
  11. ====== ============================
  12. .obj Wavefront
  13. .gltf glTF 2.0
  14. .glb glTF 2.0
  15. ====== ============================
  16. Options:
  17. -h, --help Display this help and exit.
  18. -v, --version Output version information and exit.
  19. -f <file path> Input's file path.
  20. -o <file path> Output's file path.
  21. -s, --scale <num> Scale factor.
  22. --ccw Front face is counter-clockwise winding order.
  23. --flipv Flip texture coordinate V.
  24. --obb <num> | Number of steps for calculating oriented bounding box.
  25. | Defaults to 17.
  26. | Less steps = less precise OBB.
  27. | More steps = slower calculation.
  28. --packnormal <num> | Normal packing.
  29. | 0 - unpacked 12 bytes. (default)
  30. | 1 - packed 4 bytes.
  31. --packuv <num> | Texture coordinate packing.
  32. | 0 - unpacked 8 bytes. (default)
  33. | 1 - packed 4 bytes.
  34. --tangent Calculate tangent vectors. (packing mode is the same as normal)
  35. --barycentric Adds barycentric vertex attribute. (Packed in bgfx::Attrib::Color1)
  36. -c, --compress Compress indices.
  37. --[l/r]h-up+[y/z] Coordinate system. Defaults to '--lh-up+y' — Left-Handed +Y is up.
  38. Geometry Viewer (geometryv)
  39. ---------------------------
  40. A geometry viewer.
  41. Shader Compiler (shaderc)
  42. -------------------------
  43. Shader Compiler is used to compile bgfx's cross-platform shader language, which based on GLSL.
  44. It uses an ANSI C pre-processor to transform the GLSL-like language into HLSL.
  45. This method has certain drawbacks,
  46. but overall it's simple and allows for quick authoring of cross-platform shaders.
  47. Some differences between bgfx's shaderc flavor of GLSL and vanilla GLSL:
  48. - ``bool/int`` uniforms are not allowed; all uniforms must be ``float``.
  49. - Attributes and varyings can only be accessed from ``main()``.
  50. - ``SAMPLER2D/3D/CUBE/etc.`` macros replace the ``sampler2D/3D/Cube/etc.`` tokens.
  51. - ``vec2/3/4_splat(<value>)`` replaces the ``vec2/3/4(<value>)`` constructor.
  52. ``vec2/3/4`` constructors with multiple values are still valid.
  53. - ``mtxFromCols/mtxFromRows`` must be used for constructing matrices.
  54. - ``mul(x, y)`` must be used when multiplying vectors with matrices.
  55. - A ``varying.def.sc`` file must be used to define input/output semantics and types,
  56. instead of using ``attribute/in`` and ``varying/in/out``.
  57. This file cannot include comments, and typically only one is necessary.
  58. - ``$input/$output`` tokens corresponding to inputs and outputs defined in
  59. ``varying.def.sc`` must be used at the beginning of shader.
  60. Defines
  61. ~~~~~~~
  62. Shader Compiler also has the following default defines (default value is set to 0):
  63. =============================== ======================= ========================================
  64. Define symbol Description Option
  65. =============================== ======================= ========================================
  66. ``BX_PLATFORM_ANDROID`` Android platform ``--platform android``
  67. ``BX_PLATFORM_EMSCRIPTEN`` Emscripten platform ``--platform asm.js``
  68. ``BX_PLATFORM_IOS`` iOS platform ``--platform ios``
  69. ``BX_PLATFORM_LINUX`` Linux platform ``--platform linux``
  70. ``BX_PLATFORM_OSX`` macOS platform ``--platform osx``
  71. ``BX_PLATFORM_PS4`` PlayStation 4 platform ``--platform orbis``
  72. ``BX_PLATFORM_WINDOWS`` Windows platform ``--platform windows``
  73. ``BX_PLATFORM_XBOXONE`` *Not implemented*
  74. ------------------------------- ----------------------- ----------------------------------------
  75. ``BGFX_SHADER_LANGUAGE_GLSL`` GLSL profile ``-p NNN`` and ``-p NNN_es``
  76. ``BGFX_SHADER_LANGUAGE_HLSL`` HLSL profile ``-p s_N_N``
  77. ``BGFX_SHADER_LANGUAGE_METAL`` Metal profile ``-p metal``
  78. ``BGFX_SHADER_LANGUAGE_PSSL`` PSSL profile ``-p pssl``
  79. ``BGFX_SHADER_LANGUAGE_SPIRV`` SPIR-V profile ``-p spirv`` and ``-p spirvNN-NN``
  80. ------------------------------- ----------------------- ----------------------------------------
  81. ``BGFX_SHADER_TYPE_COMPUTE`` Compute shader ``--type compute`` or ``--type c``
  82. ``BGFX_SHADER_TYPE_FRAGMENT`` Fragment shader ``--type fragment`` or ``--type f``
  83. ``BGFX_SHADER_TYPE_VERTEX`` Vertex shader ``--type vertex`` or ``--type v``
  84. =============================== ======================= ========================================
  85. Predefined Uniforms
  86. ~~~~~~~~~~~~~~~~~~~
  87. ======= =================== ====================================================================
  88. Type Name Description
  89. ======= =================== ====================================================================
  90. vec4 u_viewRect | View rectangle.
  91. | ``u_viewRect.xy`` - xy offset in screen space.
  92. | ``u_viewRect.zw`` - width/height size in screen space.
  93. vec4 u_viewTexel | Screen-to-texel space conversion.
  94. | ``u_viewTexel.xy = 1.0/u_viewRect.zw;``
  95. mat4 u_view Transform world-to-view space.
  96. mat4 u_invView Transform view-to-world space.
  97. mat4 u_proj Transform view-to-clip space.
  98. mat4 u_invProj Transform clip-to-view space.
  99. mat4 u_viewProj Transform world-to-clip space.
  100. mat4 u_invViewProj Transform clip-to-world space.
  101. mat4[N] u_model Transform local-to-world space array.
  102. mat4 u_modelView Transform local-to-view space.
  103. mat4 u_invModelView Transform view-to-local space.
  104. mat4 u_modelViewProj Transform local-to-clip space.
  105. float u_alphaRef | The reference value to which incoming alpha
  106. | values are compared.
  107. ======= =================== ====================================================================
  108. For more info, see the `shader helper macros
  109. <https://github.com/bkaradzic/bgfx/blob/master/src/bgfx_shader.sh>`__.
  110. Vertex Shader Attributes
  111. ~~~~~~~~~~~~~~~~~~~~~~~~
  112. ``$input`` tokens for vertex shader can be only following:
  113. ================ ===================
  114. Attribute bgfx::Attrib::Enum
  115. ================ ===================
  116. a_position Position
  117. a_normal Normal
  118. a_tangent Tangent
  119. a_bitangent Bitangent
  120. a_color0 Color0
  121. a_color1 Color1
  122. a_color2 Color2
  123. a_color3 Color3
  124. a_indices Indices
  125. a_weight Weight
  126. a_texcoord0 TexCoord0
  127. a_texcoord1 TexCoord1
  128. a_texcoord2 TexCoord2
  129. a_texcoord3 TexCoord3
  130. a_texcoord4 TexCoord4
  131. a_texcoord5 TexCoord5
  132. a_texcoord6 TexCoord6
  133. a_texcoord7 TexCoord7
  134. ================ ===================
  135. In ``varying.def.sc``, instance buffer input must use ``i_dataN`` as identifier where ``N`` is the index
  136. of the attribute in the buffer. Type must be ``vec4``, and the stride must be multiple of 16.
  137. The semantic must be ``TEXCOORDN`` with a decreasing index starting from ``TEXCOORD7``.
  138. ::
  139. vec4 i_data0 : TEXCOORD7;
  140. vec4 i_data1 : TEXCOORD6;
  141. vec4 i_data2 : TEXCOORD5;
  142. vec4 i_data3 : TEXCOORD4;
  143. vec4 i_data4 : TEXCOORD3;
  144. Options
  145. ~~~~~~~
  146. Options:
  147. -h, --help Display this help and exit.
  148. -v, --version Output version information and exit.
  149. -f <file path> Input's file path.
  150. -i <include path> Include path. (for multiple paths use -i multiple times)
  151. -o <file path> Output's file path.
  152. --bin2c <array name> Generate C header file. If array name is not specified base file name will be used as name.
  153. --depends Generate makefile style depends file.
  154. --platform <platform> Target platform.
  155. -p, --profile <profile> Shader model.
  156. Defaults to GLSL.
  157. --preprocess Only pre-process.
  158. --define <defines> Add defines to preprocessor. (semicolon separated)
  159. --raw Do not process shader. No preprocessor, and no glsl-optimizer. (GLSL only)
  160. --type <type> Shader type.
  161. Can be 'vertex', 'fragment, or 'compute'.
  162. --varyingdef <file path> A varying.def.sc's file path.
  163. --verbose Be verbose.
  164. (Vulkan, DirectX and Metal):
  165. --debug Debug information.
  166. (DirectX only):
  167. --disasm Disassemble a compiled shader.
  168. -O <level> Set optimization level.
  169. Can be 0–3.
  170. --Werror Treat warnings as errors.
  171. Building shaders
  172. ~~~~~~~~~~~~~~~~
  173. Shaders can be compiled for all renderers by using the ``shaderc`` tool.
  174. A Makefile to simplify building shaders is provided in the `bgfx examples
  175. <https://github.com/bkaradzic/bgfx/tree/master/examples>`__.
  176. D3D shaders can be only compiled on Windows.
  177. Texture Compiler (texturec)
  178. ---------------------------
  179. Convert PNG, TGA, DDS, KTX, and PVR textures into bgfx-supported texture formats.
  180. Usage::
  181. texturec -f <in> -o <out> [-t <texture format>]
  182. Supported file formats:
  183. ====== ================ ============================
  184. Format In/Out Description
  185. ====== ================ ============================
  186. .bmp (input) Windows Bitmap.
  187. .dds (input, output) Direct Draw Surface.
  188. .exr (input, output) OpenEXR.
  189. .gif (input) Graphics Interchange Format.
  190. .jpg (input) JPEG Interchange Format.
  191. .hdr (input, output) Radiance RGBE.
  192. .ktx (input, output) Khronos Texture.
  193. .png (input, output) Portable Network Graphics.
  194. .psd (input) Photoshop Document.
  195. .pvr (input) PowerVR.
  196. .tga (input) Truevision TGA.
  197. ====== ================ ============================
  198. Options:
  199. Options:
  200. -h, --help Help.
  201. -v, --version Version information only.
  202. -f <file path> Input file path.
  203. -o <file path> Output file path.
  204. -t <format> Output format type (BC1/2/3/4/5, ETC1, PVR14, etc.).
  205. -q <quality> Encoding quality (default, fastest, highest).
  206. -m, --mips Generate mip-maps.
  207. --mipskip <N> Skip <N> number of mips.
  208. -n, --normalmap Input texture is normal map. (Implies --linear)
  209. --equirect Input texture is equirectangular projection of cubemap.
  210. --strip Input texture is horizontal or vertical strip of cubemap.
  211. --sdf Compute SDF texture.
  212. --ref <alpha> Alpha reference value.
  213. --iqa Image Quality Assessment
  214. --pma Premultiply alpha into RGB channel.
  215. --linear Input and output texture is linear color space (gamma correction won't be applied).
  216. --max <max size> Maximum width/height (image will be scaled down and
  217. aspect ratio will be preserved)
  218. --radiance <model> Radiance cubemap filter. (Lighting model: Phong, PhongBrdf, Blinn, BlinnBrdf, GGX)
  219. --as <extension> Save as.
  220. --formats List all supported formats.
  221. --validate **DEBUG** Validate that output image produced matches after loading.
  222. Texture Viewer (texturev)
  223. -------------------------
  224. A texture viewer.