@luma.gl/shadertools 8.5.13 → 8.5.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.min.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +10 -10
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/assemble-shaders.js +6 -2
- package/dist/es5/lib/assemble-shaders.js.map +1 -1
- package/dist/es5/lib/constants.js +1 -1
- package/dist/es5/lib/constants.js.map +1 -1
- package/dist/es5/lib/filters/prop-types.js.map +1 -1
- package/dist/es5/lib/inject-shader.js +2 -2
- package/dist/es5/lib/inject-shader.js.map +1 -1
- package/dist/es5/lib/platform-defines.js.map +1 -1
- package/dist/es5/lib/resolve-modules.js +2 -2
- package/dist/es5/lib/resolve-modules.js.map +1 -1
- package/dist/es5/lib/shader-module.js +1 -1
- package/dist/es5/lib/shader-module.js.map +1 -1
- package/dist/es5/lib/transpile-shader.js +1 -1
- package/dist/es5/lib/transpile-shader.js.map +1 -1
- package/dist/es5/modules/dirlight/dirlight.js.map +1 -1
- package/dist/es5/modules/fp32/fp32.js.map +1 -1
- package/dist/es5/modules/fp64/fp64-arithmetic.glsl.js.map +1 -1
- package/dist/es5/modules/fp64/fp64-functions.glsl.js.map +1 -1
- package/dist/es5/modules/fp64/fp64-utils.js +1 -1
- package/dist/es5/modules/fp64/fp64-utils.js.map +1 -1
- package/dist/es5/modules/fp64/fp64.js +6 -5
- package/dist/es5/modules/fp64/fp64.js.map +1 -1
- package/dist/es5/modules/fxaa/fxaa.js.map +1 -1
- package/dist/es5/modules/geometry/geometry.js.map +1 -1
- package/dist/es5/modules/image-adjust-filters/brightnesscontrast.js.map +1 -1
- package/dist/es5/modules/image-adjust-filters/denoise.js.map +1 -1
- package/dist/es5/modules/image-adjust-filters/huesaturation.js.map +1 -1
- package/dist/es5/modules/image-adjust-filters/noise.js.map +1 -1
- package/dist/es5/modules/image-adjust-filters/sepia.js.map +1 -1
- package/dist/es5/modules/image-adjust-filters/vibrance.js.map +1 -1
- package/dist/es5/modules/image-adjust-filters/vignette.js.map +1 -1
- package/dist/es5/modules/image-blur-filters/tiltshift.js.map +1 -1
- package/dist/es5/modules/image-blur-filters/triangleblur.js.map +1 -1
- package/dist/es5/modules/image-blur-filters/zoomblur.js.map +1 -1
- package/dist/es5/modules/image-fun-filters/colorhalftone.js.map +1 -1
- package/dist/es5/modules/image-fun-filters/dotscreen.js.map +1 -1
- package/dist/es5/modules/image-fun-filters/edgework.js.map +1 -1
- package/dist/es5/modules/image-fun-filters/hexagonalpixelate.js.map +1 -1
- package/dist/es5/modules/image-fun-filters/ink.js.map +1 -1
- package/dist/es5/modules/image-fun-filters/magnify.js.map +1 -1
- package/dist/es5/modules/image-warp-filters/bulgepinch.js.map +1 -1
- package/dist/es5/modules/image-warp-filters/swirl.js.map +1 -1
- package/dist/es5/modules/image-warp-filters/warp.js.map +1 -1
- package/dist/es5/modules/index.js +62 -62
- package/dist/es5/modules/index.js.map +1 -1
- package/dist/es5/modules/lights/lights.glsl.js.map +1 -1
- package/dist/es5/modules/lights/lights.js +1 -1
- package/dist/es5/modules/lights/lights.js.map +1 -1
- package/dist/es5/modules/module-injectors.js +1 -1
- package/dist/es5/modules/module-injectors.js.map +1 -1
- package/dist/es5/modules/pbr/pbr-fragment.glsl.js.map +1 -1
- package/dist/es5/modules/pbr/pbr-vertex.glsl.js.map +1 -1
- package/dist/es5/modules/pbr/pbr.js.map +1 -1
- package/dist/es5/modules/phong-lighting/phong-lighting.glsl.js.map +1 -1
- package/dist/es5/modules/phong-lighting/phong-lighting.js.map +1 -1
- package/dist/es5/modules/picking/picking.js.map +1 -1
- package/dist/es5/modules/project/project.js.map +1 -1
- package/dist/es5/modules/transform/transform.js.map +1 -1
- package/dist/es5/modules/utils/random.js.map +1 -1
- package/dist/es5/utils/assert.js.map +1 -1
- package/dist/es5/utils/index.js.map +1 -1
- package/dist/es5/utils/is-old-ie.js.map +1 -1
- package/dist/es5/utils/shader-utils.js +3 -3
- package/dist/es5/utils/shader-utils.js.map +1 -1
- package/dist/es5/utils/webgl-info.js +2 -2
- package/dist/es5/utils/webgl-info.js.map +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/assemble-shaders.js +38 -51
- package/dist/esm/lib/assemble-shaders.js.map +1 -1
- package/dist/esm/lib/constants.js.map +1 -1
- package/dist/esm/lib/filters/prop-types.js.map +1 -1
- package/dist/esm/lib/inject-shader.js +4 -3
- package/dist/esm/lib/inject-shader.js.map +1 -1
- package/dist/esm/lib/platform-defines.js +9 -80
- package/dist/esm/lib/platform-defines.js.map +1 -1
- package/dist/esm/lib/resolve-modules.js +9 -7
- package/dist/esm/lib/resolve-modules.js.map +1 -1
- package/dist/esm/lib/shader-module.js +20 -23
- package/dist/esm/lib/shader-module.js.map +1 -1
- package/dist/esm/lib/transpile-shader.js +5 -5
- package/dist/esm/lib/transpile-shader.js.map +1 -1
- package/dist/esm/modules/dirlight/dirlight.js +3 -9
- package/dist/esm/modules/dirlight/dirlight.js.map +1 -1
- package/dist/esm/modules/fp32/fp32.js +1 -148
- package/dist/esm/modules/fp32/fp32.js.map +1 -1
- package/dist/esm/modules/fp64/fp64-arithmetic.glsl.js +1 -143
- package/dist/esm/modules/fp64/fp64-arithmetic.glsl.js.map +1 -1
- package/dist/esm/modules/fp64/fp64-functions.glsl.js +1 -630
- package/dist/esm/modules/fp64/fp64-functions.glsl.js.map +1 -1
- package/dist/esm/modules/fp64/fp64-utils.js +3 -1
- package/dist/esm/modules/fp64/fp64-utils.js.map +1 -1
- package/dist/esm/modules/fp64/fp64.js.map +1 -1
- package/dist/esm/modules/fxaa/fxaa.js +1 -535
- package/dist/esm/modules/fxaa/fxaa.js.map +1 -1
- package/dist/esm/modules/geometry/geometry.js +2 -28
- package/dist/esm/modules/geometry/geometry.js.map +1 -1
- package/dist/esm/modules/image-adjust-filters/brightnesscontrast.js +1 -18
- package/dist/esm/modules/image-adjust-filters/brightnesscontrast.js.map +1 -1
- package/dist/esm/modules/image-adjust-filters/denoise.js +1 -22
- package/dist/esm/modules/image-adjust-filters/denoise.js.map +1 -1
- package/dist/esm/modules/image-adjust-filters/huesaturation.js +1 -28
- package/dist/esm/modules/image-adjust-filters/huesaturation.js.map +1 -1
- package/dist/esm/modules/image-adjust-filters/noise.js +1 -19
- package/dist/esm/modules/image-adjust-filters/noise.js.map +1 -1
- package/dist/esm/modules/image-adjust-filters/sepia.js +1 -20
- package/dist/esm/modules/image-adjust-filters/sepia.js.map +1 -1
- package/dist/esm/modules/image-adjust-filters/vibrance.js +1 -15
- package/dist/esm/modules/image-adjust-filters/vibrance.js.map +1 -1
- package/dist/esm/modules/image-adjust-filters/vignette.js +1 -14
- package/dist/esm/modules/image-adjust-filters/vignette.js.map +1 -1
- package/dist/esm/modules/image-blur-filters/tiltshift.js +1 -37
- package/dist/esm/modules/image-blur-filters/tiltshift.js.map +1 -1
- package/dist/esm/modules/image-blur-filters/triangleblur.js +1 -27
- package/dist/esm/modules/image-blur-filters/triangleblur.js.map +1 -1
- package/dist/esm/modules/image-blur-filters/zoomblur.js +1 -26
- package/dist/esm/modules/image-blur-filters/zoomblur.js.map +1 -1
- package/dist/esm/modules/image-fun-filters/colorhalftone.js +1 -34
- package/dist/esm/modules/image-fun-filters/colorhalftone.js.map +1 -1
- package/dist/esm/modules/image-fun-filters/dotscreen.js +1 -22
- package/dist/esm/modules/image-fun-filters/dotscreen.js.map +1 -1
- package/dist/esm/modules/image-fun-filters/edgework.js +1 -50
- package/dist/esm/modules/image-fun-filters/edgework.js.map +1 -1
- package/dist/esm/modules/image-fun-filters/hexagonalpixelate.js +1 -42
- package/dist/esm/modules/image-fun-filters/hexagonalpixelate.js.map +1 -1
- package/dist/esm/modules/image-fun-filters/ink.js +1 -27
- package/dist/esm/modules/image-fun-filters/ink.js.map +1 -1
- package/dist/esm/modules/image-fun-filters/magnify.js +1 -20
- package/dist/esm/modules/image-fun-filters/magnify.js.map +1 -1
- package/dist/esm/modules/image-warp-filters/bulgepinch.js +1 -27
- package/dist/esm/modules/image-warp-filters/bulgepinch.js.map +1 -1
- package/dist/esm/modules/image-warp-filters/swirl.js +1 -29
- package/dist/esm/modules/image-warp-filters/swirl.js.map +1 -1
- package/dist/esm/modules/image-warp-filters/warp.js +1 -11
- package/dist/esm/modules/image-warp-filters/warp.js.map +1 -1
- package/dist/esm/modules/index.js.map +1 -1
- package/dist/esm/modules/lights/lights.glsl.js +1 -34
- package/dist/esm/modules/lights/lights.glsl.js.map +1 -1
- package/dist/esm/modules/lights/lights.js +19 -15
- package/dist/esm/modules/lights/lights.js.map +1 -1
- package/dist/esm/modules/module-injectors.js +2 -27
- package/dist/esm/modules/module-injectors.js.map +1 -1
- package/dist/esm/modules/pbr/pbr-fragment.glsl.js +1 -351
- package/dist/esm/modules/pbr/pbr-fragment.glsl.js.map +1 -1
- package/dist/esm/modules/pbr/pbr-vertex.glsl.js +1 -39
- package/dist/esm/modules/pbr/pbr-vertex.glsl.js.map +1 -1
- package/dist/esm/modules/pbr/pbr.js.map +1 -1
- package/dist/esm/modules/phong-lighting/phong-lighting.glsl.js +1 -75
- package/dist/esm/modules/phong-lighting/phong-lighting.glsl.js.map +1 -1
- package/dist/esm/modules/phong-lighting/phong-lighting.js +3 -1
- package/dist/esm/modules/phong-lighting/phong-lighting.js.map +1 -1
- package/dist/esm/modules/picking/picking.js +4 -87
- package/dist/esm/modules/picking/picking.js.map +1 -1
- package/dist/esm/modules/project/project.js +6 -69
- package/dist/esm/modules/project/project.js.map +1 -1
- package/dist/esm/modules/transform/transform.js +1 -28
- package/dist/esm/modules/transform/transform.js.map +1 -1
- package/dist/esm/modules/utils/random.js +1 -5
- package/dist/esm/modules/utils/random.js.map +1 -1
- package/dist/esm/utils/assert.js.map +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/is-old-ie.js +2 -1
- package/dist/esm/utils/is-old-ie.js.map +1 -1
- package/dist/esm/utils/shader-utils.js +11 -24
- package/dist/esm/utils/shader-utils.js.map +1 -1
- package/dist/esm/utils/webgl-info.js +3 -2
- package/dist/esm/utils/webgl-info.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"webgl-info.js","names":["GL_VENDOR","GL_RENDERER","GL_VERSION","GL_SHADING_LANGUAGE_VERSION","WEBGL_FEATURES","GLSL_FRAG_DATA","GLSL_FRAG_DEPTH","GLSL_DERIVATIVES","GLSL_TEXTURE_LOD","FEATURES","Object","keys","forEach","key","isWebGL2","gl","WebGL2RenderingContext","Boolean","_version","getContextInfo","info","getExtension","vendor","getParameter","UNMASKED_VENDOR_WEBGL","renderer","UNMASKED_RENDERER_WEBGL","gpuVendor","identifyGPUVendor","gpuInfo","version","shadingLanguageVersion","match","compiledGlslExtensions","canCompileGLGSExtension","cap","opts","feature","assert","isOldIE","extensionName","behavior","source","shader","createShader","shaderSource","compileShader","canCompile","getShaderParameter","deleteShader","getFeature","value","hasFeatures","features","Array","isArray","every"],"sources":["../../../src/utils/webgl-info.js"],"sourcesContent":["// Feature detection for WebGL\n//\n// Provides a function that enables simple checking of which WebGL features are\n// available in an WebGL1 or WebGL2 environment.\n\n/* eslint-disable no-inline-comments, max-len */\nimport isOldIE from './is-old-ie';\nimport assert from './assert';\n\nconst GL_VENDOR = 0x1f00;\nconst GL_RENDERER = 0x1f01;\nconst GL_VERSION = 0x1f02;\nconst GL_SHADING_LANGUAGE_VERSION = 0x8b8c;\n\n// Defines luma.gl \"feature\" names and semantics\nconst WEBGL_FEATURES = {\n // GLSL extensions\n GLSL_FRAG_DATA: ['WEBGL_draw_buffers', true], // TODO - name makes no sense in GLSL 3.00\n GLSL_FRAG_DEPTH: ['EXT_frag_depth', true],\n GLSL_DERIVATIVES: ['OES_standard_derivatives', true],\n GLSL_TEXTURE_LOD: ['EXT_shader_texture_lod', true]\n};\n\n// Create a key-mirrored FEATURES array\nconst FEATURES = {};\nObject.keys(WEBGL_FEATURES).forEach(key => {\n FEATURES[key] = key;\n});\n\nexport {FEATURES};\n\nfunction isWebGL2(gl) {\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n return Boolean(gl && gl._version === 2);\n}\n\nexport function getContextInfo(gl) {\n const info = gl.getExtension('WEBGL_debug_renderer_info');\n const vendor = gl.getParameter((info && info.UNMASKED_VENDOR_WEBGL) || GL_VENDOR);\n const renderer = gl.getParameter((info && info.UNMASKED_RENDERER_WEBGL) || GL_RENDERER);\n const gpuVendor = identifyGPUVendor(vendor, renderer);\n const gpuInfo = {\n gpuVendor,\n vendor,\n renderer,\n version: gl.getParameter(GL_VERSION),\n shadingLanguageVersion: gl.getParameter(GL_SHADING_LANGUAGE_VERSION)\n };\n return gpuInfo;\n}\n\nfunction identifyGPUVendor(vendor, renderer) {\n if (vendor.match(/NVIDIA/i) || renderer.match(/NVIDIA/i)) {\n return 'NVIDIA';\n }\n if (vendor.match(/INTEL/i) || renderer.match(/INTEL/i)) {\n return 'INTEL';\n }\n if (\n vendor.match(/AMD/i) ||\n renderer.match(/AMD/i) ||\n vendor.match(/ATI/i) ||\n renderer.match(/ATI/i)\n ) {\n return 'AMD';\n }\n return 'UNKNOWN GPU';\n}\n\nconst compiledGlslExtensions = {};\n\n// Enables feature detection in IE11 due to a bug where gl.getExtension may return true\n// but fail to compile when the extension is enabled in the shader. Specifically,\n// the OES_standard_derivatives and WEBGL_draw_buffers extensions fails to compile in IE11 even though its included\n// in the list of supported extensions.\n// opts allows user agent to be overridden for testing\n/*\n* Inputs :\n* gl : WebGL context\n* cap : Key of WEBGL_FEATURES object identifying the extension\n* opts :\n* behavior : behavior of extension to be tested, by defualt `enable` is used\n* Returns : true, if shader is compiled successfully, false otherwise\n*/\nexport function canCompileGLGSExtension(gl, cap, opts = {}) {\n const feature = WEBGL_FEATURES[cap];\n assert(feature, cap);\n\n if (!isOldIE(opts)) {\n return true;\n }\n\n if (cap in compiledGlslExtensions) {\n return compiledGlslExtensions[cap];\n }\n\n const extensionName = feature[0];\n const behavior = opts.behavior || 'enable';\n const source = `#extension GL_${extensionName} : ${behavior}\\nvoid main(void) {}`;\n\n const shader = gl.createShader(gl.VERTEX_SHADER);\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);\n gl.deleteShader(shader);\n compiledGlslExtensions[cap] = canCompile;\n return canCompile;\n}\n\n// TODO - cache the value\nfunction getFeature(gl, cap) {\n const feature = WEBGL_FEATURES[cap];\n assert(feature, cap);\n\n // Get extension name from table\n const extensionName = isWebGL2(gl) ? feature[1] || feature[0] : feature[0];\n\n // Check if the value is dependent on checking an extension\n const value =\n typeof extensionName === 'string' ? Boolean(gl.getExtension(extensionName)) : extensionName;\n\n assert(value === false || value === true);\n\n return value;\n}\n\nexport function hasFeatures(gl, features) {\n features = Array.isArray(features) ? features : [features];\n return features.every(feature => getFeature(gl, feature));\n}\n"],"mappings":";;;;;;;;;;;;AAMA;;AACA;;AAEA,IAAMA,SAAS,GAAG,MAAlB;AACA,IAAMC,WAAW,GAAG,MAApB;AACA,IAAMC,UAAU,GAAG,MAAnB;AACA,IAAMC,2BAA2B,GAAG,MAApC;AAGA,IAAMC,cAAc,GAAG;EAErBC,cAAc,EAAE,CAAC,oBAAD,EAAuB,IAAvB,CAFK;EAGrBC,eAAe,EAAE,CAAC,gBAAD,EAAmB,IAAnB,CAHI;EAIrBC,gBAAgB,EAAE,CAAC,0BAAD,EAA6B,IAA7B,CAJG;EAKrBC,gBAAgB,EAAE,CAAC,wBAAD,EAA2B,IAA3B;AALG,CAAvB;AASA,IAAMC,QAAQ,GAAG,EAAjB;;AACAC,MAAM,CAACC,IAAP,CAAYP,cAAZ,EAA4BQ,OAA5B,CAAoC,UAAAC,GAAG,EAAI;EACzCJ,QAAQ,CAACI,GAAD,CAAR,GAAgBA,GAAhB;AACD,CA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AAgBF,GAAhB;EAGA,IAAMK,aAAa,GAAG1B,QAAQ,CAACC,EAAD,CAAR,GAAesB,OAAO,CAAC,CAAD,CAAP,IAAcA,OAAO,CAAC,CAAD,CAApC,GAA0CA,OAAO,CAAC,CAAD,CAAvE;EAGA,IAAMc,KAAK,GACT,OAAOX,aAAP,KAAyB,QAAzB,GAAoCvB,OAAO,CAACF,EAAE,CAACM,YAAH,CAAgBmB,aAAhB,CAAD,CAA3C,GAA8EA,aADhF;EAGA,IAAAF,eAAA,EAAOa,KAAK,KAAK,KAAV,IAAmBA,KAAK,KAAK,IAApC;EAEA,OAAOA,KAAP;AACD;;AAEM,SAASC,WAAT,CAAqBrC,EAArB,EAAyBsC,QAAzB,EAAmC;EACxCA,QAAQ,GAAGC,KAAK,CAACC,OAAN,CAAcF,QAAd,IAA0BA,QAA1B,GAAqC,CAACA,QAAD,CAAhD;EACA,OAAOA,QAAQ,CAACG,KAAT,CAAe,UAAAnB,OAAO;IAAA,OAAIa,UAAU,CAACnC,EAAD,EAAKsB,OAAL,CAAd;EAAA,CAAtB,CAAP;AACD"}
|
package/dist/esm/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","luma","module","exports","Object","assign"],"sources":["../../src/bundle.js"],"sourcesContent":["const moduleExports = require('./index');\n\n// @ts-ignore\nglobalThis.luma = globalThis.luma || {};\n// @ts-ignore\nmodule.exports = Object.assign(globalThis.luma, moduleExports);\n"],"mappings":"AAAA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AAGAC,UAAU,CAACC,IAAX,GAAkBD,UAAU,CAACC,IAAX,IAAmB,EAArC;AAEAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,IAAzB,EAA+BH,aAA/B,CAAjB"}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["assembleShaders","combineInjects","normalizeShaderModule","getQualifierDetails","getPassthroughFS","typeToChannelSuffix","typeToChannelCount","convertToVec4"],"sources":["../../src/index.js"],"sourcesContent":["// shadertools exports\n\n// DOCUMENTED APIS\nexport {assembleShaders} from './lib/assemble-shaders';\n\n// HELPERS\nexport {combineInjects} from './lib/inject-shader';\nexport {normalizeShaderModule} from './lib/shader-module';\n\n// UTILS\nexport {\n getQualifierDetails,\n getPassthroughFS,\n typeToChannelSuffix,\n typeToChannelCount,\n convertToVec4\n} from './utils/shader-utils';\n\n// SHADER MODULES\nexport * from './modules';\n"],"mappings":"AAGA,SAAQA,eAAR,QAA8B,wBAA9B;AAGA,SAAQC,cAAR,QAA6B,qBAA7B;AACA,SAAQC,qBAAR,QAAoC,qBAApC;AAGA,SACEC,mBADF,EAEEC,gBAFF,EAGEC,mBAHF,EAIEC,kBAJF,EAKEC,aALF,QAMO,sBANP;AASA,cAAc,WAAd"}
|
|
@@ -4,15 +4,12 @@ import { getPlatformShaderDefines, getVersionDefines } from './platform-defines'
|
|
|
4
4
|
import injectShader, { DECLARATION_INJECT_MARKER } from './inject-shader';
|
|
5
5
|
import transpileShader from './transpile-shader';
|
|
6
6
|
import { assert } from '../utils';
|
|
7
|
-
const INJECT_SHADER_DECLARATIONS =
|
|
7
|
+
const INJECT_SHADER_DECLARATIONS = "\n\n".concat(DECLARATION_INJECT_MARKER, "\n\n");
|
|
8
8
|
const SHADER_TYPE = {
|
|
9
9
|
[VERTEX_SHADER]: 'vertex',
|
|
10
10
|
[FRAGMENT_SHADER]: 'fragment'
|
|
11
11
|
};
|
|
12
|
-
const FRAGMENT_SHADER_PROLOGUE =
|
|
13
|
-
precision highp float;
|
|
14
|
-
|
|
15
|
-
`;
|
|
12
|
+
const FRAGMENT_SHADER_PROLOGUE = "precision highp float;\n\n";
|
|
16
13
|
export function assembleShaders(gl, opts) {
|
|
17
14
|
const {
|
|
18
15
|
vs,
|
|
@@ -35,18 +32,19 @@ export function assembleShaders(gl, opts) {
|
|
|
35
32
|
};
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
function assembleShader(gl, {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
function assembleShader(gl, _ref) {
|
|
36
|
+
let {
|
|
37
|
+
id,
|
|
38
|
+
source,
|
|
39
|
+
type,
|
|
40
|
+
modules,
|
|
41
|
+
defines = {},
|
|
42
|
+
hookFunctions = [],
|
|
43
|
+
inject = {},
|
|
44
|
+
transpileToGLSL100 = false,
|
|
45
|
+
prologue = true,
|
|
46
|
+
log
|
|
47
|
+
} = _ref;
|
|
50
48
|
assert(typeof source === 'string', 'shader source must be a string');
|
|
51
49
|
const isVertex = type === VERTEX_SHADER;
|
|
52
50
|
const sourceLines = source.split('\n');
|
|
@@ -59,7 +57,7 @@ function assembleShader(gl, {
|
|
|
59
57
|
versionLine = sourceLines[0];
|
|
60
58
|
coreSource = sourceLines.slice(1).join('\n');
|
|
61
59
|
} else {
|
|
62
|
-
versionLine =
|
|
60
|
+
versionLine = "#version ".concat(glslVersion);
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
const allDefines = {};
|
|
@@ -67,22 +65,13 @@ function assembleShader(gl, {
|
|
|
67
65
|
Object.assign(allDefines, module.getDefines());
|
|
68
66
|
});
|
|
69
67
|
Object.assign(allDefines, defines);
|
|
70
|
-
let assembledSource = prologue ?
|
|
71
|
-
${versionLine}
|
|
72
|
-
${getShaderName({
|
|
68
|
+
let assembledSource = prologue ? "".concat(versionLine, "\n").concat(getShaderName({
|
|
73
69
|
id,
|
|
74
70
|
source,
|
|
75
71
|
type
|
|
76
|
-
})
|
|
77
|
-
${getShaderType({
|
|
72
|
+
}), "\n").concat(getShaderType({
|
|
78
73
|
type
|
|
79
|
-
})
|
|
80
|
-
${getPlatformShaderDefines(gl)}
|
|
81
|
-
${getVersionDefines(gl, glslVersion, !isVertex)}
|
|
82
|
-
${getApplicationDefines(allDefines)}
|
|
83
|
-
${isVertex ? '' : FRAGMENT_SHADER_PROLOGUE}
|
|
84
|
-
` : `${versionLine}
|
|
85
|
-
`;
|
|
74
|
+
}), "\n").concat(getPlatformShaderDefines(gl), "\n").concat(getVersionDefines(gl, glslVersion, !isVertex), "\n").concat(getApplicationDefines(allDefines), "\n").concat(isVertex ? '' : FRAGMENT_SHADER_PROLOGUE, "\n") : "".concat(versionLine, "\n");
|
|
86
75
|
const hookFunctionMap = normalizeHookFunctions(hookFunctions);
|
|
87
76
|
const hookInjections = {};
|
|
88
77
|
const declInjections = {};
|
|
@@ -159,27 +148,25 @@ function assembleGetUniforms(modules) {
|
|
|
159
148
|
};
|
|
160
149
|
}
|
|
161
150
|
|
|
162
|
-
function getShaderType({
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
#define SHADER_TYPE_
|
|
167
|
-
`;
|
|
151
|
+
function getShaderType(_ref2) {
|
|
152
|
+
let {
|
|
153
|
+
type
|
|
154
|
+
} = _ref2;
|
|
155
|
+
return "\n#define SHADER_TYPE_".concat(SHADER_TYPE[type].toUpperCase(), "\n");
|
|
168
156
|
}
|
|
169
157
|
|
|
170
|
-
function getShaderName({
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
158
|
+
function getShaderName(_ref3) {
|
|
159
|
+
let {
|
|
160
|
+
id,
|
|
161
|
+
source,
|
|
162
|
+
type
|
|
163
|
+
} = _ref3;
|
|
175
164
|
const injectShaderName = id && typeof id === 'string' && source.indexOf('SHADER_NAME') === -1;
|
|
176
|
-
return injectShaderName ?
|
|
177
|
-
#define SHADER_NAME ${id}_${SHADER_TYPE[type]}
|
|
178
|
-
|
|
179
|
-
` : '';
|
|
165
|
+
return injectShaderName ? "\n#define SHADER_NAME ".concat(id, "_").concat(SHADER_TYPE[type], "\n\n") : '';
|
|
180
166
|
}
|
|
181
167
|
|
|
182
|
-
function getApplicationDefines(
|
|
168
|
+
function getApplicationDefines() {
|
|
169
|
+
let defines = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
183
170
|
let count = 0;
|
|
184
171
|
let sourceText = '';
|
|
185
172
|
|
|
@@ -192,7 +179,7 @@ function getApplicationDefines(defines = {}) {
|
|
|
192
179
|
const value = defines[define];
|
|
193
180
|
|
|
194
181
|
if (value || Number.isFinite(value)) {
|
|
195
|
-
sourceText +=
|
|
182
|
+
sourceText += "#define ".concat(define.toUpperCase(), " ").concat(defines[define], "\n");
|
|
196
183
|
}
|
|
197
184
|
}
|
|
198
185
|
|
|
@@ -208,10 +195,10 @@ function getHookFunctions(hookFunctions, hookInjections) {
|
|
|
208
195
|
|
|
209
196
|
for (const hookName in hookFunctions) {
|
|
210
197
|
const hookFunction = hookFunctions[hookName];
|
|
211
|
-
result +=
|
|
198
|
+
result += "void ".concat(hookFunction.signature, " {\n");
|
|
212
199
|
|
|
213
200
|
if (hookFunction.header) {
|
|
214
|
-
result +=
|
|
201
|
+
result += " ".concat(hookFunction.header);
|
|
215
202
|
}
|
|
216
203
|
|
|
217
204
|
if (hookInjections[hookName]) {
|
|
@@ -219,12 +206,12 @@ function getHookFunctions(hookFunctions, hookInjections) {
|
|
|
219
206
|
injections.sort((a, b) => a.order - b.order);
|
|
220
207
|
|
|
221
208
|
for (const injection of injections) {
|
|
222
|
-
result +=
|
|
209
|
+
result += " ".concat(injection.injection, "\n");
|
|
223
210
|
}
|
|
224
211
|
}
|
|
225
212
|
|
|
226
213
|
if (hookFunction.footer) {
|
|
227
|
-
result +=
|
|
214
|
+
result += " ".concat(hookFunction.footer);
|
|
228
215
|
}
|
|
229
216
|
|
|
230
217
|
result += '}\n';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/assemble-shaders.js"],"names":["VERTEX_SHADER","FRAGMENT_SHADER","resolveModules","getPlatformShaderDefines","getVersionDefines","injectShader","DECLARATION_INJECT_MARKER","transpileShader","assert","INJECT_SHADER_DECLARATIONS","SHADER_TYPE","FRAGMENT_SHADER_PROLOGUE","assembleShaders","gl","opts","vs","fs","modules","assembleShader","Object","assign","source","type","getUniforms","assembleGetUniforms","id","defines","hookFunctions","inject","transpileToGLSL100","prologue","log","isVertex","sourceLines","split","glslVersion","versionLine","coreSource","indexOf","slice","join","allDefines","forEach","module","getDefines","assembledSource","getShaderName","getShaderType","getApplicationDefines","hookFunctionMap","normalizeHookFunctions","hookInjections","declInjections","mainInjections","key","injection","order","match","hash","name","checkDeprecations","moduleSource","getModuleSource","injections","injectionType","push","getHookFunctions","uniforms","moduleUniforms","toUpperCase","injectShaderName","count","sourceText","define","value","Number","isFinite","result","hookName","hookFunction","signature","header","sort","a","b","footer","hook","trim","stage","replace"],"mappings":"AAAA,SAAQA,aAAR,EAAuBC,eAAvB,QAA6C,aAA7C;AACA,SAAQC,cAAR,QAA6B,mBAA7B;AACA,SAAQC,wBAAR,EAAkCC,iBAAlC,QAA0D,oBAA1D;AACA,OAAOC,YAAP,IAAsBC,yBAAtB,QAAsD,iBAAtD;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AACA,SAAQC,MAAR,QAAqB,UAArB;AAEA,MAAMC,0BAA0B,GAAI,OAAMH,yBAA0B,MAApE;AAEA,MAAMI,WAAW,GAAG;AAClB,GAACV,aAAD,GAAiB,QADC;AAElB,GAACC,eAAD,GAAmB;AAFD,CAApB;AAOA,MAAMU,wBAAwB,GAAI;AAClC;AACA;AACA,CAHA;AAMA,OAAO,SAASC,eAAT,CAAyBC,EAAzB,EAA6BC,IAA7B,EAAmC;AACxC,QAAM;AAACC,IAAAA,EAAD;AAAKC,IAAAA;AAAL,MAAWF,IAAjB;AACA,QAAMG,OAAO,GAAGf,cAAc,CAACY,IAAI,CAACG,OAAL,IAAgB,EAAjB,CAA9B;AACA,SAAO;AACLJ,IAAAA,EADK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IAAAA,IAAI,GAAGA,IAAI,CAACC,IAAL,EAAP;AACA,UAAM,CAACC,KAAD,EAAQR,SAAR,IAAqBM,IAAI,CAACpD,KAAL,CAAW,GAAX,CAA3B;AACA,UAAMyB,IAAI,GAAG2B,IAAI,CAACG,OAAL,CAAa,MAAb,EAAqB,EAArB,CAAb;AACAZ,IAAAA,MAAM,CAACW,KAAD,CAAN,CAAc7B,IAAd,IAAsBxC,MAAM,CAACC,MAAP,CAAcN,IAAd,EAAoB;AAACkE,MAAAA;AAAD,KAApB,CAAtB;AACD,GAZD;AAcA,SAAOH,MAAP;AACD","sourcesContent":["import {VERTEX_SHADER, FRAGMENT_SHADER} from './constants';\nimport {resolveModules} from './resolve-modules';\nimport {getPlatformShaderDefines, getVersionDefines} from './platform-defines';\nimport injectShader, {DECLARATION_INJECT_MARKER} from './inject-shader';\nimport transpileShader from './transpile-shader';\nimport {assert} from '../utils';\n\nconst INJECT_SHADER_DECLARATIONS = `\\n\\n${DECLARATION_INJECT_MARKER}\\n\\n`;\n\nconst SHADER_TYPE = {\n [VERTEX_SHADER]: 'vertex',\n [FRAGMENT_SHADER]: 'fragment'\n};\n\n// Precision prologue to inject before functions are injected in shader\n// TODO - extract any existing prologue in the fragment source and move it up...\nconst FRAGMENT_SHADER_PROLOGUE = `\\\nprecision highp float;\n\n`;\n\n// Inject a list of modules\nexport function assembleShaders(gl, opts) {\n const {vs, fs} = opts;\n const modules = resolveModules(opts.modules || []);\n return {\n gl,\n vs: assembleShader(gl, Object.assign({}, opts, {source: vs, type: VERTEX_SHADER, modules})),\n fs: assembleShader(gl, Object.assign({}, opts, {source: fs, type: FRAGMENT_SHADER, modules})),\n getUniforms: assembleGetUniforms(modules)\n };\n}\n\n// Pulls together complete source code for either a vertex or a fragment shader\n// adding prologues, requested module chunks, and any final injections.\nfunction assembleShader(\n gl,\n {\n id,\n source,\n type,\n modules,\n defines = {},\n hookFunctions = [],\n inject = {},\n transpileToGLSL100 = false,\n prologue = true,\n log\n }\n) {\n assert(typeof source === 'string', 'shader source must be a string');\n\n const isVertex = type === VERTEX_SHADER;\n\n const sourceLines = source.split('\\n');\n let glslVersion = 100;\n let versionLine = '';\n let coreSource = source;\n // Extract any version directive string from source.\n // TODO : keep all pre-processor statements at the begining of the shader.\n if (sourceLines[0].indexOf('#version ') === 0) {\n glslVersion = 300; // TODO - regexp that matches actual version number\n versionLine = sourceLines[0];\n coreSource = sourceLines.slice(1).join('\\n');\n } else {\n versionLine = `#version ${glslVersion}`;\n }\n\n // Combine Module and Application Defines\n const allDefines = {};\n modules.forEach(module => {\n Object.assign(allDefines, module.getDefines());\n });\n Object.assign(allDefines, defines);\n\n // Add platform defines (use these to work around platform-specific bugs and limitations)\n // Add common defines (GLSL version compatibility, feature detection)\n // Add precision declaration for fragment shaders\n let assembledSource = prologue\n ? `\\\n${versionLine}\n${getShaderName({id, source, type})}\n${getShaderType({type})}\n${getPlatformShaderDefines(gl)}\n${getVersionDefines(gl, glslVersion, !isVertex)}\n${getApplicationDefines(allDefines)}\n${isVertex ? '' : FRAGMENT_SHADER_PROLOGUE}\n`\n : `${versionLine}\n`;\n\n const hookFunctionMap = normalizeHookFunctions(hookFunctions);\n\n // Add source of dependent modules in resolved order\n const hookInjections = {};\n const declInjections = {};\n const mainInjections = {};\n\n for (const key in inject) {\n const injection =\n typeof inject[key] === 'string' ? {injection: inject[key], order: 0} : inject[key];\n const match = key.match(/^(v|f)s:(#)?([\\w-]+)$/);\n if (match) {\n const hash = match[2];\n const name = match[3];\n if (hash) {\n if (name === 'decl') {\n declInjections[key] = [injection];\n } else {\n mainInjections[key] = [injection];\n }\n } else {\n hookInjections[key] = [injection];\n }\n } else {\n // Regex injection\n mainInjections[key] = [injection];\n }\n }\n\n for (const module of modules) {\n if (log) {\n module.checkDeprecations(coreSource, log);\n }\n const moduleSource = module.getModuleSource(type, glslVersion);\n // Add the module source, and a #define that declares it presence\n assembledSource += moduleSource;\n\n const injections = module.injections[type];\n for (const key in injections) {\n const match = key.match(/^(v|f)s:#([\\w-]+)$/);\n if (match) {\n const name = match[2];\n const injectionType = name === 'decl' ? declInjections : mainInjections;\n injectionType[key] = injectionType[key] || [];\n injectionType[key].push(injections[key]);\n } else {\n hookInjections[key] = hookInjections[key] || [];\n hookInjections[key].push(injections[key]);\n }\n }\n }\n\n // For injectShader\n assembledSource += INJECT_SHADER_DECLARATIONS;\n\n assembledSource = injectShader(assembledSource, type, declInjections);\n\n assembledSource += getHookFunctions(hookFunctionMap[type], hookInjections);\n\n // Add the version directive and actual source of this shader\n assembledSource += coreSource;\n\n // Apply any requested shader injections\n assembledSource = injectShader(assembledSource, type, mainInjections);\n\n assembledSource = transpileShader(\n assembledSource,\n transpileToGLSL100 ? 100 : glslVersion,\n isVertex\n );\n\n return assembledSource;\n}\n\n// Returns a combined `getUniforms` covering the options for all the modules,\n// the created function will pass on options to the inidividual `getUniforms`\n// function of each shader module and combine the results into one object that\n// can be passed to setUniforms.\nfunction assembleGetUniforms(modules) {\n return function getUniforms(opts) {\n const uniforms = {};\n for (const module of modules) {\n // `modules` is already sorted by dependency level. This guarantees that\n // modules have access to the uniforms that are generated by their dependencies.\n const moduleUniforms = module.getUniforms(opts, uniforms);\n Object.assign(uniforms, moduleUniforms);\n }\n return uniforms;\n };\n}\n\nfunction getShaderType({type}) {\n return `\n#define SHADER_TYPE_${SHADER_TYPE[type].toUpperCase()}\n`;\n}\n\n// Generate \"glslify-compatible\" SHADER_NAME defines\n// These are understood by the GLSL error parsing function\n// If id is provided and no SHADER_NAME constant is present in source, create one\nfunction getShaderName({id, source, type}) {\n const injectShaderName = id && typeof id === 'string' && source.indexOf('SHADER_NAME') === -1;\n return injectShaderName\n ? `\n#define SHADER_NAME ${id}_${SHADER_TYPE[type]}\n\n`\n : '';\n}\n\n// Generates application defines from an object\nfunction getApplicationDefines(defines = {}) {\n let count = 0;\n let sourceText = '';\n for (const define in defines) {\n if (count === 0) {\n sourceText += '\\n// APPLICATION DEFINES\\n';\n }\n count++;\n\n const value = defines[define];\n if (value || Number.isFinite(value)) {\n sourceText += `#define ${define.toUpperCase()} ${defines[define]}\\n`;\n }\n }\n if (count === 0) {\n sourceText += '\\n';\n }\n return sourceText;\n}\n\nfunction getHookFunctions(hookFunctions, hookInjections) {\n let result = '';\n for (const hookName in hookFunctions) {\n const hookFunction = hookFunctions[hookName];\n result += `void ${hookFunction.signature} {\\n`;\n if (hookFunction.header) {\n result += ` ${hookFunction.header}`;\n }\n if (hookInjections[hookName]) {\n const injections = hookInjections[hookName];\n injections.sort((a, b) => a.order - b.order);\n for (const injection of injections) {\n result += ` ${injection.injection}\\n`;\n }\n }\n if (hookFunction.footer) {\n result += ` ${hookFunction.footer}`;\n }\n result += '}\\n';\n }\n\n return result;\n}\n\nfunction normalizeHookFunctions(hookFunctions) {\n const result = {\n vs: {},\n fs: {}\n };\n\n hookFunctions.forEach(hook => {\n let opts;\n if (typeof hook !== 'string') {\n opts = hook;\n hook = opts.hook;\n } else {\n opts = {};\n }\n hook = hook.trim();\n const [stage, signature] = hook.split(':');\n const name = hook.replace(/\\(.+/, '');\n result[stage][name] = Object.assign(opts, {signature});\n });\n\n return result;\n}\n"],"file":"assemble-shaders.js"}
|
|
1
|
+
{"version":3,"file":"assemble-shaders.js","names":["VERTEX_SHADER","FRAGMENT_SHADER","resolveModules","getPlatformShaderDefines","getVersionDefines","injectShader","DECLARATION_INJECT_MARKER","transpileShader","assert","INJECT_SHADER_DECLARATIONS","SHADER_TYPE","FRAGMENT_SHADER_PROLOGUE","assembleShaders","gl","opts","vs","fs","modules","assembleShader","Object","assign","source","type","getUniforms","assembleGetUniforms","id","defines","hookFunctions","inject","transpileToGLSL100","prologue","log","isVertex","sourceLines","split","glslVersion","versionLine","coreSource","indexOf","slice","join","allDefines","forEach","module","getDefines","assembledSource","getShaderName","getShaderType","getApplicationDefines","hookFunctionMap","normalizeHookFunctions","hookInjections","declInjections","mainInjections","key","injection","order","match","hash","name","checkDeprecations","moduleSource","getModuleSource","injections","injectionType","push","getHookFunctions","uniforms","moduleUniforms","toUpperCase","injectShaderName","count","sourceText","define","value","Number","isFinite","result","hookName","hookFunction","signature","header","sort","a","b","footer","hook","trim","stage","replace"],"sources":["../../../src/lib/assemble-shaders.js"],"sourcesContent":["import {VERTEX_SHADER, FRAGMENT_SHADER} from './constants';\nimport {resolveModules} from './resolve-modules';\nimport {getPlatformShaderDefines, getVersionDefines} from './platform-defines';\nimport injectShader, {DECLARATION_INJECT_MARKER} from './inject-shader';\nimport transpileShader from './transpile-shader';\nimport {assert} from '../utils';\n\nconst INJECT_SHADER_DECLARATIONS = `\\n\\n${DECLARATION_INJECT_MARKER}\\n\\n`;\n\nconst SHADER_TYPE = {\n [VERTEX_SHADER]: 'vertex',\n [FRAGMENT_SHADER]: 'fragment'\n};\n\n// Precision prologue to inject before functions are injected in shader\n// TODO - extract any existing prologue in the fragment source and move it up...\nconst FRAGMENT_SHADER_PROLOGUE = `\\\nprecision highp float;\n\n`;\n\n// Inject a list of modules\nexport function assembleShaders(gl, opts) {\n const {vs, fs} = opts;\n const modules = resolveModules(opts.modules || []);\n return {\n gl,\n vs: assembleShader(gl, Object.assign({}, opts, {source: vs, type: VERTEX_SHADER, modules})),\n fs: assembleShader(gl, Object.assign({}, opts, {source: fs, type: FRAGMENT_SHADER, modules})),\n getUniforms: assembleGetUniforms(modules)\n };\n}\n\n// Pulls together complete source code for either a vertex or a fragment shader\n// adding prologues, requested module chunks, and any final injections.\nfunction assembleShader(\n gl,\n {\n id,\n source,\n type,\n modules,\n defines = {},\n hookFunctions = [],\n inject = {},\n transpileToGLSL100 = false,\n prologue = true,\n log\n }\n) {\n assert(typeof source === 'string', 'shader source must be a string');\n\n const isVertex = type === VERTEX_SHADER;\n\n const sourceLines = source.split('\\n');\n let glslVersion = 100;\n let versionLine = '';\n let coreSource = source;\n // Extract any version directive string from source.\n // TODO : keep all pre-processor statements at the begining of the shader.\n if (sourceLines[0].indexOf('#version ') === 0) {\n glslVersion = 300; // TODO - regexp that matches actual version number\n versionLine = sourceLines[0];\n coreSource = sourceLines.slice(1).join('\\n');\n } else {\n versionLine = `#version ${glslVersion}`;\n }\n\n // Combine Module and Application Defines\n const allDefines = {};\n modules.forEach(module => {\n Object.assign(allDefines, module.getDefines());\n });\n Object.assign(allDefines, defines);\n\n // Add platform defines (use these to work around platform-specific bugs and limitations)\n // Add common defines (GLSL version compatibility, feature detection)\n // Add precision declaration for fragment shaders\n let assembledSource = prologue\n ? `\\\n${versionLine}\n${getShaderName({id, source, type})}\n${getShaderType({type})}\n${getPlatformShaderDefines(gl)}\n${getVersionDefines(gl, glslVersion, !isVertex)}\n${getApplicationDefines(allDefines)}\n${isVertex ? '' : FRAGMENT_SHADER_PROLOGUE}\n`\n : `${versionLine}\n`;\n\n const hookFunctionMap = normalizeHookFunctions(hookFunctions);\n\n // Add source of dependent modules in resolved order\n const hookInjections = {};\n const declInjections = {};\n const mainInjections = {};\n\n for (const key in inject) {\n const injection =\n typeof inject[key] === 'string' ? {injection: inject[key], order: 0} : inject[key];\n const match = key.match(/^(v|f)s:(#)?([\\w-]+)$/);\n if (match) {\n const hash = match[2];\n const name = match[3];\n if (hash) {\n if (name === 'decl') {\n declInjections[key] = [injection];\n } else {\n mainInjections[key] = [injection];\n }\n } else {\n hookInjections[key] = [injection];\n }\n } else {\n // Regex injection\n mainInjections[key] = [injection];\n }\n }\n\n for (const module of modules) {\n if (log) {\n module.checkDeprecations(coreSource, log);\n }\n const moduleSource = module.getModuleSource(type, glslVersion);\n // Add the module source, and a #define that declares it presence\n assembledSource += moduleSource;\n\n const injections = module.injections[type];\n for (const key in injections) {\n const match = key.match(/^(v|f)s:#([\\w-]+)$/);\n if (match) {\n const name = match[2];\n const injectionType = name === 'decl' ? declInjections : mainInjections;\n injectionType[key] = injectionType[key] || [];\n injectionType[key].push(injections[key]);\n } else {\n hookInjections[key] = hookInjections[key] || [];\n hookInjections[key].push(injections[key]);\n }\n }\n }\n\n // For injectShader\n assembledSource += INJECT_SHADER_DECLARATIONS;\n\n assembledSource = injectShader(assembledSource, type, declInjections);\n\n assembledSource += getHookFunctions(hookFunctionMap[type], hookInjections);\n\n // Add the version directive and actual source of this shader\n assembledSource += coreSource;\n\n // Apply any requested shader injections\n assembledSource = injectShader(assembledSource, type, mainInjections);\n\n assembledSource = transpileShader(\n assembledSource,\n transpileToGLSL100 ? 100 : glslVersion,\n isVertex\n );\n\n return assembledSource;\n}\n\n// Returns a combined `getUniforms` covering the options for all the modules,\n// the created function will pass on options to the inidividual `getUniforms`\n// function of each shader module and combine the results into one object that\n// can be passed to setUniforms.\nfunction assembleGetUniforms(modules) {\n return function getUniforms(opts) {\n const uniforms = {};\n for (const module of modules) {\n // `modules` is already sorted by dependency level. This guarantees that\n // modules have access to the uniforms that are generated by their dependencies.\n const moduleUniforms = module.getUniforms(opts, uniforms);\n Object.assign(uniforms, moduleUniforms);\n }\n return uniforms;\n };\n}\n\nfunction getShaderType({type}) {\n return `\n#define SHADER_TYPE_${SHADER_TYPE[type].toUpperCase()}\n`;\n}\n\n// Generate \"glslify-compatible\" SHADER_NAME defines\n// These are understood by the GLSL error parsing function\n// If id is provided and no SHADER_NAME constant is present in source, create one\nfunction getShaderName({id, source, type}) {\n const injectShaderName = id && typeof id === 'string' && source.indexOf('SHADER_NAME') === -1;\n return injectShaderName\n ? `\n#define SHADER_NAME ${id}_${SHADER_TYPE[type]}\n\n`\n : '';\n}\n\n// Generates application defines from an object\nfunction getApplicationDefines(defines = {}) {\n let count = 0;\n let sourceText = '';\n for (const define in defines) {\n if (count === 0) {\n sourceText += '\\n// APPLICATION DEFINES\\n';\n }\n count++;\n\n const value = defines[define];\n if (value || Number.isFinite(value)) {\n sourceText += `#define ${define.toUpperCase()} ${defines[define]}\\n`;\n }\n }\n if (count === 0) {\n sourceText += '\\n';\n }\n return sourceText;\n}\n\nfunction getHookFunctions(hookFunctions, hookInjections) {\n let result = '';\n for (const hookName in hookFunctions) {\n const hookFunction = hookFunctions[hookName];\n result += `void ${hookFunction.signature} {\\n`;\n if (hookFunction.header) {\n result += ` ${hookFunction.header}`;\n }\n if (hookInjections[hookName]) {\n const injections = hookInjections[hookName];\n injections.sort((a, b) => a.order - b.order);\n for (const injection of injections) {\n result += ` ${injection.injection}\\n`;\n }\n }\n if (hookFunction.footer) {\n result += ` ${hookFunction.footer}`;\n }\n result += '}\\n';\n }\n\n return result;\n}\n\nfunction normalizeHookFunctions(hookFunctions) {\n const result = {\n vs: {},\n fs: {}\n };\n\n hookFunctions.forEach(hook => {\n let opts;\n if (typeof hook !== 'string') {\n opts = hook;\n hook = opts.hook;\n } else {\n opts = {};\n }\n hook = hook.trim();\n const [stage, signature] = hook.split(':');\n const name = hook.replace(/\\(.+/, '');\n result[stage][name] = Object.assign(opts, {signature});\n });\n\n return result;\n}\n"],"mappings":"AAAA,SAAQA,aAAR,EAAuBC,eAAvB,QAA6C,aAA7C;AACA,SAAQC,cAAR,QAA6B,mBAA7B;AACA,SAAQC,wBAAR,EAAkCC,iBAAlC,QAA0D,oBAA1D;AACA,OAAOC,YAAP,IAAsBC,yBAAtB,QAAsD,iBAAtD;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AACA,SAAQC,MAAR,QAAqB,UAArB;AAEA,MAAMC,0BAA0B,iBAAUH,yBAAV,SAAhC;AAEA,MAAMI,WAAW,GAAG;EAClB,CAACV,aAAD,GAAiB,QADC;EAElB,CAACC,eAAD,GAAmB;AAFD,CAApB;AAOA,MAAMU,wBAAwB,+BAA9B;AAMA,OAAO,SAASC,eAAT,CAAyBC,EAAzB,EAA6BC,IAA7B,EAAmC;EACxC,MAAM;IAACC,EAAD;IAAKC;EAAL,IAAWF,IAAjB;EACA,MAAMG,OAAO,GAAGf,cAAc,CAACY,IAAI,CAACG,OAAL,IAAgB,EAAjB,CAA9B;EACA,OAAO;IACLJ,EADK;IAELE,EAAE,EAAEG,cAAc,CAACL,EAAD,EAAKM,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBN,IAAlB,EAAwB;MAACO,MAAM,E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,EAAyB;MACvBR,MAAM,gBAASE,YAAY,CAACM,MAAtB,CAAN;IACD;;IACDR,MAAM,IAAI,KAAV;EACD;;EAED,OAAOA,MAAP;AACD;;AAED,SAAS3B,sBAAT,CAAgCvB,aAAhC,EAA+C;EAC7C,MAAMkD,MAAM,GAAG;IACb9D,EAAE,EAAE,EADS;IAEbC,EAAE,EAAE;EAFS,CAAf;EAKAW,aAAa,CAACe,OAAd,CAAsB4C,IAAI,IAAI;IAC5B,IAAIxE,IAAJ;;IACA,IAAI,OAAOwE,IAAP,KAAgB,QAApB,EAA8B;MAC5BxE,IAAI,GAAGwE,IAAP;MACAA,IAAI,GAAGxE,IAAI,CAACwE,IAAZ;IACD,CAHD,MAGO;MACLxE,IAAI,GAAG,EAAP;IACD;;IACDwE,IAAI,GAAGA,IAAI,CAACC,IAAL,EAAP;IACA,MAAM,CAACC,KAAD,EAAQR,SAAR,IAAqBM,IAAI,CAACpD,KAAL,CAAW,GAAX,CAA3B;IACA,MAAMyB,IAAI,GAAG2B,IAAI,CAACG,OAAL,CAAa,MAAb,EAAqB,EAArB,CAAb;IACAZ,MAAM,CAACW,KAAD,CAAN,CAAc7B,IAAd,IAAsBxC,MAAM,CAACC,MAAP,CAAcN,IAAd,EAAoB;MAACkE;IAAD,CAApB,CAAtB;EACD,CAZD;EAcA,OAAOH,MAAP;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"constants.js","names":["VERTEX_SHADER","FRAGMENT_SHADER"],"sources":["../../../src/lib/constants.js"],"sourcesContent":["export const VERTEX_SHADER = 'vs';\nexport const FRAGMENT_SHADER = 'fs';\n"],"mappings":"AAAA,OAAO,MAAMA,aAAa,GAAG,IAAtB;AACP,OAAO,MAAMC,eAAe,GAAG,IAAxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"prop-types.js","names":["TYPE_DEFINITIONS","number","validate","value","propType","Number","isFinite","max","min","array","Array","isArray","ArrayBuffer","isView","parsePropTypes","propDefs","propTypes","propName","propDef","parsePropType","type","getTypeOf","Object","assign"],"sources":["../../../../src/lib/filters/prop-types.js"],"sourcesContent":["const TYPE_DEFINITIONS = {\n number: {\n validate(value, propType) {\n return (\n Number.isFinite(value) &&\n (!('max' in propType) || value <= propType.max) &&\n (!('min' in propType) || value >= propType.min)\n );\n }\n },\n array: {\n validate(value, propType) {\n return Array.isArray(value) || ArrayBuffer.isView(value);\n }\n }\n};\n\nexport function parsePropTypes(propDefs) {\n const propTypes = {};\n for (const propName in propDefs) {\n const propDef = propDefs[propName];\n const propType = parsePropType(propDef);\n propTypes[propName] = propType;\n }\n return propTypes;\n}\n\n// Parses one property definition entry. Either contains:\n// * a valid prop type object ({type, ...})\n// * or just a default value, in which case type and name inference is used\nfunction parsePropType(propDef) {\n let type = getTypeOf(propDef);\n if (type === 'object') {\n if (!propDef) {\n return {type: 'object', value: null};\n }\n if ('type' in propDef) {\n return Object.assign({}, propDef, TYPE_DEFINITIONS[propDef.type]);\n }\n if (!('value' in propDef)) {\n // If no type and value this object is likely the value\n return {type: 'object', value: propDef};\n }\n type = getTypeOf(propDef.value);\n return Object.assign({type}, propDef, TYPE_DEFINITIONS[type]);\n }\n return Object.assign({type, value: propDef}, TYPE_DEFINITIONS[type]);\n}\n\n// improved version of javascript typeof that can distinguish arrays and null values\nfunction getTypeOf(value) {\n if (Array.isArray(value) || ArrayBuffer.isView(value)) {\n return 'array';\n }\n return typeof value;\n}\n"],"mappings":"AAAA,MAAMA,gBAAgB,GAAG;EACvBC,MAAM,EAAE;IACNC,QAAQ,CAACC,KAAD,EAAQC,QAAR,EAAkB;MACxB,OACEC,MAAM,CAACC,QAAP,CAAgBH,KAAhB,MACC,EAAE,SAASC,QAAX,KAAwBD,KAAK,IAAIC,QAAQ,CAACG,GAD3C,MAEC,EAAE,SAASH,QAAX,KAAwBD,KAAK,IAAIC,QAAQ,CAACI,GAF3C,CADF;IAKD;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,CAAc;IAACH,IAAD;IAAOjB,KAAK,EAAEe;EAAd,CAAd,EAAsClB,gBAAgB,CAACoB,IAAD,CAAtD,CAAP;AACD;;AAGD,SAASC,SAAT,CAAmBlB,KAAnB,EAA0B;EACxB,IAAIO,KAAK,CAACC,OAAN,CAAcR,KAAd,KAAwBS,WAAW,CAACC,MAAZ,CAAmBV,KAAnB,CAA5B,EAAuD;IACrD,OAAO,OAAP;EACD;;EACD,OAAO,OAAOA,KAAd;AACD"}
|
|
@@ -9,7 +9,8 @@ export const DECLARATION_INJECT_MARKER = '__LUMA_INJECT_DECLARATIONS__';
|
|
|
9
9
|
const REGEX_START_OF_MAIN = /void\s+main\s*\([^)]*\)\s*\{\n?/;
|
|
10
10
|
const REGEX_END_OF_MAIN = /}\n?[^{}]*$/;
|
|
11
11
|
const fragments = [];
|
|
12
|
-
export default function injectShader(source, type, inject
|
|
12
|
+
export default function injectShader(source, type, inject) {
|
|
13
|
+
let injectStandardStubs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
13
14
|
const isVertex = type === VERTEX_SHADER;
|
|
14
15
|
|
|
15
16
|
for (const key in inject) {
|
|
@@ -21,7 +22,7 @@ export default function injectShader(source, type, inject, injectStandardStubs =
|
|
|
21
22
|
fragments[i] = fragmentData[i].injection;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const fragmentString =
|
|
25
|
+
const fragmentString = "".concat(fragments.join('\n'), "\n");
|
|
25
26
|
|
|
26
27
|
switch (key) {
|
|
27
28
|
case 'vs:#decl':
|
|
@@ -84,7 +85,7 @@ export function combineInjects(injects) {
|
|
|
84
85
|
assert(Array.isArray(injects) && injects.length > 1);
|
|
85
86
|
injects.forEach(inject => {
|
|
86
87
|
for (const key in inject) {
|
|
87
|
-
result[key] = result[key] ?
|
|
88
|
+
result[key] = result[key] ? "".concat(result[key], "\n").concat(inject[key]) : inject[key];
|
|
88
89
|
}
|
|
89
90
|
});
|
|
90
91
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"inject-shader.js","names":["MODULE_INJECTORS_VS","MODULE_INJECTORS_FS","VERTEX_SHADER","FRAGMENT_SHADER","assert","MODULE_INJECTORS","DECLARATION_INJECT_MARKER","REGEX_START_OF_MAIN","REGEX_END_OF_MAIN","fragments","injectShader","source","type","inject","injectStandardStubs","isVertex","key","fragmentData","sort","a","b","order","length","i","len","injection","fragmentString","join","replace","match","combineInjects","injects","result","Array","isArray","forEach"],"sources":["../../../src/lib/inject-shader.js"],"sourcesContent":["import {MODULE_INJECTORS_VS, MODULE_INJECTORS_FS} from '../modules/module-injectors';\nimport {VERTEX_SHADER, FRAGMENT_SHADER} from './constants';\nimport {assert} from '../utils';\n\n// TODO - experimental\nconst MODULE_INJECTORS = {\n [VERTEX_SHADER]: MODULE_INJECTORS_VS,\n [FRAGMENT_SHADER]: MODULE_INJECTORS_FS\n};\n\nexport const DECLARATION_INJECT_MARKER = '__LUMA_INJECT_DECLARATIONS__'; // Uniform/attribute declarations\n\nconst REGEX_START_OF_MAIN = /void\\s+main\\s*\\([^)]*\\)\\s*\\{\\n?/; // Beginning of main\nconst REGEX_END_OF_MAIN = /}\\n?[^{}]*$/; // End of main, assumes main is last function\nconst fragments = [];\n\n// A minimal shader injection/templating system.\n// RFC: https://github.com/visgl/luma.gl/blob/7.0-release/dev-docs/RFCs/v6.0/shader-injection-rfc.md\n/* eslint-disable complexity */\nexport default function injectShader(source, type, inject, injectStandardStubs = false) {\n const isVertex = type === VERTEX_SHADER;\n\n for (const key in inject) {\n const fragmentData = inject[key];\n fragmentData.sort((a, b) => a.order - b.order);\n fragments.length = fragmentData.length;\n for (let i = 0, len = fragmentData.length; i < len; ++i) {\n fragments[i] = fragmentData[i].injection;\n }\n const fragmentString = `${fragments.join('\\n')}\\n`;\n switch (key) {\n // declarations are injected before the main function\n case 'vs:#decl':\n if (isVertex) {\n source = source.replace(DECLARATION_INJECT_MARKER, fragmentString);\n }\n break;\n // inject code at the beginning of the main function\n case 'vs:#main-start':\n if (isVertex) {\n source = source.replace(REGEX_START_OF_MAIN, match => match + fragmentString);\n }\n break;\n // inject code at the end of main function\n case 'vs:#main-end':\n if (isVertex) {\n source = source.replace(REGEX_END_OF_MAIN, match => fragmentString + match);\n }\n break;\n // declarations are injected before the main function\n case 'fs:#decl':\n if (!isVertex) {\n source = source.replace(DECLARATION_INJECT_MARKER, fragmentString);\n }\n break;\n // inject code at the beginning of the main function\n case 'fs:#main-start':\n if (!isVertex) {\n source = source.replace(REGEX_START_OF_MAIN, match => match + fragmentString);\n }\n break;\n // inject code at the end of main function\n case 'fs:#main-end':\n if (!isVertex) {\n source = source.replace(REGEX_END_OF_MAIN, match => fragmentString + match);\n }\n break;\n\n default:\n // TODO(Tarek): I think this usage should be deprecated.\n\n // inject code after key, leaving key in place\n source = source.replace(key, match => match + fragmentString);\n }\n }\n\n // Remove if it hasn't already been replaced\n source = source.replace(DECLARATION_INJECT_MARKER, '');\n\n // Finally, if requested, insert an automatic module injector chunk\n if (injectStandardStubs) {\n source = source.replace(/\\}\\s*$/, match => match + MODULE_INJECTORS[type]);\n }\n\n return source;\n}\n\n/* eslint-enable complexity */\n\n// Takes an array of inject objects and combines them into one\nexport function combineInjects(injects) {\n const result = {};\n assert(Array.isArray(injects) && injects.length > 1);\n injects.forEach(inject => {\n for (const key in inject) {\n result[key] = result[key] ? `${result[key]}\\n${inject[key]}` : inject[key];\n }\n });\n return result;\n}\n"],"mappings":"AAAA,SAAQA,mBAAR,EAA6BC,mBAA7B,QAAuD,6BAAvD;AACA,SAAQC,aAAR,EAAuBC,eAAvB,QAA6C,aAA7C;AACA,SAAQC,MAAR,QAAqB,UAArB;AAGA,MAAMC,gBAAgB,GAAG;EACvB,CAACH,aAAD,GAAiBF,mBADM;EAEvB,CAACG,eAAD,GAAmBF;AAFI,CAAzB;AAKA,OAAO,MAAMK,yBAAyB,GAAG,8BAAlC;AAEP,MAAMC,mBAAmB,GAAG,i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,CAAvB,eAAiCH,MAAM,CAACG,GAAD,CAAvC,IAAiDH,MAAM,CAACG,GAAD,CAArE;IACD;EACF,CAJD;EAKA,OAAOgB,MAAP;AACD"}
|
|
@@ -4,108 +4,37 @@ export function getPlatformShaderDefines(gl) {
|
|
|
4
4
|
|
|
5
5
|
switch (debugInfo.gpuVendor.toLowerCase()) {
|
|
6
6
|
case 'nvidia':
|
|
7
|
-
return
|
|
8
|
-
#define NVIDIA_GPU
|
|
9
|
-
// Nvidia optimizes away the calculation necessary for emulated fp64
|
|
10
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
11
|
-
`;
|
|
7
|
+
return "#define NVIDIA_GPU\n// Nvidia optimizes away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n";
|
|
12
8
|
|
|
13
9
|
case 'intel':
|
|
14
|
-
return
|
|
15
|
-
#define INTEL_GPU
|
|
16
|
-
// Intel optimizes away the calculation necessary for emulated fp64
|
|
17
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
18
|
-
// Intel's built-in 'tan' function doesn't have acceptable precision
|
|
19
|
-
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
20
|
-
// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
|
|
21
|
-
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
22
|
-
`;
|
|
10
|
+
return "#define INTEL_GPU\n// Intel optimizes away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n// Intel's built-in 'tan' function doesn't have acceptable precision\n#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1\n// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow\n#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1\n";
|
|
23
11
|
|
|
24
12
|
case 'amd':
|
|
25
|
-
return
|
|
26
|
-
#define AMD_GPU
|
|
27
|
-
`;
|
|
13
|
+
return "#define AMD_GPU\n";
|
|
28
14
|
|
|
29
15
|
default:
|
|
30
|
-
return
|
|
31
|
-
#define DEFAULT_GPU
|
|
32
|
-
// Prevent driver from optimizing away the calculation necessary for emulated fp64
|
|
33
|
-
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
34
|
-
// Intel's built-in 'tan' function doesn't have acceptable precision
|
|
35
|
-
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
36
|
-
// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow
|
|
37
|
-
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
38
|
-
`;
|
|
16
|
+
return "#define DEFAULT_GPU\n// Prevent driver from optimizing away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n// Intel's built-in 'tan' function doesn't have acceptable precision\n#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1\n// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow\n#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1\n";
|
|
39
17
|
}
|
|
40
18
|
}
|
|
41
19
|
export function getVersionDefines(gl, glslVersion, isFragment) {
|
|
42
|
-
let versionDefines =
|
|
43
|
-
#if (__VERSION__ > 120)
|
|
44
|
-
|
|
45
|
-
# define FEATURE_GLSL_DERIVATIVES
|
|
46
|
-
# define FEATURE_GLSL_DRAW_BUFFERS
|
|
47
|
-
# define FEATURE_GLSL_FRAG_DEPTH
|
|
48
|
-
# define FEATURE_GLSL_TEXTURE_LOD
|
|
49
|
-
|
|
50
|
-
// DEPRECATED FLAGS, remove in v9
|
|
51
|
-
# define FRAG_DEPTH
|
|
52
|
-
# define DERIVATIVES
|
|
53
|
-
# define DRAW_BUFFERS
|
|
54
|
-
# define TEXTURE_LOD
|
|
55
|
-
|
|
56
|
-
#endif // __VERSION
|
|
57
|
-
`;
|
|
20
|
+
let versionDefines = "#if (__VERSION__ > 120)\n\n# define FEATURE_GLSL_DERIVATIVES\n# define FEATURE_GLSL_DRAW_BUFFERS\n# define FEATURE_GLSL_FRAG_DEPTH\n# define FEATURE_GLSL_TEXTURE_LOD\n\n// DEPRECATED FLAGS, remove in v9\n# define FRAG_DEPTH\n# define DERIVATIVES\n# define DRAW_BUFFERS\n# define TEXTURE_LOD\n\n#endif // __VERSION\n";
|
|
58
21
|
|
|
59
22
|
if (hasFeatures(gl, FEATURES.GLSL_FRAG_DEPTH)) {
|
|
60
|
-
versionDefines +=
|
|
61
|
-
|
|
62
|
-
// FRAG_DEPTH => gl_FragDepth is available
|
|
63
|
-
#ifdef GL_EXT_frag_depth
|
|
64
|
-
#extension GL_EXT_frag_depth : enable
|
|
65
|
-
# define FEATURE_GLSL_FRAG_DEPTH
|
|
66
|
-
# define FRAG_DEPTH
|
|
67
|
-
# define gl_FragDepth gl_FragDepthEXT
|
|
68
|
-
#endif
|
|
69
|
-
`;
|
|
23
|
+
versionDefines += "\n// FRAG_DEPTH => gl_FragDepth is available\n#ifdef GL_EXT_frag_depth\n#extension GL_EXT_frag_depth : enable\n# define FEATURE_GLSL_FRAG_DEPTH\n# define FRAG_DEPTH\n# define gl_FragDepth gl_FragDepthEXT\n#endif\n";
|
|
70
24
|
}
|
|
71
25
|
|
|
72
26
|
if (hasFeatures(gl, FEATURES.GLSL_DERIVATIVES) && canCompileGLGSExtension(gl, FEATURES.GLSL_DERIVATIVES)) {
|
|
73
|
-
versionDefines +=
|
|
74
|
-
|
|
75
|
-
// DERIVATIVES => dxdF, dxdY and fwidth are available
|
|
76
|
-
#ifdef GL_OES_standard_derivatives
|
|
77
|
-
#extension GL_OES_standard_derivatives : enable
|
|
78
|
-
# define FEATURE_GLSL_DERIVATIVES
|
|
79
|
-
# define DERIVATIVES
|
|
80
|
-
#endif
|
|
81
|
-
`;
|
|
27
|
+
versionDefines += "\n// DERIVATIVES => dxdF, dxdY and fwidth are available\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives : enable\n# define FEATURE_GLSL_DERIVATIVES\n# define DERIVATIVES\n#endif\n";
|
|
82
28
|
}
|
|
83
29
|
|
|
84
30
|
if (hasFeatures(gl, FEATURES.GLSL_FRAG_DATA) && canCompileGLGSExtension(gl, FEATURES.GLSL_FRAG_DATA, {
|
|
85
31
|
behavior: 'require'
|
|
86
32
|
})) {
|
|
87
|
-
versionDefines +=
|
|
88
|
-
|
|
89
|
-
// DRAW_BUFFERS => gl_FragData[] is available
|
|
90
|
-
#ifdef GL_EXT_draw_buffers
|
|
91
|
-
#extension GL_EXT_draw_buffers : require
|
|
92
|
-
#define FEATURE_GLSL_DRAW_BUFFERS
|
|
93
|
-
#define DRAW_BUFFERS
|
|
94
|
-
#endif
|
|
95
|
-
`;
|
|
33
|
+
versionDefines += "\n// DRAW_BUFFERS => gl_FragData[] is available\n#ifdef GL_EXT_draw_buffers\n#extension GL_EXT_draw_buffers : require\n#define FEATURE_GLSL_DRAW_BUFFERS\n#define DRAW_BUFFERS\n#endif\n";
|
|
96
34
|
}
|
|
97
35
|
|
|
98
36
|
if (hasFeatures(gl, FEATURES.GLSL_TEXTURE_LOD)) {
|
|
99
|
-
versionDefines +=
|
|
100
|
-
// TEXTURE_LOD => texture2DLod etc are available
|
|
101
|
-
#ifdef GL_EXT_shader_texture_lod
|
|
102
|
-
#extension GL_EXT_shader_texture_lod : enable
|
|
103
|
-
|
|
104
|
-
# define FEATURE_GLSL_TEXTURE_LOD
|
|
105
|
-
# define TEXTURE_LOD
|
|
106
|
-
|
|
107
|
-
#endif
|
|
108
|
-
`;
|
|
37
|
+
versionDefines += "// TEXTURE_LOD => texture2DLod etc are available\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod : enable\n\n# define FEATURE_GLSL_TEXTURE_LOD\n# define TEXTURE_LOD\n\n#endif\n";
|
|
109
38
|
}
|
|
110
39
|
|
|
111
40
|
return versionDefines;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"platform-defines.js","names":["getContextInfo","hasFeatures","canCompileGLGSExtension","FEATURES","getPlatformShaderDefines","gl","debugInfo","gpuVendor","toLowerCase","getVersionDefines","glslVersion","isFragment","versionDefines","GLSL_FRAG_DEPTH","GLSL_DERIVATIVES","GLSL_FRAG_DATA","behavior","GLSL_TEXTURE_LOD"],"sources":["../../../src/lib/platform-defines.js"],"sourcesContent":["import {getContextInfo, hasFeatures, canCompileGLGSExtension, FEATURES} from '../utils/webgl-info';\n\nexport function getPlatformShaderDefines(gl) {\n const debugInfo = getContextInfo(gl);\n\n switch (debugInfo.gpuVendor.toLowerCase()) {\n case 'nvidia':\n return `\\\n#define NVIDIA_GPU\n// Nvidia optimizes away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n`;\n\n case 'intel':\n return `\\\n#define INTEL_GPU\n// Intel optimizes away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n// Intel's built-in 'tan' function doesn't have acceptable precision\n#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1\n// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow\n#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1\n`;\n\n case 'amd':\n // AMD Does not eliminate fp64 code\n return `\\\n#define AMD_GPU\n`;\n\n default:\n // We don't know what GPU it is, could be that the GPU driver or\n // browser is not implementing UNMASKED_RENDERER constant and not\n // reporting a correct name\n return `\\\n#define DEFAULT_GPU\n// Prevent driver from optimizing away the calculation necessary for emulated fp64\n#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1\n// Intel's built-in 'tan' function doesn't have acceptable precision\n#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1\n// Intel GPU doesn't have full 32 bits precision in same cases, causes overflow\n#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1\n`;\n }\n}\n\nexport function getVersionDefines(gl, glslVersion, isFragment) {\n // Add shadertools defines to let shaders portably v1/v3 check for features\n let versionDefines = `\\\n#if (__VERSION__ > 120)\n\n# define FEATURE_GLSL_DERIVATIVES\n# define FEATURE_GLSL_DRAW_BUFFERS\n# define FEATURE_GLSL_FRAG_DEPTH\n# define FEATURE_GLSL_TEXTURE_LOD\n\n// DEPRECATED FLAGS, remove in v9\n# define FRAG_DEPTH\n# define DERIVATIVES\n# define DRAW_BUFFERS\n# define TEXTURE_LOD\n\n#endif // __VERSION\n`;\n\n if (hasFeatures(gl, FEATURES.GLSL_FRAG_DEPTH)) {\n versionDefines += `\\\n\n// FRAG_DEPTH => gl_FragDepth is available\n#ifdef GL_EXT_frag_depth\n#extension GL_EXT_frag_depth : enable\n# define FEATURE_GLSL_FRAG_DEPTH\n# define FRAG_DEPTH\n# define gl_FragDepth gl_FragDepthEXT\n#endif\n`;\n }\n if (\n hasFeatures(gl, FEATURES.GLSL_DERIVATIVES) &&\n canCompileGLGSExtension(gl, FEATURES.GLSL_DERIVATIVES)\n ) {\n versionDefines += `\\\n\n// DERIVATIVES => dxdF, dxdY and fwidth are available\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives : enable\n# define FEATURE_GLSL_DERIVATIVES\n# define DERIVATIVES\n#endif\n`;\n }\n if (\n hasFeatures(gl, FEATURES.GLSL_FRAG_DATA) &&\n canCompileGLGSExtension(gl, FEATURES.GLSL_FRAG_DATA, {behavior: 'require'})\n ) {\n versionDefines += `\\\n\n// DRAW_BUFFERS => gl_FragData[] is available\n#ifdef GL_EXT_draw_buffers\n#extension GL_EXT_draw_buffers : require\n#define FEATURE_GLSL_DRAW_BUFFERS\n#define DRAW_BUFFERS\n#endif\n`;\n }\n if (hasFeatures(gl, FEATURES.GLSL_TEXTURE_LOD)) {\n versionDefines += `\\\n// TEXTURE_LOD => texture2DLod etc are available\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod : enable\n\n# define FEATURE_GLSL_TEXTURE_LOD\n# define TEXTURE_LOD\n\n#endif\n`;\n }\n return versionDefines;\n}\n"],"mappings":"AAAA,SAAQA,cAAR,EAAwBC,WAAxB,EAAqCC,uBAArC,EAA8DC,QAA9D,QAA6E,qBAA7E;AAEA,OAAO,SAASC,wBAAT,CAAkCC,EAAlC,EAAsC;EAC3C,MAAMC,SAAS,GAAGN,cAAc,CAACK,EAAD,CAAhC;;EAEA,QAAQC,SAAS,CAACC,SAAV,CAAoBC,WAApB,EAAR;IACE,KAAK,QAAL;MACE;;IAMF,KAAK,OAAL;MACE;;IAUF,KAAK,KAAL;MAEE;;IAIF;MAIE;EA7BJ;AAuCD;AAED,OAAO,SAASC,iBAAT,CAA2BJ,EAA3B,EAA+BK,WAA/B,EAA4CC,UAA5C,EAAwD;EAE7D,IAAIC,cAAc,gUAAlB;;EAiBA,IAAIX,WAAW,CAACI,EAAD,EAAKF,QAAQ,CAACU,eAAd,CAAf,EAA+C;IAC7CD,cAAc,2NAAd;EAUD;;EACD,IACEX,WAAW,CAACI,EAAD,EAAKF,QAAQ,CAACW,gBAAd,CAAX,IACAZ,uBAAuB,CAACG,EAAD,EAAKF,QAAQ,CAACW,gBAAd,CAFzB,EAGE;IACAF,cAAc,qNAAd;EASD;;EACD,IACEX,WAAW,CAACI,EAAD,EAAKF,QAAQ,CAACY,cAAd,CAAX,IACAb,uBAAuB,CAACG,EAAD,EAAKF,QAAQ,CAACY,cAAd,EAA8B;IAACC,QAAQ,EAAE;EAAX,CAA9B,CAFzB,EAGE;IACAJ,cAAc,8LAAd;EASD;;EACD,IAAIX,WAAW,CAACI,EAAD,EAAKF,QAAQ,CAACc,gBAAd,CAAf,EAAgD;IAC9CL,cAAc,8MAAd;EAUD;;EACD,OAAOA,cAAP;AACD"}
|
|
@@ -16,12 +16,14 @@ function getShaderDependencies(modules) {
|
|
|
16
16
|
return Object.keys(moduleDepth).sort((a, b) => moduleDepth[b] - moduleDepth[a]).map(name => moduleMap[name]);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function getDependencyGraph({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
function getDependencyGraph(_ref) {
|
|
20
|
+
let {
|
|
21
|
+
modules,
|
|
22
|
+
level,
|
|
23
|
+
moduleMap,
|
|
24
|
+
moduleDepth
|
|
25
|
+
} = _ref;
|
|
26
|
+
|
|
25
27
|
if (level >= 5) {
|
|
26
28
|
throw new Error('Possible loop in shader dependency graph');
|
|
27
29
|
}
|
|
@@ -52,7 +54,7 @@ function instantiateModules(modules, seen) {
|
|
|
52
54
|
return module;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
assert(typeof module !== 'string',
|
|
57
|
+
assert(typeof module !== 'string', "Shader module use by name is deprecated. Import shader module '".concat(module, "' and use it directly."));
|
|
56
58
|
assert(module.name, 'shader module has no name');
|
|
57
59
|
module = new ShaderModule(module);
|
|
58
60
|
module.dependencies = instantiateModules(module.dependencies);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"resolve-modules.js","names":["ShaderModule","assert","resolveModules","modules","getShaderDependencies","instantiateModules","moduleMap","moduleDepth","getDependencyGraph","level","Object","keys","sort","a","b","map","name","Error","module","undefined","dependencies","seen","TEST_EXPORTS"],"sources":["../../../src/lib/resolve-modules.js"],"sourcesContent":["import ShaderModule from './shader-module';\nimport {assert} from '../utils';\n\n// Instantiate shader modules and any dependencies resolve dependencies\nexport function resolveModules(modules) {\n return getShaderDependencies(instantiateModules(modules));\n}\n\n/**\n * Takes a list of shader module names and returns a new list of\n * shader module names that includes all dependencies, sorted so\n * that modules that are dependencies of other modules come first.\n *\n * If the shader glsl code from the returned modules is concatenated\n * in the reverse order, it is guaranteed that all functions be resolved and\n * that all function and variable definitions come before use.\n *\n * @param {String[]} modules - Array of modules (inline modules or module names)\n * @return {String[]} - Array of modules\n */\nfunction getShaderDependencies(modules) {\n const moduleMap = {};\n const moduleDepth = {};\n getDependencyGraph({modules, level: 0, moduleMap, moduleDepth});\n\n // Return a reverse sort so that dependencies come before the modules that use them\n return Object.keys(moduleDepth)\n .sort((a, b) => moduleDepth[b] - moduleDepth[a])\n .map(name => moduleMap[name]);\n}\n\n/**\n * Recursively checks module dpendencies to calculate dependency\n * level of each module.\n *\n * @param {object} options\n * @param {object[]} options.modules - Array of modules\n * @param {number} options.level - Current level\n * @param {object} options.moduleMap -\n * @param {object} options.moduleDepth - Current level\n * @return {object} - Map of module name to its level\n */\n// Adds another level of dependencies to the result map\nfunction getDependencyGraph({modules, level, moduleMap, moduleDepth}) {\n if (level >= 5) {\n throw new Error('Possible loop in shader dependency graph');\n }\n\n // Update level on all current modules\n for (const module of modules) {\n moduleMap[module.name] = module;\n if (moduleDepth[module.name] === undefined || moduleDepth[module.name] < level) {\n moduleDepth[module.name] = level;\n }\n }\n\n // Recurse\n for (const module of modules) {\n if (module.dependencies) {\n getDependencyGraph({modules: module.dependencies, level: level + 1, moduleMap, moduleDepth});\n }\n }\n}\n\nfunction instantiateModules(modules, seen) {\n return modules.map(module => {\n if (module instanceof ShaderModule) {\n return module;\n }\n\n assert(\n typeof module !== 'string',\n `Shader module use by name is deprecated. Import shader module '${module}' and use it directly.`\n );\n assert(module.name, 'shader module has no name');\n\n module = new ShaderModule(module);\n module.dependencies = instantiateModules(module.dependencies);\n\n return module;\n });\n}\n\nexport const TEST_EXPORTS = {\n getShaderDependencies,\n getDependencyGraph\n};\n"],"mappings":"AAAA,OAAOA,YAAP,MAAyB,iBAAzB;AACA,SAAQC,MAAR,QAAqB,UAArB;AAGA,OAAO,SAASC,cAAT,CAAwBC,OAAxB,EAAiC;EACtC,OAAOC,qBAAqB,CAACC,kBAAkB,CAACF,OAAD,CAAnB,CAA5B;AACD;;AAcD,SAASC,qBAAT,CAA+BD,OAA/B,EAAwC;EACtC,MAAMG,SAAS,GAAG,EAAlB;EACA,MAAMC,WAAW,GAAG,EAApB;EACAC,kBAAkB,CAAC;IAACL,OAAD;IAAUM,KAAK,EAAE,CA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