Difference between revisions of "Shading Technique - Gloss Mapping"
(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={{!!}} | ||
− | |||
− | |||
== 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 10: | ||
'''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 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>}} | ||
− | + | 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 mask value. | |
+ | //setSpecMask( 0.3 ); | ||
+ | //Change the "0.3" value to "gloss", Like this: | ||
+ | setSpecMask( gloss ); | ||
+ | </source>}} | ||
== Example Result == | == Example Result == | ||
− | + | [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/> | ||
− | - | + | - Ask for permission to upload a ZIP of my finished xml/tga files ;)<BR/> |
}} | }} |
Latest revision as of 11:41, 6 August 2008
|
|