2
0

default.shader 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. include = ["core/shaders/common.shader"]
  2. render_states = {
  3. debug_line = {
  4. rgb_write_enable = true
  5. alpha_write_enable = true
  6. depth_write_enable = true
  7. depth_test_enable = true
  8. blend_enable = false
  9. depth_function = "lequal"
  10. cull_mode = "cw"
  11. primitive_type = "pt_lines"
  12. }
  13. debug_line_noz = {
  14. rgb_write_enable = true
  15. alpha_write_enable = true
  16. depth_write_enable = true
  17. depth_test_enable = false
  18. blend_enable = false
  19. depth_function = "lequal"
  20. cull_mode = "cw"
  21. primitive_type = "pt_lines"
  22. }
  23. gui = {
  24. rgb_write_enable = true
  25. alpha_write_enable = true
  26. depth_write_enable = true
  27. depth_test_enable = true
  28. depth_function = "lequal"
  29. blend_enable = true
  30. blend_src = "src_alpha"
  31. blend_dst = "inv_src_alpha"
  32. cull_mode = "cw"
  33. }
  34. sprite = {
  35. rgb_write_enable = true
  36. alpha_write_enable = true
  37. depth_write_enable = true
  38. depth_test_enable = true
  39. depth_function = "lequal"
  40. blend_enable = true
  41. blend_src = "src_alpha"
  42. blend_dst = "inv_src_alpha"
  43. cull_mode = "cw"
  44. }
  45. mesh = {
  46. rgb_write_enable = true
  47. alpha_write_enable = true
  48. blend_enable = false
  49. depth_write_enable = true
  50. depth_test_enable = true
  51. depth_function = "lequal"
  52. cull_mode = "ccw"
  53. }
  54. }
  55. bgfx_shaders = {
  56. debug_line = {
  57. includes = "common"
  58. varying = "
  59. vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
  60. vec3 a_position : POSITION;
  61. vec4 a_color0 : COLOR0;
  62. "
  63. vs_input_output = "
  64. $input a_position, a_color0
  65. $output v_color0
  66. "
  67. vs_code = "
  68. void main()
  69. {
  70. gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
  71. v_color0 = a_color0;
  72. }
  73. "
  74. fs_input_output = "
  75. $input v_color0
  76. "
  77. fs_code = "
  78. void main()
  79. {
  80. gl_FragColor = v_color0;
  81. }
  82. "
  83. }
  84. gui = {
  85. includes = "common"
  86. varying = "
  87. vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
  88. vec2 a_position : POSITION;
  89. vec2 a_texcoord0 : TEXCOORD0;
  90. "
  91. vs_input_output = "
  92. $input = a_position, a_texcoord0
  93. $output v_texcoord0
  94. "
  95. vs_code = "
  96. void main()
  97. {
  98. gl_Position = mul(u_modelViewProj, vec4(a_position, 0.0, 1.0));
  99. #ifdef DIFFUSE_MAP
  100. v_texcoord0 = a_texcoord0;
  101. #endif // DIFFUSE_MAP
  102. }
  103. "
  104. fs_input_output = "
  105. $input v_texcoord0
  106. "
  107. fs_code = "
  108. #ifdef DIFFUSE_MAP
  109. SAMPLER2D(u_albedo, 0);
  110. #endif // DIFFUSE_MAP
  111. uniform vec3 u_color = vec3(1, 1, 1);
  112. void main()
  113. {
  114. #ifdef DIFFUSE_MAP
  115. gl_FragColor = texture2D(u_albedo, v_texcoord0) * vec4(u_color, 1.0);
  116. #else
  117. gl_FragColor = vec4(u_color, 1.0);
  118. #endif // DIFFUSE_MAP
  119. }
  120. "
  121. }
  122. sprite = {
  123. includes = "common"
  124. varying = "
  125. vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
  126. vec2 a_position : POSITION;
  127. vec2 a_texcoord0 : TEXCOORD0;
  128. "
  129. vs_input_output = "
  130. $input = a_position, a_texcoord0
  131. $output v_texcoord0
  132. "
  133. vs_code = "
  134. void main()
  135. {
  136. gl_Position = mul(u_modelViewProj, vec4(a_position, 0.0, 1.0));
  137. v_texcoord0 = a_texcoord0;
  138. }
  139. "
  140. fs_input_output = "
  141. $input v_texcoord0
  142. "
  143. fs_code = "
  144. SAMPLER2D(u_albedo, 0);
  145. uniform vec3 u_color = vec3(1, 1, 1);
  146. void main()
  147. {
  148. gl_FragColor = texture2D(u_albedo, v_texcoord0) * vec4(u_color, 1.0);
  149. }
  150. "
  151. }
  152. mesh = {
  153. includes = "common"
  154. varying =
  155. "
  156. vec3 v_normal : NORMAL = vec3(0.0, 0.0, 0.0);
  157. vec4 v_view : TEXCOORD0 = vec4(0.0, 0.0, 0.0, 0.0);
  158. vec2 v_uv0 : TEXCOORD1 = vec2(0.0, 0.0);
  159. vec3 a_position : POSITION;
  160. vec3 a_normal : NORMAL;
  161. vec2 a_texcoord0 : TEXCOORD0;
  162. "
  163. vs_input_output =
  164. "
  165. $input a_position, a_normal, a_texcoord0
  166. $output v_normal, v_view, v_uv0
  167. "
  168. vs_code =
  169. "
  170. void main()
  171. {
  172. gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
  173. v_view = mul(u_modelView, vec4(a_position, 1.0));
  174. v_normal = normalize(mul(u_modelView, vec4(a_normal, 0.0)).xyz);
  175. v_uv0 = a_texcoord0;
  176. }
  177. "
  178. fs_input_output =
  179. "
  180. $input v_normal, v_view, v_uv0
  181. "
  182. fs_code =
  183. "
  184. SAMPLER2D(u_albedo, 0);
  185. uniform vec4 u_light_pos; // In world-space
  186. uniform vec4 u_light_dir; // In view-space
  187. uniform vec4 u_light_col;
  188. uniform vec4 u_ambient = vec4(0.5f, 0.5f, 0.5f, 0.0f);
  189. uniform vec4 u_diffuse = vec4(1.0f, 1.0f, 1.0f, 0.0f);
  190. uniform vec4 u_specular = vec4(0.0f, 0.0f, 0.0f, 0.0f);
  191. void main()
  192. {
  193. // normalize both input vectors
  194. vec3 n = normalize(v_normal);
  195. vec3 e = normalize(v_view.xyz);
  196. float intensity = max(0.0f, dot(n, u_light_dir.xyz));
  197. vec4 colorOut = max(intensity * (u_diffuse * u_light_col), u_ambient);
  198. gl_FragColor = colorOut * texture2D(u_albedo, v_uv0);
  199. }
  200. "
  201. }
  202. mesh_unlit = {
  203. includes = "common"
  204. varying =
  205. "
  206. vec3 v_normal : NORMAL = vec3(0.0, 0.0, 0.0);
  207. vec4 v_view : TEXCOORD0 = vec4(0.0, 0.0, 0.0, 0.0);
  208. vec2 v_uv0 : TEXCOORD1 = vec2(0.0, 0.0);
  209. vec3 a_position : POSITION;
  210. vec3 a_normal : NORMAL;
  211. vec2 a_texcoord0 : TEXCOORD0;
  212. "
  213. vs_input_output =
  214. "
  215. $input a_position, a_normal, a_texcoord0
  216. $output v_normal, v_view, v_uv0
  217. "
  218. vs_code =
  219. "
  220. void main()
  221. {
  222. gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
  223. v_view = mul(u_modelView, vec4(a_position, 1.0));
  224. v_normal = normalize(mul(u_modelView, vec4(a_normal, 0.0)).xyz);
  225. v_uv0 = a_texcoord0;
  226. }
  227. "
  228. fs_input_output =
  229. "
  230. $input v_normal, v_view, v_uv0
  231. "
  232. fs_code =
  233. "
  234. SAMPLER2D(u_albedo, 0);
  235. uniform vec4 u_light_pos; // In world-space
  236. uniform vec4 u_light_dir; // In view-space
  237. uniform vec4 u_light_col;
  238. uniform vec4 u_ambient = vec4(0.5f, 0.5f, 0.5f, 0.0f);
  239. uniform vec4 u_diffuse = vec4(1.0f, 1.0f, 1.0f, 0.0f);
  240. uniform vec4 u_specular = vec4(0.0f, 0.0f, 0.0f, 0.0f);
  241. void main()
  242. {
  243. // normalize both input vectors
  244. vec3 n = normalize(v_normal);
  245. vec3 e = normalize(v_view.xyz);
  246. float intensity = max(0.0f, dot(n, u_light_dir.xyz));
  247. vec4 colorOut = max(intensity * (u_diffuse * u_light_col), u_ambient);
  248. gl_FragColor = texture2D(u_albedo, v_uv0);
  249. }
  250. "
  251. }
  252. }
  253. shaders = {
  254. debug_line = {
  255. bgfx_shader = "debug_line"
  256. render_state = "debug_line"
  257. }
  258. debug_line_noz = {
  259. bgfx_shader = "debug_line"
  260. render_state = "debug_line_noz"
  261. }
  262. gui = {
  263. bgfx_shader = "gui"
  264. render_state = "gui"
  265. }
  266. sprite = {
  267. bgfx_shader = "sprite"
  268. render_state = "sprite"
  269. }
  270. mesh = {
  271. bgfx_shader = "mesh"
  272. render_state = "mesh"
  273. }
  274. mesh_notexture = {
  275. bgfx_shader = "mesh"
  276. render_state = "mesh"
  277. }
  278. mesh_unlit = {
  279. bgfx_shader = "mesh_unlit"
  280. render_state = "mesh"
  281. }
  282. }