Namespace: material
Language: Lua
Type: Defold Lua
File: script_material.cpp
Source: engine/gamesys/src/gamesys/scripts/script_material.cpp
Functions for interacting with materials.
Type: FUNCTION Returns a table of all the shader constants in the material. This function will return all the shader constants that are used in both the vertex and the fragment shaders.
Parameters
path (hash |
string) - The path to the resource |
Returns
table (table) - A table of tables, where each entry contains info about the shader constants:namehash the hashed name of the constant</dd>
typenumber the type of the constant. Supported values:</dd> </dl>
material.CONSTANT_TYPE_USERmaterial.CONSTANT_TYPE_USER_MATRIX4material.CONSTANT_TYPE_VIEWPROJmaterial.CONSTANT_TYPE_WORLDmaterial.CONSTANT_TYPE_TEXTUREmaterial.CONSTANT_TYPE_VIEWmaterial.CONSTANT_TYPE_PROJECTIONmaterial.CONSTANT_TYPE_NORMALmaterial.CONSTANT_TYPE_WORLDVIEWmaterial.CONSTANT_TYPE_WORLDVIEWPROJmaterial.CONSTANT_TYPE_TIMEmaterial.CONSTANT_TYPE_WORLD_INVERSEmaterial.CONSTANT_TYPE_VIEW_INVERSEmaterial.CONSTANT_TYPE_PROJECTION_INVERSEmaterial.CONSTANT_TYPE_VIEWPROJ_INVERSEmaterial.CONSTANT_TYPE_WORLDVIEW_INVERSEmaterial.CONSTANT_TYPE_WORLDVIEWPROJ_INVERSEvaluevmath.vector4 | vmath.matrix4 the value(s) of the constant. If the constant is an array, the value will be a table of vmath.vector4 or vmath.matrix4 if the type is material.CONSTANT_TYPE_USER_MATRIX4.</dd>
</dl>
Examples
Get the shader constants from a material specified as a resource property
go.property("my_material", resource.material())
function init(self)
local constants = material.get_constants(self.my_material)
end
Type: FUNCTION Returns a table of all the texture samplers in the material. This function will return all the texture samplers that are used in both the vertex and the fragment shaders.
Parameters
path (hash |
string) - The path to the resource |
Returns
table (table) - A table of tables, where each entry contains info about the texture samplers:namehash the hashed name of the texture sampler</dd>
u_wrapnumber the u wrap mode of the texture sampler. Supported values:</dd> </dl>
graphics.TEXTURE_WRAP_CLAMP_TO_BORDERgraphics.TEXTURE_WRAP_CLAMP_TO_EDGEgraphics.TEXTURE_WRAP_MIRRORED_REPEATgraphics.TEXTURE_WRAP_REPEATv_wrapnumber the v wrap mode of the texture sampler. Supported values:</dd> </dl>
graphics.TEXTURE_WRAP_CLAMP_TO_BORDERgraphics.TEXTURE_WRAP_CLAMP_TO_EDGEgraphics.TEXTURE_WRAP_MIRRORED_REPEATgraphics.TEXTURE_WRAP_REPEATmin_filternumber the min filter mode of the texture sampler. Supported values:</dd> </dl>
graphics.TEXTURE_FILTER_DEFAULTgraphics.TEXTURE_FILTER_NEARESTgraphics.TEXTURE_FILTER_LINEARgraphics.TEXTURE_FILTER_NEAREST_MIPMAP_NEARESTgraphics.TEXTURE_FILTER_NEAREST_MIPMAP_LINEARgraphics.TEXTURE_FILTER_LINEAR_MIPMAP_NEARESTgraphics.TEXTURE_FILTER_LINEAR_MIPMAP_LINEARmag_filternumber the mag filter mode of the texture sampler</dd> </dl>
graphics.TEXTURE_FILTER_DEFAULTgraphics.TEXTURE_FILTER_NEARESTgraphics.TEXTURE_FILTER_LINEARmax_anisotropynumber the max anisotropy of the texture sampler</dd> </dl>
Examples
Get the texture samplers from a material specified as a resource property
go.property("my_material", resource.material())
function init(self)
local samplers = material.get_samplers(self.my_material)
end
Type: FUNCTION Returns a table of all the textures from the material.
Parameters
path (hash |
string) - The path to the resource |
Returns
table (table) - A table of tables, where each entry contains info about the material textures:pathhash the resource path of the texture. Only available if the texture is a resource.</dd>
handlehash the runtime handle of the texture.</dd>
widthnumber the width of the texture</dd>
heightnumber the height of the texture</dd>
depthnumber the depth of the texture. Corresponds to the number of layers in an array texture.</dd>
mipmapsnumber the number of mipmaps in the texture</dd>
typenumber the type of the texture. Supported values:</dd> </dl>
graphics.TEXTURE_TYPE_2Dgraphics.TEXTURE_TYPE_2D_ARRAYgraphics.TEXTURE_TYPE_CUBE_MAPgraphics.TEXTURE_TYPE_IMAGE_2Dgraphics.TEXTURE_TYPE_3Dgraphics.TEXTURE_TYPE_IMAGE_3Dflagsnumber the flags of the texture. This field is a bit mask of these supported flags:</dd> </dl>
graphics.TEXTURE_USAGE_FLAG_SAMPLEgraphics.TEXTURE_USAGE_FLAG_MEMORYLESSgraphics.TEXTURE_USAGE_FLAG_STORAGEgraphics.TEXTURE_USAGE_FLAG_INPUTgraphics.TEXTURE_USAGE_FLAG_COLORExamples
Get the textures from a material specified as a resource property
go.property("my_material", resource.material())
function init(self)
local textures = material.get_textures(self.my_material)
end
Type: FUNCTION Returns a table of all the vertex attributes in the material. This function will return all the vertex attributes that are used in the vertex shader of the material.
Parameters
path (hash |
string) - The path to the resource |
Returns
table (table) - A table of tables, where each entry contains info about the vertex attributes:namehash the hashed name of the vertex attribute</dd>
valuevmath.vector4 | vmath.vector3 | vmath.matrix4 | number | table the value of the vertex attribute. Matrix attributes that do not map to vmath.matrix4 are returned as a table of numbers.</dd>
normalizeboolean whether the value is normalized when passed into the shader</dd>
data_typenumber the data type of the vertex attribute. Supported values:</dd> </dl>
graphics.DATA_TYPE_BYTEgraphics.DATA_TYPE_UNSIGNED_BYTEgraphics.DATA_TYPE_SHORTgraphics.DATA_TYPE_UNSIGNED_SHORTgraphics.DATA_TYPE_INTgraphics.DATA_TYPE_UNSIGNED_INTgraphics.DATA_TYPE_FLOATcoordinate_spacenumber the coordinate space of the vertex attribute. Supported values:</dd> </dl>
graphics.COORDINATE_SPACE_WORLDgraphics.COORDINATE_SPACE_LOCALsemantic_typenumber the semantic type of the vertex attribute. Supported values:</dd> </dl>
graphics.SEMANTIC_TYPE_NONEgraphics.SEMANTIC_TYPE_POSITIONgraphics.SEMANTIC_TYPE_TEXCOORDgraphics.SEMANTIC_TYPE_PAGE_INDEXgraphics.SEMANTIC_TYPE_COLORgraphics.SEMANTIC_TYPE_NORMALgraphics.SEMANTIC_TYPE_TANGENTgraphics.SEMANTIC_TYPE_WORLD_MATRIXgraphics.SEMANTIC_TYPE_NORMAL_MATRIXgraphics.SEMANTIC_TYPE_BONE_WEIGHTSgraphics.SEMANTIC_TYPE_BONE_INDICESgraphics.SEMANTIC_TYPE_TEXTURE_TRANSFORM_2DExamples
Get the vertex attributes from a material specified as a resource property
go.property("my_material", resource.material())
function init(self)
local vertex_attributes = material.get_vertex_attributes(self.my_material)
end
Type: FUNCTION Sets shader constants in a material, if the constants exist.
Parameters
path (hash |
string) - The path to the resource |
constants (table) - A table keyed by constant name with args tables as values. Constants can be partially updated. Supported entries:typenumber the type of the constant. Supported values:</dd> </dl>
material.CONSTANT_TYPE_USERmaterial.CONSTANT_TYPE_USER_MATRIX4material.CONSTANT_TYPE_VIEWPROJmaterial.CONSTANT_TYPE_WORLDmaterial.CONSTANT_TYPE_TEXTUREmaterial.CONSTANT_TYPE_VIEWmaterial.CONSTANT_TYPE_PROJECTIONmaterial.CONSTANT_TYPE_NORMALmaterial.CONSTANT_TYPE_WORLDVIEWmaterial.CONSTANT_TYPE_WORLDVIEWPROJmaterial.CONSTANT_TYPE_TIMEmaterial.CONSTANT_TYPE_WORLD_INVERSEmaterial.CONSTANT_TYPE_VIEW_INVERSEmaterial.CONSTANT_TYPE_PROJECTION_INVERSEmaterial.CONSTANT_TYPE_VIEWPROJ_INVERSEmaterial.CONSTANT_TYPE_WORLDVIEW_INVERSEmaterial.CONSTANT_TYPE_WORLDVIEWPROJ_INVERSEvaluevmath.vector4 | vmath.vector3 | vmath.matrix4 | number | table the value(s) of the constant. If the shader constant is an array, the amount of values to update depends on how many values that are passed in the ‘value’ field.</dd> </dl>
Examples
Set a shader constant in a material specified as a resource property
go.property("my_material", resource.material())
function update(self)
-- update the 'tint' constant
material.set_constants(self.my_material, {
tint = { value = vmath.vector4(1, 0, 0, 1) }
})
-- change the type of the 'view_proj' constant to CONSTANT_TYPE_USER_MATRIX4 so the renderer can set our custom data
material.set_constants(self.my_material, {
view_proj = { value = self.my_view_proj, type = material.CONSTANT_TYPE_USER_MATRIX4 }
})
end
Type: FUNCTION Sets texture samplers in a material, if the samplers exist. Use this function to change the settings of texture samplers. To set actual textures that should be bound to the samplers, use the material.set_textures function instead.
Parameters
path (hash |
string) - The path to the resource |
samplers (table) - A table keyed by sampler name with args tables as values. Partial updates are supported. Supported entries:u_wrapnumber the u wrap mode of the texture sampler. Supported values:</dd> </dl>
graphics.TEXTURE_WRAP_CLAMP_TO_BORDERgraphics.TEXTURE_WRAP_CLAMP_TO_EDGEgraphics.TEXTURE_WRAP_MIRRORED_REPEATgraphics.TEXTURE_WRAP_REPEATv_wrapnumber the v wrap mode of the texture sampler. Supported values:</dd> </dl>
graphics.TEXTURE_WRAP_CLAMP_TO_BORDERgraphics.TEXTURE_WRAP_CLAMP_TO_EDGEgraphics.TEXTURE_WRAP_MIRRORED_REPEATgraphics.TEXTURE_WRAP_REPEATmin_filternumber the min filter mode of the texture sampler. Supported values:</dd> </dl>
graphics.TEXTURE_FILTER_DEFAULTgraphics.TEXTURE_FILTER_NEARESTgraphics.TEXTURE_FILTER_LINEARgraphics.TEXTURE_FILTER_NEAREST_MIPMAP_NEARESTgraphics.TEXTURE_FILTER_NEAREST_MIPMAP_LINEARgraphics.TEXTURE_FILTER_LINEAR_MIPMAP_NEARESTgraphics.TEXTURE_FILTER_LINEAR_MIPMAP_LINEARmag_filternumber the mag filter mode of the texture sampler</dd> </dl>
graphics.TEXTURE_FILTER_DEFAULTgraphics.TEXTURE_FILTER_NEARESTgraphics.TEXTURE_FILTER_LINEARmax_anisotropynumber the max anisotropy of the texture sampler</dd> </dl>
Examples
Configures a sampler in a material specified as a resource property
go.property("my_material", resource.material())
function init(self)
material.set_samplers(self.my_material, {
texture_sampler = { u_wrap = graphics.TEXTURE_WRAP_REPEAT, v_wrap = graphics.TEXTURE_WRAP_MIRRORED_REPEAT }
})
end
Type: FUNCTION Sets textures in a material, if the samplers exist.
Parameters
path (hash |
string) - The path to the resource |
textures (table) - A table keyed by sampler name with texture resources as values.Examples
Set a texture in a material from a resource
go.property("my_material", resource.material())
go.property("my_texture", resource.texture())
function init(self)
material.set_textures(self.my_material, {
my_texture = self.my_texture
})
end
Type: FUNCTION Sets vertex attributes in a material, if the vertex attributes exist.
Parameters
path (hash |
string) - The path to the resource |
attributes (table) - A table keyed by vertex attribute name with args tables as values. Partial updates are supported. Supported entries:valuevmath.vector4 | vmath.vector3 | vmath.matrix4 | number | table the value of the vertex attribute. Use a table of numbers for matrix attributes that do not map to vmath.matrix4.</dd>
normalizeboolean whether the value is normalized when passed into the shader</dd>
data_typenumber the data type of the vertex attribute. Supported values:</dd> </dl>
graphics.DATA_TYPE_BYTEgraphics.DATA_TYPE_UNSIGNED_BYTEgraphics.DATA_TYPE_SHORTgraphics.DATA_TYPE_UNSIGNED_SHORTgraphics.DATA_TYPE_INTgraphics.DATA_TYPE_UNSIGNED_INTgraphics.DATA_TYPE_FLOATcoordinate_spacenumber the coordinate space of the vertex attribute. Supported values:</dd> </dl>
graphics.COORDINATE_SPACE_DEFAULTgraphics.COORDINATE_SPACE_WORLDgraphics.COORDINATE_SPACE_LOCALsemantic_typenumber the semantic type of the vertex attribute. Supported values:</dd> </dl>
graphics.SEMANTIC_TYPE_NONEgraphics.SEMANTIC_TYPE_POSITIONgraphics.SEMANTIC_TYPE_TEXCOORDgraphics.SEMANTIC_TYPE_PAGE_INDEXgraphics.SEMANTIC_TYPE_COLORgraphics.SEMANTIC_TYPE_NORMALgraphics.SEMANTIC_TYPE_TANGENTgraphics.SEMANTIC_TYPE_WORLD_MATRIXgraphics.SEMANTIC_TYPE_NORMAL_MATRIXgraphics.SEMANTIC_TYPE_BONE_WEIGHTSgraphics.SEMANTIC_TYPE_BONE_INDICESgraphics.SEMANTIC_TYPE_TEXTURE_TRANSFORM_2DExamples
Configures a vertex attribute in a material specified as a resource property
go.property("my_material", resource.material())
function init(self)
material.set_vertex_attributes(self.my_material, {
tint_attribute = { value = vmath.vec4(1, 0, 0, 1), semantic_type = graphics.SEMANTIC_TYPE_COLOR },
weights = { value = vmath.vec4(0, 1, 0, 0), semantic_type = graphics.SEMANTIC_TYPE_NONE }
})
end