Skip to content

Material System Details

Patrick Cozzi edited this page Mar 19, 2014 · 42 revisions

Design and implementation ideas for our material system.

Much of this is implemented. See Fabric.

Done: Phase 1

  • Done: Add simple tests that verify the material by rendering a polygon. Currently, we don't have tests for most materials.
  • Done: Explore materials implemented using procedural textures, i.e., brick, marble, granite, wood, asphalt, etc. Later, we'll procedurally shade a city with these building blocks.
  • Done: Add better reference documentation.
  • Done: Add an opacity/alpha map material.
  • Done: Decouple diffuse and specular components.
    • Split agi_getMaterialColor into two separate GLSL functions: agi_getMaterialDiffuseComponent and agi_getMaterialSpecularComponent.
    • Add gloss/specular map material.
    • This will slightly impact the lighting code.
  • Done: Allow the material to modify the surface normal.
    • Add a third GLSL function that materials can optionally implement called agi_getMaterialNormal that takes and returns a normal.
    • Implement a bump map material using this. Implement a normal map material too.
  • Done: Add the world-space eye direction, i.e. the vector from the camera to the fragment in world coordinates, to agi_getMaterial* (or do we only need it for agi_getMaterialDiffuseComponent initially?). Use this to implement:
    • A diffuse reflective material that uses an environment map for reflection, and a 2D texture for the diffuse component. Blend these with a reflectivity parameter.
    • A diffuse refractive material that also uses an environment map. Expose the two indices of refraction.
    • A Fresnel material - approximate, of course.
    • Include optional reflection and refractive maps for the above reflective and refractive materials, maybe Fresnel.
  • Done: All materials should return the specular exponent.
  • Done: All materials should return the emission color.
    • Add a material for an emission map.

Done: Phase 2

  • Done: How do we combine multiple materials, e.g.,
    • A diffuse map and an alpha map to render .png files, for example. See #43.
    • A diffuse map and a specular map.
    • Crumbling bricks that combine brick and bump map materials.
    • A bumpy diffuse reflective surface that combines the bump map and diffuse reflection materials.
    • A diffuse map, diffuse reflective, specular map, and bump map. A bumpy, diffuse lit and reflective surface with shiny areas.
    • Blend two diffuse maps based on a parameter, e.g., terrain height, or third map.

Done: Phase 3

  • Done: Polylines
    • Polylines currently use very simple shaders, and are rendered in three passes using the stencil buffer to achieve an outline effect (turn ANGLE off; start Chrome with --use-gl=desktop).
    • Replace the three-pass algorithm with a single pass algorithm that, in a fragment shader, uses the distance from the fragment to the line to determine if the fragment is part of the outline. Read Tron, Volumetric Lines, and Meshless Tubes.
    • First hard-code the above in the Polyline, then factor it out into a new PolylineOutlineMaterial.
    • Create a PolylineGlowMaterial based on Tron, Volumetric Lines, and Meshless Tubes.
    • Make Polylines work with the rest of the materials as reasonable. Polylines will need to be able to compute at least 1D texture coordinates. I could see some potential for 2D and 3D coordinates as well. All materials will not work with all primitives. We'll need to document a feature matrix.

Phase 4

Details to follow...

Phase 5

  • How does this fit with the effects framework for models? Can they work well together?
  • Do we need the ability to modify and remove material classes (not instances)?
  • Do we need the ability to pull different components from different textures? For example, for a diffuse map, pull the red and green components from one texture, and the blue from another.

Phase ?

  • Lines like this._drawUniforms = combine(this._uniforms, this._material.uniforms); should account for uniform name conflicts.
  • Render to cube map for reflections and refractions.
  • Existing Materials
    • Add (Texture coordinates) offset in addition to the repeat uniform.
    • Ability to mipmap textures.
  • New Materials
    • Erosion. Perhaps screen-space too?
  • JSON schema features.
    • Fold top-level uniforms into lower uniforms, e.g., to implement Image.
    • Support uniform arrays.
    • Add externalSource for external GLSL source files.
    • Easy way to feed output of one material to input of another material. For example, when combining normal mapping and cube-map reflection, make the output from normal mapping input to the reflection to get reflections from the bumpy surface.
  • Author materials with Sandcastle.
  • More general (cached) built-in textures, e.g., { components : "a", values : [1.0] } instead of agi_defaultTexture.

Questions

  • How important is it to support multiple texture coordinates, i.e., different coordinates for different materials on the same object?
  • Do we have a need for relief mapping, etc?
  • How do screen-space techniques like fog, glow, and bloom fit in?

Other Material Systems