Guest User

Untitled

a guest
Jan 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #pragma arguments
  2. uniform vec2 trailPoints[5];
  3. uniform float count;
  4.  
  5. #pragma body
  6. float trailRadius = 10.0;
  7.  
  8. float x = _surface.diffuseTexcoord.x;
  9. float x100 = float(x * 100);
  10.  
  11. float y = _surface.diffuseTexcoord.y;
  12. float y100 = float(y * 100);
  13.  
  14. for (int i = 0; i < int(count); i++) {
  15. vec2 position = trailPoints[i];
  16. if ((x100 > position.x - trailRadius && x100 < position.x + trailRadius) && (y100 > position.y - trailRadius && y100 < position.y + trailRadius)) {
  17. _surface.diffuse.rgb = vec3(0.0, 10.0 ,0.0);
  18. }
  19. }
  20.  
  21. if let geometry = self.floorNode.geometry {
  22. if let material = geometry.firstMaterial {
  23.  
  24. // this is the temporary data which I use to find the problem.
  25. // this data will be dynamic later on.
  26. let myValueArray:[float2] = [float2(x:80, y:80),float2(x:60, y:60),float2(x:40, y:40),float2(x:20, y:20),float2(x:0, y:0)]
  27.  
  28. // Passing array count to shader. There is no problem here.
  29. var count = Float(myValueArray.count)
  30. let countData = Data(buffer: UnsafeBufferPointer(start: &count, count: 1))
  31. material.setValue(countData, forKey: "count")
  32.  
  33. // and here is the problem start.
  34. var unsafeValueArray = myValueArray
  35. // myValueArray converted to data with its size.
  36. let valueArrayData = Data(buffer: UnsafeBufferPointer(start: myValueArray, count: myValueArray.count))
  37. material.setValue(valueArrayData, forKey: "trailPoints")
  38. }
  39. }
  40.  
  41. let valueArrayData = Data(buffer: UnsafeBufferPointer(start: myValueArray, count: 1))
Add Comment
Please, Sign In to add comment