Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma arguments
- uniform vec2 trailPoints[5];
- uniform float count;
- #pragma body
- float trailRadius = 10.0;
- float x = _surface.diffuseTexcoord.x;
- float x100 = float(x * 100);
- float y = _surface.diffuseTexcoord.y;
- float y100 = float(y * 100);
- for (int i = 0; i < int(count); i++) {
- vec2 position = trailPoints[i];
- if ((x100 > position.x - trailRadius && x100 < position.x + trailRadius) && (y100 > position.y - trailRadius && y100 < position.y + trailRadius)) {
- _surface.diffuse.rgb = vec3(0.0, 10.0 ,0.0);
- }
- }
- if let geometry = self.floorNode.geometry {
- if let material = geometry.firstMaterial {
- // this is the temporary data which I use to find the problem.
- // this data will be dynamic later on.
- 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)]
- // Passing array count to shader. There is no problem here.
- var count = Float(myValueArray.count)
- let countData = Data(buffer: UnsafeBufferPointer(start: &count, count: 1))
- material.setValue(countData, forKey: "count")
- // and here is the problem start.
- var unsafeValueArray = myValueArray
- // myValueArray converted to data with its size.
- let valueArrayData = Data(buffer: UnsafeBufferPointer(start: myValueArray, count: myValueArray.count))
- material.setValue(valueArrayData, forKey: "trailPoints")
- }
- }
- let valueArrayData = Data(buffer: UnsafeBufferPointer(start: myValueArray, count: 1))
Add Comment
Please, Sign In to add comment