Advertisement
SoloCodeNet

lava shader

Jan 17th, 2021
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. shader_type spatial;
  2. render_mode shadows_disabled;
  3. //render_mode unshaded;
  4.  
  5. uniform vec4 main_color : hint_color;
  6. uniform vec4 intersection_color : hint_color;
  7. uniform float intersection_max_threshold = 0.5;
  8. uniform sampler2D displ_tex : hint_white;
  9. uniform sampler2D noise1;
  10. uniform sampler2D noise2;
  11. uniform float displ_amount = 0.6;
  12. uniform float near = 0.15;
  13. uniform float far = 300.0;
  14.  
  15. float linearize(float c_depth) {
  16.     c_depth = 2.0 * c_depth - 1.0;
  17.     return near * far / (far + c_depth * (near - far));
  18. }
  19.  
  20. void fragment(){
  21.     // partie LAVA
  22.     float t = TIME * 0.005;
  23.     vec3 v1 = texture(noise1, UV +t).rgb;
  24.     vec3 v2 = texture(noise2, UV -t).rgb;
  25.     float sum = (v1.r + v2.r) - 0.7;
  26.    
  27. //  vec4 back = vec4(1.0, 0.0, 0.0, 1.0);
  28.     float fin = 0.0;
  29.     if(sum > 0.0 && sum < 0.2) fin = 0.2;
  30.     if(sum > 0.2 && sum <= 0.7) fin  = 0.0;
  31.     if(sum > 0.7 ) fin  = 1.0;
  32.  
  33.     vec3 lava = vec3(fin) + mix(main_color.rgb, intersection_color.rgb, 0.5) ;
  34.    
  35. //  partie FOAM
  36.     float zdepth = linearize(texture(DEPTH_TEXTURE, SCREEN_UV).x);
  37.     float zpos = linearize(FRAGCOORD.z);
  38.     float diff = zdepth - zpos;
  39.  
  40.     vec2 displ = texture(displ_tex, UV - TIME / 20.0).gb;
  41.     displ = ((displ * 2.0) - 1.0) * displ_amount;
  42.     diff += displ.x;
  43.  
  44.     vec4 col =  mix(intersection_color, main_color, step(intersection_max_threshold, diff));
  45.     vec3 final = col.rgb+ lava;
  46.  
  47.     ALBEDO = final;
  48.     EMISSION =final * 1.5;
  49.  
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement