Three.js 尝试渲染水体等对象时出现 Can not resolve #include <colorspace_fragment> 问题

发布时间 2023-07-29 10:03:00作者: Nitdie
对 Water对象渲染时出现

Can not resolve #include <colorspace_fragment> at includeReplacer (WebGLProgram.js:220:1) ....

查询发现是库文件中

const string = ShaderChunk[ include ];

该变量的值变为null, 使程序错误 (此时include的值为 colorspace_fragment)

查询ShaderChunk.js文件后,发现color_fragment来自于color_fragment.glsl.js, 查询发现其代码如下:

export default /* glsl */`
#if defined( USE_COLOR_ALPHA )

    diffuseColor *= vColor;

#elif defined( USE_COLOR )

    diffuseColor.rgb *= vColor;

#endif
`;

这是一个的模板字符串,其内容是一个 GLSL 片元着色器代码。

在使用另一版本的Three.js库后(通过npm install 安装)该问题解决,但color_fragment.glsl.js文件内容仍是同样的,因此仍未知问题出现在哪里