acegiak

Untitled

Jul 5th, 2026
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type spatial;
  2.  
  3. // Varyings
  4. varying float flatness;
  5. varying vec3 power_normal;
  6. varying vec3 triplanar_pos;
  7. varying float biome_amount[12];
  8.  
  9. uniform vec4 BlendValues = vec4(3.0,-2.0,0.0,1.0);
  10.  
  11. uniform sampler2DArray TopTexes:filter_nearest;
  12. uniform sampler2DArray SideTexes:filter_nearest;
  13. uniform vec4[10] TopColors:source_color;
  14. uniform vec4[10] SideColors:source_color;
  15. uniform vec4[10] DebugColors:source_color;
  16. uniform float[10] TopScales;
  17. uniform float[10] SideScales;
  18. uniform int BiomeCount;
  19.  
  20.  
  21. uniform float[10] BiomeOverride;
  22. uniform bool UseOverride = false;
  23.  
  24.  
  25.  
  26. vec2 hash( vec2 p )
  27. {
  28.     return fract( sin( p * mat2( vec2( 127.1, 311.7 ), vec2( 269.5, 183.3 ) ) ) * 43758.5453 );
  29. }
  30.  
  31. void vertex(){
  32.     vec3 object_normal = NORMAL;
  33.     vec3 world_normal = vec3(0.0,1.0,0.0);
  34.     flatness = dot(object_normal,world_normal);
  35.     power_normal = normalize(pow(abs(object_normal),vec3(10.0,10.0,10.0)));
  36.     triplanar_pos = VERTEX*vec3(1.0,-1.0,1.0);
  37.     triplanar_pos = (MODEL_MATRIX * vec4(triplanar_pos, 1.0)).xyz;
  38.  
  39.  
  40.     biome_amount[0] = CUSTOM0.r;
  41.     biome_amount[1] = CUSTOM0.g;
  42.     biome_amount[2] = CUSTOM0.b;
  43.     biome_amount[3] = CUSTOM0.a;
  44.     biome_amount[4] = CUSTOM1.r;
  45.     biome_amount[5] = CUSTOM1.g;
  46.     biome_amount[6] = CUSTOM1.b;
  47.     biome_amount[7] = CUSTOM1.a;
  48.     biome_amount[8] = CUSTOM2.r;
  49.     biome_amount[9] = CUSTOM2.g;
  50.     biome_amount[10] = CUSTOM2.b;
  51.     biome_amount[11] = CUSTOM2.a;
  52.  
  53. }
  54.  
  55. vec4 stochastic_sample(sampler2DArray tex, float layer, vec2 uv){
  56.     vec2 skewV = mat2(vec2(1.0,1.0),vec2(-0.57735027 , 1.15470054))*uv * 3.464;
  57.  
  58.     vec2 vxID = floor(skewV);
  59.     vec2 fracV = fract(skewV);
  60.     vec3 barry = vec3(fracV.x,fracV.y,1.0-fracV.x-fracV.y);
  61.  
  62.     mat4 bw_vx = barry.z>0.0?
  63.         mat4(vec4(vxID,0.0,0.0),vec4((vxID+vec2(0.0,1.0)),0.0,0.0),vec4(vxID+vec2(1.0,0.0),0,0),vec4(barry.zyx,0)):
  64.         mat4(vec4(vxID+vec2(1.0,1.0),0.0,0.0),vec4((vxID+vec2(1.0,0.0)),0.0,0.0),vec4(vxID+vec2(0.0,1.0),0,0),vec4(-barry.z,1.0-barry.y,1.0-barry.x,0));
  65.  
  66.     vec2 ddx = dFdx(uv);
  67.     vec2 ddy = dFdy(uv);
  68.  
  69.     return (textureGrad(tex,vec3(uv+hash(bw_vx[0].xy),layer),ddx,ddy)*bw_vx[3].x) +
  70.     (textureGrad(tex,vec3(uv+hash(bw_vx[1].xy),layer),ddx,ddy)*bw_vx[3].y) +
  71.     (textureGrad(tex,vec3(uv+hash(bw_vx[2].xy),layer),ddx,ddy)*bw_vx[3].z)
  72.     ;
  73.  
  74. }
  75.  
  76. vec4 triplanar_texture(sampler2DArray p_sampler, float layer, vec3 p_weights, vec3 p_triplanar_pos, float uv_scale) {
  77.     vec4 samp = vec4(0.0);
  78.     samp += stochastic_sample(p_sampler, layer, p_triplanar_pos.xy*vec2(uv_scale,uv_scale)) * p_weights.z;
  79.     samp += stochastic_sample(p_sampler, layer, p_triplanar_pos.xz*vec2(uv_scale,uv_scale)) * p_weights.y;
  80.     samp += stochastic_sample(p_sampler, layer, p_triplanar_pos.zy * vec2(-1.0,1.0)*vec2(uv_scale,uv_scale)) * p_weights.x;
  81.     return samp;
  82. }
  83.  
  84.  
  85.  
  86.  
  87. void fragment() {
  88.     vec4 color = COLOR;
  89.  
  90.     vec3 totalcolor = vec3(0.0,0.0,0.0);
  91.     float totalsum = 0.0;
  92.  
  93.     for(int i = 0; i<BiomeCount;i++){
  94.         float amount = biome_amount[i];
  95.         if(UseOverride){
  96.             amount = BiomeOverride[i];
  97.         }
  98.  
  99.         vec4 wall_tex = triplanar_texture(SideTexes, float(i), power_normal, triplanar_pos,SideScales[i]);
  100.         vec3 wall = wall_tex.rgb * SideColors[i].rgb;
  101.  
  102.         vec4 top_tex = triplanar_texture(TopTexes,float(i), power_normal, triplanar_pos,TopScales[i]);
  103.         vec3 top = top_tex.rgb * TopColors[i].rgb;
  104.  
  105.         float blend = clamp((flatness*BlendValues.x)+BlendValues.y,BlendValues.z,BlendValues.w);
  106.         vec3 col = mix(wall,top,blend);
  107.  
  108.         totalcolor += (col.rgb*amount);
  109.         totalsum += amount;
  110.     }
  111.     ALBEDO = totalcolor;
  112.     if(totalsum<=0.0){
  113.         ALBEDO = vec3(biome_amount[7],biome_amount[8],biome_amount[9]);
  114.     }
  115.     //ALBEDO = color.rgb;
  116. }
  117.  
Advertisement
Add Comment
Please, Sign In to add comment