设置要在绘制时应用的 p5.Shader 对象。
着色器是在图形处理单元 (GPU) 上运行的程序。 它们可以同时处理许多像素或顶点,从而可以快速执行许多图形任务。 它们是用一种名为 GLSL 并与绘图中的其余代码一起运行。p5.Shader 对象可以使用 createShader() 和 loadShader() 函数。
参数 s 是要应用的 p5.Shader 对象。 例如,调用 shader(myShader) 应用 myShader 来处理画布上的每个像素。 该着色器将用于:
- 如果纹理包含统一的纹理,则在启用纹理时填充
sampler2D。li> - 如果包含该属性,则在启用灯光时填充
aNormal,或者如果它具有以下任何 uniform:uUseLighting、uAmbientLightCount、uDirectionalLightCount、uPointLightCount、uAmbientColor、uDirectionalDiffuseColors、uDirectionalSpecularColors、uPointLightLocation、uPointLightDiffuseColors、uPointLightSpecularColors、uLightingDirection,或uSpecular。 - 当没有灯光或纹理时进行填充。
- Strokes if it includes the uniform
uStrokeWeight.
源代码来自一个 p5.Shader 对象的片段和顶点着色器将在第一次传递给 shader() 时进行编译。参见 MDN 了解有关编译着色器的更多信息。
调用 resetShader() 可恢复绘图的默认着色器。
注意:着色器只能在 WebGL 模式下使用。
示例
语法
shader(s)
参数
s
p5.Shader:
应用对象 p5.Shader。
This page is generated from the comments in src/webgl/material.js . Please feel free to edit it and submit a pull request!