Matcap + NormalMap + Triplanar

Shader code
shader_type spatial;
render_mode unshaded;

uniform sampler2D matcap: hint_albedo;
uniform sampler2D normal_map: hint_normal;
uniform vec3 scale;
uniform vec3 offset;

varying vec3 t_pos;
varying vec3 pn;

vec4 triplanar_texture(sampler2D samp,vec3 pn,vec3 t_pos) {
	vec4 samp=vec4(0.0);
	samp+= texture(samp,t_pos.xy) * pn.z;
	samp+= texture(samp,t_pos.xz) * pn.y;
	samp+= texture(samp,t_pos.zy * vec2(-1.0,1.0)) * pn.x;
	return samp;
}

void vertex() {
	pn=pow(abs(NORMAL),vec3(1.0));
	pn/=dot(pn,vec3(1.0));
	t_pos = VERTEX * scale + offset;
	t_pos *= vec3(1.0,-1.0, 1.0);
}

void fragment() {
	vec4 normal = (triplanar_texture(normal_map, pn, t_pos) * 2.0 - 1.0);
	vec3 normalV = mat3(TANGENT, BINORMAL, NORMAL) * normal.xyz;
	vec2 uv = normalV.xy * vec2(0.48, -0.48) + 0.5;
	ALBEDO = texture(matcap, uv).rgb;
}
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 Menrush

Matcap + NormalMap

Related shaders

Matcap + NormalMap

View-MatCap

View-Matcap Based Fake Vertex Lighting

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments