参考 pixelInputs

pixelInputs

此 API 是实验性的

其行为可能在 p5.js 的未来版本中发生变化。

A shader hook block that modifies the properties of each pixel before the final color is calculated. This hook can be used inside buildMaterialShader() and similar shader modify() calls to adjust per-pixel data before lighting is applied. Modifications happen between the .begin() and .end() methods of the hook.

The properties of pixelInputs depend on the shader:

  • In buildMaterialShader():

    • normal: a three-component vector representing the surface normal.
    • texCoord: a two-component vector representing the texture coordinates (u, v).
    • ambientLight: a three-component vector representing the ambient light color.
    • ambientMaterial: a three-component vector representing the material's ambient color.
    • specularMaterial: a three-component vector representing the material's specular color.
    • emissiveMaterial: a three-component vector representing the material's emissive color.
    • color: a four-component vector representing the base color (red, green, blue, alpha).
    • shininess: a number controlling specular highlights.
    • metalness: a number controlling the metalness factor.
  • In buildStrokeShader():

    • color: a four-component vector representing the stroke color (red, green, blue, alpha).
    • tangent: a two-component vector representing the stroke tangent.
    • center: a two-component vector representing the cap/join center.
    • position: a two-component vector representing the current fragment position.
    • strokeWeight: a number representing the stroke weight in pixels.

This hook is available in:

示例

Notice any errors or typos? Please let us know. Please feel free to edit src/strands/p5.strands.js and open a pull request!

相关参考