-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
\#4: port updateVelocity to shader preprocessor
- Loading branch information
1 parent
ce6a006
commit 95140b5
Showing
4 changed files
with
66 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {compile, glsl} from '../glslpp'; | ||
import {foreachNeighbor} from './foreachNeighbor'; | ||
import { | ||
collisionDistance, | ||
dt, | ||
eta, | ||
fPressureSampler, | ||
massSampler, | ||
particleRestitution, | ||
positionSampler, | ||
velocityGuessSampler, | ||
velocitySampler, | ||
} from './uniforms'; | ||
|
||
export const updateVelocityFs = compile(glsl` | ||
out vec4 outVelocity; | ||
void main() { | ||
ivec2 texCoord = ivec2(gl_FragCoord.xy); | ||
vec2 velocityGuess = texelFetch(${velocityGuessSampler}, texCoord, 0).rg; | ||
vec2 ownPos = texelFetch(${positionSampler}, texCoord, 0).rg; | ||
vec2 ownVel = texelFetch(${velocitySampler}, texCoord, 0).rg; | ||
float ownMass = texelFetch(${massSampler}, texCoord, 0).r; | ||
vec2 fPressure = texelFetch(${fPressureSampler}, texCoord, 0).rg; | ||
vec2 velocity = velocityGuess + (${dt} / ownMass) * fPressure; | ||
float collidedMass = 0.; | ||
vec2 dvCollsion = vec2(0.); | ||
${foreachNeighbor}(neighborTexCoord, { | ||
float neighborMass = texelFetch(${massSampler}, neighborTexCoord, 0).x; | ||
vec2 neighborPos = texelFetch(${positionSampler}, neighborTexCoord, 0).xy; | ||
vec2 neighborVel = texelFetch(${velocitySampler}, neighborTexCoord, 0).xy; | ||
vec2 dx = ownPos - neighborPos; | ||
vec2 dv = ownVel - neighborVel; | ||
float d = length(dx) + ${eta}; | ||
float dotDxDv = dot(dx, dv); | ||
if (d < ${collisionDistance} && dotDxDv < 0.) { | ||
collidedMass += neighborMass; | ||
dvCollsion += neighborMass * (1. + ${particleRestitution}) * (dotDxDv / d) * (dx / d); | ||
} | ||
}) | ||
float collisionTerm = 1. / (ownMass + collidedMass); | ||
velocity -= collisionTerm * dvCollsion; | ||
outVelocity = vec4(velocity, 0.0, 0.0); | ||
} | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.