particle_shader.tres 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. [gd_resource type="Shader" format=2]
  2. [resource]
  3. code = "shader_type particles;
  4. uniform float rows = 16;
  5. uniform float spacing = 1.0;
  6. uniform sampler2D heightmap;
  7. //uniform float amplitude = 15.0;
  8. //uniform vec2 heightmap_size = vec2(300.0, 300.0);
  9. uniform sampler2D noisemap;
  10. //float get_height(vec2 pos) {
  11. // pos -= 0.5 * heightmap_size;
  12. // pos /= heightmap_size;
  13. // return amplitude * texture(heightmap, pos).r;
  14. //}
  15. void vertex() {
  16. // obtain our position based on which particle we're rendering
  17. vec3 pos = vec3(0.0, 0.0, 0.0);
  18. pos.z = float(INDEX);
  19. pos.x = mod(pos.z, rows);
  20. pos.z = (pos.z - pos.x) / rows;
  21. // center this
  22. pos.x -= rows * 0.5;
  23. pos.z -= rows * 0.5;
  24. // and now apply our spacing
  25. pos *= spacing;
  26. // now center on our particle location but within our spacing
  27. //pos.x += EMISSION_TRANSFORM[3][0] - mod(EMISSION_TRANSFORM[3][0], spacing);
  28. //pos.z += EMISSION_TRANSFORM[3][2] - mod(EMISSION_TRANSFORM[3][2], spacing);
  29. // now add some noise based on our _world_ position
  30. vec3 noise = texture(noisemap, pos.xz * 0.001).rgb;
  31. pos.x += noise.x * spacing;
  32. pos.z += noise.y * spacing;
  33. // apply our height
  34. pos.y = 1.0;//get_height(pos.xz);
  35. float y2 = 1.0;//get_height(pos.xz + vec2(1.0, 0.0));
  36. float y3 = 1.0;//get_height(pos.xz + vec2(0.0, 1.0));
  37. if (abs(y2 - pos.y) > 0.5) {
  38. pos.y = -10000.0;
  39. } else if (abs(y3 - pos.y) > 0.5) {
  40. pos.y = -10000.0;
  41. }
  42. // rotate our transform
  43. TRANSFORM[0][0] = cos(noise.z * 3.0);
  44. TRANSFORM[0][2] = -sin(noise.z * 3.0);
  45. TRANSFORM[2][0] = sin(noise.z * 3.0);
  46. TRANSFORM[2][2] = cos(noise.z * 3.0);
  47. // update our transform to place
  48. TRANSFORM[3][0] = pos.x;
  49. TRANSFORM[3][1] = pos.y;
  50. TRANSFORM[3][2] = pos.z;
  51. }"