ground_shader.tres 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 vec3 uv2_scale;
  32. uniform vec3 uv2_offset;
  33. void vertex() {
  34. UV=UV*uv1_scale.xy+uv1_offset.xy;
  35. }
  36. void fragment() {
  37. vec2 base_uv = UV;
  38. /*
  39. {
  40. vec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL));
  41. float num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));
  42. float layer_depth = 1.0 / num_layers;
  43. float current_layer_depth = 0.0;
  44. vec2 P = view_dir.xy * depth_scale;
  45. vec2 delta = P / num_layers;
  46. vec2 ofs = base_uv;
  47. float depth = textureLod(texture_depth, ofs, 0.0).r;
  48. float current_depth = 0.0;
  49. while(current_depth < depth) {
  50. ofs -= delta;
  51. depth = textureLod(texture_depth, ofs, 0.0).r;
  52. current_depth += layer_depth;
  53. }
  54. vec2 prev_ofs = ofs + delta;
  55. float after_depth = depth - current_depth;
  56. float before_depth = textureLod(texture_depth, prev_ofs, 0.0).r - current_depth + layer_depth;
  57. float weight = after_depth / (after_depth - before_depth);
  58. ofs = mix(ofs,prev_ofs,weight);
  59. //base_uv=ofs;
  60. }*/
  61. vec2 scaled_uv = base_uv*vec2(512,512);
  62. vec4 albedo_tex = texture(texture_albedo,scaled_uv);
  63. vec4 albedo_tex_big = texture(texture_albedo_big,base_uv);
  64. ALBEDO = albedo.rgb * (albedo_tex.rgb + albedo_tex_big.rgb);
  65. float roughness_tex = dot(texture(texture_roughness,scaled_uv),roughness_texture_channel);
  66. ROUGHNESS = roughness_tex * roughness;
  67. SPECULAR = specular;
  68. NORMALMAP = texture(texture_normal,scaled_uv).rgb;
  69. NORMALMAP_DEPTH = normal_scale;
  70. AO = dot(texture(texture_ambient_occlusion,scaled_uv),ao_texture_channel);
  71. AO_LIGHT_AFFECT = ao_light_affect;
  72. }
  73. "
  74. [resource]
  75. shader = SubResource( 1 )
  76. shader_param/albedo = Color( 1, 1, 1, 1 )
  77. shader_param/specular = 0.5
  78. shader_param/roughness = 1.0
  79. shader_param/point_size = 1.0
  80. shader_param/roughness_texture_channel = Plane( 1, 0, 0, 0 )
  81. shader_param/normal_scale = -1.0
  82. shader_param/ao_texture_channel = Plane( 1, 0, 0, 0 )
  83. shader_param/ao_light_affect = 0.0
  84. shader_param/depth_scale = 0.05
  85. shader_param/depth_min_layers = 8
  86. shader_param/depth_max_layers = 32
  87. shader_param/depth_flip = Vector2( 1, 1 )
  88. shader_param/uv1_scale = Vector3( 1, 1, 1 )
  89. shader_param/uv1_offset = Vector3( 0, 0, 0 )
  90. shader_param/uv2_scale = Vector3( 1, 1, 1 )
  91. shader_param/uv2_offset = Vector3( 0, 0, 0 )
  92. shader_param/texture_albedo = ExtResource( 6 )
  93. shader_param/texture_roughness = ExtResource( 4 )
  94. shader_param/texture_normal = ExtResource( 5 )
  95. shader_param/texture_ambient_occlusion = ExtResource( 2 )
  96. shader_param/texture_depth = ExtResource( 1 )