Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
FluidSimulation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Amanda Ghassaei
FluidSimulation
Commits
6665bfce
Commit
6665bfce
authored
Apr 03, 2017
by
amandaghassaei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
boundary cond
parent
9cc33b08
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
14 deletions
+35
-14
index.html
index.html
+11
-5
js/GLBoilerplate.js
js/GLBoilerplate.js
+2
-2
js/main.js
js/main.js
+22
-7
No files found.
index.html
View file @
6665bfce
...
...
@@ -27,11 +27,17 @@
void
main
()
{
vec2
fragCoord
=
gl_FragCoord
.
xy
;
vec4
neighborVal
;
if
(
fragCoord
.
x
<
1.0
){
neighborVal
=
texture2D
(
u_texture
,
(
fragCoord
+
vec2
(
1.0
,
0.0
))
/
u_textureSize
);
gl_FragColor
=
u_scale
*
neighborVal
;
gl_FragColor
=
u_scale
*
texture2D
(
u_texture
,
(
fragCoord
+
vec2
(
1.0
,
0.0
))
/
u_textureSize
);
return
;
}
else
if
(
fragCoord
.
x
>=
u_textureSize
.
x
-
1.0
){
gl_FragColor
=
u_scale
*
texture2D
(
u_texture
,
(
fragCoord
+
vec2
(
-
1.0
,
0.0
))
/
u_textureSize
);
return
;
}
else
if
(
fragCoord
.
y
<
1.0
){
gl_FragColor
=
u_scale
*
texture2D
(
u_texture
,
(
fragCoord
+
vec2
(
0.0
,
1.0
))
/
u_textureSize
);
return
;
}
else
if
(
fragCoord
.
y
>=
u_textureSize
.
y
-
1.0
){
gl_FragColor
=
u_scale
*
texture2D
(
u_texture
,
(
fragCoord
+
vec2
(
0.0
,
-
1.0
))
/
u_textureSize
);
return
;
}
...
...
@@ -216,7 +222,7 @@
vec2
materialVal
;
//empty boundary
if
(
pos
.
x
<
0.0
||
pos
.
x
>=
u_textureSize
.
x
-
1.0
||
pos
.
y
<
0.0
||
pos
.
y
>=
u_textureSize
.
y
-
1.0
)
materialVal
=
vec2
(
0.0
);
if
(
pos
.
x
<
0.0
||
pos
.
x
>=
u_textureSize
.
x
||
pos
.
y
<
0.0
||
pos
.
y
>=
u_textureSize
.
y
)
materialVal
=
vec2
(
0.0
);
else
materialVal
=
bilinearInterp
(
pos
,
u_material
,
u_textureSize
);
gl_FragColor
=
vec4
(
materialVal
,
0
,
0
);
...
...
js/GLBoilerplate.js
View file @
6665bfce
...
...
@@ -122,8 +122,8 @@ function initBoilerPlate(){
function
loadVertexData
(
gl
,
program
)
{
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
gl
.
createBuffer
());
var
val
=
0.9
;
gl
.
bufferData
(
gl
.
ARRAY_BUFFER
,
new
Float32Array
([
-
val
,
-
val
,
val
,
-
val
,
-
val
,
val
,
val
,
val
,
val
,
val
,
val
,
-
val
,
-
val
,
val
,
-
val
,
-
val
]),
gl
.
STATIC_DRAW
);
var
val
=
1.0
;
gl
.
bufferData
(
gl
.
ARRAY_BUFFER
,
new
Float32Array
([
-
val
,
-
val
,
val
,
-
val
,
-
val
,
val
,
val
,
val
]),
gl
.
STATIC_DRAW
);
// look up where the vertex data needs to go.
var
positionLocation
=
gl
.
getAttribLocation
(
program
,
"
a_position
"
);
...
...
js/main.js
View file @
6665bfce
...
...
@@ -84,9 +84,10 @@ function render(){
GPU
.
setUniformForProgram
(
"
advect
"
,
"
u_scale
"
,
1
,
"
1f
"
);
GPU
.
step
(
"
advect
"
,
[
"
velocity
"
,
"
velocity
"
],
"
nextVelocity
"
);
// GPU.setProgram("boundary");
// GPU.setUniformForProgram("boundary", "u_scale", -1, "1f");
// GPU.stepBoundary("boundary", ["nextVelocity"], "velocity");
GPU
.
setProgram
(
"
boundary
"
);
GPU
.
setUniformForProgram
(
"
boundary
"
,
"
u_scale
"
,
-
1
,
"
1f
"
);
GPU
.
step
(
"
boundary
"
,
[
"
nextVelocity
"
],
"
velocity
"
);
// GPU.swapTextures("velocity", "nextVelocity");
//diffuse velocity
GPU
.
setProgram
(
"
jacobi
"
);
...
...
@@ -98,6 +99,9 @@ function render(){
GPU
.
step
(
"
jacobi
"
,
[
"
nextVelocity
"
,
"
nextVelocity
"
],
"
velocity
"
);
}
GPU
.
step
(
"
boundary
"
,
[
"
velocity
"
],
"
nextVelocity
"
);
GPU
.
swapTextures
(
"
velocity
"
,
"
nextVelocity
"
);
//apply force
GPU
.
setProgram
(
"
force
"
);
if
(
mouseEnable
){
...
...
@@ -109,7 +113,9 @@ function render(){
GPU
.
setUniformForProgram
(
"
force
"
,
"
u_mouseEnable
"
,
0.0
,
"
1f
"
);
}
GPU
.
step
(
"
force
"
,
[
"
velocity
"
],
"
nextVelocity
"
);
GPU
.
swapTextures
(
"
velocity
"
,
"
nextVelocity
"
);
// GPU.swapTextures("velocity", "nextVelocity");
GPU
.
step
(
"
boundary
"
,
[
"
nextVelocity
"
],
"
velocity
"
);
// compute pressure
GPU
.
step
(
"
diverge
"
,
[
"
velocity
"
],
"
velocityDivergence
"
);
//calc velocity divergence
...
...
@@ -121,9 +127,16 @@ function render(){
GPU
.
step
(
"
jacobi
"
,
[
"
velocityDivergence
"
,
"
nextPressure
"
],
"
pressure
"
);
//diffuse velocity
}
GPU
.
setProgram
(
"
boundary
"
);
GPU
.
setUniformForProgram
(
"
boundary
"
,
"
u_scale
"
,
1
,
"
1f
"
);
GPU
.
step
(
"
boundary
"
,
[
"
pressure
"
],
"
nextPressure
"
);
// subtract pressure gradient
GPU
.
step
(
"
gradientSubtraction
"
,
[
"
velocity
"
,
"
pressure
"
],
"
nextVelocity
"
);
GPU
.
swapTextures
(
"
velocity
"
,
"
nextVelocity
"
);
GPU
.
step
(
"
gradientSubtraction
"
,
[
"
velocity
"
,
"
nextPressure
"
],
"
nextVelocity
"
);
// GPU.swapTextures("velocity", "nextVelocity");
GPU
.
setProgram
(
"
boundary
"
);
GPU
.
setUniformForProgram
(
"
boundary
"
,
"
u_scale
"
,
-
1
,
"
1f
"
);
GPU
.
step
(
"
boundary
"
,
[
"
nextVelocity
"
],
"
velocity
"
);
// move material
GPU
.
setSize
(
actualWidth
,
actualHeight
);
...
...
@@ -150,11 +163,13 @@ function resetWindow(){
var
maxDim
=
Math
.
max
(
actualHeight
,
actualWidth
);
var
_scale
=
maxDim
/
150
;
if
(
_scale
<
1
)
_scale
=
1
;
width
=
Math
.
floor
(
actualWidth
/
_scale
);
height
=
Math
.
floor
(
actualHeight
/
_scale
);
scale
=
(
width
/
actualWidth
+
height
/
actualHeight
)
/
2
;
console
.
log
(
scale
);
canvas
.
width
=
actualWidth
;
canvas
.
height
=
actualHeight
;
...
...
@@ -168,7 +183,7 @@ function resetWindow(){
GPU
.
setProgram
(
"
diverge
"
);
GPU
.
setUniformForProgram
(
"
diverge
"
,
"
u_textureSize
"
,
[
width
,
height
],
"
2f
"
);
GPU
.
setProgram
(
"
force
"
);
GPU
.
setUniformForProgram
(
"
force
"
,
"
u_reciprocalRadius
"
,
0.
1
/
scale
,
"
1f
"
);
GPU
.
setUniformForProgram
(
"
force
"
,
"
u_reciprocalRadius
"
,
0.
03
/
scale
,
"
1f
"
);
GPU
.
setUniformForProgram
(
"
force
"
,
"
u_textureSize
"
,
[
width
,
height
],
"
2f
"
);
GPU
.
setProgram
(
"
jacobi
"
);
GPU
.
setUniformForProgram
(
"
jacobi
"
,
"
u_textureSize
"
,
[
width
,
height
],
"
2f
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment