example.gdshader 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. shader_type canvas_item;
  2. shader_type spatial;
  3. /* ************************************************************************** */
  4. // types
  5. void a;
  6. bool b = true;
  7. bool b2 = false;
  8. bvec2 c;
  9. bvec3 d;
  10. bvec4 e;
  11. int f;
  12. ivec2 g;
  13. ivec3 h;
  14. ivec4 i;
  15. uint j;
  16. uvec2 k;
  17. uvec3 l;
  18. uvec4 m;
  19. float n;
  20. vec2 o;
  21. vec3 p;
  22. vec4 q;
  23. mat2 r;
  24. mat3 s;
  25. mat4 t;
  26. sampler2D u;
  27. isampler2D v;
  28. usampler2D w;
  29. samplerCube x;
  30. // qualifiers
  31. uniform int qualifier_a;
  32. global uniform int qualifier_b;
  33. instance uniform int qualifier_c;
  34. varying flat int qualifier_d;
  35. // hints
  36. uniform sampler2D hint_a : hint_albedo; // godot 3
  37. uniform sampler2D hint_b : source_color; // godot 4
  38. uniform sampler2D hint_c : hint_black; // godot 3
  39. uniform sampler2D hint_d : hint_white; // godot 3
  40. uniform sampler2D hint_e : hint_default_black; // godot 4
  41. uniform sampler2D hint_f : hint_default_white; // godot 4
  42. uniform sampler2D hint_g : hint_aniso;
  43. uniform vec4 hint_h : hint_color;
  44. uniform float hint_i : hint_range(0, 1);
  45. uniform vec4 hint_o : hint_color = vec4(1.0);
  46. /* ************************************************************************** */
  47. // the remaining examples are copied directly from
  48. // https://docs.godotengine.org/en/3.0/tutorials/shading/shading_language.html
  49. float a = 2; // valid
  50. float a = 2.0; // valid
  51. float a = float(2); // valid
  52. // The required amount of scalars
  53. vec4 a = vec4(0.0, 1.0, 2.0, 3.0);
  54. // Complementary vectors and/or scalars
  55. vec4 a = vec4(vec2(0.0, 1.0), vec2(2.0, 3.0));
  56. vec4 a = vec4(vec3(0.0, 1.0, 2.0), 3.0);
  57. // A single scalar for the whole vector
  58. vec4 a = vec4(0.0);
  59. // if and else
  60. if (cond) {
  61. } else {
  62. }
  63. // for loops
  64. for (int i = 0; i < 10; i++) {
  65. }
  66. // while
  67. while (true) {
  68. }
  69. int sum2(int a, int b) {
  70. return a + b;
  71. }
  72. void sum3(int a, int b, inout int result) {
  73. result = a + b;
  74. }
  75. /* ************************************************************************** */
  76. struct Test {
  77. vec3 color;
  78. };
  79. struct MyStruct {
  80. float power;
  81. vec3 color;
  82. Test result;
  83. };
  84. Test foo(MyStruct a, MyStruct b) {
  85. MyStruct k;
  86. k.result.color = (a.color + b.color) * k.power;
  87. return k.result;
  88. }
  89. void fragment() {
  90. MyStruct inst = MyStruct(0.0, vec3(0.0), Test(vec3(1.0)));
  91. Test result = foo(inst, MyStruct(1.0, vec3(0, 1, 0), Test(vec3(0.0))));
  92. }