1
0

reference-libobs-graphics-effects.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. Effects (Shaders)
  2. =================
  3. Effects are a single collection of related shaders. They're used for
  4. easily writing vertex and pixel shaders together all in the same file in
  5. HLSL format.
  6. .. code:: cpp
  7. #include <graphics/graphics.h>
  8. .. type:: struct gs_effect gs_effect_t
  9. Effect object.
  10. .. type:: struct gs_effect_technique gs_technique_t
  11. Technique object.
  12. .. type:: struct gs_effect_param gs_eparam_t
  13. Effect parameter object.
  14. ---------------------
  15. .. function:: gs_effect_t *gs_effect_create_from_file(const char *file, char **error_string)
  16. Creates an effect from file.
  17. :param file: Path to the effect file
  18. :param error_string: Receives a pointer to the error string, which
  19. must be freed with :c:func:`bfree()`. If
  20. *NULL*, this parameter is ignored.
  21. :return: The effect object, or *NULL* on error
  22. ---------------------
  23. .. function:: gs_effect_t *gs_effect_create(const char *effect_string, const char *filename, char **error_string)
  24. Creates an effect from a string.
  25. :param effect_String: Effect string
  26. :param error_string: Receives a pointer to the error string, which
  27. must be freed with :c:func:`bfree()`. If
  28. *NULL*, this parameter is ignored.
  29. :return: The effect object, or *NULL* on error
  30. ---------------------
  31. .. function:: void gs_effect_destroy(gs_effect_t *effect)
  32. Destroys the effect
  33. :param effect: Effect object
  34. ---------------------
  35. .. function:: gs_technique_t *gs_effect_get_technique(const gs_effect_t *effect, const char *name)
  36. Gets a technique of the effect.
  37. :param effect: Effect object
  38. :param name: Name of the technique
  39. :return: Technique object, or *NULL* if not found
  40. ---------------------
  41. .. function:: gs_technique_t *gs_effect_get_current_technique(const gs_effect_t *effect)
  42. Gets the current active technique of the effect.
  43. :param effect: Effect object
  44. :return: Technique object, or *NULL* if none currently active
  45. ---------------------
  46. .. function:: size_t gs_technique_begin(gs_technique_t *technique)
  47. Begins a technique.
  48. :param technique: Technique object
  49. :return: Number of passes this technique uses
  50. ---------------------
  51. .. function:: void gs_technique_end(gs_technique_t *technique)
  52. Ends a technique. Make sure all active passes have been ended before
  53. calling.
  54. :param technique: Technique object
  55. ---------------------
  56. .. function:: bool gs_technique_begin_pass(gs_technique_t *technique, size_t pass)
  57. Begins a pass. Automatically loads the vertex/pixel shaders
  58. associated with this pass. Draw after calling this function.
  59. :param technique: Technique object
  60. :param pass: Pass index
  61. :return: *true* if the pass is valid, *false* otherwise
  62. ---------------------
  63. .. function:: bool gs_technique_begin_pass_by_name(gs_technique_t *technique, const char *name)
  64. Begins a pass by its name if the pass has a name. Automatically
  65. loads the vertex/pixel shaders associated with this pass. Draw after
  66. calling this function.
  67. :param technique: Technique object
  68. :param name: Name of the pass
  69. :return: *true* if the pass is valid, *false* otherwise
  70. ---------------------
  71. .. function:: void gs_technique_end_pass(gs_technique_t *technique)
  72. Ends a pass.
  73. :param technique: Technique object
  74. ---------------------
  75. .. function:: size_t gs_effect_get_num_params(const gs_effect_t *effect)
  76. Gets the number of parameters associated with the effect.
  77. :param effect: Effect object
  78. :return: Number of parameters the effect has
  79. ---------------------
  80. .. function:: gs_eparam_t *gs_effect_get_param_by_idx(const gs_effect_t *effect, size_t param)
  81. Gets a parameter of an effect by its index.
  82. :param effect: Effect object
  83. :param param: Parameter index
  84. :return: The effect parameter object, or *NULL* if index
  85. invalid
  86. ---------------------
  87. .. function:: gs_eparam_t *gs_effect_get_param_by_name(const gs_effect_t *effect, const char *name)
  88. Gets parameter of an effect by its name.
  89. :param effect: Effect object
  90. :param name: Name of the parameter
  91. :return: The effect parameter object, or *NULL* if not found
  92. ---------------------
  93. .. function:: size_t gs_param_get_num_annotations(const gs_eparam_t *param)
  94. Gets the number of annotations associated with the parameter.
  95. :param param: Param object
  96. :return: Number of annotations the param has
  97. ---------------------
  98. .. function:: gs_eparam_t *gs_param_get_annotation_by_idx(const gs_eparam_t *param, size_t annotation)
  99. Gets an annotation of a param by its index.
  100. :param param: Param object
  101. :param param: Annotation index
  102. :return: The effect parameter object (annotation), or *NULL* if index
  103. invalid
  104. ---------------------
  105. .. function:: gs_eparam_t *gs_param_get_annotation_by_name(const gs_eparam_t *pardam, const char *annotation)
  106. Gets parameter of an effect by its name.
  107. :param param: Param object
  108. :param name: Name of the annotation
  109. :return: The effect parameter object (annotation), or *NULL* if not found
  110. ---------------------
  111. .. function:: bool gs_effect_loop(gs_effect_t *effect, const char *name)
  112. Helper function that automatically begins techniques/passes.
  113. :param effect: Effect object
  114. :param name: Name of the technique to execute
  115. :return: *true* to draw, *false* when complete
  116. Here is an example of how this function is typically used:
  117. .. code:: cpp
  118. for (gs_effect_loop(effect, "my_technique")) {
  119. /* perform drawing here */
  120. [...]
  121. }
  122. ---------------------
  123. .. function:: gs_eparam_t *gs_effect_get_viewproj_matrix(const gs_effect_t *effect)
  124. Gets the view/projection matrix parameter ("viewproj") of the effect.
  125. :param effect: Effect object
  126. :return: The view/projection matrix parameter of the effect
  127. ---------------------
  128. .. function:: gs_eparam_t *gs_effect_get_world_matrix(const gs_effect_t *effect)
  129. Gets the world matrix parameter ("world") of the effect.
  130. :param effect: Effect object
  131. :return: The world matrix parameter of the effect
  132. ---------------------
  133. .. function:: void gs_effect_get_param_info(const gs_eparam_t *param, struct gs_effect_param_info *info)
  134. Gets information about an effect parameter.
  135. :param param: Effect parameter
  136. :param info: Pointer to receive the data
  137. Relevant data types used with this function:
  138. .. code:: cpp
  139. enum gs_shader_param_type {
  140. GS_SHADER_PARAM_UNKNOWN,
  141. GS_SHADER_PARAM_BOOL,
  142. GS_SHADER_PARAM_FLOAT,
  143. GS_SHADER_PARAM_INT,
  144. GS_SHADER_PARAM_STRING,
  145. GS_SHADER_PARAM_VEC2,
  146. GS_SHADER_PARAM_VEC3,
  147. GS_SHADER_PARAM_VEC4,
  148. GS_SHADER_PARAM_INT2,
  149. GS_SHADER_PARAM_INT3,
  150. GS_SHADER_PARAM_INT4,
  151. GS_SHADER_PARAM_MATRIX4X4,
  152. GS_SHADER_PARAM_TEXTURE,
  153. };
  154. struct gs_effect_param_info {
  155. const char *name;
  156. enum gs_shader_param_type type;
  157. }
  158. ---------------------
  159. .. function:: void gs_effect_set_bool(gs_eparam_t *param, bool val)
  160. Sets a boolean parameter.
  161. :param param: Effect parameter
  162. :param val: Boolean value
  163. ---------------------
  164. .. function:: void gs_effect_set_float(gs_eparam_t *param, float val)
  165. Sets a floating point parameter.
  166. :param param: Effect parameter
  167. :param val: Floating point value
  168. ---------------------
  169. .. function:: void gs_effect_set_int(gs_eparam_t *param, int val)
  170. Sets a integer parameter.
  171. :param param: Effect parameter
  172. :param val: Integer value
  173. ---------------------
  174. .. function:: void gs_effect_set_matrix4(gs_eparam_t *param, const struct matrix4 *val)
  175. Sets a matrix parameter.
  176. :param param: Effect parameter
  177. :param val: Matrix
  178. ---------------------
  179. .. function:: void gs_effect_set_vec2(gs_eparam_t *param, const struct vec2 *val)
  180. Sets a 2-component vector parameter.
  181. :param param: Effect parameter
  182. :param val: Vector
  183. ---------------------
  184. .. function:: void gs_effect_set_vec3(gs_eparam_t *param, const struct vec3 *val)
  185. Sets a 3-component vector parameter.
  186. :param param: Effect parameter
  187. :param val: Vector
  188. ---------------------
  189. .. function:: void gs_effect_set_vec4(gs_eparam_t *param, const struct vec4 *val)
  190. Sets a 4-component vector parameter.
  191. :param param: Effect parameter
  192. :param val: Vector
  193. ---------------------
  194. .. function:: void gs_effect_set_color(gs_eparam_t *param, uint32_t argb)
  195. Convenience function for setting a color value via an integer value.
  196. :param param: Effect parameter
  197. :param argb: Integer color value (i.e. hex value would be
  198. 0xAARRGGBB)
  199. ---------------------
  200. .. function:: void gs_effect_set_texture(gs_eparam_t *param, gs_texture_t *val)
  201. Sets a texture parameter.
  202. :param param: Effect parameter
  203. :param val: Texture
  204. ---------------------
  205. .. function:: void gs_effect_set_texture_srgb(gs_eparam_t *param, gs_texture_t *val)
  206. Sets a texture parameter using SRGB view if available.
  207. :param param: Effect parameter
  208. :param val: Texture
  209. ---------------------
  210. .. function:: void gs_effect_set_val(gs_eparam_t *param, const void *val, size_t size)
  211. Sets a parameter with data manually.
  212. :param param: Effect parameter
  213. :param val: Pointer to data
  214. :param size: Size of data
  215. ---------------------
  216. .. function:: void gs_effect_set_default(gs_eparam_t *param)
  217. Sets the parameter to its default value
  218. :param: Effect parameter
  219. ---------------------
  220. .. function:: void gs_effect_set_next_sampler(gs_eparam_t *param, gs_samplerstate_t *sampler)
  221. Manually changes the sampler for an effect parameter the next time
  222. it's used.
  223. :param param: Effect parameter
  224. :param sampler: Sampler state object
  225. ---------------------
  226. .. function:: void *gs_effect_get_val(gs_eparam_t *param)
  227. Returns a copy of the param's current value.
  228. :param param: Effect parameter
  229. :return: A pointer to the copied byte value of the param's current value. Freed with :c:func:`bfree()`.
  230. ---------------------
  231. .. function:: void gs_effect_get_default_val(gs_eparam_t *param)
  232. Returns a copy of the param's default value.
  233. :param param: Effect parameter
  234. :return: A pointer to the copied byte value of the param's default value. Freed with :c:func:`bfree()`.
  235. ---------------------
  236. .. function:: size_t gs_effect_get_val_size(gs_eparam_t *param)
  237. Returns the size in bytes of the param's current value.
  238. :param param: Effect parameter
  239. :return: The size in bytes of the param's current value.
  240. ---------------------
  241. .. function:: size_t gs_effect_get_default_val_size(gs_eparam_t *param)
  242. Returns the size in bytes of the param's default value.
  243. :param param: Effect parameter
  244. :return: The size in bytes of the param's default value.