Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 float point_size : hint_range(0,128);
- uniform sampler2D texture_metallic : hint_white;
- uniform vec4 metallic_texture_channel;
- uniform sampler2D texture_roughness : hint_white;
- uniform vec4 roughness_texture_channel;
- uniform sampler2D texture_normal : hint_normal;
- uniform float normal_scale : hint_range(-16,16);
- uniform vec3 uv1_scale;
- uniform vec3 uv1_offset;
- uniform vec3 uv2_scale;
- uniform vec3 uv2_offset;
- vec2 hash2D2D (vec2 s)
- {
- //magic numbers
- return fract(sin(mod(vec2(dot(s, vec2(127.1,311.7)), dot(s, vec2(269.5,183.3))), 3.14159))*43758.5453);
- }
- //stochastic sampling
- vec4 textureStochastic(sampler2D tex, vec2 UV)
- {
- //triangle vertices and blend weights
- //BW_vx[0...2].xyz = triangle verts
- //BW_vx[3].xy = blend weights (z is unused)
- mat4 BW_vx;
- //uv transformed into triangular grid space with UV scaled by approximation of 2*sqrt(3)
- vec2 newUV = (mat2(vec2(1.0 , 0.0) , vec2(-0.57735027 , 1.15470054))* UV * 3.464);
- //vertex IDs and barycentric coords
- vec2 vxID = vec2 (floor(newUV));
- vec3 fracted = vec3 (fract(newUV), 0);
- fracted.z = 1.0-fracted.x-fracted.y;
- BW_vx = ((fracted.z>0.0) ?
- mat4(vec4(vxID, 0,0), vec4(vxID + vec2(0, 1), 0,0), vec4(vxID + vec2(1, 0), 0,0), vec4(fracted,0)) :
- mat4(vec4(vxID + vec2 (1, 1), 0,0), vec4(vxID + vec2 (1, 0), 0,0), vec4(vxID + vec2 (0, 1), 0,0), vec4(-fracted.z, 1.0-fracted.y, 1.0-fracted.x,0)));
- //calculate derivatives to avoid triangular grid artifacts
- vec2 dx = dFdx(UV);
- vec2 dy = dFdy(UV);
- vec2 fakegradient = smoothstep(dx,dy,vec2(0.5,0.5));
- //blend samples with calculated weights
- return (texture(tex, UV + hash2D2D(BW_vx[0].xy), 1) * BW_vx[3].x +
- texture(tex, UV + hash2D2D(BW_vx[1].xy), 1) * BW_vx[3].y +
- texture(tex, UV + hash2D2D(BW_vx[2].xy), 1) * BW_vx[3].z);
- }
- void vertex() {
- UV=UV*uv1_scale.xy+uv1_offset.xy;
- }
- void fragment() {
- vec2 base_uv = UV;
- vec4 albedo_tex = textureStochastic(texture_albedo,base_uv);
- vec4 albedo_tex_a = textureStochastic(texture_albedo,base_uv+vec2(1,3));
- vec4 albedo_tex_b = textureStochastic(texture_albedo,base_uv);
- float f = albedo_tex.x*8.0;
- albedo_tex = mix( albedo_tex_a, albedo_tex_b, smoothstep(0.2,0.8,f-0.1*(albedo_tex_a-albedo_tex_b)));
- ALBEDO = albedo.rgb * albedo_tex.rgb;
- float metallic_tex = dot(textureStochastic(texture_metallic,base_uv),metallic_texture_channel);
- METALLIC = metallic_tex * metallic;
- float roughness_tex = dot(textureStochastic(texture_roughness,base_uv),roughness_texture_channel);
- ROUGHNESS = roughness_tex * roughness;
- SPECULAR = specular;
- NORMALMAP = textureStochastic(texture_normal,base_uv).rgb;
- NORMALMAP_DEPTH = normal_scale;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement