Skip to content

Instantly share code, notes, and snippets.

@but80
Created May 13, 2015 15:45
Show Gist options
  • Save but80/3038a735543087b5fe6a to your computer and use it in GitHub Desktop.
Save but80/3038a735543087b5fe6a to your computer and use it in GitHub Desktop.
// ...
uniform float4 _GAmplitude;
uniform float4 _GFrequency;
uniform float4 _GSteepness;
uniform float4 _GSpeed;
uniform float4 _GDirectionAB;
uniform float4 _GDirectionCD;
// ここから挿入
struct OceanParticle {
half3 position;
half velocity;
half force;
};
uint XDivision;
uint ZDivision;
uint XCount;
uint ZCount;
StructuredBuffer<OceanParticle> Particles;
// ここまで
// ...
v2f vert(appdata_full v)
{
v2f o;
half3 worldSpaceVertex = mul(_Object2World,(v.vertex)).xyz;
half3 vtxForAni = (worldSpaceVertex).xzz;
// ここから挿入
half3 nrml = half3(0,1,0);
half3 offsets = half3(0,0,0);
int kj = (int)v.vertex.x + (int)(XDivision / 2u);
int ki = (int)v.vertex.z + (int)(ZDivision / 2u);
if (0<=kj && kj<(int)XCount && 0<=ki && ki<(int)ZCount) {
int kp = ki * XCount + kj;
OceanParticle ptc = Particles[kp];
OceanParticle ptcN = Particles[kp - (0<ki ? 1 : 0) * XCount];
OceanParticle ptcS = Particles[kp + (ki<(int)ZDivision ? 1 : 0) * XCount];
OceanParticle ptcE = Particles[kp + (kj<(int)XDivision ? 1 : 0)];
OceanParticle ptcW = Particles[kp - (0<kj ? 1 : 0)];
half dydx = (ptcE.position.y - ptcW.position.y) / 2;
half dydz = (ptcS.position.y + ptcN.position.y) / 2;
nrml = normalize(cross(half3(0,dydz,1), half3(1,dydx,0)));
offsets.y = ptc.position.y * 4;
}
// ここまで
// ここからコメントアウト
//Gerstner (
// offsets, nrml, v.vertex.xyz, vtxForAni, // offsets, nrml will be written
// _GAmplitude, // amplitude
// _GFrequency, // frequency
// _GSteepness, // steepness
// _GSpeed, // speed
// _GDirectionAB, // direction # 1, 2
// _GDirectionCD // direction # 3, 4
//);
// ここまで
v.vertex.xyz += offsets;
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment