GLSL built-in function

matrixCompMult()

Multiplies matrices component by component rather than algebraically.

Demo version: GLSL ES 1.00 / WebGL 1Demo stage: Fragment

Syntax

mat matrixCompMult(mat x, mat y)

Parameters

x
Input value or left-hand vector
y
Right-hand vector or comparison value

Return value

A matrix of the same shape with result[column][row] = x[column][row] * y[column][row].

Live example

Edit the code and the preview updates as you type.

What matrixCompMult does

Multiplies matrices component by component rather than algebraically.

Read the preview

The zero in the second matrix removes the first matrix's 0.2 component. Set that zero to 1.0 in mat2(1.0,1.0,0.0,1.0) to restore the missing shear in the grid.

Core call

matrixCompMult(mat2(1.0,0.5,0.2,1.0),mat2(1.0,1.0,0.0,1.0))*vec2(x,y);

Both matrices must have the same dimensions; matrix * matrix is algebraic multiplication.

Experiment

Change the second matrix to mat2(1.0,0.0,0.0,1.0). Component-wise multiplication then removes both off-diagonal entries, producing an axis-aligned grid.

Specification

GLSL ES 1.00 built-in functions, chapter 8

Related functions