Skip to content

Instantly share code, notes, and snippets.

@cabbibo
Created October 7, 2018 15:11
Show Gist options
  • Save cabbibo/021694e0a23890d9ddfb6c1facc3ccf4 to your computer and use it in GitHub Desktop.
Save cabbibo/021694e0a23890d9ddfb6c1facc3ccf4 to your computer and use it in GitHub Desktop.
#pragma kernel PlacePoint
struct Vert{
float3 pos;
float3 vel;
float3 nor;
float3 tang;
float2 uv;
float used;
float3 triIDs;
float3 triWeights;
float3 debug;
};
struct SkinnedVert{
float3 pos;
float3 vel;
float3 nor;
float3 tang;
float2 uv;
float used;
float3 targetPos;
float3 bindPos;
float3 bindNor;
float3 bindTan;
float4 boneWeights;
float4 boneIDs;
float debug;
};
#include "../Chunks/snoise.cginc"
#include "../Chunks/curlNoise.cginc"
int _Whirlwind;
RWStructuredBuffer<Vert> _VertBuffer;
RWStructuredBuffer<SkinnedVert> _SkinnedBuffer;
#define NR_THREADS 128
[numthreads(NR_THREADS,1,1)]
void PlacePoint(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID) {
int pID = threadID + u3GroupID.x * NR_THREADS;
Vert vert = _VertBuffer[pID];
SkinnedVert v0 = _SkinnedBuffer[int(vert.triIDs.x)];
SkinnedVert v1 = _SkinnedBuffer[int(vert.triIDs.y)];
SkinnedVert v2 = _SkinnedBuffer[int(vert.triIDs.z)];
float3 fPos = v0.pos * vert.triWeights.x;
fPos += v1.pos * vert.triWeights.y;
fPos += v2.pos * vert.triWeights.z;
float3 fNor = v0.nor * vert.triWeights.x;
fNor += v1.nor * vert.triWeights.y;
fNor += v2.nor * vert.triWeights.z;
float3 fTan = v0.tang * vert.triWeights.x;
fTan += v1.tang * vert.triWeights.y;
fTan += v2.tang * vert.triWeights.z;
float2 fUV = v0.uv * vert.triWeights.x;
fUV += v1.uv * vert.triWeights.y;
fUV += v2.uv * vert.triWeights.z;
vert.nor = normalize(fNor);
vert.tang = fTan;
vert.uv = fUV;
vert.debug = 1;//float3( vert.boneWeights[0] , vert.boneWeights[1], vert.boneWeights[2] );
if( _Whirlwind == 0 ){
vert.pos = fPos;
}else if( _Whirlwind == 1){
float3 force = float3(0,0,0);
float3 dif = vert.pos - fPos;
force = -dif;
float rand= (sin( float(pID) * 1000 ) + 4)/4;
vert.vel += force * .01 * rand;
vert.pos += vert.vel;
//
// /vert.pos += vert.vel;
vert.vel *= .9;
//vert.pos = fPos;
}else if( _Whirlwind == 2){
float3 force = .01*float3(0,1,0);
float3 dif = vert.pos;
float y = dif.y;
dif.y = 0;
float3 cForce = cross( normalize(dif) , float3(0,1,0));
force -= dif / y;
force += cForce;
float rand= (sin( float(pID) * 1000 ) + 4)/4;
vert.vel += force * .01 * rand;
vert.pos += vert.vel;
vert.vel *= .9;
}else{
float3 force = .01*float3(0,1,0);
float3 dif = vert.pos;
float y = dif.y;
dif.y = 0;
float3 cForce = curlNoise( vert.pos * .3 );//cross( normalize(dif) , float3(0,1,0));
force += cForce;
float rand= (sin( float(pID) * 1000 ) + 4)/4;
vert.vel += force * .0004 * rand;
vert.pos += vert.vel;
vert.vel *= .95;
}
_VertBuffer[pID] = vert;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment