89 lines
3.5 KiB
Text
89 lines
3.5 KiB
Text
// NOTE: Shader automatically converted from Godot Engine 4.0.alpha2's StandardMaterial3D.
|
|
|
|
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,filter_linear_mipmap,repeat_enable;
|
|
uniform float point_size : hint_range(0,128);
|
|
uniform float roughness : hint_range(0,1);
|
|
uniform sampler2D texture_metallic : hint_white,filter_linear_mipmap,repeat_enable;
|
|
uniform vec4 metallic_texture_channel;
|
|
uniform sampler2D texture_roughness : hint_roughness_gray,filter_linear_mipmap,repeat_enable;
|
|
uniform float specular;
|
|
uniform float metallic;
|
|
uniform sampler2D texture_normal : hint_roughness_normal,filter_linear_mipmap,repeat_enable;
|
|
uniform float normal_scale : hint_range(-16,16);
|
|
uniform sampler2D texture_heightmap : hint_black,filter_linear_mipmap,repeat_enable;
|
|
uniform float heightmap_scale;
|
|
uniform int heightmap_min_layers;
|
|
uniform int heightmap_max_layers;
|
|
uniform vec2 heightmap_flip;
|
|
uniform vec3 uv1_scale;
|
|
uniform vec3 uv1_offset;
|
|
uniform vec3 uv2_scale;
|
|
uniform vec3 uv2_offset;
|
|
|
|
vec4 hash4( vec2 p ) { return fract(sin(vec4( 1.0+dot(p,vec2(37.0,17.0)),
|
|
2.0+dot(p,vec2(11.0,47.0)),
|
|
3.0+dot(p,vec2(41.0,29.0)),
|
|
4.0+dot(p,vec2(23.0,31.0))))*103.0); }
|
|
|
|
vec4 reduce_tiling( sampler2D samp, in vec2 uv )
|
|
{
|
|
vec2 iuv = floor( uv );
|
|
vec2 fuv = fract( uv );
|
|
|
|
// generate per-tile transform
|
|
vec4 ofa = hash4( iuv + vec2(0.0,0.0) );
|
|
vec4 ofb = hash4( iuv + vec2(1.0,0.0) );
|
|
vec4 ofc = hash4( iuv + vec2(0.0,1.0) );
|
|
vec4 ofd = hash4( iuv + vec2(1.0,1.0) );
|
|
|
|
vec2 ddx = dFdx( uv );
|
|
vec2 ddy = dFdy( uv );
|
|
|
|
// transform per-tile uvs
|
|
ofa.zw = sign(ofa.zw-0.5);
|
|
ofb.zw = sign(ofb.zw-0.5);
|
|
ofc.zw = sign(ofc.zw-0.5);
|
|
ofd.zw = sign(ofd.zw-0.5);
|
|
|
|
// uv's, and derivarives (for correct mipmapping)
|
|
vec2 uva = uv*ofa.zw + ofa.xy; vec2 ddxa = ddx*ofa.zw; vec2 ddya = ddy*ofa.zw;
|
|
vec2 uvb = uv*ofb.zw + ofb.xy; vec2 ddxb = ddx*ofb.zw; vec2 ddyb = ddy*ofb.zw;
|
|
vec2 uvc = uv*ofc.zw + ofc.xy; vec2 ddxc = ddx*ofc.zw; vec2 ddyc = ddy*ofc.zw;
|
|
vec2 uvd = uv*ofd.zw + ofd.xy; vec2 ddxd = ddx*ofd.zw; vec2 ddyd = ddy*ofd.zw;
|
|
|
|
// fetch and blend
|
|
vec2 b = smoothstep(0.25,0.75,fuv);
|
|
|
|
return mix( mix( textureGrad( samp, uva, ddxa, ddya ),
|
|
textureGrad( samp, uvb, ddxb, ddyb ), b.x ),
|
|
mix( textureGrad( samp, uvc, ddxc, ddyc ),
|
|
textureGrad( samp, uvd, ddxd, ddyd ), b.x), b.y );
|
|
}
|
|
|
|
void vertex() {
|
|
UV=UV*uv1_scale.xy+uv1_offset.xy;
|
|
}
|
|
|
|
|
|
void fragment() {
|
|
vec2 base_uv = UV;
|
|
{
|
|
vec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*heightmap_flip.x,-BINORMAL*heightmap_flip.y,NORMAL));
|
|
float depth = 1.0 - reduce_tiling(texture_heightmap, base_uv).r;
|
|
vec2 ofs = base_uv - view_dir.xy * depth * heightmap_scale;
|
|
base_uv=ofs;
|
|
}
|
|
vec4 albedo_tex = reduce_tiling(texture_albedo,base_uv);
|
|
ALBEDO = albedo.rgb * albedo_tex.rgb;
|
|
float metallic_tex = dot(reduce_tiling(texture_metallic,base_uv),metallic_texture_channel);
|
|
METALLIC = metallic_tex * metallic;
|
|
vec4 roughness_texture_channel = vec4(0.333333,0.333333,0.333333,0.0);
|
|
float roughness_tex = dot(reduce_tiling(texture_roughness,base_uv),roughness_texture_channel);
|
|
ROUGHNESS = roughness_tex * roughness;
|
|
SPECULAR = specular;
|
|
NORMAL_MAP = reduce_tiling(texture_normal,base_uv).rgb;
|
|
NORMAL_MAP_DEPTH = normal_scale;
|
|
}
|