GeeXLab
Current version: 0.17.x
»GeeXLab homepage

FurMark
Current version: 1.19.1
»FurMark homepage
»FurMark 1.9.x Submissions

GPU Caps Viewer
Current version: 1.37.0.0
»GPU Caps Viewer homepage
»GPU DB Submissions

GPU Shark
Current version: 0.10.0.4
»GPU Shark homepage


Blogs
»JeGX's HackLab

Geeks3D's Articles
»GPU Memory Speed Demystified

»Multi-Threading Programming Resources

»GeForce and Radeon OpenCL Overview

»How to Get your Multi-core CPU Busy at 100%

»How To Make a VGA Dummy Plug

»Night Vision Post Processing Filter


PhysX FluidMark
Current version: 1.5.2
»FluidMark homepage
»FluidMark 1.4.x Submissions

TessMark
Current version: 0.3.0
»TessMark homepage

ShaderToyMark
Current version: 0.3.0
»ShaderToyMark homepage
»ShaderToyMark Scores

Demoniak3D
Current Version: 1.23.0
»Demoniak3D
»Download
»Libraries and Plugins
»Demos
»Online Help - Reference Guide
»Codes Samples

3D Graphics Search Engine:

The Geeks Of 3D

 
The Art of Texturing Using The OpenGL Shading Language

By Jerome Guinot aka 'JeGX' - jegx [at] ozone3d (dot) net

Initial draft: April 15, 2006


[ Index ]

Introduction | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7 | Page 8 | Conclusion

»Next Page



5 - Special Textures

5.1 - Gloss Maps

A gloss map is a texture that encodes reflectivity areas. The following picture shows such a texture:


Gloss Map
Fig. 15 - an example of gloss map

The white encodes high reflectivity areas and the black those with low reflectivity. The following image, from the DEMO_Gloss_Map.xml demo shows the use of this gloss maps:


Gloss Mapping
Fig. 16 - the DEMO_Gloss_Map.xml demo

The following GLSL code is the one of the pixel shader of the DEMO_Gloss_Map.xml demo:

[Pixel_Shader]
			
uniform samplerCube cubeMap;
uniform sampler2D colorMap;
uniform sampler2D glossMap;

void main (void)
{
	vec4 output_color;
	
	// Perform a simple 2D texture look up.
	vec4 base_color = texture2D(colorMap, gl_TexCoord[0].st * 2.0).rgba;
	
	// Do a gloss map look up and compute the reflectivity.
	vec3 gloss_color = texture2D(glossMap, gl_TexCoord[0].st).rgb;
	float reflectivity = 0.30*gloss_color.r + 
			0.59*gloss_color.g + 
			0.11*gloss_color.b;

	// Perform a cube map look up.
	vec4 cube_color = textureCube(cubeMap, gl_TexCoord[1].xyz).rgba;

	// Write the final pixel.
	gl_FragColor = base_color + (cube_color*reflectivity);
}

This pixel shader is an altered version of the CEM one. The reflectivity factor is calculated from the relation used to convert a color into a gray value. Thus, you can use color gloss map if you want.



5.2 - Alpha Maps

An alpha map is a binary texture in the meaning it contains information that allows all or nothing based choices. Alpha maps are usually used for tests at the pixel level (alpha-testing) in order to know if a pixel is either fully opaque or fully transparent. In this last case, the pixel is not sent to the framebuffer, saving a little of fillrate.

There is a handy keyword in GLSL to prevent a fragment (pixel in processing in the OpenGL terminology) to update the framebuffer: discard. According to the OpenGL implementations, the instructions that follow the discard keyword can or can not be executed but in all cases the framebuffer will not be updated. discard is available in the pixel shader only.

The following image shows the alpha map used in the DEMO_Alpha_Map.xml demo:


Alpha Map
Fig. 17 - an example of alpha map


Alpha Mapping
Fig. 18 - the DEMO_Alpha_Map.xml demo

Below, a piece of code that shows the use of the discard keyword:

[Pixel_Shader]
			
uniform sampler2D colorMap;
uniform sampler2D alphaMap;

void main (void)
{
	vec4 alpha_color = texture2D(alphaMap, gl_TexCoord[0].xy);
	
	if(alpha_color.r<0.1)
	{
		discard;
	}

	gl_FragColor  = texture2D(colorMap, gl_TexCoord[0].xy);
}




[ Index ]

Introduction | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7 | Page 8 | Conclusion

»Next Page





GeeXLab demos


GLSL - Mesh exploder


PhysX 3 cloth demo


Normal visualizer with GS


Compute Shaders test on Radeon


Raymarching in GLSL



Geeks3D latest news


Geeks3D forum news


Misc
»Texture DataPack #1
»Asus Silent Knight CPU Cooler
Page generated in 0.010803937911987 seconds.