Team Fortress 2 Shader
Kind of eye-balled it from here: https://youtu.be/ebvbVO1QE5o?t=127
Any feedback from people with more in-depth knowledge of TF2 materials greatly appreciated.
Note:
Phong exponent texture determines smoothness/spread of the specular blob but unlike a roughness map, the value goes from black to white like a specular map (accurate to TF2) so keep that in mind while using it on your own models.
Shader code
shader_type spatial;
group_uniforms Diffuse;
uniform sampler2D diffuse_texture : source_color, filter_linear_mipmap;
uniform vec3 diffuse_color : source_color = vec3(1.0, 1.0, 1.0);
uniform sampler2D lightwarp : source_color, filter_linear, repeat_disable;
group_uniforms Normal;
uniform sampler2D normal_texture : hint_normal, filter_linear_mipmap;
uniform float normal_strength : hint_range(0.0, 16.0) = 1.0;
group_uniforms Phong;
uniform sampler2D phong_texture : source_color, filter_linear_mipmap;
uniform sampler2D phong_exponent_texture : source_color, filter_linear_mipmap;
uniform float phong : hint_range(0.0, 1.0) = .25;
uniform float phong_exponent : hint_range(0.0, 1.0) = .25;
group_uniforms Rim;
uniform float rim_strength : hint_range(0.0, 1.0) = .5;
uniform float rim_spread : hint_range(1.0, 8.0) = 6.0;
float fresnel(float amount, vec3 normal, vec3 view)
{
return pow((1.0-clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0 )), amount);
}
void fragment() {
ALBEDO = texture(diffuse_texture, UV).rgb * diffuse_color;
ROUGHNESS = 0.5;
SPECULAR = 0.0;
METALLIC = 0.0;
ALBEDO += fresnel(rim_spread, VIEW, NORMAL) * rim_strength;
NORMAL_MAP = texture(normal_texture, UV).rgb;
NORMAL_MAP_DEPTH = normal_strength;
}
void light() {
float wrap = 0.5;
// DIFFUSE
float NdotL = clamp( dot(NORMAL, LIGHT), 0.0, 1.0);
float wrapped = pow(NdotL * wrap + (1.0-wrap), 2.0);
vec4 lw = texture(lightwarp, vec2(wrapped, 0.0));
DIFFUSE_LIGHT += lw.rgb * LIGHT_COLOR * ATTENUATION;
// PHONG
if (phong_exponent > 0.0) {
float _phong_mask_tex = texture(phong_texture, UV).w;
float _phong_exponent_tex = texture(phong_exponent_texture, UV).w;
float _phong_strength = (_phong_mask_tex * phong);
float _phong_exponent = (phong_exponent * _phong_exponent_tex);
vec3 halfdir = normalize(VIEW+LIGHT);
float NdotV = clamp( dot(NORMAL, halfdir), 0.0, 1.0);
float _p = pow(NdotV, 256.0 * _phong_exponent) * _phong_exponent * _phong_strength * 0.1;
SPECULAR_LIGHT += (_p * LIGHT_COLOR * ATTENUATION);
}
}
Meds?
I wish you long life and prosperity 🙂
hey this is pretty cool 🙂