sources.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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_attributes_source = `//
  6. // Vertex attributes
  7. //
  8. layout(location = 0) in vec3 VertexPosition;
  9. layout(location = 1) in vec3 VertexNormal;
  10. layout(location = 2) in vec3 VertexColor;
  11. layout(location = 3) in vec2 VertexTexcoord;
  12. layout(location = 4) in float VertexDistance;
  13. layout(location = 5) in vec4 VertexTexoffsets;
  14. `
  15. const include_lights_source = `//
  16. // Lights uniforms
  17. //
  18. // Ambient lights uniforms
  19. #if AMB_LIGHTS>0
  20. uniform vec3 AmbientLightColor[AMB_LIGHTS];
  21. #endif
  22. // Directional lights uniform array. Each directional light uses 2 elements
  23. #if DIR_LIGHTS>0
  24. uniform vec3 DirLight[2*DIR_LIGHTS];
  25. // Macros to access elements inside the DirectionalLight uniform array
  26. #define DirLightColor(a) DirLight[2*a]
  27. #define DirLightPosition(a) DirLight[2*a+1]
  28. #endif
  29. // Point lights uniform array. Each point light uses 3 elements
  30. #if POINT_LIGHTS>0
  31. uniform vec3 PointLight[3*POINT_LIGHTS];
  32. // Macros to access elements inside the PointLight uniform array
  33. #define PointLightColor(a) PointLight[3*a]
  34. #define PointLightPosition(a) PointLight[3*a+1]
  35. #define PointLightLinearDecay(a) PointLight[3*a+2].x
  36. #define PointLightQuadraticDecay(a) PointLight[3*a+2].y
  37. #endif
  38. #if SPOT_LIGHTS>0
  39. // Spot lights uniforms. Each spot light uses 5 elements
  40. uniform vec3 SpotLight[5*SPOT_LIGHTS];
  41. // Macros to access elements inside the PointLight uniform array
  42. #define SpotLightColor(a) SpotLight[5*a]
  43. #define SpotLightPosition(a) SpotLight[5*a+1]
  44. #define SpotLightDirection(a) SpotLight[5*a+2]
  45. #define SpotLightAngularDecay(a) SpotLight[5*a+3].x
  46. #define SpotLightCutoffAngle(a) SpotLight[5*a+3].y
  47. #define SpotLightLinearDecay(a) SpotLight[5*a+3].z
  48. #define SpotLightQuadraticDecay(a) SpotLight[5*a+4].x
  49. #endif
  50. `
  51. const include_material_source = `//
  52. // Material properties uniform
  53. //
  54. // Material parameters uniform array
  55. uniform vec3 Material[6];
  56. // Macros to access elements inside the Material array
  57. #define MatAmbientColor Material[0]
  58. #define MatDiffuseColor Material[1]
  59. #define MatSpecularColor Material[2]
  60. #define MatEmissiveColor Material[3]
  61. #define MatShininess Material[4].x
  62. #define MatOpacity Material[4].y
  63. #define MatPointSize Material[4].z
  64. #define MatPointRotationZ Material[5].x
  65. #if MAT_TEXTURES > 0
  66. // Texture unit sampler array
  67. uniform sampler2D MatTexture[MAT_TEXTURES];
  68. // Texture parameters (3*vec2 per texture)
  69. uniform vec2 MatTexinfo[3*MAT_TEXTURES];
  70. // Macros to access elements inside the MatTexinfo array
  71. #define MatTexOffset(a) MatTexinfo[(3*a)]
  72. #define MatTexRepeat(a) MatTexinfo[(3*a)+1]
  73. #define MatTexFlipY(a) bool(MatTexinfo[(3*a)+2].x)
  74. #define MatTexVisible(a) bool(MatTexinfo[(3*a)+2].y)
  75. #endif
  76. // GLSL 3.30 does not allow indexing texture sampler with non constant values.
  77. // This macro is used to mix the texture with the specified index with the material color.
  78. // It should be called for each texture index. It uses two externally defined variables:
  79. // vec4 texColor
  80. // vec4 texMixed
  81. // TODO alpha blending (dont use mix) see panel shader
  82. #define MIX_TEXTURE(i) \
  83. if (MatTexVisible(i)) { \
  84. texColor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i)); \
  85. if (i == 0) { \
  86. texMixed = texColor; \
  87. } else { \
  88. texMixed = mix(texMixed, texColor, texColor.a); \
  89. } \
  90. }
  91. `
  92. const include_phong_model_source = `/***
  93. phong lighting model
  94. Parameters:
  95. position: input vertex position in camera coordinates
  96. normal: input vertex normal in camera coordinates
  97. camDir: input camera directions
  98. matAmbient: input material ambient color
  99. matDiffuse: input material diffuse color
  100. ambdiff: output ambient+diffuse color
  101. spec: output specular color
  102. Uniforms:
  103. AmbientLightColor[]
  104. DiffuseLightColor[]
  105. DiffuseLightPosition[]
  106. PointLightColor[]
  107. PointLightPosition[]
  108. PointLightLinearDecay[]
  109. PointLightQuadraticDecay[]
  110. MatSpecularColor
  111. MatShininess
  112. *****/
  113. void phongModel(vec4 position, vec3 normal, vec3 camDir, vec3 matAmbient, vec3 matDiffuse, out vec3 ambdiff, out vec3 spec) {
  114. vec3 ambientTotal = vec3(0.0);
  115. vec3 diffuseTotal = vec3(0.0);
  116. vec3 specularTotal = vec3(0.0);
  117. #if AMB_LIGHTS>0
  118. // Ambient lights
  119. for (int i = 0; i < AMB_LIGHTS; i++) {
  120. ambientTotal += AmbientLightColor[i] * matAmbient;
  121. }
  122. #endif
  123. #if DIR_LIGHTS>0
  124. // Directional lights
  125. for (int i = 0; i < DIR_LIGHTS; i++) {
  126. // Diffuse reflection
  127. // DirLightPosition is the direction of the current light
  128. vec3 lightDirection = normalize(DirLightPosition(i));
  129. // Calculates the dot product between the light direction and this vertex normal.
  130. float dotNormal = max(dot(lightDirection, normal), 0.0);
  131. diffuseTotal += DirLightColor(i) * matDiffuse * dotNormal;
  132. // Specular reflection
  133. // Calculates the light reflection vector
  134. vec3 ref = reflect(-lightDirection, normal);
  135. if (dotNormal > 0.0) {
  136. specularTotal += DirLightColor(i) * MatSpecularColor * pow(max(dot(ref, camDir), 0.0), MatShininess);
  137. }
  138. }
  139. #endif
  140. #if POINT_LIGHTS>0
  141. // Point lights
  142. for (int i = 0; i < POINT_LIGHTS; i++) {
  143. // Common calculations
  144. // Calculates the direction and distance from the current vertex to this point light.
  145. vec3 lightDirection = PointLightPosition(i) - vec3(position);
  146. float lightDistance = length(lightDirection);
  147. // Normalizes the lightDirection
  148. lightDirection = lightDirection / lightDistance;
  149. // Calculates the attenuation due to the distance of the light
  150. float attenuation = 1.0 / (1.0 + PointLightLinearDecay(i) * lightDistance +
  151. PointLightQuadraticDecay(i) * lightDistance * lightDistance);
  152. // Diffuse reflection
  153. float dotNormal = max(dot(lightDirection, normal), 0.0);
  154. diffuseTotal += PointLightColor(i) * matDiffuse * dotNormal * attenuation;
  155. // Specular reflection
  156. // Calculates the light reflection vector
  157. vec3 ref = reflect(-lightDirection, normal);
  158. if (dotNormal > 0.0) {
  159. specularTotal += PointLightColor(i) * MatSpecularColor *
  160. pow(max(dot(ref, camDir), 0.0), MatShininess) * attenuation;
  161. }
  162. }
  163. #endif
  164. #if SPOT_LIGHTS>0
  165. for (int i = 0; i < SPOT_LIGHTS; i++) {
  166. // Calculates the direction and distance from the current vertex to this spot light.
  167. vec3 lightDirection = SpotLightPosition(i) - vec3(position);
  168. float lightDistance = length(lightDirection);
  169. lightDirection = lightDirection / lightDistance;
  170. // Calculates the attenuation due to the distance of the light
  171. float attenuation = 1.0 / (1.0 + SpotLightLinearDecay(i) * lightDistance +
  172. SpotLightQuadraticDecay(i) * lightDistance * lightDistance);
  173. // Calculates the angle between the vertex direction and spot direction
  174. // If this angle is greater than the cutoff the spotlight will not contribute
  175. // to the final color.
  176. float angle = acos(dot(-lightDirection, SpotLightDirection(i)));
  177. float cutoff = radians(clamp(SpotLightCutoffAngle(i), 0.0, 90.0));
  178. if (angle < cutoff) {
  179. float spotFactor = pow(dot(-lightDirection, SpotLightDirection(i)), SpotLightAngularDecay(i));
  180. // Diffuse reflection
  181. float dotNormal = max(dot(lightDirection, normal), 0.0);
  182. diffuseTotal += SpotLightColor(i) * matDiffuse * dotNormal * attenuation * spotFactor;
  183. // Specular reflection
  184. vec3 ref = reflect(-lightDirection, normal);
  185. if (dotNormal > 0.0) {
  186. specularTotal += SpotLightColor(i) * MatSpecularColor * pow(max(dot(ref, camDir), 0.0), MatShininess) * attenuation * spotFactor;
  187. }
  188. }
  189. }
  190. #endif
  191. // Sets output colors
  192. ambdiff = ambientTotal + MatEmissiveColor + diffuseTotal;
  193. spec = specularTotal;
  194. }
  195. `
  196. const basic_fragment_source = `//
  197. // Fragment Shader template
  198. //
  199. in vec3 Color;
  200. out vec4 FragColor;
  201. void main() {
  202. FragColor = vec4(Color, 1.0);
  203. }
  204. `
  205. const basic_vertex_source = `//
  206. // Vertex shader basic
  207. //
  208. #include <attributes>
  209. // Model uniforms
  210. uniform mat4 MVP;
  211. // Final output color for fragment shader
  212. out vec3 Color;
  213. void main() {
  214. Color = VertexColor;
  215. gl_Position = MVP * vec4(VertexPosition, 1.0);
  216. }
  217. `
  218. const panel_fragment_source = `//
  219. // Fragment Shader template
  220. //
  221. // Texture uniforms
  222. uniform sampler2D MatTexture;
  223. uniform vec2 MatTexinfo[3];
  224. // Macros to access elements inside the MatTexinfo array
  225. #define MatTexOffset MatTexinfo[0]
  226. #define MatTexRepeat MatTexinfo[1]
  227. #define MatTexFlipY bool(MatTexinfo[2].x) // not used
  228. #define MatTexVisible bool(MatTexinfo[2].y) // not used
  229. // Inputs from vertex shader
  230. in vec2 FragTexcoord;
  231. // Input uniform
  232. uniform vec4 Panel[8];
  233. #define Bounds Panel[0] // panel bounds in texture coordinates
  234. #define Border Panel[1] // panel border in texture coordinates
  235. #define Padding Panel[2] // panel padding in texture coordinates
  236. #define Content Panel[3] // panel content area in texture coordinates
  237. #define BorderColor Panel[4] // panel border color
  238. #define PaddingColor Panel[5] // panel padding color
  239. #define ContentColor Panel[6] // panel content color
  240. #define TextureValid bool(Panel[7].x) // texture valid flag
  241. // Output
  242. out vec4 FragColor;
  243. /***
  244. * Checks if current fragment texture coordinate is inside the
  245. * supplied rectangle in texture coordinates:
  246. * rect[0] - position x [0,1]
  247. * rect[1] - position y [0,1]
  248. * rect[2] - width [0,1]
  249. * rect[3] - height [0,1]
  250. */
  251. bool checkRect(vec4 rect) {
  252. if (FragTexcoord.x < rect[0]) {
  253. return false;
  254. }
  255. if (FragTexcoord.x > rect[0] + rect[2]) {
  256. return false;
  257. }
  258. if (FragTexcoord.y < rect[1]) {
  259. return false;
  260. }
  261. if (FragTexcoord.y > rect[1] + rect[3]) {
  262. return false;
  263. }
  264. return true;
  265. }
  266. void main() {
  267. // Discard fragment outside of received bounds
  268. // Bounds[0] - xmin
  269. // Bounds[1] - ymin
  270. // Bounds[2] - xmax
  271. // Bounds[3] - ymax
  272. if (FragTexcoord.x <= Bounds[0] || FragTexcoord.x >= Bounds[2]) {
  273. discard;
  274. }
  275. if (FragTexcoord.y <= Bounds[1] || FragTexcoord.y >= Bounds[3]) {
  276. discard;
  277. }
  278. // Check if fragment is inside content area
  279. if (checkRect(Content)) {
  280. // If no texture, the color will be the material color.
  281. vec4 color = ContentColor;
  282. if (TextureValid) {
  283. // Adjust texture coordinates to fit texture inside the content area
  284. vec2 offset = vec2(-Content[0], -Content[1]);
  285. vec2 factor = vec2(1/Content[2], 1/Content[3]);
  286. vec2 texcoord = (FragTexcoord + offset) * factor;
  287. vec4 texColor = texture(MatTexture, texcoord * MatTexRepeat + MatTexOffset);
  288. // Mix content color with texture color.
  289. // Note that doing a simple linear interpolation (e.g. using mix()) is not correct!
  290. // The right formula can be found here: https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
  291. // For a more in-depth discussion: http://apoorvaj.io/alpha-compositing-opengl-blending-and-premultiplied-alpha.html#toc4
  292. // Pre-multiply the content color
  293. vec4 contentPre = ContentColor;
  294. contentPre.rgb *= contentPre.a;
  295. // Pre-multiply the texture color
  296. vec4 texPre = texColor;
  297. texPre.rgb *= texPre.a;
  298. // Combine colors the premultiplied final color
  299. color = texPre + contentPre * (1 - texPre.a);
  300. // Un-pre-multiply (pre-divide? :P)
  301. color.rgb /= color.a;
  302. }
  303. FragColor = color;
  304. return;
  305. }
  306. // Checks if fragment is inside paddings area
  307. if (checkRect(Padding)) {
  308. FragColor = PaddingColor;
  309. return;
  310. }
  311. // Checks if fragment is inside borders area
  312. if (checkRect(Border)) {
  313. FragColor = BorderColor;
  314. return;
  315. }
  316. // Fragment is in margins area (always transparent)
  317. FragColor = vec4(1,1,1,0);
  318. }
  319. `
  320. const panel_vertex_source = `//
  321. // Vertex shader panel
  322. //
  323. #include <attributes>
  324. // Model uniforms
  325. uniform mat4 ModelMatrix;
  326. // Outputs for fragment shader
  327. out vec2 FragTexcoord;
  328. void main() {
  329. // Always flip texture coordinates
  330. vec2 texcoord = VertexTexcoord;
  331. texcoord.y = 1 - texcoord.y;
  332. FragTexcoord = texcoord;
  333. // Set position
  334. vec4 pos = vec4(VertexPosition.xyz, 1);
  335. gl_Position = ModelMatrix * pos;
  336. }
  337. `
  338. const phong_fragment_source = `//
  339. // Fragment Shader template
  340. //
  341. // Inputs from vertex shader
  342. in vec4 Position; // Vertex position in camera coordinates.
  343. in vec3 Normal; // Vertex normal in camera coordinates.
  344. in vec3 CamDir; // Direction from vertex to camera
  345. in vec2 FragTexcoord;
  346. #include <lights>
  347. #include <material>
  348. #include <phong_model>
  349. // Final fragment color
  350. out vec4 FragColor;
  351. void main() {
  352. // Mix material color with textures colors
  353. vec4 texMixed = vec4(1);
  354. vec4 texColor;
  355. #if MAT_TEXTURES==1
  356. MIX_TEXTURE(0)
  357. #elif MAT_TEXTURES==2
  358. MIX_TEXTURE(0)
  359. MIX_TEXTURE(1)
  360. #elif MAT_TEXTURES==3
  361. MIX_TEXTURE(0)
  362. MIX_TEXTURE(1)
  363. MIX_TEXTURE(2)
  364. #endif
  365. // Combine material with texture colors
  366. vec4 matDiffuse = vec4(MatDiffuseColor, MatOpacity) * texMixed;
  367. vec4 matAmbient = vec4(MatAmbientColor, MatOpacity) * texMixed;
  368. // Inverts the fragment normal if not FrontFacing
  369. vec3 fragNormal = Normal;
  370. if (!gl_FrontFacing) {
  371. fragNormal = -fragNormal;
  372. }
  373. // Calculates the Ambient+Diffuse and Specular colors for this fragment using the Phong model.
  374. vec3 Ambdiff, Spec;
  375. phongModel(Position, fragNormal, CamDir, vec3(matAmbient), vec3(matDiffuse), Ambdiff, Spec);
  376. // Final fragment color
  377. FragColor = min(vec4(Ambdiff + Spec, matDiffuse.a), vec4(1.0));
  378. }
  379. `
  380. const phong_vertex_source = `//
  381. // Vertex Shader
  382. //
  383. #include <attributes>
  384. // Model uniforms
  385. uniform mat4 ModelViewMatrix;
  386. uniform mat3 NormalMatrix;
  387. uniform mat4 MVP;
  388. #include <material>
  389. // Output variables for Fragment shader
  390. out vec4 Position;
  391. out vec3 Normal;
  392. out vec3 CamDir;
  393. out vec2 FragTexcoord;
  394. void main() {
  395. // Transform this vertex position to camera coordinates.
  396. Position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  397. // Transform this vertex normal to camera coordinates.
  398. Normal = normalize(NormalMatrix * VertexNormal);
  399. // Calculate the direction vector from the vertex to the camera
  400. // The camera is at 0,0,0
  401. CamDir = normalize(-Position.xyz);
  402. // Flips texture coordinate Y if requested.
  403. vec2 texcoord = VertexTexcoord;
  404. #if MAT_TEXTURES>0
  405. if (MatTexFlipY(0)) {
  406. texcoord.y = 1 - texcoord.y;
  407. }
  408. #endif
  409. FragTexcoord = texcoord;
  410. gl_Position = MVP * vec4(VertexPosition, 1.0);
  411. }
  412. `
  413. const physical_fragment_source = `//
  414. // Physically Based Shading of a microfacet surface material - Fragment Shader
  415. // Modified from reference implementation at https://github.com/KhronosGroup/glTF-WebGL-PBR
  416. //
  417. // References:
  418. // [1] Real Shading in Unreal Engine 4
  419. // http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
  420. // [2] Physically Based Shading at Disney
  421. // http://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf
  422. // [3] README.md - Environment Maps
  423. // https://github.com/KhronosGroup/glTF-WebGL-PBR/#environment-maps
  424. // [4] "An Inexpensive BRDF Model for Physically based Rendering" by Christophe Schlick
  425. // https://www.cs.virginia.edu/~jdl/bib/appearance/analytic%20models/schlick94b.pdf
  426. //#extension GL_EXT_shader_texture_lod: enable
  427. //#extension GL_OES_standard_derivatives : enable
  428. precision highp float;
  429. //uniform vec3 u_LightDirection;
  430. //uniform vec3 u_LightColor;
  431. //#ifdef USE_IBL
  432. //uniform samplerCube u_DiffuseEnvSampler;
  433. //uniform samplerCube u_SpecularEnvSampler;
  434. //uniform sampler2D u_brdfLUT;
  435. //#endif
  436. #ifdef HAS_BASECOLORMAP
  437. uniform sampler2D uBaseColorSampler;
  438. #endif
  439. #ifdef HAS_METALROUGHNESSMAP
  440. uniform sampler2D uMetallicRoughnessSampler;
  441. #endif
  442. #ifdef HAS_NORMALMAP
  443. uniform sampler2D uNormalSampler;
  444. //uniform float uNormalScale;
  445. #endif
  446. #ifdef HAS_EMISSIVEMAP
  447. uniform sampler2D uEmissiveSampler;
  448. #endif
  449. #ifdef HAS_OCCLUSIONMAP
  450. uniform sampler2D uOcclusionSampler;
  451. uniform float uOcclusionStrength;
  452. #endif
  453. // Material parameters uniform array
  454. uniform vec4 Material[3];
  455. // Macros to access elements inside the Material array
  456. #define uBaseColor Material[0]
  457. #define uEmissiveColor Material[1]
  458. #define uMetallicFactor Material[2].x
  459. #define uRoughnessFactor Material[2].y
  460. #include <lights>
  461. // Inputs from vertex shader
  462. in vec3 Position; // Vertex position in camera coordinates.
  463. in vec3 Normal; // Vertex normal in camera coordinates.
  464. in vec3 CamDir; // Direction from vertex to camera
  465. in vec2 FragTexcoord;
  466. // Final fragment color
  467. out vec4 FragColor;
  468. // Encapsulate the various inputs used by the various functions in the shading equation
  469. // We store values in this struct to simplify the integration of alternative implementations
  470. // of the shading terms, outlined in the Readme.MD Appendix.
  471. struct PBRLightInfo
  472. {
  473. float NdotL; // cos angle between normal and light direction
  474. float NdotV; // cos angle between normal and view direction
  475. float NdotH; // cos angle between normal and half vector
  476. float LdotH; // cos angle between light direction and half vector
  477. float VdotH; // cos angle between view direction and half vector
  478. };
  479. struct PBRInfo
  480. {
  481. float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
  482. float metalness; // metallic value at the surface
  483. vec3 reflectance0; // full reflectance color (normal incidence angle)
  484. vec3 reflectance90; // reflectance color at grazing angle
  485. float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
  486. vec3 diffuseColor; // color contribution from diffuse lighting
  487. vec3 specularColor; // color contribution from specular lighting
  488. };
  489. const float M_PI = 3.141592653589793;
  490. const float c_MinRoughness = 0.04;
  491. vec4 SRGBtoLINEAR(vec4 srgbIn) {
  492. //#ifdef MANUAL_SRGB
  493. // #ifdef SRGB_FAST_APPROXIMATION
  494. // vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
  495. // #else //SRGB_FAST_APPROXIMATION
  496. vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
  497. vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
  498. // #endif //SRGB_FAST_APPROXIMATION
  499. return vec4(linOut,srgbIn.w);
  500. //#else //MANUAL_SRGB
  501. // return srgbIn;
  502. //#endif //MANUAL_SRGB
  503. }
  504. // Find the normal for this fragment, pulling either from a predefined normal map
  505. // or from the interpolated mesh normal and tangent attributes.
  506. vec3 getNormal()
  507. {
  508. // Retrieve the tangent space matrix
  509. //#ifndef HAS_TANGENTS
  510. vec3 pos_dx = dFdx(Position);
  511. vec3 pos_dy = dFdy(Position);
  512. vec3 tex_dx = dFdx(vec3(FragTexcoord, 0.0));
  513. vec3 tex_dy = dFdy(vec3(FragTexcoord, 0.0));
  514. vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
  515. //#ifdef HAS_NORMALS
  516. vec3 ng = normalize(Normal);
  517. //#else
  518. // vec3 ng = cross(pos_dx, pos_dy);
  519. //#endif
  520. t = normalize(t - ng * dot(ng, t));
  521. vec3 b = normalize(cross(ng, t));
  522. mat3 tbn = mat3(t, b, ng);
  523. //#else // HAS_TANGENTS
  524. // mat3 tbn = v_TBN;
  525. //#endif
  526. #ifdef HAS_NORMALMAP
  527. float uNormalScale = 1.0;
  528. vec3 n = texture2D(uNormalSampler, FragTexcoord).rgb;
  529. n = normalize(tbn * ((2.0 * n - 1.0) * vec3(uNormalScale, uNormalScale, 1.0)));
  530. #else
  531. // The tbn matrix is linearly interpolated, so we need to re-normalize
  532. vec3 n = normalize(tbn[2].xyz);
  533. #endif
  534. return n;
  535. }
  536. // Calculation of the lighting contribution from an optional Image Based Light source.
  537. // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
  538. // See our README.md on Environment Maps [3] for additional discussion.
  539. vec3 getIBLContribution(PBRInfo pbrInputs, PBRLightInfo pbrLight, vec3 n, vec3 reflection)
  540. {
  541. float mipCount = 9.0; // resolution of 512x512
  542. float lod = (pbrInputs.perceptualRoughness * mipCount);
  543. // retrieve a scale and bias to F0. See [1], Figure 3
  544. vec3 brdf = vec3(0.5,0.5,0.5);//SRGBtoLINEAR(texture2D(u_brdfLUT, vec2(pbrLight.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
  545. vec3 diffuseLight = vec3(0.5,0.5,0.5);//SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
  546. //#ifdef USE_TEX_LOD
  547. // vec3 specularLight = SRGBtoLINEAR(textureCubeLodEXT(u_SpecularEnvSampler, reflection, lod)).rgb;
  548. //#else
  549. vec3 specularLight = vec3(0.5,0.5,0.5);//SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
  550. //#endif
  551. vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;
  552. vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);
  553. // For presentation, this allows us to disable IBL terms
  554. // diffuse *= u_ScaleIBLAmbient.x;
  555. // specular *= u_ScaleIBLAmbient.y;
  556. return diffuse + specular;
  557. }
  558. // Basic Lambertian diffuse
  559. // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
  560. // See also [1], Equation 1
  561. vec3 diffuse(PBRInfo pbrInputs)
  562. {
  563. return pbrInputs.diffuseColor / M_PI;
  564. }
  565. // The following equation models the Fresnel reflectance term of the spec equation (aka F())
  566. // Implementation of fresnel from [4], Equation 15
  567. vec3 specularReflection(PBRInfo pbrInputs, PBRLightInfo pbrLight)
  568. {
  569. return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrLight.VdotH, 0.0, 1.0), 5.0);
  570. }
  571. // This calculates the specular geometric attenuation (aka G()),
  572. // where rougher material will reflect less light back to the viewer.
  573. // This implementation is based on [1] Equation 4, and we adopt their modifications to
  574. // alphaRoughness as input as originally proposed in [2].
  575. float geometricOcclusion(PBRInfo pbrInputs, PBRLightInfo pbrLight)
  576. {
  577. float NdotL = pbrLight.NdotL;
  578. float NdotV = pbrLight.NdotV;
  579. float r = pbrInputs.alphaRoughness;
  580. float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
  581. float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
  582. return attenuationL * attenuationV;
  583. }
  584. // The following equation(s) model the distribution of microfacet normals across the area being drawn (aka D())
  585. // Implementation from "Average Irregularity Representation of a Roughened Surface for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
  586. // Follows the distribution function recommended in the SIGGRAPH 2013 course notes from EPIC Games [1], Equation 3.
  587. float microfacetDistribution(PBRInfo pbrInputs, PBRLightInfo pbrLight)
  588. {
  589. float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
  590. float f = (pbrLight.NdotH * roughnessSq - pbrLight.NdotH) * pbrLight.NdotH + 1.0;
  591. return roughnessSq / (M_PI * f * f);
  592. }
  593. vec3 pbrModel(PBRInfo pbrInputs, vec3 lightColor, vec3 lightDir) {
  594. vec3 n = getNormal(); // normal at surface point
  595. vec3 v = normalize(CamDir); // Vector from surface point to camera
  596. vec3 l = normalize(lightDir); // Vector from surface point to light
  597. vec3 h = normalize(l+v); // Half vector between both l and v
  598. vec3 reflection = -normalize(reflect(v, n));
  599. float NdotL = clamp(dot(n, l), 0.001, 1.0);
  600. float NdotV = abs(dot(n, v)) + 0.001;
  601. float NdotH = clamp(dot(n, h), 0.0, 1.0);
  602. float LdotH = clamp(dot(l, h), 0.0, 1.0);
  603. float VdotH = clamp(dot(v, h), 0.0, 1.0);
  604. PBRLightInfo pbrLight = PBRLightInfo(
  605. NdotL,
  606. NdotV,
  607. NdotH,
  608. LdotH,
  609. VdotH
  610. );
  611. // Calculate the shading terms for the microfacet specular shading model
  612. vec3 F = specularReflection(pbrInputs, pbrLight);
  613. float G = geometricOcclusion(pbrInputs, pbrLight);
  614. float D = microfacetDistribution(pbrInputs, pbrLight);
  615. // Calculation of analytical lighting contribution
  616. vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
  617. vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV);
  618. // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
  619. vec3 color = NdotL * lightColor * (diffuseContrib + specContrib);
  620. return color;
  621. }
  622. void main() {
  623. float perceptualRoughness = uRoughnessFactor;
  624. float metallic = uMetallicFactor;
  625. #ifdef HAS_METALROUGHNESSMAP
  626. // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
  627. // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
  628. vec4 mrSample = texture2D(uMetallicRoughnessSampler, FragTexcoord);
  629. perceptualRoughness = mrSample.g * perceptualRoughness;
  630. metallic = mrSample.b * metallic;
  631. #endif
  632. perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
  633. metallic = clamp(metallic, 0.0, 1.0);
  634. // Roughness is authored as perceptual roughness; as is convention,
  635. // convert to material roughness by squaring the perceptual roughness [2].
  636. float alphaRoughness = perceptualRoughness * perceptualRoughness;
  637. // The albedo may be defined from a base texture or a flat color
  638. #ifdef HAS_BASECOLORMAP
  639. vec4 baseColor = SRGBtoLINEAR(texture2D(uBaseColorSampler, FragTexcoord)) * uBaseColor;
  640. #else
  641. vec4 baseColor = uBaseColor;
  642. #endif
  643. vec3 f0 = vec3(0.04);
  644. vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
  645. diffuseColor *= 1.0 - metallic;
  646. vec3 specularColor = mix(f0, baseColor.rgb, uMetallicFactor);
  647. // Compute reflectance.
  648. float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
  649. // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect.
  650. // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflectance to 0%.
  651. float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
  652. vec3 specularEnvironmentR0 = specularColor.rgb;
  653. vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
  654. PBRInfo pbrInputs = PBRInfo(
  655. perceptualRoughness,
  656. metallic,
  657. specularEnvironmentR0,
  658. specularEnvironmentR90,
  659. alphaRoughness,
  660. diffuseColor,
  661. specularColor
  662. );
  663. // vec3 normal = getNormal();
  664. vec3 color = vec3(0.0);
  665. #if AMB_LIGHTS>0
  666. // Ambient lights
  667. for (int i = 0; i < AMB_LIGHTS; i++) {
  668. color += AmbientLightColor[i] * pbrInputs.diffuseColor;
  669. }
  670. #endif
  671. #if DIR_LIGHTS>0
  672. // Directional lights
  673. for (int i = 0; i < DIR_LIGHTS; i++) {
  674. // Diffuse reflection
  675. // DirLightPosition is the direction of the current light
  676. vec3 lightDirection = normalize(DirLightPosition(i));
  677. // PBR
  678. color += pbrModel(pbrInputs, DirLightColor(i), lightDirection);
  679. }
  680. #endif
  681. #if POINT_LIGHTS>0
  682. // Point lights
  683. for (int i = 0; i < POINT_LIGHTS; i++) {
  684. // Common calculations
  685. // Calculates the direction and distance from the current vertex to this point light.
  686. vec3 lightDirection = PointLightPosition(i) - vec3(Position);
  687. float lightDistance = length(lightDirection);
  688. // Normalizes the lightDirection
  689. lightDirection = lightDirection / lightDistance;
  690. // Calculates the attenuation due to the distance of the light
  691. float attenuation = 1.0 / (1.0 + PointLightLinearDecay(i) * lightDistance +
  692. PointLightQuadraticDecay(i) * lightDistance * lightDistance);
  693. vec3 attenuatedColor = PointLightColor(i) * attenuation;
  694. // PBR
  695. color += pbrModel(pbrInputs, attenuatedColor, lightDirection);
  696. }
  697. #endif
  698. #if SPOT_LIGHTS>0
  699. for (int i = 0; i < SPOT_LIGHTS; i++) {
  700. // Calculates the direction and distance from the current vertex to this spot light.
  701. vec3 lightDirection = SpotLightPosition(i) - vec3(Position);
  702. float lightDistance = length(lightDirection);
  703. lightDirection = lightDirection / lightDistance;
  704. // Calculates the attenuation due to the distance of the light
  705. float attenuation = 1.0 / (1.0 + SpotLightLinearDecay(i) * lightDistance +
  706. SpotLightQuadraticDecay(i) * lightDistance * lightDistance);
  707. // Calculates the angle between the vertex direction and spot direction
  708. // If this angle is greater than the cutoff the spotlight will not contribute
  709. // to the final color.
  710. float angle = acos(dot(-lightDirection, SpotLightDirection(i)));
  711. float cutoff = radians(clamp(SpotLightCutoffAngle(i), 0.0, 90.0));
  712. if (angle < cutoff) {
  713. float spotFactor = pow(dot(-lightDirection, SpotLightDirection(i)), SpotLightAngularDecay(i));
  714. vec3 attenuatedColor = SpotLightColor(i) * attenuation * spotFactor;
  715. // PBR
  716. color += pbrModel(pbrInputs, attenuatedColor, lightDirection);
  717. }
  718. }
  719. #endif
  720. // Calculate lighting contribution from image based lighting source (IBL)
  721. //#ifdef USE_IBL
  722. // color += getIBLContribution(pbrInputs, n, reflection);
  723. //#endif
  724. // Apply optional PBR terms for additional (optional) shading
  725. #ifdef HAS_OCCLUSIONMAP
  726. float ao = texture2D(uOcclusionSampler, FragTexcoord).r;
  727. color = mix(color, color * ao, 1.0);//, uOcclusionStrength);
  728. #endif
  729. #ifdef HAS_EMISSIVEMAP
  730. vec3 emissive = SRGBtoLINEAR(texture2D(uEmissiveSampler, FragTexcoord)).rgb * vec3(uEmissiveColor);
  731. #else
  732. vec3 emissive = vec3(uEmissiveColor);
  733. #endif
  734. color += emissive;
  735. // Base Color
  736. // FragColor = baseColor;
  737. // Normal
  738. // FragColor = vec4(n, 1.0);
  739. // Emissive Color
  740. // FragColor = vec4(emissive, 1.0);
  741. // F
  742. // color = F;
  743. // G
  744. // color = vec3(G);
  745. // D
  746. // color = vec3(D);
  747. // Specular
  748. // color = specContrib;
  749. // Diffuse
  750. // color = diffuseContrib;
  751. // Roughness
  752. // color = vec3(perceptualRoughness);
  753. // Metallic
  754. // color = vec3(metallic);
  755. // Final fragment color
  756. FragColor = vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
  757. }
  758. `
  759. const physical_vertex_source = `//
  760. // Physically Based Shading of a microfacet surface material - Vertex Shader
  761. // Modified from reference implementation at https://github.com/KhronosGroup/glTF-WebGL-PBR
  762. //
  763. #include <attributes>
  764. // Model uniforms
  765. uniform mat4 ModelViewMatrix;
  766. uniform mat3 NormalMatrix;
  767. uniform mat4 MVP;
  768. // Output variables for Fragment shader
  769. out vec3 Position;
  770. out vec3 Normal;
  771. out vec3 CamDir;
  772. out vec2 FragTexcoord;
  773. void main() {
  774. // Transform this vertex position to camera coordinates.
  775. Position = vec3(ModelViewMatrix * vec4(VertexPosition, 1.0));
  776. // Transform this vertex normal to camera coordinates.
  777. Normal = normalize(NormalMatrix * VertexNormal);
  778. // Calculate the direction vector from the vertex to the camera
  779. // The camera is at 0,0,0
  780. CamDir = normalize(-Position.xyz);
  781. // Flips texture coordinate Y if requested.
  782. vec2 texcoord = VertexTexcoord;
  783. // #if MAT_TEXTURES>0
  784. // if (MatTexFlipY(0)) {
  785. // texcoord.y = 1 - texcoord.y;
  786. // }
  787. // #endif
  788. FragTexcoord = texcoord;
  789. gl_Position = MVP * vec4(VertexPosition, 1.0);
  790. }
  791. `
  792. const point_fragment_source = `#include <material>
  793. // GLSL 3.30 does not allow indexing texture sampler with non constant values.
  794. // This macro is used to mix the texture with the specified index with the material color.
  795. // It should be called for each texture index.
  796. #define MIX_POINT_TEXTURE(i) \
  797. if (MatTexVisible(i)) { \
  798. vec2 pt = gl_PointCoord - vec2(0.5); \
  799. vec4 texColor = texture(MatTexture[i], (Rotation * pt + vec2(0.5)) * MatTexRepeat(i) + MatTexOffset(i)); \
  800. if (i == 0) { \
  801. texMixed = texColor; \
  802. } else { \
  803. texMixed = mix(texMixed, texColor, texColor.a); \
  804. } \
  805. }
  806. // Inputs from vertex shader
  807. in vec3 Color;
  808. flat in mat2 Rotation;
  809. // Output
  810. out vec4 FragColor;
  811. void main() {
  812. // Mix material color with textures colors
  813. vec4 texMixed = vec4(1);
  814. #if MAT_TEXTURES==1
  815. MIX_POINT_TEXTURE(0)
  816. #elif MAT_TEXTURES==2
  817. MIX_POINT_TEXTURE(0)
  818. MIX_POINT_TEXTURE(1)
  819. #elif MAT_TEXTURES==3
  820. MIX_POINT_TEXTURE(0)
  821. MIX_POINT_TEXTURE(1)
  822. MIX_POINT_TEXTURE(2)
  823. #endif
  824. // Generates final color
  825. FragColor = min(vec4(Color, MatOpacity) * texMixed, vec4(1));
  826. }
  827. `
  828. const point_vertex_source = `#include <attributes>
  829. // Model uniforms
  830. uniform mat4 MVP;
  831. // Material uniforms
  832. #include <material>
  833. // Outputs for fragment shader
  834. out vec3 Color;
  835. flat out mat2 Rotation;
  836. void main() {
  837. // Rotation matrix for fragment shader
  838. float rotSin = sin(MatPointRotationZ);
  839. float rotCos = cos(MatPointRotationZ);
  840. Rotation = mat2(rotCos, rotSin, - rotSin, rotCos);
  841. // Sets the vertex position
  842. vec4 pos = MVP * vec4(VertexPosition, 1.0);
  843. gl_Position = pos;
  844. // Sets the size of the rasterized point decreasing with distance
  845. gl_PointSize = (1.0 - pos.z / pos.w) * MatPointSize;
  846. // Outputs color
  847. Color = MatEmissiveColor;
  848. }
  849. `
  850. const sprite_fragment_source = `//
  851. // Fragment shader for sprite
  852. //
  853. #include <material>
  854. // Inputs from vertex shader
  855. in vec3 Color;
  856. in vec2 FragTexcoord;
  857. // Output
  858. out vec4 FragColor;
  859. void main() {
  860. // Combine all texture colors and opacity
  861. vec4 texCombined = vec4(1);
  862. #if MAT_TEXTURES>0
  863. for (int i = 0; i < {{.MatTexturesMax}}; i++) {
  864. vec4 texcolor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i));
  865. if (i == 0) {
  866. texCombined = texcolor;
  867. } else {
  868. texCombined = mix(texCombined, texcolor, texcolor.a);
  869. }
  870. }
  871. #endif
  872. // Combine material color with texture
  873. FragColor = min(vec4(Color, MatOpacity) * texCombined, vec4(1));
  874. }
  875. `
  876. const sprite_vertex_source = `//
  877. // Vertex shader for sprites
  878. //
  879. #include <attributes>
  880. // Input uniforms
  881. uniform mat4 MVP;
  882. #include <material>
  883. // Outputs for fragment shader
  884. out vec3 Color;
  885. out vec2 FragTexcoord;
  886. void main() {
  887. // Applies transformation to vertex position
  888. gl_Position = MVP * vec4(VertexPosition, 1.0);
  889. // Outputs color
  890. Color = MatDiffuseColor;
  891. // Flips texture coordinate Y if requested.
  892. vec2 texcoord = VertexTexcoord;
  893. #if MAT_TEXTURES>0
  894. if (MatTexFlipY[0]) {
  895. texcoord.y = 1 - texcoord.y;
  896. }
  897. #endif
  898. FragTexcoord = texcoord;
  899. }
  900. `
  901. const standard_fragment_source = `//
  902. // Fragment Shader template
  903. //
  904. #include <material>
  905. // Inputs from Vertex shader
  906. in vec3 ColorFrontAmbdiff;
  907. in vec3 ColorFrontSpec;
  908. in vec3 ColorBackAmbdiff;
  909. in vec3 ColorBackSpec;
  910. in vec2 FragTexcoord;
  911. // Output
  912. out vec4 FragColor;
  913. void main() {
  914. // Mix material color with textures colors
  915. vec4 texMixed = vec4(1);
  916. vec4 texColor;
  917. #if MAT_TEXTURES==1
  918. MIX_TEXTURE(0)
  919. #elif MAT_TEXTURES==2
  920. MIX_TEXTURE(0)
  921. MIX_TEXTURE(1)
  922. #elif MAT_TEXTURES==3
  923. MIX_TEXTURE(0)
  924. MIX_TEXTURE(1)
  925. MIX_TEXTURE(2)
  926. #endif
  927. vec4 colorAmbDiff;
  928. vec4 colorSpec;
  929. if (gl_FrontFacing) {
  930. colorAmbDiff = vec4(ColorFrontAmbdiff, MatOpacity);
  931. colorSpec = vec4(ColorFrontSpec, 0);
  932. } else {
  933. colorAmbDiff = vec4(ColorBackAmbdiff, MatOpacity);
  934. colorSpec = vec4(ColorBackSpec, 0);
  935. }
  936. FragColor = min(colorAmbDiff * texMixed + colorSpec, vec4(1));
  937. }
  938. `
  939. const standard_vertex_source = `//
  940. // Vertex shader standard
  941. //
  942. #include <attributes>
  943. // Model uniforms
  944. uniform mat4 ModelViewMatrix;
  945. uniform mat3 NormalMatrix;
  946. uniform mat4 MVP;
  947. #include <lights>
  948. #include <material>
  949. #include <phong_model>
  950. // Outputs for the fragment shader.
  951. out vec3 ColorFrontAmbdiff;
  952. out vec3 ColorFrontSpec;
  953. out vec3 ColorBackAmbdiff;
  954. out vec3 ColorBackSpec;
  955. out vec2 FragTexcoord;
  956. void main() {
  957. // Transform this vertex normal to camera coordinates.
  958. vec3 normal = normalize(NormalMatrix * VertexNormal);
  959. // Calculate this vertex position in camera coordinates
  960. vec4 position = ModelViewMatrix * vec4(VertexPosition, 1.0);
  961. // Calculate the direction vector from the vertex to the camera
  962. // The camera is at 0,0,0
  963. vec3 camDir = normalize(-position.xyz);
  964. // Calculates the vertex Ambient+Diffuse and Specular colors using the Phong model
  965. // for the front and back
  966. phongModel(position, normal, camDir, MatAmbientColor, MatDiffuseColor, ColorFrontAmbdiff, ColorFrontSpec);
  967. phongModel(position, -normal, camDir, MatAmbientColor, MatDiffuseColor, ColorBackAmbdiff, ColorBackSpec);
  968. vec2 texcoord = VertexTexcoord;
  969. #if MAT_TEXTURES > 0
  970. // Flips texture coordinate Y if requested.
  971. if (MatTexFlipY(0)) {
  972. texcoord.y = 1 - texcoord.y;
  973. }
  974. #endif
  975. FragTexcoord = texcoord;
  976. gl_Position = MVP * vec4(VertexPosition, 1.0);
  977. }
  978. `
  979. // Maps include name with its source code
  980. var includeMap = map[string]string{
  981. "attributes": include_attributes_source,
  982. "lights": include_lights_source,
  983. "material": include_material_source,
  984. "phong_model": include_phong_model_source,
  985. }
  986. // Maps shader name with its source code
  987. var shaderMap = map[string]string{
  988. "basic_fragment": basic_fragment_source,
  989. "basic_vertex": basic_vertex_source,
  990. "panel_fragment": panel_fragment_source,
  991. "panel_vertex": panel_vertex_source,
  992. "phong_fragment": phong_fragment_source,
  993. "phong_vertex": phong_vertex_source,
  994. "physical_fragment": physical_fragment_source,
  995. "physical_vertex": physical_vertex_source,
  996. "point_fragment": point_fragment_source,
  997. "point_vertex": point_vertex_source,
  998. "sprite_fragment": sprite_fragment_source,
  999. "sprite_vertex": sprite_vertex_source,
  1000. "standard_fragment": standard_fragment_source,
  1001. "standard_vertex": standard_vertex_source,
  1002. }
  1003. // Maps program name with Proginfo struct with shaders names
  1004. var programMap = map[string]ProgramInfo{
  1005. "basic": {"basic_vertex", "basic_fragment", ""},
  1006. "panel": {"panel_vertex", "panel_fragment", ""},
  1007. "phong": {"phong_vertex", "phong_fragment", ""},
  1008. "physical": {"physical_vertex", "physical_fragment", ""},
  1009. "point": {"point_vertex", "point_fragment", ""},
  1010. "sprite": {"sprite_vertex", "sprite_fragment", ""},
  1011. "standard": {"standard_vertex", "standard_fragment", ""},
  1012. }