sources.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. // File generated by G3NSHADERS. Do not edit.
  2. // To regenerate this file install 'g3nshaders' and execute:
  3. // 'go generate' in this folder.
  4. package shaders
  5. const include_phong_model_source = `/***
  6. phong lighting model
  7. Parameters:
  8. position: input vertex position in camera coordinates
  9. normal: input vertex normal in camera coordinates
  10. camDir: input camera directions
  11. matAmbient: input material ambient color
  12. matDiffuse: input material diffuse color
  13. ambdiff: output ambient+diffuse color
  14. spec: output specular color
  15. Uniforms:
  16. AmbientLightColor[]
  17. DiffuseLightColor[]
  18. DiffuseLightPosition[]
  19. PointLightColor[]
  20. PointLightPosition[]
  21. PointLightLinearDecay[]
  22. PointLightQuadraticDecay[]
  23. MatSpecularColor
  24. MatShininess
  25. *****/
  26. void phongModel(vec4 position, vec3 normal, vec3 camDir, vec3 matAmbient, vec3 matDiffuse, out vec3 ambdiff, out vec3 spec) {
  27. vec3 ambientTotal = vec3(0.0);
  28. vec3 diffuseTotal = vec3(0.0);
  29. vec3 specularTotal = vec3(0.0);
  30. #if AMB_LIGHTS>0
  31. // Ambient lights
  32. for (int i = 0; i < AMB_LIGHTS; i++) {
  33. ambientTotal += AmbientLightColor[i] * matAmbient;
  34. }
  35. #endif
  36. #if DIR_LIGHTS>0
  37. // Directional lights
  38. for (int i = 0; i < DIR_LIGHTS; i++) {
  39. // Diffuse reflection
  40. // DirLightPosition is the direction of the current light
  41. vec3 lightDirection = normalize(DirLightPosition(i));
  42. // Calculates the dot product between the light direction and this vertex normal.
  43. float dotNormal = max(dot(lightDirection, normal), 0.0);
  44. diffuseTotal += DirLightColor(i) * matDiffuse * dotNormal;
  45. // Specular reflection
  46. // Calculates the light reflection vector
  47. vec3 ref = reflect(-lightDirection, normal);
  48. if (dotNormal > 0.0) {
  49. specularTotal += DirLightColor(i) * MatSpecularColor * pow(max(dot(ref, camDir), 0.0), MatShininess);
  50. }
  51. }
  52. #endif
  53. #if POINT_LIGHTS>0
  54. // Point lights
  55. for (int i = 0; i < POINT_LIGHTS; i++) {
  56. // Common calculations
  57. // Calculates the direction and distance from the current vertex to this point light.
  58. vec3 lightDirection = PointLightPosition(i) - vec3(position);
  59. float lightDistance = length(lightDirection);
  60. // Normalizes the lightDirection
  61. lightDirection = lightDirection / lightDistance;
  62. // Calculates the attenuation due to the distance of the light
  63. float attenuation = 1.0 / (1.0 + PointLightLinearDecay(i) * lightDistance +
  64. PointLightQuadraticDecay(i) * lightDistance * lightDistance);
  65. // Diffuse reflection
  66. float dotNormal = max(dot(lightDirection, normal), 0.0);
  67. diffuseTotal += PointLightColor(i) * matDiffuse * dotNormal * attenuation;
  68. // Specular reflection
  69. // Calculates the light reflection vector
  70. vec3 ref = reflect(-lightDirection, normal);
  71. if (dotNormal > 0.0) {
  72. specularTotal += PointLightColor(i) * MatSpecularColor *
  73. pow(max(dot(ref, camDir), 0.0), MatShininess) * attenuation;
  74. }
  75. }
  76. #endif
  77. #if SPOT_LIGHTS>0
  78. for (int i = 0; i < SPOT_LIGHTS; i++) {
  79. // Calculates the direction and distance from the current vertex to this spot light.
  80. vec3 lightDirection = SpotLightPosition(i) - vec3(position);
  81. float lightDistance = length(lightDirection);
  82. lightDirection = lightDirection / lightDistance;
  83. // Calculates the attenuation due to the distance of the light
  84. float attenuation = 1.0 / (1.0 + SpotLightLinearDecay(i) * lightDistance +
  85. SpotLightQuadraticDecay(i) * lightDistance * lightDistance);
  86. // Calculates the angle between the vertex direction and spot direction
  87. // If this angle is greater than the cutoff the spotlight will not contribute
  88. // to the final color.
  89. float angle = acos(dot(-lightDirection, SpotLightDirection(i)));
  90. float cutoff = radians(clamp(SpotLightCutoffAngle(i), 0.0, 90.0));
  91. if (angle < cutoff) {
  92. float spotFactor = pow(dot(-lightDirection, SpotLightDirection(i)), SpotLightAngularDecay(i));
  93. // Diffuse reflection
  94. float dotNormal = max(dot(lightDirection, normal), 0.0);
  95. diffuseTotal += SpotLightColor(i) * matDiffuse * dotNormal * attenuation * spotFactor;
  96. // Specular reflection
  97. vec3 ref = reflect(-lightDirection, normal);
  98. if (dotNormal > 0.0) {
  99. specularTotal += SpotLightColor(i) * MatSpecularColor * pow(max(dot(ref, camDir), 0.0), MatShininess) * attenuation * spotFactor;
  100. }
  101. }
  102. }
  103. #endif
  104. // Sets output colors
  105. ambdiff = ambientTotal + MatEmissiveColor + diffuseTotal;
  106. spec = specularTotal;
  107. }
  108. `
  109. const include_material_source = `//
  110. // Material properties uniform
  111. //
  112. uniform vec3 Material[6];
  113. // Macros to access elements inside the MatTexinfo array
  114. // Each texture uses 3 vec2 elements.
  115. #define MatAmbientColor Material[0]
  116. #define MatDiffuseColor Material[1]
  117. #define MatSpecularColor Material[2]
  118. #define MatEmissiveColor Material[3]
  119. #define MatShininess Material[4].x
  120. #define MatOpacity Material[4].y
  121. #define MatPointSize Material[4].z
  122. #define MatPointRotationZ Material[5].x
  123. #if MAT_TEXTURES > 0
  124. // Texture unit sampler array
  125. uniform sampler2D MatTexture[MAT_TEXTURES];
  126. // Texture parameters (3*vec2 per texture)
  127. uniform mat3 MatTexinfo[MAT_TEXTURES];
  128. // Macros to access elements inside the MatTexinfo array
  129. #define MatTexOffset(a) MatTexinfo[a][0].xy
  130. #define MatTexRepeat(a) MatTexinfo[a][1].xy
  131. #define MatTexFlipY(a) bool(MatTexinfo[a][2].x)
  132. #define MatTexVisible(a) bool(MatTexinfo[a][2].y)
  133. #endif
  134. // GLSL 3.30 does not allow indexing texture sampler with non constant values.
  135. // This macro is used to mix the texture with the specified index with the material color.
  136. // It should be called for each texture index. It uses two externally defined variables:
  137. // vec4 texColor
  138. // vec4 texMixed
  139. #define MIX_TEXTURE(i) \
  140. if (MatTexVisible(i)) { \
  141. texColor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i)); \
  142. if (i == 0) { \
  143. texMixed = texColor; \
  144. } else { \
  145. texMixed = mix(texMixed, texColor, texColor.a); \
  146. } \
  147. }
  148. `
  149. const include_lights_source = `//
  150. // Lights uniforms
  151. //
  152. // Ambient lights uniforms
  153. #if AMB_LIGHTS>0
  154. uniform vec3 AmbientLightColor[AMB_LIGHTS];
  155. #endif
  156. // Directional lights uniform array. Each directional light uses 2 elements
  157. #if DIR_LIGHTS>0
  158. uniform vec3 DirLight[2*DIR_LIGHTS];
  159. // Macros to access elements inside the DirectionalLight uniform array
  160. #define DirLightColor(a) DirLight[2*a]
  161. #define DirLightPosition(a) DirLight[2*a+1]
  162. #endif
  163. // Point lights uniform array. Each point light uses 3 elements
  164. #if POINT_LIGHTS>0
  165. uniform vec3 PointLight[3*POINT_LIGHTS];
  166. // Macros to access elements inside the PointLight uniform array
  167. #define PointLightColor(a) PointLight[3*a]
  168. #define PointLightPosition(a) PointLight[3*a+1]
  169. #define PointLightLinearDecay(a) PointLight[3*a+2].x
  170. #define PointLightQuadraticDecay(a) PointLight[3*a+2].y
  171. #endif
  172. #if SPOT_LIGHTS>0
  173. // Spot lights uniforms. Each spot light uses 5 elements
  174. uniform vec3 SpotLight[5*SPOT_LIGHTS];
  175. // Macros to access elements inside the PointLight uniform array
  176. #define SpotLightColor(a) SpotLight[5*a]
  177. #define SpotLightPosition(a) SpotLight[5*a+1]
  178. #define SpotLightDirection(a) SpotLight[5*a+2]
  179. #define SpotLightAngularDecay(a) SpotLight[5*a+3].x
  180. #define SpotLightCutoffAngle(a) SpotLight[5*a+3].y
  181. #define SpotLightLinearDecay(a) SpotLight[5*a+3].z
  182. #define SpotLightQuadraticDecay(a) SpotLight[5*a+4].x
  183. #endif
  184. `
  185. const include_attributes_source = `//
  186. // Vertex attributes
  187. //
  188. layout(location = 0) in vec3 VertexPosition;
  189. layout(location = 1) in vec3 VertexNormal;
  190. layout(location = 2) in vec3 VertexColor;
  191. layout(location = 3) in vec2 VertexTexcoord;
  192. layout(location = 4) in float VertexDistance;
  193. layout(location = 5) in vec4 VertexTexoffsets;
  194. `
  195. const basic_fragment_source = `//
  196. // Fragment Shader template
  197. //
  198. in vec3 Color;
  199. out vec4 FragColor;
  200. void main() {
  201. FragColor = vec4(Color, 1.0);
  202. }
  203. `
  204. const standard_fragment_source = `//
  205. // Fragment Shader template
  206. //
  207. #include <material>
  208. // Inputs from Vertex shader
  209. in vec3 ColorFrontAmbdiff;
  210. in vec3 ColorFrontSpec;
  211. in vec3 ColorBackAmbdiff;
  212. in vec3 ColorBackSpec;
  213. in vec2 FragTexcoord;
  214. // Output
  215. out vec4 FragColor;
  216. void main() {
  217. // Mix material color with textures colors
  218. vec4 texMixed = vec4(1);
  219. vec4 texColor;
  220. #if MAT_TEXTURES==1
  221. MIX_TEXTURE(0)
  222. #elif MAT_TEXTURES==2
  223. MIX_TEXTURE(0)
  224. MIX_TEXTURE(1)
  225. #elif MAT_TEXTURES==3
  226. MIX_TEXTURE(0)
  227. MIX_TEXTURE(1)
  228. MIX_TEXTURE(2)
  229. #endif
  230. vec4 colorAmbDiff;
  231. vec4 colorSpec;
  232. if (gl_FrontFacing) {
  233. colorAmbDiff = vec4(ColorFrontAmbdiff, MatOpacity);
  234. colorSpec = vec4(ColorFrontSpec, 0);
  235. } else {
  236. colorAmbDiff = vec4(ColorBackAmbdiff, MatOpacity);
  237. colorSpec = vec4(ColorBackSpec, 0);
  238. }
  239. FragColor = min(colorAmbDiff * texMixed + colorSpec, vec4(1));
  240. }
  241. `
  242. const panel_vertex_source = `//
  243. // Vertex shader panel
  244. //
  245. #include <attributes>
  246. // Model uniforms
  247. uniform mat4 ModelMatrix;
  248. // Outputs for fragment shader
  249. out vec2 FragTexcoord;
  250. void main() {
  251. // Always flip texture coordinates
  252. vec2 texcoord = VertexTexcoord;
  253. texcoord.y = 1 - texcoord.y;
  254. FragTexcoord = texcoord;
  255. // Set position
  256. vec4 pos = vec4(VertexPosition.xyz, 1);
  257. gl_Position = ModelMatrix * pos;
  258. }
  259. `
  260. const sprite_fragment_source = `//
  261. // Fragment shader for sprite
  262. //
  263. #include <material>
  264. // Inputs from vertex shader
  265. in vec3 Color;
  266. in vec2 FragTexcoord;
  267. // Output
  268. out vec4 FragColor;
  269. void main() {
  270. // Combine all texture colors and opacity
  271. vec4 texCombined = vec4(1);
  272. #if MAT_TEXTURES>0
  273. for (int i = 0; i < {{.MatTexturesMax}}; i++) {
  274. vec4 texcolor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i));
  275. if (i == 0) {
  276. texCombined = texcolor;
  277. } else {
  278. texCombined = mix(texCombined, texcolor, texcolor.a);
  279. }
  280. }
  281. #endif
  282. // Combine material color with texture
  283. FragColor = min(vec4(Color, MatOpacity) * texCombined, vec4(1));
  284. }
  285. `
  286. const point_fragment_source = `#include <material>
  287. // Inputs from vertex shader
  288. in vec3 Color;
  289. flat in mat2 Rotation;
  290. // Output
  291. out vec4 FragColor;
  292. void main() {
  293. vec4 texCombined = vec4(1);
  294. #if MAT_TEXTURES > 0
  295. // Combine all texture colors and opacity
  296. for (int i = 0; i < MAT_TEXTURES; i++) {
  297. vec2 pt = gl_PointCoord - vec2(0.5);
  298. vec4 texcolor = texture(MatTexture[i], (Rotation * pt + vec2(0.5)) * MatTexRepeat(i) + MatTexOffset(i));
  299. if (i == 0) {
  300. texCombined = texcolor;
  301. } else {
  302. texCombined = mix(texCombined, texcolor, texcolor.a);
  303. }
  304. }
  305. #endif
  306. // Combine material color with texture
  307. FragColor = min(vec4(Color, MatOpacity) * texCombined, vec4(1));
  308. }
  309. `
  310. const phong_vertex_source = `//
  311. // Vertex Shader
  312. //
  313. #include <attributes>
  314. // Model uniforms
  315. uniform mat4 ModelViewMatrix;
  316. uniform mat3 NormalMatrix;
  317. uniform mat4 MVP;
  318. #include <material>
  319. // Output variables for Fragment shader
  320. out vec4 Position;
  321. out vec3 Normal;
  322. out vec3 CamDir;
  323. out vec2 FragTexcoord;
  324. void main() {
  325. // Transform this vertex position to camera coordinates.
  326. Position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  327. // Transform this vertex normal to camera coordinates.
  328. Normal = normalize(NormalMatrix * VertexNormal);
  329. // Calculate the direction vector from the vertex to the camera
  330. // The camera is at 0,0,0
  331. CamDir = normalize(-Position.xyz);
  332. // Flips texture coordinate Y if requested.
  333. vec2 texcoord = VertexTexcoord;
  334. #if MAT_TEXTURES>0
  335. if (MatTexFlipY(0)) {
  336. texcoord.y = 1 - texcoord.y;
  337. }
  338. #endif
  339. FragTexcoord = texcoord;
  340. gl_Position = MVP * vec4(VertexPosition, 1.0);
  341. }
  342. `
  343. const panel_fragment_source = `//
  344. // Fragment Shader template
  345. //
  346. // Textures uniforms
  347. uniform sampler2D MatTexture[1];
  348. uniform mat3 MatTexinfo[1];
  349. // Macros to access elements inside MatTexinfo uniform
  350. #define MatTexOffset(a) MatTexinfo[a][0].xy
  351. #define MatTexRepeat(a) MatTexinfo[a][1].xy
  352. #define MatTexFlipY(a) bool(MatTexinfo[a][2].x)
  353. #define MatTexVisible(a) bool(MatTexinfo[a][2].y)
  354. // Inputs from vertex shader
  355. in vec2 FragTexcoord;
  356. // Input uniform
  357. uniform vec4 Panel[8];
  358. #define Bounds Panel[0] // panel bounds in texture coordinates
  359. #define Border Panel[1] // panel border in texture coordinates
  360. #define Padding Panel[2] // panel padding in texture coordinates
  361. #define Content Panel[3] // panel content area in texture coordinates
  362. #define BorderColor Panel[4] // panel border color
  363. #define PaddingColor Panel[5] // panel padding color
  364. #define ContentColor Panel[6] // panel content color
  365. #define TextureValid bool(Panel[7].x) // texture valid flag
  366. // Output
  367. out vec4 FragColor;
  368. /***
  369. * Checks if current fragment texture coordinate is inside the
  370. * supplied rectangle in texture coordinates:
  371. * rect[0] - position x [0,1]
  372. * rect[1] - position y [0,1]
  373. * rect[2] - width [0,1]
  374. * rect[3] - height [0,1]
  375. */
  376. bool checkRect(vec4 rect) {
  377. if (FragTexcoord.x < rect[0]) {
  378. return false;
  379. }
  380. if (FragTexcoord.x > rect[0] + rect[2]) {
  381. return false;
  382. }
  383. if (FragTexcoord.y < rect[1]) {
  384. return false;
  385. }
  386. if (FragTexcoord.y > rect[1] + rect[3]) {
  387. return false;
  388. }
  389. return true;
  390. }
  391. void main() {
  392. // Discard fragment outside of received bounds
  393. // Bounds[0] - xmin
  394. // Bounds[1] - ymin
  395. // Bounds[2] - xmax
  396. // Bounds[3] - ymax
  397. if (FragTexcoord.x <= Bounds[0] || FragTexcoord.x >= Bounds[2]) {
  398. discard;
  399. }
  400. if (FragTexcoord.y <= Bounds[1] || FragTexcoord.y >= Bounds[3]) {
  401. discard;
  402. }
  403. // Check if fragment is inside content area
  404. if (checkRect(Content)) {
  405. // If no texture, the color will be the material color.
  406. vec4 color = ContentColor;
  407. if (TextureValid) {
  408. // Adjust texture coordinates to fit texture inside the content area
  409. vec2 offset = vec2(-Content[0], -Content[1]);
  410. vec2 factor = vec2(1/Content[2], 1/Content[3]);
  411. vec2 texcoord = (FragTexcoord + offset) * factor;
  412. vec4 texColor = texture(MatTexture[0], texcoord * MatTexRepeat(0) + MatTexOffset(0));
  413. // Mix content color with texture color ???
  414. //color = mix(color, texColor, texColor.a);
  415. color = texColor;
  416. }
  417. FragColor = color;
  418. return;
  419. }
  420. // Checks if fragment is inside paddings area
  421. if (checkRect(Padding)) {
  422. FragColor = PaddingColor;
  423. return;
  424. }
  425. // Checks if fragment is inside borders area
  426. if (checkRect(Border)) {
  427. FragColor = BorderColor;
  428. return;
  429. }
  430. // Fragment is in margins area (always transparent)
  431. FragColor = vec4(1,1,1,0);
  432. }
  433. `
  434. const phong_fragment_source = `//
  435. // Fragment Shader template
  436. //
  437. // Inputs from vertex shader
  438. in vec4 Position; // Vertex position in camera coordinates.
  439. in vec3 Normal; // Vertex normal in camera coordinates.
  440. in vec3 CamDir; // Direction from vertex to camera
  441. in vec2 FragTexcoord;
  442. #include <lights>
  443. #include <material>
  444. #include <phong_model>
  445. // Final fragment color
  446. out vec4 FragColor;
  447. void main() {
  448. // Mix material color with textures colors
  449. vec4 texMixed = vec4(1);
  450. vec4 texColor;
  451. #if MAT_TEXTURES==1
  452. MIX_TEXTURE(0)
  453. #elif MAT_TEXTURES==2
  454. MIX_TEXTURE(0)
  455. MIX_TEXTURE(1)
  456. #elif MAT_TEXTURES==3
  457. MIX_TEXTURE(0)
  458. MIX_TEXTURE(1)
  459. MIX_TEXTURE(2)
  460. #endif
  461. // Combine material with texture colors
  462. vec4 matDiffuse = vec4(MatDiffuseColor, MatOpacity) * texMixed;
  463. vec4 matAmbient = vec4(MatAmbientColor, MatOpacity) * texMixed;
  464. // Inverts the fragment normal if not FrontFacing
  465. vec3 fragNormal = Normal;
  466. if (!gl_FrontFacing) {
  467. fragNormal = -fragNormal;
  468. }
  469. // Calculates the Ambient+Diffuse and Specular colors for this fragment using the Phong model.
  470. vec3 Ambdiff, Spec;
  471. phongModel(Position, fragNormal, CamDir, vec3(matAmbient), vec3(matDiffuse), Ambdiff, Spec);
  472. // Final fragment color
  473. FragColor = min(vec4(Ambdiff + Spec, matDiffuse.a), vec4(1.0));
  474. }
  475. `
  476. const sprite_vertex_source = `//
  477. // Vertex shader for sprites
  478. //
  479. #include <attributes>
  480. // Input uniforms
  481. uniform mat4 MVP;
  482. #include <material>
  483. // Outputs for fragment shader
  484. out vec3 Color;
  485. out vec2 FragTexcoord;
  486. void main() {
  487. // Applies transformation to vertex position
  488. gl_Position = MVP * vec4(VertexPosition, 1.0);
  489. // Outputs color
  490. Color = MatDiffuseColor;
  491. // Flips texture coordinate Y if requested.
  492. vec2 texcoord = VertexTexcoord;
  493. #if MAT_TEXTURES>0
  494. if (MatTexFlipY[0]) {
  495. texcoord.y = 1 - texcoord.y;
  496. }
  497. #endif
  498. FragTexcoord = texcoord;
  499. }
  500. `
  501. const standard_vertex_source = `//
  502. // Vertex shader standard
  503. //
  504. #include <attributes>
  505. // Model uniforms
  506. uniform mat4 ModelViewMatrix;
  507. uniform mat3 NormalMatrix;
  508. uniform mat4 MVP;
  509. #include <lights>
  510. #include <material>
  511. #include <phong_model>
  512. // Outputs for the fragment shader.
  513. out vec3 ColorFrontAmbdiff;
  514. out vec3 ColorFrontSpec;
  515. out vec3 ColorBackAmbdiff;
  516. out vec3 ColorBackSpec;
  517. out vec2 FragTexcoord;
  518. void main() {
  519. // Transform this vertex normal to camera coordinates.
  520. vec3 normal = normalize(NormalMatrix * VertexNormal);
  521. // Calculate this vertex position in camera coordinates
  522. vec4 position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  523. // Calculate the direction vector from the vertex to the camera
  524. // The camera is at 0,0,0
  525. vec3 camDir = normalize(-position.xyz);
  526. // Calculates the vertex Ambient+Diffuse and Specular colors using the Phong model
  527. // for the front and back
  528. phongModel(position, normal, camDir, MatAmbientColor, MatDiffuseColor, ColorFrontAmbdiff, ColorFrontSpec);
  529. phongModel(position, -normal, camDir, MatAmbientColor, MatDiffuseColor, ColorBackAmbdiff, ColorBackSpec);
  530. vec2 texcoord = VertexTexcoord;
  531. #if MAT_TEXTURES > 0
  532. // Flips texture coordinate Y if requested.
  533. if (MatTexFlipY(0)) {
  534. texcoord.y = 1 - texcoord.y;
  535. }
  536. #endif
  537. FragTexcoord = texcoord;
  538. gl_Position = MVP * vec4(VertexPosition, 1.0);
  539. }
  540. `
  541. const point_vertex_source = `#include <attributes>
  542. // Model uniforms
  543. uniform mat4 MVP;
  544. // Material uniforms
  545. #include <material>
  546. // Outputs for fragment shader
  547. out vec3 Color;
  548. flat out mat2 Rotation;
  549. void main() {
  550. // Rotation matrix for fragment shader
  551. float rotSin = sin(MatPointRotationZ);
  552. float rotCos = cos(MatPointRotationZ);
  553. Rotation = mat2(rotCos, rotSin, - rotSin, rotCos);
  554. // Sets the vertex position
  555. vec4 pos = MVP * vec4(VertexPosition, 1.0);
  556. gl_Position = pos;
  557. // Sets the size of the rasterized point decreasing with distance
  558. gl_PointSize = (1.0 - pos.z / pos.w) * MatPointSize;
  559. // Outputs color
  560. Color = MatEmissiveColor;
  561. }
  562. `
  563. const basic_vertex_source = `//
  564. // Vertex shader basic
  565. //
  566. #include <attributes>
  567. // Model uniforms
  568. uniform mat4 MVP;
  569. // Final output color for fragment shader
  570. out vec3 Color;
  571. void main() {
  572. Color = VertexColor;
  573. gl_Position = MVP * vec4(VertexPosition, 1.0);
  574. }
  575. `
  576. // Maps include name with its source code
  577. var includeMap = map[string]string{
  578. "phong_model": include_phong_model_source,
  579. "material": include_material_source,
  580. "lights": include_lights_source,
  581. "attributes": include_attributes_source,
  582. }
  583. // Maps shader name with its source code
  584. var shaderMap = map[string]string{
  585. "basic_fragment": basic_fragment_source,
  586. "standard_fragment": standard_fragment_source,
  587. "panel_vertex": panel_vertex_source,
  588. "sprite_fragment": sprite_fragment_source,
  589. "point_fragment": point_fragment_source,
  590. "phong_vertex": phong_vertex_source,
  591. "panel_fragment": panel_fragment_source,
  592. "phong_fragment": phong_fragment_source,
  593. "sprite_vertex": sprite_vertex_source,
  594. "standard_vertex": standard_vertex_source,
  595. "point_vertex": point_vertex_source,
  596. "basic_vertex": basic_vertex_source,
  597. }
  598. // Maps program name with Proginfo struct with shaders names
  599. var programMap = map[string]ProgramInfo{
  600. "basic": {"basic_vertex", "basic_fragment", ""},
  601. "panel": {"panel_vertex", "panel_fragment", ""},
  602. "phong": {"phong_vertex", "phong_fragment", ""},
  603. "point": {"point_vertex", "point_fragment", ""},
  604. "sprite": {"sprite_vertex", "sprite_fragment", ""},
  605. "standard": {"standard_vertex", "standard_fragment", ""},
  606. }