@luma.gl/shadertools
Advanced tools
Comparing version 7.2.0-alpha.3 to 7.2.0-alpha.4
@@ -8,2 +8,18 @@ "use strict"; | ||
}); | ||
var _exportNames = { | ||
MODULAR_SHADERS: true, | ||
registerShaderModules: true, | ||
setDefaultShaderModules: true, | ||
getDefaultShaderModules: true, | ||
assembleShaders: true, | ||
createShaderHook: true, | ||
createModuleInjection: true, | ||
combineInjects: true, | ||
normalizeShaderModule: true, | ||
getQualifierDetails: true, | ||
getPassthroughFS: true, | ||
typeToChannelSuffix: true, | ||
typeToChannelCount: true, | ||
convertToVec4: true | ||
}; | ||
Object.defineProperty(exports, "registerShaderModules", { | ||
@@ -54,3 +70,3 @@ enumerable: true, | ||
get: function get() { | ||
return _normalizeModule.normalizeShaderModule; | ||
return _shaderModule.normalizeShaderModule; | ||
} | ||
@@ -88,68 +104,2 @@ }); | ||
}); | ||
Object.defineProperty(exports, "fp32", { | ||
enumerable: true, | ||
get: function get() { | ||
return _fp["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "fp64", { | ||
enumerable: true, | ||
get: function get() { | ||
return _fp2["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "project", { | ||
enumerable: true, | ||
get: function get() { | ||
return _project["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "lights", { | ||
enumerable: true, | ||
get: function get() { | ||
return _lights["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "dirlight", { | ||
enumerable: true, | ||
get: function get() { | ||
return _dirlight["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "picking", { | ||
enumerable: true, | ||
get: function get() { | ||
return _picking["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "diffuse", { | ||
enumerable: true, | ||
get: function get() { | ||
return _diffuse["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "gouraudlighting", { | ||
enumerable: true, | ||
get: function get() { | ||
return _phongLighting.gouraudlighting; | ||
} | ||
}); | ||
Object.defineProperty(exports, "phonglighting", { | ||
enumerable: true, | ||
get: function get() { | ||
return _phongLighting.phonglighting; | ||
} | ||
}); | ||
Object.defineProperty(exports, "pbr", { | ||
enumerable: true, | ||
get: function get() { | ||
return _pbr["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "_transform", { | ||
enumerable: true, | ||
get: function get() { | ||
return _transform["default"]; | ||
} | ||
}); | ||
exports.MODULAR_SHADERS = void 0; | ||
@@ -167,32 +117,24 @@ | ||
var _normalizeModule = require("./lib/filters/normalize-module"); | ||
var _shaderModule = require("./lib/shader-module"); | ||
var _shaderUtils = require("./utils/shader-utils"); | ||
var _fp = _interopRequireDefault(require("./modules/fp32/fp32")); | ||
var _modules = require("./modules"); | ||
var _fp2 = _interopRequireDefault(require("./modules/fp64/fp64")); | ||
var _project = _interopRequireDefault(require("./modules/project/project")); | ||
var _lights = _interopRequireDefault(require("./modules/lights/lights")); | ||
var _dirlight = _interopRequireDefault(require("./modules/dirlight/dirlight")); | ||
var _picking = _interopRequireDefault(require("./modules/picking/picking")); | ||
var _diffuse = _interopRequireDefault(require("./modules/diffuse/diffuse")); | ||
var _phongLighting = require("./modules/phong-lighting/phong-lighting"); | ||
var _pbr = _interopRequireDefault(require("./modules/pbr/pbr")); | ||
var _transform = _interopRequireDefault(require("./modules/transform/transform")); | ||
Object.keys(_modules).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _modules[key]; | ||
} | ||
}); | ||
}); | ||
var MODULAR_SHADERS = { | ||
vs: _modularVertex["default"], | ||
fs: _modularFragment["default"], | ||
defaultUniforms: {} | ||
uniforms: {} | ||
}; | ||
exports.MODULAR_SHADERS = MODULAR_SHADERS; | ||
//# sourceMappingURL=index.js.map |
@@ -66,4 +66,3 @@ "use strict"; | ||
function assembleShaders(gl) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
function assembleShaders(gl, opts) { | ||
var vs = opts.vs, | ||
@@ -93,4 +92,3 @@ fs = opts.fs; | ||
type = _ref.type, | ||
_ref$modules = _ref.modules, | ||
modules = _ref$modules === void 0 ? [] : _ref$modules, | ||
modules = _ref.modules, | ||
_ref$defines = _ref.defines, | ||
@@ -163,3 +161,6 @@ defines = _ref$defines === void 0 ? {} : _ref$defines, | ||
default: | ||
module.checkDeprecations(coreSource, log); | ||
if (log) { | ||
module.checkDeprecations(coreSource, log); | ||
} | ||
var moduleSource = module.getModuleSource(type, glslVersion); | ||
@@ -166,0 +167,0 @@ assembledSource += moduleSource; |
@@ -12,16 +12,11 @@ "use strict"; | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var TYPE_DEFINITIONS = { | ||
"boolean": { | ||
number: { | ||
validate: function validate(value, propType) { | ||
return true; | ||
return Number.isFinite(value) && (!('max' in propType) || value <= propType.max) && (!('min' in propType) || value >= propType.min); | ||
} | ||
}, | ||
number: { | ||
validateType: function validateType(value, propType) { | ||
return 'value' in propType && (!('max' in propType) || Number.isFinite(propType.max)) && (!('min' in propType) || Number.isFinite(propType.min)); | ||
}, | ||
array: { | ||
validate: function validate(value, propType) { | ||
return Number.isFinite(value) && (!('max' in propType) || value <= propType.max) && (!('min' in propType) || value >= propType.min); | ||
return Array.isArray(value) || ArrayBuffer.isView(value); | ||
} | ||
@@ -33,76 +28,29 @@ } | ||
var propTypes = {}; | ||
var defaultProps = {}; | ||
for (var _i = 0, _Object$entries = Object.entries(propDefs); _i < _Object$entries.length; _i++) { | ||
var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2), | ||
propName = _Object$entries$_i[0], | ||
propDef = _Object$entries$_i[1]; | ||
var propType = parsePropType(propName, propDef); | ||
for (var propName in propDefs) { | ||
var propDef = propDefs[propName]; | ||
var propType = parsePropType(propDef); | ||
propTypes[propName] = propType; | ||
defaultProps[propName] = propType.value; | ||
} | ||
return { | ||
propTypes: propTypes, | ||
defaultProps: defaultProps | ||
}; | ||
return propTypes; | ||
} | ||
function parsePropType(name, propDef) { | ||
switch (getTypeOf(propDef)) { | ||
case 'object': | ||
propDef = normalizePropType(name, propDef); | ||
return parsePropDefinition(propDef); | ||
function parsePropType(propDef) { | ||
var type = getTypeOf(propDef); | ||
case 'array': | ||
return guessArrayType(name, propDef); | ||
case 'boolean': | ||
if (type === 'object') { | ||
if (!propDef) { | ||
return { | ||
name: name, | ||
type: 'boolean', | ||
value: propDef | ||
type: 'object', | ||
value: null | ||
}; | ||
} | ||
case 'number': | ||
return guessNumberType(name, propDef); | ||
if ('type' in propDef) { | ||
return Object.assign({}, propDef, TYPE_DEFINITIONS[propDef.type]); | ||
} | ||
case 'function': | ||
return { | ||
name: name, | ||
type: 'function', | ||
value: propDef | ||
}; | ||
default: | ||
return { | ||
name: name, | ||
type: 'unknown', | ||
value: propDef | ||
}; | ||
} | ||
} | ||
function guessArrayType(name, array) { | ||
if (/color/i.test(name) && (array.length === 3 || array.length === 4)) { | ||
return { | ||
name: name, | ||
type: 'color', | ||
value: array | ||
}; | ||
} | ||
return { | ||
name: name, | ||
type: 'array', | ||
value: array | ||
}; | ||
} | ||
function normalizePropType(name, propDef) { | ||
if (!('type' in propDef)) { | ||
if (!('value' in propDef)) { | ||
return { | ||
name: name, | ||
type: 'object', | ||
@@ -113,36 +61,14 @@ value: propDef | ||
type = getTypeOf(propDef.value); | ||
return Object.assign({ | ||
name: name, | ||
type: getTypeOf(propDef.value) | ||
}, propDef); | ||
type: type | ||
}, propDef, TYPE_DEFINITIONS[type]); | ||
} | ||
return Object.assign({ | ||
name: name | ||
}, propDef); | ||
type: type, | ||
value: propDef | ||
}, TYPE_DEFINITIONS[type]); | ||
} | ||
function parsePropDefinition(propDef) { | ||
var type = propDef.type; | ||
var typeDefinition = TYPE_DEFINITIONS[type] || {}; | ||
var typeValidator = typeDefinition.typeValidator; | ||
if (typeValidator) {} | ||
return propDef; | ||
} | ||
function guessNumberType(name, value) { | ||
var isKnownProp = /radius|scale|width|height|pixel|size|miter/i.test(name) && /^((?!scale).)*$/.test(name); | ||
var max = isKnownProp ? 100 : 1; | ||
var min = 0; | ||
return { | ||
name: name, | ||
type: 'number', | ||
max: Math.max(value, max), | ||
min: Math.min(value, min), | ||
value: value | ||
}; | ||
} | ||
function getTypeOf(value) { | ||
@@ -153,8 +79,4 @@ if (Array.isArray(value) || ArrayBuffer.isView(value)) { | ||
if (value === null) { | ||
return 'null'; | ||
} | ||
return (0, _typeof2["default"])(value); | ||
} | ||
//# sourceMappingURL=prop-types.js.map |
@@ -110,3 +110,3 @@ "use strict"; | ||
if (injectStandardStubs) { | ||
source = source.replace('}s*$', function (match) { | ||
source = source.replace(/\}\s*$/, function (match) { | ||
return match + MODULE_INJECTORS[type]; | ||
@@ -113,0 +113,0 @@ }); |
@@ -8,2 +8,3 @@ "use strict"; | ||
}); | ||
exports.normalizeShaderModule = normalizeShaderModule; | ||
exports["default"] = void 0; | ||
@@ -19,2 +20,4 @@ | ||
var _propTypes = require("./filters/prop-types"); | ||
var VERTEX_SHADER = 'vs'; | ||
@@ -30,6 +33,4 @@ var FRAGMENT_SHADER = 'fs'; | ||
dependencies = _ref$dependencies === void 0 ? [] : _ref$dependencies, | ||
_ref$getUniforms = _ref.getUniforms, | ||
getUniforms = _ref$getUniforms === void 0 ? function () { | ||
return {}; | ||
} : _ref$getUniforms, | ||
uniforms = _ref.uniforms, | ||
getUniforms = _ref.getUniforms, | ||
_ref$deprecations = _ref.deprecations, | ||
@@ -50,2 +51,6 @@ deprecations = _ref$deprecations === void 0 ? [] : _ref$deprecations, | ||
this.defines = defines; | ||
if (uniforms) { | ||
this.uniforms = (0, _propTypes.parsePropTypes)(uniforms); | ||
} | ||
} | ||
@@ -71,6 +76,2 @@ | ||
if (typeof moduleSource !== 'string') { | ||
return ''; | ||
} | ||
return "#define MODULE_".concat(this.name.toUpperCase(), "\n").concat(moduleSource, "// END MODULE_").concat(this.name, "\n\n"); | ||
@@ -81,3 +82,11 @@ } | ||
value: function getUniforms(opts, uniforms) { | ||
return this.getModuleUniforms(opts, uniforms); | ||
if (this.getModuleUniforms) { | ||
return this.getModuleUniforms(opts, uniforms); | ||
} | ||
if (this.uniforms) { | ||
return this._defaultGetUniforms(opts); | ||
} | ||
return {}; | ||
} | ||
@@ -94,5 +103,5 @@ }, { | ||
if (def.regex.test(shaderSource)) { | ||
if (def.deprecated && log) { | ||
if (def.deprecated) { | ||
log.deprecated(def.old, def["new"])(); | ||
} else if (log) { | ||
} else { | ||
log.removed(def.old, def["new"])(); | ||
@@ -105,4 +114,3 @@ } | ||
key: "_parseDeprecationDefinitions", | ||
value: function _parseDeprecationDefinitions() { | ||
var deprecations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
value: function _parseDeprecationDefinitions(deprecations) { | ||
deprecations.forEach(function (def) { | ||
@@ -120,2 +128,25 @@ switch (def.type) { | ||
} | ||
}, { | ||
key: "_defaultGetUniforms", | ||
value: function _defaultGetUniforms() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var uniforms = {}; | ||
var propTypes = this.uniforms; | ||
for (var key in propTypes) { | ||
var propDef = propTypes[key]; | ||
if (key in opts && !propDef["private"]) { | ||
if (propDef.validate) { | ||
(0, _utils.assert)(propDef.validate(opts[key], propDef), "".concat(this.name, ": invalid ").concat(key)); | ||
} | ||
uniforms[key] = opts[key]; | ||
} else { | ||
uniforms[key] = propDef.value; | ||
} | ||
} | ||
return uniforms; | ||
} | ||
}]); | ||
@@ -126,2 +157,15 @@ return ShaderModule; | ||
exports["default"] = ShaderModule; | ||
function normalizeShaderModule(module) { | ||
if (!module.normalized) { | ||
module.normalized = true; | ||
if (module.uniforms && !module.getUniforms) { | ||
var shaderModule = new ShaderModule(module); | ||
module.getUniforms = shaderModule.getUniforms.bind(shaderModule); | ||
} | ||
} | ||
return module; | ||
} | ||
//# sourceMappingURL=shader-module.js.map |
@@ -7,10 +7,2 @@ "use strict"; | ||
exports["default"] = void 0; | ||
var DEFAULT_MODULE_OPTIONS = {}; | ||
function getUniforms() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_MODULE_OPTIONS; | ||
var uniforms = {}; | ||
return uniforms; | ||
} | ||
var vs = "varying vec4 geometry_vPosition;\nvarying vec3 geometry_vNormal;\n\nvoid geometry_setNormal(vec3 normal) {\n geometry_vNormal = normal;\n}\n\nvoid geometry_setPosition(vec4 position) {\n geometry_vPosition = position;\n}\n\nvoid geometry_setPosition(vec3 position) {\n geometry_vPosition = vec4(position, 1.);\n}\n"; | ||
@@ -21,6 +13,5 @@ var fs = "varying vec4 geometry_vPosition;\nvarying vec3 geometry_vNormal;\n\nvec4 geometry_getPosition() {\n return geometry_vPosition;\n}\n\nvec3 geometry_getNormal() {\n return geometry_vNormal;\n}\n"; | ||
vs: vs, | ||
fs: fs, | ||
getUniforms: getUniforms | ||
fs: fs | ||
}; | ||
exports["default"] = _default; | ||
//# sourceMappingURL=geometry.js.map |
@@ -41,3 +41,5 @@ "use strict"; | ||
materialUniforms.lighting_uShininess = material.shininess; | ||
materialUniforms.lighting_uSpecularColor = material.specularColor; | ||
materialUniforms.lighting_uSpecularColor = material.specularColor.map(function (x) { | ||
return x / 255; | ||
}); | ||
return materialUniforms; | ||
@@ -44,0 +46,0 @@ } |
@@ -6,19 +6,10 @@ import MODULAR_VS from './shaders/modular-vertex.glsl'; | ||
export { combineInjects } from './lib/inject-shader'; | ||
export { normalizeShaderModule } from './lib/filters/normalize-module'; | ||
export { normalizeShaderModule } from './lib/shader-module'; | ||
export { getQualifierDetails, getPassthroughFS, typeToChannelSuffix, typeToChannelCount, convertToVec4 } from './utils/shader-utils'; | ||
export { default as fp32 } from './modules/fp32/fp32'; | ||
export { default as fp64 } from './modules/fp64/fp64'; | ||
export { default as project } from './modules/project/project'; | ||
export { default as lights } from './modules/lights/lights'; | ||
export { default as dirlight } from './modules/dirlight/dirlight'; | ||
export { default as picking } from './modules/picking/picking'; | ||
export { default as diffuse } from './modules/diffuse/diffuse'; | ||
export { gouraudlighting, phonglighting } from './modules/phong-lighting/phong-lighting'; | ||
export { default as pbr } from './modules/pbr/pbr'; | ||
export { default as _transform } from './modules/transform/transform'; | ||
export * from './modules'; | ||
export const MODULAR_SHADERS = { | ||
vs: MODULAR_VS, | ||
fs: MODULAR_FS, | ||
defaultUniforms: {} | ||
uniforms: {} | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -41,4 +41,3 @@ import { VERTEX_SHADER, FRAGMENT_SHADER } from './constants'; | ||
} | ||
export function assembleShaders(gl) { | ||
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
export function assembleShaders(gl, opts) { | ||
const { | ||
@@ -71,3 +70,3 @@ vs, | ||
type, | ||
modules = [], | ||
modules, | ||
defines = {}, | ||
@@ -131,3 +130,6 @@ inject = {}, | ||
default: | ||
module.checkDeprecations(coreSource, log); | ||
if (log) { | ||
module.checkDeprecations(coreSource, log); | ||
} | ||
const moduleSource = module.getModuleSource(type, glslVersion); | ||
@@ -134,0 +136,0 @@ assembledSource += moduleSource; |
const TYPE_DEFINITIONS = { | ||
boolean: { | ||
number: { | ||
validate(value, propType) { | ||
return true; | ||
return Number.isFinite(value) && (!('max' in propType) || value <= propType.max) && (!('min' in propType) || value >= propType.min); | ||
} | ||
}, | ||
number: { | ||
validateType(value, propType) { | ||
return 'value' in propType && (!('max' in propType) || Number.isFinite(propType.max)) && (!('min' in propType) || Number.isFinite(propType.min)); | ||
}, | ||
array: { | ||
validate(value, propType) { | ||
return Number.isFinite(value) && (!('max' in propType) || value <= propType.max) && (!('min' in propType) || value >= propType.min); | ||
return Array.isArray(value) || ArrayBuffer.isView(value); | ||
} | ||
@@ -21,72 +17,29 @@ | ||
const propTypes = {}; | ||
const defaultProps = {}; | ||
for (const [propName, propDef] of Object.entries(propDefs)) { | ||
const propType = parsePropType(propName, propDef); | ||
for (const propName in propDefs) { | ||
const propDef = propDefs[propName]; | ||
const propType = parsePropType(propDef); | ||
propTypes[propName] = propType; | ||
defaultProps[propName] = propType.value; | ||
} | ||
return { | ||
propTypes, | ||
defaultProps | ||
}; | ||
return propTypes; | ||
} | ||
function parsePropType(name, propDef) { | ||
switch (getTypeOf(propDef)) { | ||
case 'object': | ||
propDef = normalizePropType(name, propDef); | ||
return parsePropDefinition(propDef); | ||
function parsePropType(propDef) { | ||
let type = getTypeOf(propDef); | ||
case 'array': | ||
return guessArrayType(name, propDef); | ||
case 'boolean': | ||
if (type === 'object') { | ||
if (!propDef) { | ||
return { | ||
name, | ||
type: 'boolean', | ||
value: propDef | ||
type: 'object', | ||
value: null | ||
}; | ||
} | ||
case 'number': | ||
return guessNumberType(name, propDef); | ||
if ('type' in propDef) { | ||
return Object.assign({}, propDef, TYPE_DEFINITIONS[propDef.type]); | ||
} | ||
case 'function': | ||
return { | ||
name, | ||
type: 'function', | ||
value: propDef | ||
}; | ||
default: | ||
return { | ||
name, | ||
type: 'unknown', | ||
value: propDef | ||
}; | ||
} | ||
} | ||
function guessArrayType(name, array) { | ||
if (/color/i.test(name) && (array.length === 3 || array.length === 4)) { | ||
return { | ||
name, | ||
type: 'color', | ||
value: array | ||
}; | ||
} | ||
return { | ||
name, | ||
type: 'array', | ||
value: array | ||
}; | ||
} | ||
function normalizePropType(name, propDef) { | ||
if (!('type' in propDef)) { | ||
if (!('value' in propDef)) { | ||
return { | ||
name, | ||
type: 'object', | ||
@@ -97,40 +50,14 @@ value: propDef | ||
type = getTypeOf(propDef.value); | ||
return Object.assign({ | ||
name, | ||
type: getTypeOf(propDef.value) | ||
}, propDef); | ||
type | ||
}, propDef, TYPE_DEFINITIONS[type]); | ||
} | ||
return Object.assign({ | ||
name | ||
}, propDef); | ||
type, | ||
value: propDef | ||
}, TYPE_DEFINITIONS[type]); | ||
} | ||
function parsePropDefinition(propDef) { | ||
const { | ||
type | ||
} = propDef; | ||
const typeDefinition = TYPE_DEFINITIONS[type] || {}; | ||
const { | ||
typeValidator | ||
} = typeDefinition; | ||
if (typeValidator) {} | ||
return propDef; | ||
} | ||
function guessNumberType(name, value) { | ||
const isKnownProp = /radius|scale|width|height|pixel|size|miter/i.test(name) && /^((?!scale).)*$/.test(name); | ||
const max = isKnownProp ? 100 : 1; | ||
const min = 0; | ||
return { | ||
name, | ||
type: 'number', | ||
max: Math.max(value, max), | ||
min: Math.min(value, min), | ||
value | ||
}; | ||
} | ||
function getTypeOf(value) { | ||
@@ -141,8 +68,4 @@ if (Array.isArray(value) || ArrayBuffer.isView(value)) { | ||
if (value === null) { | ||
return 'null'; | ||
} | ||
return typeof value; | ||
} | ||
//# sourceMappingURL=prop-types.js.map |
@@ -77,3 +77,3 @@ import { MODULE_INJECTORS_VS, MODULE_INJECTORS_FS } from '../modules/module-injectors'; | ||
if (injectStandardStubs) { | ||
source = source.replace('}s*$', match => match + MODULE_INJECTORS[type]); | ||
source = source.replace(/\}\s*$/, match => match + MODULE_INJECTORS[type]); | ||
} | ||
@@ -80,0 +80,0 @@ |
import transpileShader from './transpile-shader'; | ||
import { assert } from '../utils'; | ||
import { parsePropTypes } from './filters/prop-types'; | ||
const VERTEX_SHADER = 'vs'; | ||
@@ -12,3 +13,4 @@ const FRAGMENT_SHADER = 'fs'; | ||
dependencies = [], | ||
getUniforms = () => ({}), | ||
uniforms, | ||
getUniforms, | ||
deprecations = [], | ||
@@ -27,2 +29,6 @@ defines = {}, | ||
this.defines = defines; | ||
if (uniforms) { | ||
this.uniforms = parsePropTypes(uniforms); | ||
} | ||
} | ||
@@ -46,6 +52,2 @@ | ||
if (typeof moduleSource !== 'string') { | ||
return ''; | ||
} | ||
return "#define MODULE_".concat(this.name.toUpperCase(), "\n").concat(moduleSource, "// END MODULE_").concat(this.name, "\n\n"); | ||
@@ -55,3 +57,11 @@ } | ||
getUniforms(opts, uniforms) { | ||
return this.getModuleUniforms(opts, uniforms); | ||
if (this.getModuleUniforms) { | ||
return this.getModuleUniforms(opts, uniforms); | ||
} | ||
if (this.uniforms) { | ||
return this._defaultGetUniforms(opts); | ||
} | ||
return {}; | ||
} | ||
@@ -66,5 +76,5 @@ | ||
if (def.regex.test(shaderSource)) { | ||
if (def.deprecated && log) { | ||
if (def.deprecated) { | ||
log.deprecated(def.old, def.new)(); | ||
} else if (log) { | ||
} else { | ||
log.removed(def.old, def.new)(); | ||
@@ -76,4 +86,3 @@ } | ||
_parseDeprecationDefinitions() { | ||
let deprecations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
_parseDeprecationDefinitions(deprecations) { | ||
deprecations.forEach(def => { | ||
@@ -92,3 +101,37 @@ switch (def.type) { | ||
_defaultGetUniforms() { | ||
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const uniforms = {}; | ||
const propTypes = this.uniforms; | ||
for (const key in propTypes) { | ||
const propDef = propTypes[key]; | ||
if (key in opts && !propDef.private) { | ||
if (propDef.validate) { | ||
assert(propDef.validate(opts[key], propDef), "".concat(this.name, ": invalid ").concat(key)); | ||
} | ||
uniforms[key] = opts[key]; | ||
} else { | ||
uniforms[key] = propDef.value; | ||
} | ||
} | ||
return uniforms; | ||
} | ||
} | ||
export function normalizeShaderModule(module) { | ||
if (!module.normalized) { | ||
module.normalized = true; | ||
if (module.uniforms && !module.getUniforms) { | ||
const shaderModule = new ShaderModule(module); | ||
module.getUniforms = shaderModule.getUniforms.bind(shaderModule); | ||
} | ||
} | ||
return module; | ||
} | ||
//# sourceMappingURL=shader-module.js.map |
@@ -1,9 +0,1 @@ | ||
const DEFAULT_MODULE_OPTIONS = {}; | ||
function getUniforms() { | ||
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_MODULE_OPTIONS; | ||
const uniforms = {}; | ||
return uniforms; | ||
} | ||
const vs = "varying vec4 geometry_vPosition;\nvarying vec3 geometry_vNormal;\n\nvoid geometry_setNormal(vec3 normal) {\n geometry_vNormal = normal;\n}\n\nvoid geometry_setPosition(vec4 position) {\n geometry_vPosition = position;\n}\n\nvoid geometry_setPosition(vec3 position) {\n geometry_vPosition = vec4(position, 1.);\n}\n"; | ||
@@ -14,5 +6,4 @@ const fs = "varying vec4 geometry_vPosition;\nvarying vec3 geometry_vNormal;\n\nvec4 geometry_getPosition() {\n return geometry_vPosition;\n}\n\nvec3 geometry_getNormal() {\n return geometry_vNormal;\n}\n"; | ||
vs, | ||
fs, | ||
getUniforms | ||
fs | ||
}; | ||
//# sourceMappingURL=geometry.js.map |
@@ -28,3 +28,3 @@ import lights from '../lights/lights'; | ||
materialUniforms.lighting_uShininess = material.shininess; | ||
materialUniforms.lighting_uSpecularColor = material.specularColor; | ||
materialUniforms.lighting_uSpecularColor = material.specularColor.map(x => x / 255); | ||
return materialUniforms; | ||
@@ -31,0 +31,0 @@ } |
@@ -6,19 +6,10 @@ import MODULAR_VS from './shaders/modular-vertex.glsl'; | ||
export { combineInjects } from './lib/inject-shader'; | ||
export { normalizeShaderModule } from './lib/filters/normalize-module'; | ||
export { normalizeShaderModule } from './lib/shader-module'; | ||
export { getQualifierDetails, getPassthroughFS, typeToChannelSuffix, typeToChannelCount, convertToVec4 } from './utils/shader-utils'; | ||
export { default as fp32 } from './modules/fp32/fp32'; | ||
export { default as fp64 } from './modules/fp64/fp64'; | ||
export { default as project } from './modules/project/project'; | ||
export { default as lights } from './modules/lights/lights'; | ||
export { default as dirlight } from './modules/dirlight/dirlight'; | ||
export { default as picking } from './modules/picking/picking'; | ||
export { default as diffuse } from './modules/diffuse/diffuse'; | ||
export { gouraudlighting, phonglighting } from './modules/phong-lighting/phong-lighting'; | ||
export { default as pbr } from './modules/pbr/pbr'; | ||
export { default as _transform } from './modules/transform/transform'; | ||
export * from './modules'; | ||
export var MODULAR_SHADERS = { | ||
vs: MODULAR_VS, | ||
fs: MODULAR_FS, | ||
defaultUniforms: {} | ||
uniforms: {} | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -44,4 +44,3 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
} | ||
export function assembleShaders(gl) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
export function assembleShaders(gl, opts) { | ||
var vs = opts.vs, | ||
@@ -71,4 +70,3 @@ fs = opts.fs; | ||
type = _ref.type, | ||
_ref$modules = _ref.modules, | ||
modules = _ref$modules === void 0 ? [] : _ref$modules, | ||
modules = _ref.modules, | ||
_ref$defines = _ref.defines, | ||
@@ -141,3 +139,6 @@ defines = _ref$defines === void 0 ? {} : _ref$defines, | ||
default: | ||
module.checkDeprecations(coreSource, log); | ||
if (log) { | ||
module.checkDeprecations(coreSource, log); | ||
} | ||
var moduleSource = module.getModuleSource(type, glslVersion); | ||
@@ -144,0 +145,0 @@ assembledSource += moduleSource; |
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
var TYPE_DEFINITIONS = { | ||
"boolean": { | ||
number: { | ||
validate: function validate(value, propType) { | ||
return true; | ||
return Number.isFinite(value) && (!('max' in propType) || value <= propType.max) && (!('min' in propType) || value >= propType.min); | ||
} | ||
}, | ||
number: { | ||
validateType: function validateType(value, propType) { | ||
return 'value' in propType && (!('max' in propType) || Number.isFinite(propType.max)) && (!('min' in propType) || Number.isFinite(propType.min)); | ||
}, | ||
array: { | ||
validate: function validate(value, propType) { | ||
return Number.isFinite(value) && (!('max' in propType) || value <= propType.max) && (!('min' in propType) || value >= propType.min); | ||
return Array.isArray(value) || ArrayBuffer.isView(value); | ||
} | ||
@@ -20,76 +16,29 @@ } | ||
var propTypes = {}; | ||
var defaultProps = {}; | ||
for (var _i = 0, _Object$entries = Object.entries(propDefs); _i < _Object$entries.length; _i++) { | ||
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), | ||
propName = _Object$entries$_i[0], | ||
propDef = _Object$entries$_i[1]; | ||
var propType = parsePropType(propName, propDef); | ||
for (var propName in propDefs) { | ||
var propDef = propDefs[propName]; | ||
var propType = parsePropType(propDef); | ||
propTypes[propName] = propType; | ||
defaultProps[propName] = propType.value; | ||
} | ||
return { | ||
propTypes: propTypes, | ||
defaultProps: defaultProps | ||
}; | ||
return propTypes; | ||
} | ||
function parsePropType(name, propDef) { | ||
switch (getTypeOf(propDef)) { | ||
case 'object': | ||
propDef = normalizePropType(name, propDef); | ||
return parsePropDefinition(propDef); | ||
function parsePropType(propDef) { | ||
var type = getTypeOf(propDef); | ||
case 'array': | ||
return guessArrayType(name, propDef); | ||
case 'boolean': | ||
if (type === 'object') { | ||
if (!propDef) { | ||
return { | ||
name: name, | ||
type: 'boolean', | ||
value: propDef | ||
type: 'object', | ||
value: null | ||
}; | ||
} | ||
case 'number': | ||
return guessNumberType(name, propDef); | ||
if ('type' in propDef) { | ||
return Object.assign({}, propDef, TYPE_DEFINITIONS[propDef.type]); | ||
} | ||
case 'function': | ||
return { | ||
name: name, | ||
type: 'function', | ||
value: propDef | ||
}; | ||
default: | ||
return { | ||
name: name, | ||
type: 'unknown', | ||
value: propDef | ||
}; | ||
} | ||
} | ||
function guessArrayType(name, array) { | ||
if (/color/i.test(name) && (array.length === 3 || array.length === 4)) { | ||
return { | ||
name: name, | ||
type: 'color', | ||
value: array | ||
}; | ||
} | ||
return { | ||
name: name, | ||
type: 'array', | ||
value: array | ||
}; | ||
} | ||
function normalizePropType(name, propDef) { | ||
if (!('type' in propDef)) { | ||
if (!('value' in propDef)) { | ||
return { | ||
name: name, | ||
type: 'object', | ||
@@ -100,36 +49,14 @@ value: propDef | ||
type = getTypeOf(propDef.value); | ||
return Object.assign({ | ||
name: name, | ||
type: getTypeOf(propDef.value) | ||
}, propDef); | ||
type: type | ||
}, propDef, TYPE_DEFINITIONS[type]); | ||
} | ||
return Object.assign({ | ||
name: name | ||
}, propDef); | ||
type: type, | ||
value: propDef | ||
}, TYPE_DEFINITIONS[type]); | ||
} | ||
function parsePropDefinition(propDef) { | ||
var type = propDef.type; | ||
var typeDefinition = TYPE_DEFINITIONS[type] || {}; | ||
var typeValidator = typeDefinition.typeValidator; | ||
if (typeValidator) {} | ||
return propDef; | ||
} | ||
function guessNumberType(name, value) { | ||
var isKnownProp = /radius|scale|width|height|pixel|size|miter/i.test(name) && /^((?!scale).)*$/.test(name); | ||
var max = isKnownProp ? 100 : 1; | ||
var min = 0; | ||
return { | ||
name: name, | ||
type: 'number', | ||
max: Math.max(value, max), | ||
min: Math.min(value, min), | ||
value: value | ||
}; | ||
} | ||
function getTypeOf(value) { | ||
@@ -140,8 +67,4 @@ if (Array.isArray(value) || ArrayBuffer.isView(value)) { | ||
if (value === null) { | ||
return 'null'; | ||
} | ||
return _typeof(value); | ||
} | ||
//# sourceMappingURL=prop-types.js.map |
@@ -94,3 +94,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
if (injectStandardStubs) { | ||
source = source.replace('}s*$', function (match) { | ||
source = source.replace(/\}\s*$/, function (match) { | ||
return match + MODULE_INJECTORS[type]; | ||
@@ -97,0 +97,0 @@ }); |
@@ -5,2 +5,3 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; | ||
import { assert } from '../utils'; | ||
import { parsePropTypes } from './filters/prop-types'; | ||
var VERTEX_SHADER = 'vs'; | ||
@@ -16,6 +17,4 @@ var FRAGMENT_SHADER = 'fs'; | ||
dependencies = _ref$dependencies === void 0 ? [] : _ref$dependencies, | ||
_ref$getUniforms = _ref.getUniforms, | ||
getUniforms = _ref$getUniforms === void 0 ? function () { | ||
return {}; | ||
} : _ref$getUniforms, | ||
uniforms = _ref.uniforms, | ||
getUniforms = _ref.getUniforms, | ||
_ref$deprecations = _ref.deprecations, | ||
@@ -38,2 +37,6 @@ deprecations = _ref$deprecations === void 0 ? [] : _ref$deprecations, | ||
this.defines = defines; | ||
if (uniforms) { | ||
this.uniforms = parsePropTypes(uniforms); | ||
} | ||
} | ||
@@ -59,6 +62,2 @@ | ||
if (typeof moduleSource !== 'string') { | ||
return ''; | ||
} | ||
return "#define MODULE_".concat(this.name.toUpperCase(), "\n").concat(moduleSource, "// END MODULE_").concat(this.name, "\n\n"); | ||
@@ -69,3 +68,11 @@ } | ||
value: function getUniforms(opts, uniforms) { | ||
return this.getModuleUniforms(opts, uniforms); | ||
if (this.getModuleUniforms) { | ||
return this.getModuleUniforms(opts, uniforms); | ||
} | ||
if (this.uniforms) { | ||
return this._defaultGetUniforms(opts); | ||
} | ||
return {}; | ||
} | ||
@@ -82,5 +89,5 @@ }, { | ||
if (def.regex.test(shaderSource)) { | ||
if (def.deprecated && log) { | ||
if (def.deprecated) { | ||
log.deprecated(def.old, def["new"])(); | ||
} else if (log) { | ||
} else { | ||
log.removed(def.old, def["new"])(); | ||
@@ -93,4 +100,3 @@ } | ||
key: "_parseDeprecationDefinitions", | ||
value: function _parseDeprecationDefinitions() { | ||
var deprecations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
value: function _parseDeprecationDefinitions(deprecations) { | ||
deprecations.forEach(function (def) { | ||
@@ -108,2 +114,25 @@ switch (def.type) { | ||
} | ||
}, { | ||
key: "_defaultGetUniforms", | ||
value: function _defaultGetUniforms() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var uniforms = {}; | ||
var propTypes = this.uniforms; | ||
for (var key in propTypes) { | ||
var propDef = propTypes[key]; | ||
if (key in opts && !propDef["private"]) { | ||
if (propDef.validate) { | ||
assert(propDef.validate(opts[key], propDef), "".concat(this.name, ": invalid ").concat(key)); | ||
} | ||
uniforms[key] = opts[key]; | ||
} else { | ||
uniforms[key] = propDef.value; | ||
} | ||
} | ||
return uniforms; | ||
} | ||
}]); | ||
@@ -115,2 +144,14 @@ | ||
export { ShaderModule as default }; | ||
export function normalizeShaderModule(module) { | ||
if (!module.normalized) { | ||
module.normalized = true; | ||
if (module.uniforms && !module.getUniforms) { | ||
var shaderModule = new ShaderModule(module); | ||
module.getUniforms = shaderModule.getUniforms.bind(shaderModule); | ||
} | ||
} | ||
return module; | ||
} | ||
//# sourceMappingURL=shader-module.js.map |
@@ -1,9 +0,1 @@ | ||
var DEFAULT_MODULE_OPTIONS = {}; | ||
function getUniforms() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_MODULE_OPTIONS; | ||
var uniforms = {}; | ||
return uniforms; | ||
} | ||
var vs = "varying vec4 geometry_vPosition;\nvarying vec3 geometry_vNormal;\n\nvoid geometry_setNormal(vec3 normal) {\n geometry_vNormal = normal;\n}\n\nvoid geometry_setPosition(vec4 position) {\n geometry_vPosition = position;\n}\n\nvoid geometry_setPosition(vec3 position) {\n geometry_vPosition = vec4(position, 1.);\n}\n"; | ||
@@ -14,5 +6,4 @@ var fs = "varying vec4 geometry_vPosition;\nvarying vec3 geometry_vNormal;\n\nvec4 geometry_getPosition() {\n return geometry_vPosition;\n}\n\nvec3 geometry_getNormal() {\n return geometry_vNormal;\n}\n"; | ||
vs: vs, | ||
fs: fs, | ||
getUniforms: getUniforms | ||
fs: fs | ||
}; | ||
//# sourceMappingURL=geometry.js.map |
@@ -28,3 +28,5 @@ import lights from '../lights/lights'; | ||
materialUniforms.lighting_uShininess = material.shininess; | ||
materialUniforms.lighting_uSpecularColor = material.specularColor; | ||
materialUniforms.lighting_uSpecularColor = material.specularColor.map(function (x) { | ||
return x / 255; | ||
}); | ||
return materialUniforms; | ||
@@ -31,0 +33,0 @@ } |
{ | ||
"name": "@luma.gl/shadertools", | ||
"version": "7.2.0-alpha.3", | ||
"version": "7.2.0-alpha.4", | ||
"description": "Shader module system for luma.gl", | ||
@@ -42,3 +42,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "ca4f57e62c5b48e931743e7a6f469e1da7914e0e" | ||
"gitHead": "72d3e96ab960915865f7d0dcd58f6a5ab64aa23b" | ||
} |
@@ -19,3 +19,3 @@ // shadertools exports | ||
export {combineInjects} from './lib/inject-shader'; | ||
export {normalizeShaderModule} from './lib/filters/normalize-module'; | ||
export {normalizeShaderModule} from './lib/shader-module'; | ||
@@ -32,19 +32,8 @@ // UTILS | ||
// SHADER MODULES | ||
export {default as fp32} from './modules/fp32/fp32'; | ||
export {default as fp64} from './modules/fp64/fp64'; | ||
export {default as project} from './modules/project/project'; | ||
export {default as lights} from './modules/lights/lights'; | ||
export {default as dirlight} from './modules/dirlight/dirlight'; | ||
export {default as picking} from './modules/picking/picking'; | ||
export {default as diffuse} from './modules/diffuse/diffuse'; | ||
export {gouraudlighting, phonglighting} from './modules/phong-lighting/phong-lighting'; | ||
export {default as pbr} from './modules/pbr/pbr'; | ||
export * from './modules'; | ||
// experimental | ||
export {default as _transform} from './modules/transform/transform'; | ||
export const MODULAR_SHADERS = { | ||
vs: MODULAR_VS, | ||
fs: MODULAR_FS, | ||
defaultUniforms: {} | ||
uniforms: {} | ||
}; |
@@ -52,3 +52,3 @@ import {VERTEX_SHADER, FRAGMENT_SHADER} from './constants'; | ||
// Inject a list of modules | ||
export function assembleShaders(gl, opts = {}) { | ||
export function assembleShaders(gl, opts) { | ||
const {vs, fs} = opts; | ||
@@ -69,3 +69,3 @@ const modules = resolveModules(opts.modules || []); | ||
gl, | ||
{id, source, type, modules = [], defines = {}, inject = {}, prologue = true, log} | ||
{id, source, type, modules, defines = {}, inject = {}, prologue = true, log} | ||
) { | ||
@@ -138,3 +138,5 @@ assert(typeof source === 'string', 'shader source must be a string'); | ||
default: | ||
module.checkDeprecations(coreSource, log); | ||
if (log) { | ||
module.checkDeprecations(coreSource, log); | ||
} | ||
const moduleSource = module.getModuleSource(type, glslVersion); | ||
@@ -141,0 +143,0 @@ // Add the module source, and a #define that declares it presence |
@@ -1,17 +0,3 @@ | ||
// // import assert from '../../utils'; // TODO | ||
const TYPE_DEFINITIONS = { | ||
boolean: { | ||
validate(value, propType) { | ||
return true; | ||
} | ||
}, | ||
number: { | ||
validateType(value, propType) { | ||
return ( | ||
'value' in propType && | ||
(!('max' in propType) || Number.isFinite(propType.max)) && | ||
(!('min' in propType) || Number.isFinite(propType.min)) | ||
); | ||
}, | ||
validate(value, propType) { | ||
@@ -24,2 +10,7 @@ return ( | ||
} | ||
}, | ||
array: { | ||
validate(value, propType) { | ||
return Array.isArray(value) || ArrayBuffer.isView(value); | ||
} | ||
} | ||
@@ -30,9 +21,8 @@ }; | ||
const propTypes = {}; | ||
const defaultProps = {}; | ||
for (const [propName, propDef] of Object.entries(propDefs)) { | ||
const propType = parsePropType(propName, propDef); | ||
for (const propName in propDefs) { | ||
const propDef = propDefs[propName]; | ||
const propType = parsePropType(propDef); | ||
propTypes[propName] = propType; | ||
defaultProps[propName] = propType.value; | ||
} | ||
return {propTypes, defaultProps}; | ||
return propTypes; | ||
} | ||
@@ -43,69 +33,21 @@ | ||
// * or just a default value, in which case type and name inference is used | ||
function parsePropType(name, propDef) { | ||
switch (getTypeOf(propDef)) { | ||
case 'object': | ||
propDef = normalizePropType(name, propDef); | ||
return parsePropDefinition(propDef); | ||
case 'array': | ||
return guessArrayType(name, propDef); | ||
case 'boolean': | ||
return {name, type: 'boolean', value: propDef}; | ||
case 'number': | ||
return guessNumberType(name, propDef); | ||
case 'function': | ||
return {name, type: 'function', value: propDef}; | ||
// return guessFunctionType(name, propDef); | ||
default: | ||
return {name, type: 'unknown', value: propDef}; | ||
} | ||
} | ||
function guessArrayType(name, array) { | ||
if (/color/i.test(name) && (array.length === 3 || array.length === 4)) { | ||
return {name, type: 'color', value: array}; | ||
} | ||
return {name, type: 'array', value: array}; | ||
} | ||
function normalizePropType(name, propDef) { | ||
if (!('type' in propDef)) { | ||
function parsePropType(propDef) { | ||
let type = getTypeOf(propDef); | ||
if (type === 'object') { | ||
if (!propDef) { | ||
return {type: 'object', value: null}; | ||
} | ||
if ('type' in propDef) { | ||
return Object.assign({}, propDef, TYPE_DEFINITIONS[propDef.type]); | ||
} | ||
if (!('value' in propDef)) { | ||
// If no type and value this object is likely the value | ||
return {name, type: 'object', value: propDef}; | ||
return {type: 'object', value: propDef}; | ||
} | ||
return Object.assign({name, type: getTypeOf(propDef.value)}, propDef); | ||
type = getTypeOf(propDef.value); | ||
return Object.assign({type}, propDef, TYPE_DEFINITIONS[type]); | ||
} | ||
return Object.assign({name}, propDef); | ||
return Object.assign({type, value: propDef}, TYPE_DEFINITIONS[type]); | ||
} | ||
function parsePropDefinition(propDef) { | ||
const {type} = propDef; | ||
const typeDefinition = TYPE_DEFINITIONS[type] || {}; | ||
const {typeValidator} = typeDefinition; | ||
if (typeValidator) { | ||
// assert(typeValidator(propDef), 'Illegal prop type'); | ||
} | ||
return propDef; | ||
} | ||
function guessNumberType(name, value) { | ||
const isKnownProp = | ||
/radius|scale|width|height|pixel|size|miter/i.test(name) && /^((?!scale).)*$/.test(name); | ||
const max = isKnownProp ? 100 : 1; | ||
const min = 0; | ||
return { | ||
name, | ||
type: 'number', | ||
max: Math.max(value, max), | ||
min: Math.min(value, min), | ||
value | ||
}; | ||
} | ||
// improved version of javascript typeof that can distinguish arrays and null values | ||
@@ -116,6 +58,3 @@ function getTypeOf(value) { | ||
} | ||
if (value === null) { | ||
return 'null'; | ||
} | ||
return typeof value; | ||
} |
@@ -78,3 +78,3 @@ import {MODULE_INJECTORS_VS, MODULE_INJECTORS_FS} from '../modules/module-injectors'; | ||
if (injectStandardStubs) { | ||
source = source.replace('}s*$', match => match + MODULE_INJECTORS[type]); | ||
source = source.replace(/\}\s*$/, match => match + MODULE_INJECTORS[type]); | ||
} | ||
@@ -81,0 +81,0 @@ |
import transpileShader from './transpile-shader'; | ||
import {assert} from '../utils'; | ||
import {parsePropTypes} from './filters/prop-types'; | ||
@@ -13,3 +14,4 @@ const VERTEX_SHADER = 'vs'; | ||
dependencies = [], | ||
getUniforms = () => ({}), | ||
uniforms, | ||
getUniforms, | ||
deprecations = [], | ||
@@ -29,2 +31,6 @@ defines = {}, | ||
this.defines = defines; | ||
if (uniforms) { | ||
this.uniforms = parsePropTypes(uniforms); | ||
} | ||
} | ||
@@ -46,6 +52,2 @@ | ||
if (typeof moduleSource !== 'string') { | ||
return ''; | ||
} | ||
return `\ | ||
@@ -60,3 +62,10 @@ #define MODULE_${this.name.toUpperCase()} | ||
getUniforms(opts, uniforms) { | ||
return this.getModuleUniforms(opts, uniforms); | ||
if (this.getModuleUniforms) { | ||
return this.getModuleUniforms(opts, uniforms); | ||
} | ||
// Build uniforms from the uniforms array | ||
if (this.uniforms) { | ||
return this._defaultGetUniforms(opts); | ||
} | ||
return {}; | ||
} | ||
@@ -72,5 +81,5 @@ | ||
if (def.regex.test(shaderSource)) { | ||
if (def.deprecated && log) { | ||
if (def.deprecated) { | ||
log.deprecated(def.old, def.new)(); | ||
} else if (log) { | ||
} else { | ||
log.removed(def.old, def.new)(); | ||
@@ -82,3 +91,3 @@ } | ||
_parseDeprecationDefinitions(deprecations = []) { | ||
_parseDeprecationDefinitions(deprecations) { | ||
deprecations.forEach(def => { | ||
@@ -96,2 +105,35 @@ switch (def.type) { | ||
} | ||
_defaultGetUniforms(opts = {}) { | ||
const uniforms = {}; | ||
const propTypes = this.uniforms; | ||
for (const key in propTypes) { | ||
const propDef = propTypes[key]; | ||
if (key in opts && !propDef.private) { | ||
if (propDef.validate) { | ||
assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`); | ||
} | ||
uniforms[key] = opts[key]; | ||
} else { | ||
uniforms[key] = propDef.value; | ||
} | ||
} | ||
return uniforms; | ||
} | ||
} | ||
// This utility mutates the original module | ||
// Keeping for backward compatibility | ||
// TODO - remove in v8 | ||
export function normalizeShaderModule(module) { | ||
if (!module.normalized) { | ||
module.normalized = true; | ||
if (module.uniforms && !module.getUniforms) { | ||
const shaderModule = new ShaderModule(module); | ||
module.getUniforms = shaderModule.getUniforms.bind(shaderModule); | ||
} | ||
} | ||
return module; | ||
} |
// Cheap lighting - single directional light, single dot product, one uniform | ||
/* eslint-disable camelcase */ | ||
const DEFAULT_MODULE_OPTIONS = {}; | ||
function getUniforms(opts = DEFAULT_MODULE_OPTIONS) { | ||
const uniforms = {}; | ||
return uniforms; | ||
} | ||
// TODO - reuse normal from geometry module | ||
@@ -45,4 +37,3 @@ const vs = `\ | ||
vs, | ||
fs, | ||
getUniforms | ||
fs | ||
}; |
@@ -31,3 +31,3 @@ import lights from '../lights/lights'; | ||
materialUniforms.lighting_uShininess = material.shininess; | ||
materialUniforms.lighting_uSpecularColor = material.specularColor; | ||
materialUniforms.lighting_uSpecularColor = material.specularColor.map(x => x / 255); | ||
return materialUniforms; | ||
@@ -34,0 +34,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
1496599
336
20958
1