Difference between revisions of "Shading Technique - Gloss Mapping"

From Horde3D Wiki
Jump to: navigation, search
(Draft layout)
 
(done)
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
| {{ContentBlock|width=800|color=white
 
| {{ContentBlock|width=800|color=white
 
|content={{!!}}
 
|content={{!!}}
 
'''I'm still writing this article, based on [http://www.horde3d.org/forums/viewtopic.php?f=1&t=446 this forum post]'''
 
  
 
== 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 10:
  
 
'''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 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 );
 +
</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 mask value.
 +
//setSpecMask( 0.3 );
 +
//Change the "0.3" value to "gloss", Like this:
 +
setSpecMask( gloss );
 +
</source>}}
  
 
== Example Result ==  
 
== Example Result ==  
Insert image here
+
[http://horde3d.org/forums/download/file.php?id=50 Click here to view]
  
 
== To-Do List for this Article ==
 
== To-Do List for this Article ==
 
- Add pictures<BR/>
 
- Add pictures<BR/>
- Finish writing the descriptions ;) - this is a draft<BR/>
+
- Ask for permission to upload a ZIP of my finished xml/tga files ;)<BR/>
  
 
}}
 
}}

Latest revision as of 11:41, 6 August 2008

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
- Ask for permission to upload a ZIP of my finished xml/tga files ;)

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