Difference between revisions of "Shading Technique - Gloss Mapping"

From Horde3D Wiki
Jump to: navigation, search
(Draft layout)
 
Line 6: Line 6:
  
 
== Overview ==
 
== Overview ==
'''Defining a gloss map:''' a texture that describes whether a surface area is [http://en.wikipedia.org/wiki/Gloss_%28material_appearance%29 matte or gloss]. This texture is used as a [http://en.wikipedia.org/wiki/Masking_%28in_art%29 mask] for specular highlights.
+
'''What is a gloss map?''' a texture that describes whether a surface area is [http://en.wikipedia.org/wiki/Gloss_%28material_appearance%29 matte or gloss]. This texture is used as a [http://en.wikipedia.org/wiki/Masking_%28in_art%29 mask] for specular highlights.
  
 
'''Why might you want to use this technique?'''<br/>
 
'''Why might you want to use this technique?'''<br/>
Line 12: Line 12:
  
 
'''Requirements:'''<BR/>
 
'''Requirements:'''<BR/>
- RGBA Color Map, with the alpha channel representing the gloss map<BR/>
+
- RGBA texture, with the RGB channels representing color (as usual) and the alpha channel representing the gloss map<BR/>
 
- Bright areas in the gloss map will by shiny, dark areas will be matte<BR/>
 
- Bright areas in the gloss map will by shiny, dark areas will be matte<BR/>
  
 
== The Technique ==
 
== 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.
 
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.
In theory this is all we need:
+
 
 +
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).
 
{{CppSourceCode|
 
{{CppSourceCode|
description= GLSL Code|
+
description= GLSL Code to be modified in both ATTRIBPASS and LIGHTING.|
 
code=
 
code=
 
<source lang="cpp" line="1">
 
<source lang="cpp" line="1">
todo
+
//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;
 
</source>}}
 
</source>}}
  
''Description of what's going on in the above code''
+
This next change is for the forward shading version only.
 +
{{CppSourceCode|
 +
description= GLSL Code to be modified in LIGHTING.|
 +
code=
 +
<source lang="cpp" line="1">
 +
//This line of code performs the lighting equation. The hard-coded values of 0.3 are the specular values.
 +
//gl_FragColor.rgb =
 +
// calcPhongSpotLight( newPos, normalize( normal ), albedo, 0.3, 16.0, -vsPos.z, 0.3 );
 +
//Change the "0.3" values to "gloss", Like this:
 +
gl_FragColor.rgb =
 +
calcPhongSpotLight( newPos, normalize( normal ), albedo, gloss, 16.0, -vsPos.z, gloss );
 +
</source>}}
  
Here is an example of Horde3D's original parallax shader, with the above modifications applied:
+
This next change is for the deferred shading version only.
 
{{CppSourceCode|
 
{{CppSourceCode|
description= Full GLSL Fragment Shader |
+
description= GLSL Code to be modified in ATTRIBPASS.|
 
code=
 
code=
 
<source lang="cpp" line="1">
 
<source lang="cpp" line="1">
Todo</source>}}
+
//This line of code saves the material properties. The hard-coded value of 0.3 is the specular value.
 +
setSpecMask( gloss );
 +
//Change the "0.3" values to "gloss", Like this:
 +
setSpecMask( 0.3 );
 +
</source>}}
  
 
== Example Result ==  
 
== Example Result ==  

Revision as of 11:20, 6 August 2008

I'm still writing this article, based on this forum post

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 hard-coded values of 0.3 are the specular values.
//gl_FragColor.rgb =
//	calcPhongSpotLight( newPos, normalize( normal ), albedo, 0.3, 16.0, -vsPos.z, 0.3 );
//Change the "0.3" values to "gloss", Like this:
gl_FragColor.rgb =
	calcPhongSpotLight( newPos, normalize( normal ), albedo, gloss, 16.0, -vsPos.z, gloss );

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 value.
setSpecMask( gloss );
//Change the "0.3" values to "gloss", Like this:
setSpecMask( 0.3 );

Example Result

Insert image here

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