-
Notifications
You must be signed in to change notification settings - Fork 2
/
debandingmaterial.shader
37 lines (31 loc) · 1.24 KB
/
debandingmaterial.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo : hint_color;
uniform sampler2D texture_albedo : hint_albedo;
uniform float specular;
uniform float metallic;
uniform float roughness : hint_range(0,1);
uniform sampler2D texture_roughness : hint_white;
uniform vec4 roughness_texture_channel;
uniform sampler2D texture_emission : hint_black_albedo;
uniform float emission_energy;
uniform float debanding_dither;
const vec3 noise_magic = vec3(0.06711056, 0.00583715, 52.9829189);
void vertex() {
UV = UV;
}
void fragment() {
vec2 base_uv = UV;
vec4 albedo_tex = texture(texture_albedo, base_uv);
albedo_tex *= COLOR;
// Add noise to albedo to hide banding
float offset = fract(noise_magic.z * fract(dot(FRAGCOORD.xy, noise_magic.xy)));
albedo_tex.rgb += vec3(offset, 1.0 - offset, offset) * debanding_dither;
ALBEDO = albedo.rgb * albedo_tex.rgb;
METALLIC = metallic;
float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel);
ROUGHNESS = roughness_tex * roughness;
SPECULAR = specular;
vec3 emission_tex = texture(texture_emission, base_uv).rgb;
EMISSION = emission_tex * emission_energy;
}