Difference between revisions of "Shading Technique - Gloss Mapping"
(Draft layout) |
|||
Line 6: | Line 6: | ||
== Overview == | == Overview == | ||
− | ''' | + | '''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 | + | - 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. | ||
− | + | ||
+ | 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"> | ||
− | + | //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>}} | ||
− | + | 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>}} | ||
− | + | This next change is for the deferred shading version only. | |
{{CppSourceCode| | {{CppSourceCode| | ||
− | description= | + | description= GLSL Code to be modified in ATTRIBPASS.| |
code= | code= | ||
<source lang="cpp" line="1"> | <source lang="cpp" line="1"> | ||
− | + | //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
|
|