ST_MakeMaterial
Creates a material object for use in 3D spatial data.
Syntax
Syntax 1 — Define a material using Open Computing Language (OpenCL) color attributes:
material ST_MakeMaterial(cstring ambient default NULL,
cstring diffuse default NULL,
cstring specular default NULL,
integer shininess default NULL,
integer transparency default NULL,
integer texture_index default NULL)Syntax 2 — Reference a material stored in another table:
material ST_MakeMaterial(text table_name,
text column_name,
text key_value,
text schema_name default NULL)Syntax 3 — Define a material using a PBR JSON string in GL Transmission Format (glTF):
material ST_MakeMaterial(cstring attributes,
texture[] textures default NULL)Description
ST_MakeMaterial returns a material object. Choose the syntax based on how you want to define the material:
Syntax 1 describes the material using OpenCL color attributes (
ambient,diffuse,specular,shininess,transparency). The function converts the OpenCL-style description to a JSON-formatted output.Syntax 2 references a material stored in another table. This approach reduces the amount of mesh data and makes it easier to update materials in one place.
Syntax 3 accepts a PBR material description in glTF format as a JSON string, with an optional array of textures.
Parameters
Syntax 1
| Parameter | Type | Description |
|---|---|---|
ambient | cstring | The ambient light color, as an RGBA hexadecimal string. Example: #FF88FF00. |
diffuse | cstring | The diffuse color, as an RGBA hexadecimal string. Example: #FF88FF00. |
specular | cstring | The specular color, as an RGBA hexadecimal string. Example: #FF88FF00. |
shininess | integer | The glossiness. Valid values: 0 to 100. |
transparency | integer | The transparency. Valid values: 0 to 100. |
texture_index | integer | The index of the texture to which the material belongs. Valid values: 0 to 32767. |
Syntax 2
| Parameter | Type | Description |
|---|---|---|
table_name | text | The name of the table that contains the existing material. |
column_name | text | The name of the column that contains the existing material. |
key_value | text | The ID of the existing material, used in the WHERE clause. |
schema_name | text | The schema of the table. Defaults to the schema of the table specified in the search path. |
Syntax 3
| Parameter | Type | Description |
|---|---|---|
attributes | cstring | A PBR material description in glTF format, as a JSON string. |
textures | texture[] | The array of textures included in the material. |
Examples
Syntax 1 — OpenCL color attributes
Specify all color attributes and a texture index:
SELECT ST_AsText(ST_MakeMaterial('#FFDDEEAA', '#FFDDEEAA', '#FFDDEEAA', 30, 70, 2));Output:
{"type":"raw", "attributes": {"ambient":"#FFDDEEAA","diffuse":"#FFDDEEAA","specular":"#FFDDEEAA","shininess":30,"transparency":70,"texture":2}}Specify only the diffuse color using a named parameter:
SELECT ST_AsText(ST_MakeMaterial(diffuse => '#FFDDEEAA'));Output:
{"type":"raw", "attributes": {"diffuse":"#FFDDEEAA"}}Syntax 2 — Reference an existing material
Reference a material stored in the t_material table:
SELECT ST_AsText(ST_MakeMaterial('t_material'::text,
'the_material'::text,
'num=1'::text));Output:
{"type":"db", "attributes": {"schema":"public","table":"t_material","column":"the_material","key":"num=1"}}Syntax 3 — PBR JSON string with textures
Define a material using a PBR JSON string and include textures from a table:
SELECT ST_AsText(ST_MakeMaterial(
'{"pbrMetallicRoughness": {"baseColorFactor": [ 1.000, 0.766, 0.336, 1.0 ], "metallicFactor": 0.5,"roughnessFactor": 0.1}}',
ARRAY(SELECT the_texture FROM t_texture)));Output:
{"type":"raw", "textures":[{"compressionType" : "None", "format" : "JPEG", "wrap" : "Wrap", "type" : "Raw", "depth" : 3, "width" : 256, "height" : 256, "size" : 6, "data" : "313233343536"}], "attributes": {"pbrMetallicRoughness":{"baseColorFactor":[1.0,0.766,0.336,1.0],"metallicFactor":0.5,"roughnessFactor":0.1}}}