sources.go 39 KB

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