ground_shader.tres 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 sampler2D texture_heightmap;
  15. uniform float specular;
  16. uniform float roughness : hint_range(0,1);
  17. uniform float point_size : hint_range(0,128);
  18. uniform sampler2D texture_roughness : hint_white;
  19. uniform vec4 roughness_texture_channel;
  20. uniform sampler2D texture_normal : hint_normal;
  21. uniform float normal_scale : hint_range(-16,16);
  22. uniform sampler2D texture_ambient_occlusion : hint_white;
  23. uniform vec4 ao_texture_channel;
  24. uniform float ao_light_affect;
  25. uniform sampler2D texture_depth : hint_black;
  26. uniform float depth_scale;
  27. uniform int depth_min_layers;
  28. uniform int depth_max_layers;
  29. uniform vec2 depth_flip;
  30. uniform vec3 uv1_scale;
  31. uniform vec3 uv1_offset;
  32. uniform vec2 uv2_scale;
  33. uniform vec3 uv2_offset;
  34. uniform bool overlay_heightmap;
  35. vec4 soft_light(vec4 base, vec4 blend){
  36. vec4 limit = step(0.5, blend);
  37. 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);
  38. }
  39. vec4 overlay(vec4 base, vec4 blend){
  40. vec4 limit = step(0.5, base);
  41. return mix(2.0 * base * blend, 1.0 - 2.0 * (1.0 - base) * (1.0 - blend), limit);
  42. }
  43. vec4 color_burn(vec4 base, vec4 blend){
  44. return 1.0 - (1.0 - base) / blend;
  45. }
  46. vec4 screen(vec4 base, vec4 blend){
  47. return 1.0 - (1.0 - base) * (1.0 - blend);
  48. }
  49. void vertex() {
  50. UV=UV*uv1_scale.xy+uv1_offset.xy;
  51. float depth = texture(texture_depth, UV).a;
  52. VERTEX.y += depth * depth_scale;
  53. }
  54. void fragment() {
  55. vec2 base_uv = UV;
  56. /*
  57. {
  58. vec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL));
  59. float num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));
  60. float layer_depth = 1.0 / num_layers;
  61. float current_layer_depth = 0.0;
  62. vec2 P = view_dir.xy * depth_scale;
  63. vec2 delta = P / num_layers;
  64. vec2 ofs = base_uv;
  65. float depth = textureLod(texture_depth, ofs, 0.0).r;
  66. float current_depth = 0.0;
  67. while(current_depth < depth) {
  68. ofs -= delta;
  69. depth = textureLod(texture_depth, ofs, 0.0).r;
  70. current_depth += layer_depth;
  71. }
  72. vec2 prev_ofs = ofs + delta;
  73. float after_depth = depth - current_depth;
  74. float before_depth = textureLod(texture_depth, prev_ofs, 0.0).r - current_depth + layer_depth;
  75. float weight = after_depth / (after_depth - before_depth);
  76. ofs = mix(ofs,prev_ofs,weight);
  77. //base_uv=ofs;
  78. }*/
  79. vec2 scaled_uv = base_uv*uv2_scale;
  80. vec4 albedo_tex = texture(texture_albedo,scaled_uv);
  81. vec4 albedo_tex_big = texture(texture_albedo_big,base_uv);
  82. //ALBEDO = albedo.rgb * (albedo_tex.rgb + albedo_tex_big.rgb);
  83. ALBEDO = screen(albedo_tex, albedo_tex_big).rgb;
  84. if(overlay_heightmap){
  85. ALBEDO.r = ALBEDO.r + texture(texture_heightmap, base_uv).r;
  86. }
  87. float roughness_tex = dot(texture(texture_roughness,scaled_uv),roughness_texture_channel);
  88. ROUGHNESS = roughness_tex * roughness;
  89. SPECULAR = specular;
  90. NORMALMAP = texture(texture_normal,scaled_uv).rgb;
  91. NORMALMAP_DEPTH = normal_scale;
  92. AO = dot(texture(texture_ambient_occlusion,scaled_uv),ao_texture_channel);
  93. AO_LIGHT_AFFECT = ao_light_affect;
  94. }
  95. "
  96. [resource]
  97. shader = SubResource( 1 )
  98. shader_param/albedo = Color( 1, 1, 1, 1 )
  99. shader_param/specular = 0.5
  100. shader_param/roughness = 1.0
  101. shader_param/point_size = 1.0
  102. shader_param/roughness_texture_channel = Plane( 1, 0, 0, 0 )
  103. shader_param/normal_scale = -1.0
  104. shader_param/ao_texture_channel = Plane( 1, 0, 0, 0 )
  105. shader_param/ao_light_affect = 0.0
  106. shader_param/depth_scale = 0.05
  107. shader_param/depth_min_layers = 8
  108. shader_param/depth_max_layers = 32
  109. shader_param/depth_flip = Vector2( 1, 1 )
  110. shader_param/uv1_scale = Vector3( 1, 1, 1 )
  111. shader_param/uv1_offset = Vector3( 0, 0, 0 )
  112. shader_param/uv2_scale = Vector2( 512, 512 )
  113. shader_param/uv2_offset = Vector3( 0, 0, 0 )
  114. shader_param/overlay_heightmap = null
  115. shader_param/texture_albedo = ExtResource( 6 )
  116. shader_param/texture_roughness = ExtResource( 4 )
  117. shader_param/texture_normal = ExtResource( 5 )
  118. shader_param/texture_ambient_occlusion = ExtResource( 2 )
  119. shader_param/texture_depth = ExtResource( 1 )