glam
Version:
Experimental WebGL Engine
28 lines (22 loc) • 794 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = buildDefines;
/*
* Adds unique defines to the top of a shader. When defines differ between shaders
* a unique shader program is compiled and cached. Materials that share the same
* shader code will result in the same cached shader. The defines are located
* on the material property material.defines, and then the number of lights is
* added at the end.
*/
function wordToExpression(define) {
return "#define " + define + "\n";
}
function buildDefines(material, scene) {
var flags = material.defines.map(wordToExpression).join("");
if (material.flags.useLights) {
flags += "#define DIRECTIONAL_LIGHT_COUNT " + scene.getByType('light/directional').length + "\n";
}
return flags;
}