Advertisement
CKEIREXE

Untitled

Mar 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type spatial;
  2. render_mode diffuse_toon, specular_toon;
  3.  
  4. uniform sampler2D color_ramp : hint_black_albedo;
  5. uniform sampler2D albedo : hint_albedo;
  6. uniform float specular;
  7. uniform float roughness = 1.0;
  8. uniform bool vertical = true;
  9. uniform vec4 item_color : hint_color;
  10. uniform bool disable_lighting = false;
  11. uniform bool enable_colorization = false;
  12. uniform sampler2D color_mask;
  13.  
  14. void light() {
  15.     if (disable_lighting) {
  16.         DIFFUSE_LIGHT = ALBEDO;
  17.         return;
  18.     }
  19.    
  20.     float litness = dot(LIGHT,NORMAL);
  21.     litness = clamp(litness, 0.01,1.0);
  22.     litness = 1.0-litness; // Inverted because toon maps are inverted too
  23.     float ramp_position_x = 0.0;
  24.    
  25.     // Color ramp tinting
  26.     vec3 ramp_point = vec3(0.0);
  27.     ramp_point = texture(color_ramp, vec2(0.5,litness)).rgb;
  28.    
  29.     float NdotL = 1.0; // To avoid gradients... right?
  30.     float diffuse_brdf_NL = smoothstep(-ROUGHNESS,max(ROUGHNESS,0.01),NdotL);
  31.     DIFFUSE_LIGHT += ramp_point*LIGHT_COLOR*ATTENUATION*ALBEDO*mix(vec3(diffuse_brdf_NL), vec3(3.14159265359), vec3(0.40));
  32.    
  33.     // Specular stuff
  34.     /*vec3 R = normalize(-reflect(LIGHT,NORMAL));
  35.     float RdotV = dot(R,VIEW);
  36.     float mid = 1.0-ROUGHNESS;
  37.     mid*=mid;
  38.     float intensity = smoothstep(mid-ROUGHNESS*0.5, mid+ROUGHNESS*0.5, RdotV) * mid;*/
  39.     //DIFFUSE_LIGHT += LIGHT_COLOR * intensity * specular * ATTENUATION; // write to diffuse_light, as in toon shading you generally want no reflection
  40. }
  41. void fragment() {
  42.     ROUGHNESS = roughness;
  43.     SPECULAR=0.0;
  44.     vec3 albedo_tex = texture(albedo,UV).rgb;
  45.     vec3 color_mask_tex = texture(color_mask,UV).rgb;
  46.     if (enable_colorization == true) {
  47.         vec3 texture_base = vec3((albedo_tex.r+albedo_tex.g+albedo_tex.b)/3.0); // Greyscale texture
  48.        
  49.         vec3 colorized = item_color.rgb * (texture_base + item_color.rgb * 0.5); // Texture colorized with item color
  50.         float albedo_value = 1.0-color_mask_tex.r;
  51.         float colorized_value = 1.0-albedo_value;
  52.         colorized = colorized*colorized_value + albedo_tex*albedo_value; // Final texture
  53.         ALBEDO = colorized;
  54.     }
  55.     else {
  56.         ALBEDO = albedo_tex.rgb;
  57.     }
  58.     //ALBEDO = albedo_tex.rgb;
  59.     TRANSMISSION = vec3(0.5);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement