Advertisement
decepticlown

Godot Basic Shader

Apr 16th, 2021 (edited)
2,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. MIT License
  3.  
  4. Copyright (c) 2021 Amankumar "ACP" Chandubhai Parmar
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in all
  14. copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. SOFTWARE.
  23. */
  24.  
  25. shader_type spatial;
  26. render_mode cull_disabled, specular_schlick_ggx;
  27.  
  28. uniform float rotation_point : hint_range(0, 1, 0.1) = 0.5;
  29. uniform float rotation_degrees : hint_range(-360, 360, 1) = 0;
  30.  
  31. uniform float x_offset = 0;
  32. uniform float y_offset = 0;
  33.  
  34. uniform float x_scale = 1;
  35. uniform float y_scale = 1;
  36.  
  37. uniform float metalic : hint_range(0, 1, 0.01) = 0;
  38. uniform float specular : hint_range(0, 1, 0.01) = 0;
  39.  
  40. uniform sampler2D texture_albedo : hint_albedo;
  41. uniform float albedo_strength : hint_range(-2, 2, 0.1) = 0;
  42.  
  43. uniform sampler2D texture_roughness : hint_aniso;
  44. uniform float roughness_strength : hint_range(-2, 2, 0.1) = 0;
  45.  
  46. uniform sampler2D texture_normal : hint_normal;
  47. uniform float normal_strength : hint_range(-2, 2, 0.1) = 0;
  48.  
  49.  
  50. void vertex() {
  51. // Output:0
  52.  
  53. }
  54.  
  55. // Rotate UV
  56. vec2 rotate(vec2 uv) {
  57.     float x = ((uv.x - rotation_point) * cos(radians(rotation_degrees))) + ((uv.y - rotation_point) * sin(radians(rotation_degrees))) + rotation_point;
  58.     float y = ((uv.y - rotation_point) * cos(radians(rotation_degrees))) - ((uv.x - rotation_point) * sin(radians(rotation_degrees))) + rotation_point;
  59.     return vec2(x, y);
  60. }
  61.  
  62. // Offset UV
  63. vec2 offset(vec2 uv) {
  64.     float x  = uv.x + x_offset;
  65.     float y = uv.y + y_offset;
  66.     return vec2(x, y);
  67. }
  68.  
  69. // Scale UV
  70. vec2 scale(vec2 uv) {
  71.     float x = uv.x * x_scale;
  72.     float y = uv.y * y_scale;
  73.     return vec2(x, y);
  74. }
  75.  
  76. void fragment() {
  77.     vec2 uv = UV;
  78.    
  79.     // Apply rotation
  80.     uv = rotate(uv);
  81.    
  82.     // Apply offset
  83.     uv = offset(uv);
  84.    
  85.     // Apply scale
  86.     uv = scale(uv);
  87.    
  88.     // Output:0
  89.     METALLIC = metalic;
  90.     SPECULAR = specular;
  91.    
  92.     ALBEDO = texture(texture_albedo, uv).rgb;
  93.     ROUGHNESS = texture(texture_roughness, uv).r;
  94.    
  95.     vec4 tex = texture(texture_normal, uv);
  96.     NORMALMAP = vec3(tex.r, 1.0 - tex.g, 0.0);
  97.     NORMALMAP_DEPTH = tex.b + normal_strength;
  98. }
  99.  
  100. void light() {
  101. // Output:0
  102.  
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement