ground_shader.tres 4.5 KB

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