
|
Downloads
Demo: geexlab-demopack-gl-21/d53-matcap-viewer/
|
I discovered this incredible library of matcap textures and, to quickly test them, I made a small GeeXLab demo that displays several objects (a sphere, a torus and two glTF 3D models) with the same matcap texture. To view another matcap texture, just drag and drop a matcap texture into the demo.
A small part of the matcap lib:
A matcap (or Material Capture) is an image that combines material properties, lighting and reflections. This image is not a regular texture and has to be mapped on an object using special vertex and pixel shaders.
Here is an example of a matcap texture:
and the same matcap on various objects:
The matcap GPU program (GLSL) looks like:
vertex shader:
#version 120
uniform mat4 gxl3d_ModelViewProjectionMatrix;
uniform mat4 gxl3d_ModelViewMatrix;
varying vec4 v_normal;
void main()
{
gl_Position = gxl3d_ModelViewProjectionMatrix * gl_Vertex;
v_normal = gxl3d_ModelViewMatrix * vec4(gl_Normal.xyz, 0.0);
}
pixel shader:
#version 120
uniform sampler2D tex0;
varying vec4 v_normal;
void main (void)
{
vec3 N = normalize(v_normal.xyz);
// Multiply by 0.5 and adding 0.5 allows
// to map the normal vector coords from [-1;1] to [0;1].
vec2 muv = N.xy * 0.5 + vec2(0.5,0.5);
vec3 t = texture2D(tex0,vec2(muv.x, 1.0-muv.y)).rgb;
gl_FragColor = vec4(t, 1.0);
}
To run the demo, download GeeXLab, download the OpenGL 2.1 demopack and load in GeeXLab the following demo: geexlab-demopack-gl-21/d53-matcap-viewer/main.xml.
Here are some examples:
References
- MatCap — Render & Art pipeline optimization for mobile devices
- Creating a Spherical Reflection/Environment Mapping shader
- Pixologic Matcap Library