reference-libobs-graphics-effects.rst 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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:: typedef struct gs_effect gs_effect_t
  9. Effect object.
  10. .. type:: typedef struct gs_effect_technique gs_technique_t
  11. Technique object.
  12. .. type:: typedef 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:: bool gs_effect_loop(gs_effect_t *effect, const char *name)
  94. Helper function that automatically begins techniques/passes.
  95. :param effect: Effect object
  96. :param name: Name of the technique to execute
  97. :return: *true* to draw, *false* when complete
  98. Here is an example of how this function is typically used:
  99. .. code:: cpp
  100. for (gs_effect_loop(effect, "my_technique")) {
  101. /* perform drawing here */
  102. [...]
  103. }
  104. ---------------------
  105. .. function:: gs_eparam_t *gs_effect_get_viewproj_matrix(const gs_effect_t *effect)
  106. Gets the view/projection matrix parameter ("viewproj") of the effect.
  107. :param effect: Effect object
  108. :return: The view/projection matrix parameter of the effect
  109. ---------------------
  110. .. function:: gs_eparam_t *gs_effect_get_world_matrix(const gs_effect_t *effect)
  111. Gets the world matrix parameter ("world") of the effect.
  112. :param effect: Effect object
  113. :return: The world matrix parameter of the effect
  114. ---------------------
  115. .. function:: void gs_effect_get_param_info(const gs_eparam_t *param, struct gs_effect_param_info *info)
  116. Gets information about an effect parameter.
  117. :param param: Effect parameter
  118. :param info: Pointer to receive the data
  119. Relevant data types used with this function:
  120. .. code:: cpp
  121. enum gs_shader_param_type {
  122. GS_SHADER_PARAM_UNKNOWN,
  123. GS_SHADER_PARAM_BOOL,
  124. GS_SHADER_PARAM_FLOAT,
  125. GS_SHADER_PARAM_INT,
  126. GS_SHADER_PARAM_STRING,
  127. GS_SHADER_PARAM_VEC2,
  128. GS_SHADER_PARAM_VEC3,
  129. GS_SHADER_PARAM_VEC4,
  130. GS_SHADER_PARAM_INT2,
  131. GS_SHADER_PARAM_INT3,
  132. GS_SHADER_PARAM_INT4,
  133. GS_SHADER_PARAM_MATRIX4X4,
  134. GS_SHADER_PARAM_TEXTURE,
  135. };
  136. struct gs_effect_param_info {
  137. const char *name;
  138. enum gs_shader_param_type type;
  139. }
  140. ---------------------
  141. .. function:: void gs_effect_set_bool(gs_eparam_t *param, bool val)
  142. Sets a boolean parameter.
  143. :param param: Effect parameter
  144. :param val: Boolean value
  145. ---------------------
  146. .. function:: void gs_effect_set_float(gs_eparam_t *param, float val)
  147. Sets a floating point parameter.
  148. :param param: Effect parameter
  149. :param val: Floating point value
  150. ---------------------
  151. .. function:: void gs_effect_set_int(gs_eparam_t *param, int val)
  152. Sets a integer parameter.
  153. :param param: Effect parameter
  154. :param val: Integer value
  155. ---------------------
  156. .. function:: void gs_effect_set_matrix4(gs_eparam_t *param, const struct matrix4 *val)
  157. Sets a matrix parameter.
  158. :param param: Effect parameter
  159. :param val: Matrix
  160. ---------------------
  161. .. function:: void gs_effect_set_vec2(gs_eparam_t *param, const struct vec2 *val)
  162. Sets a 2-component vector parameter.
  163. :param param: Effect parameter
  164. :param val: Vector
  165. ---------------------
  166. .. function:: void gs_effect_set_vec3(gs_eparam_t *param, const struct vec3 *val)
  167. Sets a 3-component vector parameter.
  168. :param param: Effect parameter
  169. :param val: Vector
  170. ---------------------
  171. .. function:: void gs_effect_set_vec4(gs_eparam_t *param, const struct vec4 *val)
  172. Sets a 4-component vector parameter.
  173. :param param: Effect parameter
  174. :param val: Vector
  175. ---------------------
  176. .. function:: void gs_effect_set_color(gs_eparam_t *param, uint32_t argb)
  177. Convenience function for setting a color value via an integer value.
  178. :param param: Effect parameter
  179. :param argb: Integer color value (i.e. hex value would be
  180. 0xAARRGGBB)
  181. ---------------------
  182. .. function:: void gs_effect_set_texture(gs_eparam_t *param, gs_texture_t *val)
  183. Sets a texture parameter.
  184. :param param: Effect parameter
  185. :param val: Texture
  186. ---------------------
  187. .. function:: void gs_effect_set_val(gs_eparam_t *param, const void *val, size_t size)
  188. Sets a parameter with data manually.
  189. :param param: Effect parameter
  190. :param val: Pointer to data
  191. :param size: Size of data
  192. ---------------------
  193. .. function:: void gs_effect_set_default(gs_eparam_t *param)
  194. Sets the parameter to its default value
  195. :param: Effect parameter
  196. ---------------------
  197. .. function:: void gs_effect_set_next_sampler(gs_eparam_t *param, gs_samplerstate_t *sampler)
  198. Manually changes the sampler for an effect parameter the next time
  199. it's used.
  200. :param param: Effect parameter
  201. :param sampler: Sampler state object