NoiseTexture.cpp 662 B

12345678910111213141516171819202122232425
  1. #include <vector>
  2. #include <cstdlib>
  3. #include "client/rendering/NoiseTexture.h"
  4. NoiseTexture::NoiseTexture(uint width, uint height) {
  5. std::vector<float> data;
  6. for(uint x = 0; x < width; x++) {
  7. for(uint y = 0; y < height; y++) {
  8. data.push_back(getRandom());
  9. data.push_back(getRandom());
  10. data.push_back(getRandom());
  11. }
  12. }
  13. texture.setRGBFloatData(width, height, data.data());
  14. }
  15. void NoiseTexture::bind(uint index) const {
  16. texture.bind(index);
  17. }
  18. float NoiseTexture::getRandom() const {
  19. float r = static_cast<float> (rand()) / static_cast<float> (RAND_MAX);
  20. return r * 2.0f - 1.0f;
  21. }