最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Three.jsWebGLGLSL - What does "#include <common>" mean? - Stack Overflow

programmeradmin5浏览0评论

In this Three.js shader example a function called rand() (taking a vec2 as an argument) is used to generate random numbers.

However, the function is not defined in the shader code. Instead, it seems to get included using #include <mon> (first line of the fragment shader).

I guess #include works a bit like in C/C++, but what exactly does <mon> refer to? Is it an external file? Is it something specific to Three.js or will it also work with WebGL/GLSL in general?

In this Three.js shader example a function called rand() (taking a vec2 as an argument) is used to generate random numbers.

However, the function is not defined in the shader code. Instead, it seems to get included using #include <mon> (first line of the fragment shader).

I guess #include works a bit like in C/C++, but what exactly does <mon> refer to? Is it an external file? Is it something specific to Three.js or will it also work with WebGL/GLSL in general?

Share Improve this question edited Jan 25, 2018 at 11:13 user128511 asked Jan 25, 2018 at 9:15 lsgnglsgng 4959 silver badges22 bronze badges 1
  • 1 I think there is shader preprocessor to add mon code to the shader. But maybe i am wrong. – Unick Commented Jan 25, 2018 at 9:34
Add a ment  | 

2 Answers 2

Reset to default 9

It is to do with how three.js tries to make shaders modular via "shaderChunks".
Examples of the included three.js shaders can be see HERE.

That particular part #include <mon> is referring to this "shaderChunk", which seems to be included in most of the three.js shaders to provide mon utility type functions and variables.

As an additional information and for documentation purpose, you can use the same macro to import extra glsl code in a separate glsl file by following this structure:

#include perlin_noise3d.glsl;

assuming both files are placed in the same folder.

发布评论

评论列表(0)

  1. 暂无评论