sources.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. `
  135. const include_lights_source = `//
  136. // Lights uniforms
  137. //
  138. // Ambient lights uniforms
  139. #if AMB_LIGHTS>0
  140. uniform vec3 AmbientLightColor[AMB_LIGHTS];
  141. #endif
  142. // Directional lights uniform array. Each directional light uses 2 elements
  143. #if DIR_LIGHTS>0
  144. uniform vec3 DirLight[2*DIR_LIGHTS];
  145. // Macros to access elements inside the DirectionalLight uniform array
  146. #define DirLightColor(a) DirLight[2*a]
  147. #define DirLightPosition(a) DirLight[2*a+1]
  148. #endif
  149. // Point lights uniform array. Each point light uses 3 elements
  150. #if POINT_LIGHTS>0
  151. uniform vec3 PointLight[3*POINT_LIGHTS];
  152. // Macros to access elements inside the PointLight uniform array
  153. #define PointLightColor(a) PointLight[3*a]
  154. #define PointLightPosition(a) PointLight[3*a+1]
  155. #define PointLightLinearDecay(a) PointLight[3*a+2].x
  156. #define PointLightQuadraticDecay(a) PointLight[3*a+2].y
  157. #endif
  158. #if SPOT_LIGHTS>0
  159. // Spot lights uniforms. Each spot light uses 5 elements
  160. uniform vec3 SpotLight[5*SPOT_LIGHTS];
  161. // Macros to access elements inside the PointLight uniform array
  162. #define SpotLightColor(a) SpotLight[5*a]
  163. #define SpotLightPosition(a) SpotLight[5*a+1]
  164. #define SpotLightDirection(a) SpotLight[5*a+2]
  165. #define SpotLightAngularDecay(a) SpotLight[5*a+3].x
  166. #define SpotLightCutoffAngle(a) SpotLight[5*a+3].y
  167. #define SpotLightLinearDecay(a) SpotLight[5*a+3].z
  168. #define SpotLightQuadraticDecay(a) SpotLight[5*a+4].x
  169. #endif
  170. `
  171. const include_attributes_source = `//
  172. // Vertex attributes
  173. //
  174. layout(location = 0) in vec3 VertexPosition;
  175. layout(location = 1) in vec3 VertexNormal;
  176. layout(location = 2) in vec3 VertexColor;
  177. layout(location = 3) in vec2 VertexTexcoord;
  178. layout(location = 4) in float VertexDistance;
  179. layout(location = 5) in vec4 VertexTexoffsets;
  180. `
  181. const basic_fragment_source = `//
  182. // Fragment Shader template
  183. //
  184. in vec3 Color;
  185. out vec4 FragColor;
  186. void main() {
  187. FragColor = vec4(Color, 1.0);
  188. }
  189. `
  190. const standard_fragment_source = `//
  191. // Fragment Shader template
  192. //
  193. #include <material>
  194. // Inputs from Vertex shader
  195. in vec3 ColorFrontAmbdiff;
  196. in vec3 ColorFrontSpec;
  197. in vec3 ColorBackAmbdiff;
  198. in vec3 ColorBackSpec;
  199. in vec2 FragTexcoord;
  200. // Output
  201. out vec4 FragColor;
  202. void main() {
  203. vec4 texCombined = vec4(1);
  204. #if MAT_TEXTURES > 0
  205. // Combine all texture colors and opacity
  206. for (int i = 0; i < MAT_TEXTURES; i++) {
  207. if (MatTexVisible(i) == false) {
  208. continue;
  209. }
  210. vec4 texcolor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i));
  211. if (i == 0) {
  212. texCombined = texcolor;
  213. } else {
  214. texCombined = mix(texCombined, texcolor, texcolor.a);
  215. }
  216. }
  217. #endif
  218. vec4 colorAmbDiff;
  219. vec4 colorSpec;
  220. if (gl_FrontFacing) {
  221. colorAmbDiff = vec4(ColorFrontAmbdiff, MatOpacity);
  222. colorSpec = vec4(ColorFrontSpec, 0);
  223. } else {
  224. colorAmbDiff = vec4(ColorBackAmbdiff, MatOpacity);
  225. colorSpec = vec4(ColorBackSpec, 0);
  226. }
  227. FragColor = min(colorAmbDiff * texCombined + colorSpec, vec4(1));
  228. }
  229. `
  230. const panel_vertex_source = `//
  231. // Vertex shader panel
  232. //
  233. #include <attributes>
  234. // Model uniforms
  235. uniform mat4 ModelMatrix;
  236. // Outputs for fragment shader
  237. out vec2 FragTexcoord;
  238. void main() {
  239. // Always flip texture coordinates
  240. vec2 texcoord = VertexTexcoord;
  241. texcoord.y = 1 - texcoord.y;
  242. FragTexcoord = texcoord;
  243. // Set position
  244. vec4 pos = vec4(VertexPosition.xyz, 1);
  245. gl_Position = ModelMatrix * pos;
  246. }
  247. `
  248. const sprite_fragment_source = `//
  249. // Fragment shader for sprite
  250. //
  251. #include <material>
  252. // Inputs from vertex shader
  253. in vec3 Color;
  254. in vec2 FragTexcoord;
  255. // Output
  256. out vec4 FragColor;
  257. void main() {
  258. // Combine all texture colors and opacity
  259. vec4 texCombined = vec4(1);
  260. #if MAT_TEXTURES>0
  261. for (int i = 0; i < {{.MatTexturesMax}}; i++) {
  262. vec4 texcolor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i));
  263. if (i == 0) {
  264. texCombined = texcolor;
  265. } else {
  266. texCombined = mix(texCombined, texcolor, texcolor.a);
  267. }
  268. }
  269. #endif
  270. // Combine material color with texture
  271. FragColor = min(vec4(Color, MatOpacity) * texCombined, vec4(1));
  272. }
  273. `
  274. const point_fragment_source = `#include <material>
  275. // Inputs from vertex shader
  276. in vec3 Color;
  277. flat in mat2 Rotation;
  278. // Output
  279. out vec4 FragColor;
  280. void main() {
  281. vec4 texCombined = vec4(1);
  282. #if MAT_TEXTURES > 0
  283. // Combine all texture colors and opacity
  284. for (int i = 0; i < MAT_TEXTURES; i++) {
  285. vec2 pt = gl_PointCoord - vec2(0.5);
  286. vec4 texcolor = texture(MatTexture[i], (Rotation * pt + vec2(0.5)) * MatTexRepeat(i) + MatTexOffset(i));
  287. if (i == 0) {
  288. texCombined = texcolor;
  289. } else {
  290. texCombined = mix(texCombined, texcolor, texcolor.a);
  291. }
  292. }
  293. #endif
  294. // Combine material color with texture
  295. FragColor = min(vec4(Color, MatOpacity) * texCombined, vec4(1));
  296. }
  297. `
  298. const phong_vertex_source = `//
  299. // Vertex Shader
  300. //
  301. #include <attributes>
  302. // Model uniforms
  303. uniform mat4 ModelViewMatrix;
  304. uniform mat3 NormalMatrix;
  305. uniform mat4 MVP;
  306. #include <material>
  307. // Output variables for Fragment shader
  308. out vec4 Position;
  309. out vec3 Normal;
  310. out vec3 CamDir;
  311. out vec2 FragTexcoord;
  312. void main() {
  313. // Transform this vertex position to camera coordinates.
  314. Position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  315. // Transform this vertex normal to camera coordinates.
  316. Normal = normalize(NormalMatrix * VertexNormal);
  317. // Calculate the direction vector from the vertex to the camera
  318. // The camera is at 0,0,0
  319. CamDir = normalize(-Position.xyz);
  320. // Flips texture coordinate Y if requested.
  321. vec2 texcoord = VertexTexcoord;
  322. #if MAT_TEXTURES>0
  323. if (MatTexFlipY(0)) {
  324. texcoord.y = 1 - texcoord.y;
  325. }
  326. #endif
  327. FragTexcoord = texcoord;
  328. gl_Position = MVP * vec4(VertexPosition, 1.0);
  329. }
  330. `
  331. const panel_fragment_source = `//
  332. // Fragment Shader template
  333. //
  334. // Textures uniforms
  335. uniform sampler2D MatTexture[1];
  336. uniform mat3 MatTexinfo[1];
  337. // Macros to access elements inside MatTexinfo uniform
  338. #define MatTexOffset(a) MatTexinfo[a][0].xy
  339. #define MatTexRepeat(a) MatTexinfo[a][1].xy
  340. #define MatTexFlipY(a) bool(MatTexinfo[a][2].x)
  341. #define MatTexVisible(a) bool(MatTexinfo[a][2].y)
  342. // Inputs from vertex shader
  343. in vec2 FragTexcoord;
  344. // Input uniform
  345. uniform vec4 Panel[8];
  346. #define Bounds Panel[0] // panel bounds in texture coordinates
  347. #define Border Panel[1] // panel border in texture coordinates
  348. #define Padding Panel[2] // panel padding in texture coordinates
  349. #define Content Panel[3] // panel content area in texture coordinates
  350. #define BorderColor Panel[4] // panel border color
  351. #define PaddingColor Panel[5] // panel padding color
  352. #define ContentColor Panel[6] // panel content color
  353. #define TextureValid bool(Panel[7].x) // texture valid flag
  354. // Output
  355. out vec4 FragColor;
  356. /***
  357. * Checks if current fragment texture coordinate is inside the
  358. * supplied rectangle in texture coordinates:
  359. * rect[0] - position x [0,1]
  360. * rect[1] - position y [0,1]
  361. * rect[2] - width [0,1]
  362. * rect[3] - height [0,1]
  363. */
  364. bool checkRect(vec4 rect) {
  365. if (FragTexcoord.x < rect[0]) {
  366. return false;
  367. }
  368. if (FragTexcoord.x > rect[0] + rect[2]) {
  369. return false;
  370. }
  371. if (FragTexcoord.y < rect[1]) {
  372. return false;
  373. }
  374. if (FragTexcoord.y > rect[1] + rect[3]) {
  375. return false;
  376. }
  377. return true;
  378. }
  379. void main() {
  380. // Discard fragment outside of received bounds
  381. // Bounds[0] - xmin
  382. // Bounds[1] - ymin
  383. // Bounds[2] - xmax
  384. // Bounds[3] - ymax
  385. if (FragTexcoord.x <= Bounds[0] || FragTexcoord.x >= Bounds[2]) {
  386. discard;
  387. }
  388. if (FragTexcoord.y <= Bounds[1] || FragTexcoord.y >= Bounds[3]) {
  389. discard;
  390. }
  391. // Check if fragment is inside content area
  392. if (checkRect(Content)) {
  393. // If no texture, the color will be the material color.
  394. vec4 color = ContentColor;
  395. if (TextureValid) {
  396. // Adjust texture coordinates to fit texture inside the content area
  397. vec2 offset = vec2(-Content[0], -Content[1]);
  398. vec2 factor = vec2(1/Content[2], 1/Content[3]);
  399. vec2 texcoord = (FragTexcoord + offset) * factor;
  400. vec4 texColor = texture(MatTexture[0], texcoord * MatTexRepeat(0) + MatTexOffset(0));
  401. // Mix content color with texture color ???
  402. //color = mix(color, texColor, texColor.a);
  403. color = texColor;
  404. }
  405. FragColor = color;
  406. return;
  407. }
  408. // Checks if fragment is inside paddings area
  409. if (checkRect(Padding)) {
  410. FragColor = PaddingColor;
  411. return;
  412. }
  413. // Checks if fragment is inside borders area
  414. if (checkRect(Border)) {
  415. FragColor = BorderColor;
  416. return;
  417. }
  418. // Fragment is in margins area (always transparent)
  419. FragColor = vec4(1,1,1,0);
  420. }
  421. `
  422. const phong_fragment_source = `//
  423. // Fragment Shader template
  424. //
  425. // Inputs from vertex shader
  426. in vec4 Position; // Vertex position in camera coordinates.
  427. in vec3 Normal; // Vertex normal in camera coordinates.
  428. in vec3 CamDir; // Direction from vertex to camera
  429. in vec2 FragTexcoord;
  430. #include <lights>
  431. #include <material>
  432. #include <phong_model>
  433. // Final fragment color
  434. out vec4 FragColor;
  435. void main() {
  436. // Combine all texture colors
  437. vec4 texCombined = vec4(1);
  438. #if MAT_TEXTURES>0
  439. for (int i = 0; i < MAT_TEXTURES; i++) {
  440. if (MatTexVisible(i) == false) {
  441. continue;
  442. }
  443. vec4 texcolor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i));
  444. if (i == 0) {
  445. texCombined = texcolor;
  446. } else {
  447. texCombined = mix(texCombined, texcolor, texcolor.a);
  448. }
  449. }
  450. #endif
  451. // Combine material with texture colors
  452. vec4 matDiffuse = vec4(MatDiffuseColor, MatOpacity) * texCombined;
  453. vec4 matAmbient = vec4(MatAmbientColor, MatOpacity) * texCombined;
  454. // Inverts the fragment normal if not FrontFacing
  455. vec3 fragNormal = Normal;
  456. if (!gl_FrontFacing) {
  457. fragNormal = -fragNormal;
  458. }
  459. // Calculates the Ambient+Diffuse and Specular colors for this fragment using the Phong model.
  460. vec3 Ambdiff, Spec;
  461. phongModel(Position, fragNormal, CamDir, vec3(matAmbient), vec3(matDiffuse), Ambdiff, Spec);
  462. // Final fragment color
  463. FragColor = min(vec4(Ambdiff + Spec, matDiffuse.a), vec4(1.0));
  464. }
  465. `
  466. const sprite_vertex_source = `//
  467. // Vertex shader for sprites
  468. //
  469. #include <attributes>
  470. // Input uniforms
  471. uniform mat4 MVP;
  472. #include <material>
  473. // Outputs for fragment shader
  474. out vec3 Color;
  475. out vec2 FragTexcoord;
  476. void main() {
  477. // Applies transformation to vertex position
  478. gl_Position = MVP * vec4(VertexPosition, 1.0);
  479. // Outputs color
  480. Color = MatDiffuseColor;
  481. // Flips texture coordinate Y if requested.
  482. vec2 texcoord = VertexTexcoord;
  483. #if MAT_TEXTURES>0
  484. if (MatTexFlipY[0]) {
  485. texcoord.y = 1 - texcoord.y;
  486. }
  487. #endif
  488. FragTexcoord = texcoord;
  489. }
  490. `
  491. const standard_vertex_source = `//
  492. // Vertex shader standard
  493. //
  494. #include <attributes>
  495. // Model uniforms
  496. uniform mat4 ModelViewMatrix;
  497. uniform mat3 NormalMatrix;
  498. uniform mat4 MVP;
  499. #include <lights>
  500. #include <material>
  501. #include <phong_model>
  502. // Outputs for the fragment shader.
  503. out vec3 ColorFrontAmbdiff;
  504. out vec3 ColorFrontSpec;
  505. out vec3 ColorBackAmbdiff;
  506. out vec3 ColorBackSpec;
  507. out vec2 FragTexcoord;
  508. void main() {
  509. // Transform this vertex normal to camera coordinates.
  510. vec3 normal = normalize(NormalMatrix * VertexNormal);
  511. // Calculate this vertex position in camera coordinates
  512. vec4 position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  513. // Calculate the direction vector from the vertex to the camera
  514. // The camera is at 0,0,0
  515. vec3 camDir = normalize(-position.xyz);
  516. // Calculates the vertex Ambient+Diffuse and Specular colors using the Phong model
  517. // for the front and back
  518. phongModel(position, normal, camDir, MatAmbientColor, MatDiffuseColor, ColorFrontAmbdiff, ColorFrontSpec);
  519. phongModel(position, -normal, camDir, MatAmbientColor, MatDiffuseColor, ColorBackAmbdiff, ColorBackSpec);
  520. vec2 texcoord = VertexTexcoord;
  521. #if MAT_TEXTURES > 0
  522. // Flips texture coordinate Y if requested.
  523. if (MatTexFlipY(0)) {
  524. texcoord.y = 1 - texcoord.y;
  525. }
  526. #endif
  527. FragTexcoord = texcoord;
  528. gl_Position = MVP * vec4(VertexPosition, 1.0);
  529. }
  530. `
  531. const point_vertex_source = `#include <attributes>
  532. // Model uniforms
  533. uniform mat4 MVP;
  534. // Material uniforms
  535. #include <material>
  536. // Outputs for fragment shader
  537. out vec3 Color;
  538. flat out mat2 Rotation;
  539. void main() {
  540. // Rotation matrix for fragment shader
  541. float rotSin = sin(MatPointRotationZ);
  542. float rotCos = cos(MatPointRotationZ);
  543. Rotation = mat2(rotCos, rotSin, - rotSin, rotCos);
  544. // Sets the vertex position
  545. vec4 pos = MVP * vec4(VertexPosition, 1.0);
  546. gl_Position = pos;
  547. // Sets the size of the rasterized point decreasing with distance
  548. gl_PointSize = (1.0 - pos.z / pos.w) * MatPointSize;
  549. // Outputs color
  550. Color = MatEmissiveColor;
  551. }
  552. `
  553. const basic_vertex_source = `//
  554. // Vertex shader basic
  555. //
  556. #include <attributes>
  557. // Model uniforms
  558. uniform mat4 MVP;
  559. // Final output color for fragment shader
  560. out vec3 Color;
  561. void main() {
  562. Color = VertexColor;
  563. gl_Position = MVP * vec4(VertexPosition, 1.0);
  564. }
  565. `
  566. // Maps include name with its source code
  567. var includeMap = map[string]string{
  568. "phong_model": include_phong_model_source,
  569. "material": include_material_source,
  570. "lights": include_lights_source,
  571. "attributes": include_attributes_source,
  572. }
  573. // Maps shader name with its source code
  574. var shaderMap = map[string]string{
  575. "basic_fragment": basic_fragment_source,
  576. "standard_fragment": standard_fragment_source,
  577. "panel_vertex": panel_vertex_source,
  578. "sprite_fragment": sprite_fragment_source,
  579. "point_fragment": point_fragment_source,
  580. "phong_vertex": phong_vertex_source,
  581. "panel_fragment": panel_fragment_source,
  582. "phong_fragment": phong_fragment_source,
  583. "sprite_vertex": sprite_vertex_source,
  584. "standard_vertex": standard_vertex_source,
  585. "point_vertex": point_vertex_source,
  586. "basic_vertex": basic_vertex_source,
  587. }
  588. // Maps program name with Proginfo struct with shaders names
  589. var programMap = map[string]ProgramInfo{
  590. "basic": {"basic_vertex", "basic_fragment", ""},
  591. "panel": {"panel_vertex", "panel_fragment", ""},
  592. "phong": {"phong_vertex", "phong_fragment", ""},
  593. "point": {"point_vertex", "point_fragment", ""},
  594. "sprite": {"sprite_vertex", "sprite_fragment", ""},
  595. "standard": {"standard_vertex", "standard_fragment", ""},
  596. }