Graphics.DefiningMaterialsInEDGE - lordmundi/wikidoctest GitHub Wiki
Defining Materials in EDGE
« Defining Camera Lenses | EDGE User’s Guide | Making a Model Reflect the Environment »
Defining materials in EDGE is done by telling the speedtest plugin the details of your material, and then mapping it onto your model.
Mapping a material to a model
The main way materials defined for speedtest are mapped to a model is done by the texture filename specified by the model. Speedtest can key off of this filename and then override all of the material properties with ones that the user defines.
Another method for non-textured materials is to use the "mapto" feature of the material definition. See below for more information on that feature.
Defining materials
There are two main sections speedtest looks at for materials - the "MATERIALS" block and the "MATERIAL_TEXTURES" block.
MATERIALS block
In this block, you define a material name, and the corresponding material properties that go along with it.
# Format: material_name <attribute fields...>
# where attribute fields can be:
# diffuse( red, green, blue ) # diffuse color
# specular( red, green, blue ) # specular color
# emission( red, green, blue ) # emissive color
# shininess( value ) # shininess value. See note 2
# transparency( value ) # transparency value.
# mapto( new_material_name ) # remap to new material. See note 1 below
#
# Note 1: The mapto feature allows you to key off of a particular
# diffuse, specular, and shininess value specified in a model and
# redefine the material to something new. This works well if you
# have a large number of models using a certain material set and
# you want to override all of them to use new material properties.
#
# Note 2: Materials that have a shininess value greater than 60 will
# trigger blooming to be applied (of course, only if lighting conditions
# would have it bloom).
#
MATERIAL_TEXTURES block
In this block, you map a texture name from a model to the extra properties you want to add to that model. For example, you can add a bumpmap, redefine the texture being used, or change the material properties of the surface to a material you defined in the MATERIALS block.
# Setting material attributes by keying from texture name
#
# Format: texture_name <attribute fields...>
# where attribute fields can be:
# bumpmap( filename, bump_scale, offset ) # Add a bumpmap (parallax map). See note 1
# bumpmap_uvscale( uv_scale_x, uv_scale_y ) # Scale the UV mapping of the bumpmap. See note 2
# texturemap( filename ) # Redefine the texture file
# material( material_name ) # Redefine the material properties to material_name
# disable( ambocc ) # Disable ambient occlusion
# disable( shadows ) # Disable shadows
# disable( env ) # Disable environment reflections
# disable( blooming ) # Disable blooming
#
# Note 1: Bump maps for materials are acutally "parallax mapping". The values read
# from the greyscale image is used to indent into the polygon on the model. The
# bump_scale is the vertical scale applied to the value read from the bumpmap.
# The offset is a value which determines how far on either side of the pixel from
# bumpmap is sampled in order to determine slope. This could be important if you
# have a high frequency bumpmap for example. To see how the scale and offset are used
# in the calculation, see the fragment shader at "shaders/bmpmap.fs".
#
# Note 2: The bmpmap_uvscale scales the UV coordinates in case you want to
# have a different UV mapping for the bump map from the original texture
# UV map.
#
Example
Imagine we have an asteroid model that has a texture applied to it called "neo_2.jpg". In this example, we will add a bumpmap to the model and also change the material properties of the asteroid so that it appears golden and shiny. The following config file will create the nodes and load the model, and the SPEEDTEST block at the bottom will then override the properties of the model by keying off of the texture name.
DSP_CONFIG
{
DATA
{
SCENE_LOAD
{
MODELS
{
node(ASTEROID_SIM_POS);
node(ASTEROID_SIM_ATT); parent(ASTEROID_SIM_POS);
node(ASTEROID); model(itokawa_f0196608_20m_squished_reduced.ac); parent(ASTEROID_SIM_ATT); scale(39.3701, 39.3701, 39.3701);
}
}
}
}
DSP_SPEEDTEST
{
# Defining material names and their lighting attributes
MATERIALS
{
shiny_gold diffuse(0.3,0.11,0.0) specular(1.8,1.1,0.3) shininess(300.0)
}
# Setting material attributes from texture name
MATERIAL_TEXTURES
{
neo_2.jpg bumpmap(foilGold_2.jpg,0.02,0.3) texturemap(neo_2.jpg) material(shiny_gold)
}
}
And now we have a golden asteroid! Also, if you look close you can see the bumpmap.