GPURenderPassEncoder: phương thức setBlendConstant()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Phương thức setBlendConstant() của giao diện GPURenderPassEncoder đặt giá trị màu sắc và alpha pha trộn hằng số được dùng với các hệ số pha trộn "constant""one-minus-constant" (như được đặt trong descriptor của phương thức GPUDevice.createRenderPipeline(), trong thuộc tính blend).

Cú pháp

js
setBlendConstant(color)

Tham số

color

Một đối tượng hoặc mảng biểu diễn màu sắc để sử dụng khi pha trộn — các thành phần r, g, ba được biểu diễn dưới dạng số dấu phẩy động trong khoảng từ 0.0 đến 1.0.

Ví dụ về đối tượng:

js
const color = { r: 0.0, g: 0.5, b: 1.0, a: 1.0 };

Tương đương dưới dạng mảng trông như sau:

js
const color = [0.0, 0.5, 1.0, 1.0];

Note: Nếu không có lệnh gọi setBlendConstant() nào được thực hiện, giá trị màu sắc hằng số pha trộn mặc định là (0, 0, 0, 0) cho mỗi lần thực thi kết xuất.

Giá trị trả về

Không có (Undefined).

Ví dụ

js
// …

const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);

passEncoder.setPipeline(renderPipeline);
passEncoder.setVertexBuffer(0, vertexBuffer);
passEncoder.setBlendConstant([1.0, 0.0, 0.0, 1.0]);
passEncoder.draw(3);

passEncoder.end();

// …

Thông số kỹ thuật

Specification
WebGPU
# dom-gpurenderpassencoder-setblendconstant

Tương thích trình duyệt

Xem thêm