ground_shader.tres 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. [gd_resource type="ShaderMaterial" load_steps=9 format=2]
  2. [ext_resource path="res://tex/ground/gravel_path_Height.png" type="Texture" id=1]
  3. [ext_resource path="res://tex/ground/gravel_path-ao.png" type="Texture" id=2]
  4. [ext_resource path="res://tex/ground/gravel_path_Metallic.png" type="Texture" id=3]
  5. [ext_resource path="res://tex/ground/gravel_path_Roughness.png" type="Texture" id=4]
  6. [ext_resource path="res://tex/ground/gravel_path_Normal-dx.png" type="Texture" id=5]
  7. [ext_resource path="res://tex/ground/gravel_path-albedo.png" type="Texture" id=6]
  8. [ext_resource path="res://tex/180-91.png" type="Texture" id=7]
  9. [sub_resource type="Shader" id=1]
  10. code = "// NOTE: Shader automatically converted from Godot Engine 3.4.4.stable's SpatialMaterial.
  11. shader_type spatial;
  12. render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
  13. uniform vec4 albedo : hint_color;
  14. uniform sampler2D texture_albedo_big;
  15. uniform sampler2D texture_albedo : hint_albedo;
  16. uniform float specular;
  17. uniform float metallic;
  18. uniform float roughness : hint_range(0,1);
  19. uniform float point_size : hint_range(0,128);
  20. uniform sampler2D texture_metallic : hint_white;
  21. uniform vec4 metallic_texture_channel;
  22. uniform sampler2D texture_roughness : hint_white;
  23. uniform vec4 roughness_texture_channel;
  24. uniform sampler2D texture_normal : hint_normal;
  25. uniform float normal_scale : hint_range(-16,16);
  26. uniform sampler2D texture_ambient_occlusion : hint_white;
  27. uniform vec4 ao_texture_channel;
  28. uniform float ao_light_affect;
  29. uniform sampler2D texture_depth : hint_black;
  30. uniform float depth_scale;
  31. uniform int depth_min_layers;
  32. uniform int depth_max_layers;
  33. uniform vec2 depth_flip;
  34. uniform vec3 uv1_scale;
  35. uniform vec3 uv1_offset;
  36. uniform vec3 uv2_scale;
  37. uniform vec3 uv2_offset;
  38. void vertex() {
  39. UV=UV*uv1_scale.xy+uv1_offset.xy;
  40. }
  41. void fragment() {
  42. vec2 base_uv = UV;
  43. /*
  44. {
  45. vec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL));
  46. float num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));
  47. float layer_depth = 1.0 / num_layers;
  48. float current_layer_depth = 0.0;
  49. vec2 P = view_dir.xy * depth_scale;
  50. vec2 delta = P / num_layers;
  51. vec2 ofs = base_uv;
  52. float depth = textureLod(texture_depth, ofs, 0.0).r;
  53. float current_depth = 0.0;
  54. while(current_depth < depth) {
  55. ofs -= delta;
  56. depth = textureLod(texture_depth, ofs, 0.0).r;
  57. current_depth += layer_depth;
  58. }
  59. vec2 prev_ofs = ofs + delta;
  60. float after_depth = depth - current_depth;
  61. float before_depth = textureLod(texture_depth, prev_ofs, 0.0).r - current_depth + layer_depth;
  62. float weight = after_depth / (after_depth - before_depth);
  63. ofs = mix(ofs,prev_ofs,weight);
  64. //base_uv=ofs;
  65. }*/
  66. vec2 scaled_uv = base_uv*vec2(512,512);
  67. vec4 albedo_tex = texture(texture_albedo,scaled_uv);
  68. vec4 albedo_tex_big = texture(texture_albedo_big,base_uv);
  69. ALBEDO = albedo.rgb * (albedo_tex.rgb + albedo_tex_big.rgb);
  70. float metallic_tex = dot(texture(texture_metallic,scaled_uv),metallic_texture_channel);
  71. METALLIC = metallic_tex * metallic;
  72. float roughness_tex = dot(texture(texture_roughness,scaled_uv),roughness_texture_channel);
  73. ROUGHNESS = roughness_tex * roughness;
  74. SPECULAR = specular;
  75. NORMALMAP = texture(texture_normal,scaled_uv).rgb;
  76. NORMALMAP_DEPTH = normal_scale;
  77. AO = dot(texture(texture_ambient_occlusion,scaled_uv),ao_texture_channel);
  78. AO_LIGHT_AFFECT = ao_light_affect;
  79. }
  80. "
  81. [resource]
  82. shader = SubResource( 1 )
  83. shader_param/albedo = Color( 1, 1, 1, 1 )
  84. shader_param/specular = 0.5
  85. shader_param/metallic = 0.0
  86. shader_param/roughness = 1.0
  87. shader_param/point_size = 1.0
  88. shader_param/metallic_texture_channel = Plane( 1, 0, 0, 0 )
  89. shader_param/roughness_texture_channel = Plane( 1, 0, 0, 0 )
  90. shader_param/normal_scale = -1.0
  91. shader_param/ao_texture_channel = Plane( 1, 0, 0, 0 )
  92. shader_param/ao_light_affect = 0.0
  93. shader_param/depth_scale = 0.05
  94. shader_param/depth_min_layers = 8
  95. shader_param/depth_max_layers = 32
  96. shader_param/depth_flip = Vector2( 1, 1 )
  97. shader_param/uv1_scale = Vector3( 1, 1, 1 )
  98. shader_param/uv1_offset = Vector3( 0, 0, 0 )
  99. shader_param/uv2_scale = Vector3( 1, 1, 1 )
  100. shader_param/uv2_offset = Vector3( 0, 0, 0 )
  101. shader_param/texture_albedo_big = ExtResource( 7 )
  102. shader_param/texture_albedo = ExtResource( 6 )
  103. shader_param/texture_metallic = ExtResource( 3 )
  104. shader_param/texture_roughness = ExtResource( 4 )
  105. shader_param/texture_normal = ExtResource( 5 )
  106. shader_param/texture_ambient_occlusion = ExtResource( 2 )
  107. shader_param/texture_depth = ExtResource( 1 )