Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Each #kernel tells which function to compile; you can have many kernels
- #pragma kernel CSMain
- RWTexture2D<float4> Result;
- RWStructuredBuffer<float3> posBuffer : register(u0);
- RWStructuredBuffer<float3> colBuffer : register(u1);
- RWStructuredBuffer<float3> tarBuffer : register(u2);
- float Time;
- float4 CoreLoc;
- float rand_1_05(in float2 uv)
- {
- float2 noise = (frac(sin(dot(uv ,float2(12.9898,78.233)*2.0)) * 43758.5453));
- return abs(noise.x + noise.y) * 0.5;
- }
- float randomSpread(float2 seed)
- {
- float part1 = rand_1_05(seed);
- float part2 = 1;
- if (part1 < 0.5)
- {
- part2 = 1;
- }
- else{
- part2 = -1;
- }
- return part2;
- }
- float3 ranWithinSphere(float2 seed)
- {
- float3 temp = float3(0,0,0);
- temp.x = randomSpread(seed);
- temp.y = randomSpread(seed);
- temp.z = randomSpread(seed);
- return temp;
- }
- float distance(float3 point1, float3 point2)
- {
- float x = (point1.x - point2.x) * (point1.x - point2.x);
- float y = (point1.y - point2.y) * (point1.x - point2.y);
- float z = (point1.z - point2.z) * (point1.x - point2.z);
- return sqrt(x + y + z);
- }
- [numthreads(10,1,1)]
- void CSMain (uint3 id : SV_DispatchThreadID)
- {
- float2 seed = float2(id.x * Time, Time);
- colBuffer[id.x].x = cos(Time) * sin(Time);
- colBuffer[id.x].y = sin(Time);
- tarBuffer[id.x].x = CoreLoc.x + ((cos(Time * id.x) * sin(Time))) * 4;
- tarBuffer[id.x].y = CoreLoc.y + ((sin(Time * id.x) * cos(Time))) * 7;
- tarBuffer[id.x].z = CoreLoc.z + ((cos(Time * id.x) * sin(Time))) * 12;
- // Work your way towards the target
- float changeX = tarBuffer[id.x].x - posBuffer[id.x].x;
- float changeY = tarBuffer[id.x].y - posBuffer[id.x].y;
- float changeZ = tarBuffer[id.x].z - posBuffer[id.x].z;
- posBuffer[id.x].x += (changeX / 40);
- posBuffer[id.x].y += (changeY / 40);
- posBuffer[id.x].z += (changeZ / 40);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement