Shading Technique - Gloss Mapping

From Horde3D Wiki
Revision as of 11:41, 6 August 2008 by Darkangel (talk | contribs)
Jump to: navigation, search

Overview

What is a gloss map? a texture that describes whether a surface area is matte or gloss. This texture is used as a mask for specular highlights.

Why might you want to use this technique?
- On materials that visibly vary in "shininess", such as reflective metal that is partially dirty.

Requirements:
- RGBA texture, with the RGB channels representing color (as usual) and the alpha channel representing the gloss map
- Bright areas in the gloss map will by shiny, dark areas will be matte

The Technique

Seeing as specular lighting is already present in the shaders that are bundled with a new Horde3D installation, adding in a specular mask is exceedingly simple.

Only a few minor adjustments are required, in theory all we need to do is read the alpha channel from our texture and input that data into the specular lighting equations. I will make a modified version of the parallax shader to demonstrate how to make these additions. I'll make the changes for both the deferred and forward shading versions of the code.

The first step is the same for both the deferred and forward versions (i.e. the ATTRIBPASS and the LIGHTING contexts, respectively).

GLSL Code to be modified in both ATTRIBPASS and LIGHTING.
//This line reads the RGB values of our texture, comment it out:
//vec3 albedo = texture2D( tex0, newCoords.st ).rgb;
//And then replace it with this code that also reads the alpha channel:
vec4 albedo_gloss = texture2D( tex0, newCoords.st ).rgba;
vec3 albedo = albedo_gloss.rgb;
float gloss = albedo_gloss.a;

This next change is for the forward shading version only.

GLSL Code to be modified in LIGHTING.
//This line of code performs the lighting equation. The first hard-coded values of 0.3 is the specular mask value.
//gl_FragColor.rgb =
//	calcPhongSpotLight( newPos, normalize( normal ), albedo, 0.3, 16.0, -vsPos.z, 0.3 );
//Change the first "0.3" value to "gloss", Like this:
gl_FragColor.rgb =
	calcPhongSpotLight( newPos, normalize( normal ), albedo, gloss, 16.0, -vsPos.z, 0.3 );

This next change is for the deferred shading version only.

GLSL Code to be modified in ATTRIBPASS.
//This line of code saves the material properties. The hard-coded value of 0.3 is the specular mask value.
//setSpecMask( 0.3 );
//Change the "0.3" value to "gloss", Like this:
setSpecMask( gloss );

Example Result

Click here to view

To-Do List for this Article

- Add pictures
- Finish writing the descriptions ;) - this is a draft

Technique - Gloss mapping
File:Todo.jpg
Using an alpha channel to mask specular highlights.
Version: 1.0
Compatible with Horde3D: 1.0 beta
Release date: 2008-08-06
Author(s): DarkAngel