ST_MakeMaterial

更新时间:
复制 MD 格式

Creates a material object for a 3D geometry, controlling its rendered appearance—colors, glossiness, transparency, and textures.

Syntax

Three overloads are available, each suited to a different way of defining the material:

  • Syntax 1 — Define material properties using OpenCL-style color and lighting attributes. The function converts them internally to a JSON representation.

  • Syntax 2 — Reference a material already stored in another table, avoiding data duplication and simplifying updates.

  • Syntax 3 — Provide a Physically Based Rendering (PBR) material description directly in GL Transmission Format (glTF) JSON format.

-- Syntax 1: OpenCL-style 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 to an existing material in another table
material ST_MakeMaterial(text table_name,
                         text column_name,
                         text key_value,
                         text schema_name default NULL);

-- Syntax 3: PBR/glTF JSON description
material ST_MakeMaterial(cstring attributes,
                         texture[] textures default NULL);

Parameters

Syntax 1

ParameterTypeRequiredDefaultDescription
ambientcstringNoNULLAmbient light color as an RGBA hex string. Example: #FF88FF00.
diffusecstringNoNULLDiffuse color as an RGBA hex string. Example: #FF88FF00.
specularcstringNoNULLSpecular color as an RGBA hex string. Example: #FF88FF00.
shininessintegerNoNULLGlossiness of the surface. Valid values: 0 (fully matte) to 100 (maximum gloss).
transparencyintegerNoNULLTransparency of the surface. Valid values: 0 (fully opaque) to 100 (fully transparent).
texture_indexintegerNoNULLIndex of the texture to attach to the material. Valid values: 0 to 32767.

Syntax 2

ParameterTypeRequiredDefaultDescription
table_nametextYesThe name of the table where the existing material is stored.
column_nametextYesThe name of the column where the existing material is stored.
key_valuetextYesThe ID of the existing material, used in the WHERE clause.
schema_nametextNoNULLThe schema of the existing material. Defaults to the schema of the table in the current search path.

Syntax 3

ParameterTypeRequiredDefaultDescription
attributescstringYesPBR material description in glTF JSON format.
texturestexture[]NoNULLArray of textures to embed in the material.

Return value

A material object.

Examples

Syntax 1: OpenCL-style attributes

The following example uses all six attributes explicitly. All Syntax 1 parameters are optional and can be combined as needed.

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}}

The following example uses a single named parameter, omitting the rest. This demonstrates that Syntax 1 parameters support named-parameter syntax and are all optional.

SELECT ST_AsText(ST_MakeMaterial(diffuse => '#FFDDEEAA'));

Output:

{"type":"raw", "attributes": {"diffuse":"#FFDDEEAA"}}

Syntax 2: Reference to an existing material

The following example looks up a material stored in the t_material table, column the_material, where num=1.

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/glTF JSON with textures

The following example provides a glTF pbrMetallicRoughness JSON string and attaches textures from the t_texture 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}}}