Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shader_type spatial;
- // Varyings
- varying float flatness;
- varying vec3 power_normal;
- varying vec3 triplanar_pos;
- varying float biome_amount[12];
- uniform vec4 BlendValues = vec4(3.0,-2.0,0.0,1.0);
- uniform sampler2DArray TopTexes:filter_nearest;
- uniform sampler2DArray SideTexes:filter_nearest;
- uniform vec4[10] TopColors:source_color;
- uniform vec4[10] SideColors:source_color;
- uniform vec4[10] DebugColors:source_color;
- uniform float[10] TopScales;
- uniform float[10] SideScales;
- uniform int BiomeCount;
- uniform float[10] BiomeOverride;
- uniform bool UseOverride = false;
- vec2 hash( vec2 p )
- {
- return fract( sin( p * mat2( vec2( 127.1, 311.7 ), vec2( 269.5, 183.3 ) ) ) * 43758.5453 );
- }
- void vertex(){
- vec3 object_normal = NORMAL;
- vec3 world_normal = vec3(0.0,1.0,0.0);
- flatness = dot(object_normal,world_normal);
- power_normal = normalize(pow(abs(object_normal),vec3(10.0,10.0,10.0)));
- triplanar_pos = VERTEX*vec3(1.0,-1.0,1.0);
- triplanar_pos = (MODEL_MATRIX * vec4(triplanar_pos, 1.0)).xyz;
- biome_amount[0] = CUSTOM0.r;
- biome_amount[1] = CUSTOM0.g;
- biome_amount[2] = CUSTOM0.b;
- biome_amount[3] = CUSTOM0.a;
- biome_amount[4] = CUSTOM1.r;
- biome_amount[5] = CUSTOM1.g;
- biome_amount[6] = CUSTOM1.b;
- biome_amount[7] = CUSTOM1.a;
- biome_amount[8] = CUSTOM2.r;
- biome_amount[9] = CUSTOM2.g;
- biome_amount[10] = CUSTOM2.b;
- biome_amount[11] = CUSTOM2.a;
- }
- vec4 stochastic_sample(sampler2DArray tex, float layer, vec2 uv){
- vec2 skewV = mat2(vec2(1.0,1.0),vec2(-0.57735027 , 1.15470054))*uv * 3.464;
- vec2 vxID = floor(skewV);
- vec2 fracV = fract(skewV);
- vec3 barry = vec3(fracV.x,fracV.y,1.0-fracV.x-fracV.y);
- mat4 bw_vx = barry.z>0.0?
- 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)):
- 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));
- vec2 ddx = dFdx(uv);
- vec2 ddy = dFdy(uv);
- return (textureGrad(tex,vec3(uv+hash(bw_vx[0].xy),layer),ddx,ddy)*bw_vx[3].x) +
- (textureGrad(tex,vec3(uv+hash(bw_vx[1].xy),layer),ddx,ddy)*bw_vx[3].y) +
- (textureGrad(tex,vec3(uv+hash(bw_vx[2].xy),layer),ddx,ddy)*bw_vx[3].z)
- ;
- }
- vec4 triplanar_texture(sampler2DArray p_sampler, float layer, vec3 p_weights, vec3 p_triplanar_pos, float uv_scale) {
- vec4 samp = vec4(0.0);
- samp += stochastic_sample(p_sampler, layer, p_triplanar_pos.xy*vec2(uv_scale,uv_scale)) * p_weights.z;
- samp += stochastic_sample(p_sampler, layer, p_triplanar_pos.xz*vec2(uv_scale,uv_scale)) * p_weights.y;
- samp += stochastic_sample(p_sampler, layer, p_triplanar_pos.zy * vec2(-1.0,1.0)*vec2(uv_scale,uv_scale)) * p_weights.x;
- return samp;
- }
- void fragment() {
- vec4 color = COLOR;
- vec3 totalcolor = vec3(0.0,0.0,0.0);
- float totalsum = 0.0;
- for(int i = 0; i<BiomeCount;i++){
- float amount = biome_amount[i];
- if(UseOverride){
- amount = BiomeOverride[i];
- }
- vec4 wall_tex = triplanar_texture(SideTexes, float(i), power_normal, triplanar_pos,SideScales[i]);
- vec3 wall = wall_tex.rgb * SideColors[i].rgb;
- vec4 top_tex = triplanar_texture(TopTexes,float(i), power_normal, triplanar_pos,TopScales[i]);
- vec3 top = top_tex.rgb * TopColors[i].rgb;
- float blend = clamp((flatness*BlendValues.x)+BlendValues.y,BlendValues.z,BlendValues.w);
- vec3 col = mix(wall,top,blend);
- totalcolor += (col.rgb*amount);
- totalsum += amount;
- }
- ALBEDO = totalcolor;
- if(totalsum<=0.0){
- ALBEDO = vec3(biome_amount[7],biome_amount[8],biome_amount[9]);
- }
- //ALBEDO = color.rgb;
- }
Advertisement
Add Comment
Please, Sign In to add comment