@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
49 lines • 2.48 kB
JavaScript
const VaryingRegex = /(flat\s)?\s*varying\s*.*/;
/** @internal */
export class WebGL2ShaderProcessor {
constructor() {
this.shaderLanguage = 0 /* ShaderLanguage.GLSL */;
}
attributeProcessor(attribute) {
return attribute.replace("attribute", "in");
}
varyingCheck(varying, _isFragment) {
return VaryingRegex.test(varying);
}
varyingProcessor(varying, isFragment) {
return varying.replace("varying", isFragment ? "in" : "out");
}
postProcessor(code, defines, isFragment) {
const hasDrawBuffersExtension = code.search(/#extension.+GL_EXT_draw_buffers.+require/) !== -1;
// Remove extensions
const regex = /#extension.+(GL_OVR_multiview2|GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g;
code = code.replace(regex, "");
// Replace instructions
code = code.replace(/texture2D\s*\(/g, "texture(");
if (isFragment) {
const hasOutput = code.search(/layout *\(location *= *0\) *out/g) !== -1;
const hasDualSourceBlending = defines.indexOf("#define DUAL_SOURCE_BLENDING") !== -1;
const outputDeclaration = hasDualSourceBlending
? "layout(location = 0, index = 0) out vec4 glFragColor;\nlayout(location = 0, index = 1) out vec4 glFragColor2;\n"
: "layout(location = 0) out vec4 glFragColor;\n";
if (hasDualSourceBlending) {
code = "#extension GL_EXT_blend_func_extended : require\n" + code;
}
code = code.replace(/texture2DLodEXT\s*\(/g, "textureLod(");
code = code.replace(/textureCubeLodEXT\s*\(/g, "textureLod(");
code = code.replace(/textureCube\s*\(/g, "texture(");
code = code.replace(/gl_FragDepthEXT/g, "gl_FragDepth");
code = code.replace(/gl_FragColor/g, "glFragColor");
code = code.replace(/gl_FragData/g, "glFragData");
code = code.replace(/void\s+?main\s*\(/g, (hasDrawBuffersExtension || hasOutput ? "" : outputDeclaration) + "void main(");
}
else {
const hasMultiviewExtension = defines.indexOf("#define MULTIVIEW") !== -1;
if (hasMultiviewExtension) {
return "#extension GL_OVR_multiview2 : require\nlayout (num_views = 2) in;\n" + code;
}
}
return code;
}
}
//# sourceMappingURL=webGL2ShaderProcessors.js.map