I-Can’t-Believe-It’s-Not-Matcap (modular view-based shading)

I’m quite intrigued by especially cheap shading techniques. Matcaps are very interesting, but not particularly easy to make on the fly.

In this shader, I’ve taken a fresnel function and added the option to manually shift the normal horizontally, vertically, and … in the z-axis? (shifting the z kind of changes the ”light intensity” but I’m hesitant to call it that exactly) Just play around with the controls a bit and you should get an idea of what they do.

To enable albedo texture, uncomment lines 12 and 21, and remove line 20.

To enable normal map, uncomment lines 11, 15 and 16.

preview model by Slava_Gedich

Shader code
shader_type spatial;
render_mode unshaded;

uniform lowp vec3 color1: source_color = vec3(1.0, 1.0, 1.0);
uniform lowp vec3 color2: source_color = vec3(0.0, 0.0, 0.0);
uniform lowp float lightness : hint_range(0, 5.0) = 1.0;
uniform lowp float sharpness : hint_range(1.0, 10.0) = 1.5;
uniform lowp float x_offset : hint_range(-1.0, 1.0) = 0.0;
uniform lowp float y_offset : hint_range(-1.0, 1.0) = 0.0;
uniform lowp float z_offset : hint_range(-1.0, 2.5) = 1.0;
//uniform sampler2D normalmap: hint_normal, filter_linear_mipmap, repeat_disable;
//uniform sampler2D texture: source_color, filter_linear, repeat_disable;

void fragment () {
//	vec3 nmpd = texture(normalmap, UV).rgb - 0.5;
//	NORMAL= normalize(TANGENT * nmpd.x + BINORMAL * nmpd.y + NORMAL * -nmpd.z);
	vec3 matnm = vec3(NORMAL.x-x_offset, NORMAL.y-y_offset, NORMAL.z+z_offset);
	float fresnel = clamp((pow((1.0 - dot(normalize(matnm), normalize(VIEW))), lightness) * sharpness), 0.0, 1.0);
	vec3 matco = mix(color1, color2, fresnel);
	ALBEDO = matco;
//	ALBEDO = (texture(texture, UV).rgb)*matco;
}
Live Preview
Tags
cheap, matcap, mobile, shading
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from CountingClowns

Related shaders

guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
chuck sneedioni
chuck sneedioni
4 months ago

Splendid work