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
9cc33b08
Commit
9cc33b08
authored
Apr 03, 2017
by
amandaghassaei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding in boundary program
parent
ed182096
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
6 deletions
+48
-6
index.html
index.html
+25
-3
js/GLBoilerplate.js
js/GLBoilerplate.js
+2
-1
js/GPUMath.js
js/GPUMath.js
+11
-0
js/main.js
js/main.js
+10
-2
No files found.
index.html
View file @
9cc33b08
...
...
@@ -17,6 +17,28 @@
}
</script>
<script
id=
"boundaryShader"
type=
"x-shader/x-fragment"
>
precision
mediump
float
;
uniform
sampler2D
u_texture
;
uniform
float
u_scale
;
uniform
vec2
u_textureSize
;
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
;
return
;
}
gl_FragColor
=
texture2D
(
u_texture
,
(
fragCoord
)
/
u_textureSize
);
}
</script>
<script
id=
"2d-render-shader"
type=
"x-shader/x-fragment"
>
precision
mediump
float
;
...
...
@@ -204,9 +226,9 @@
<script
type=
"text/javascript"
src=
"dependencies/jquery-3.1.0.min.js"
></script>
<script
type=
"text/javascript"
src=
"dependencies/flat-ui.min.js"
></script>
<script
type=
"text/javascript"
src=
"GLBoilerplate.js"
></script>
<script
type=
"text/javascript"
src=
"GPUMath.js"
></script>
<script
type=
"text/javascript"
src=
"main.js"
></script>
<script
type=
"text/javascript"
src=
"
js/
GLBoilerplate.js"
></script>
<script
type=
"text/javascript"
src=
"
js/
GPUMath.js"
></script>
<script
type=
"text/javascript"
src=
"
js/
main.js"
></script>
</head>
<body>
...
...
Gl
Boilerplate.js
→
js/GL
Boilerplate.js
View file @
9cc33b08
...
...
@@ -122,7 +122,8 @@ function initBoilerPlate(){
function
loadVertexData
(
gl
,
program
)
{
gl
.
bindBuffer
(
gl
.
ARRAY_BUFFER
,
gl
.
createBuffer
());
gl
.
bufferData
(
gl
.
ARRAY_BUFFER
,
new
Float32Array
([
-
1
,
-
1
,
1
,
-
1
,
-
1
,
1
,
1
,
1
]),
gl
.
STATIC_DRAW
);
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
);
// look up where the vertex data needs to go.
var
positionLocation
=
gl
.
getAttribLocation
(
program
,
"
a_position
"
);
...
...
GPUMath.js
→
js/
GPUMath.js
View file @
9cc33b08
...
...
@@ -110,6 +110,17 @@ function initGPUMath(){
gl
.
drawArrays
(
gl
.
TRIANGLE_STRIP
,
0
,
4
);
//draw to framebuffer
};
GPUMath
.
prototype
.
stepBoundary
=
function
(
programName
,
inputTextures
,
outputTexture
){
gl
.
useProgram
(
this
.
programs
[
programName
].
program
);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
this
.
frameBuffers
[
outputTexture
]);
for
(
var
i
=
0
;
i
<
inputTextures
.
length
;
i
++
){
gl
.
activeTexture
(
gl
.
TEXTURE0
+
i
);
gl
.
bindTexture
(
gl
.
TEXTURE_2D
,
this
.
textures
[
inputTextures
[
i
]]);
}
gl
.
drawArrays
(
gl
.
LINES
,
0
,
8
);
//draw to framebuffer
};
GPUMath
.
prototype
.
swapTextures
=
function
(
texture1Name
,
texture2Name
){
var
temp
=
this
.
textures
[
texture1Name
];
this
.
textures
[
texture1Name
]
=
this
.
textures
[
texture2Name
];
...
...
main.js
→
js/
main.js
View file @
9cc33b08
...
...
@@ -65,6 +65,9 @@ function initGL() {
GPU
.
createProgram
(
"
render
"
,
"
2d-vertex-shader
"
,
"
2d-render-shader
"
);
GPU
.
setUniformForProgram
(
"
render
"
,
"
u_material
"
,
0
,
"
1i
"
);
GPU
.
createProgram
(
"
boundary
"
,
"
2d-vertex-shader
"
,
"
boundaryShader
"
);
GPU
.
setUniformForProgram
(
"
boundary
"
,
"
u_texture
"
,
0
,
"
1i
"
);
resetWindow
();
render
();
...
...
@@ -80,7 +83,10 @@ function render(){
GPU
.
setUniformForProgram
(
"
advect
"
,
"
u_textureSize
"
,
[
width
,
height
],
"
2f
"
);
GPU
.
setUniformForProgram
(
"
advect
"
,
"
u_scale
"
,
1
,
"
1f
"
);
GPU
.
step
(
"
advect
"
,
[
"
velocity
"
,
"
velocity
"
],
"
nextVelocity
"
);
GPU
.
swapTextures
(
"
velocity
"
,
"
nextVelocity
"
);
// GPU.setProgram("boundary");
// GPU.setUniformForProgram("boundary", "u_scale", -1, "1f");
// GPU.stepBoundary("boundary", ["nextVelocity"], "velocity");
//diffuse velocity
GPU
.
setProgram
(
"
jacobi
"
);
...
...
@@ -143,7 +149,7 @@ function resetWindow(){
actualHeight
=
body
.
clientHeight
;
var
maxDim
=
Math
.
max
(
actualHeight
,
actualWidth
);
var
_scale
=
maxDim
/
20
0
;
var
_scale
=
maxDim
/
15
0
;
width
=
Math
.
floor
(
actualWidth
/
_scale
);
height
=
Math
.
floor
(
actualHeight
/
_scale
);
...
...
@@ -168,6 +174,8 @@ function resetWindow(){
GPU
.
setUniformForProgram
(
"
jacobi
"
,
"
u_textureSize
"
,
[
width
,
height
],
"
2f
"
);
GPU
.
setProgram
(
"
render
"
);
GPU
.
setUniformForProgram
(
"
render
"
,
"
u_textureSize
"
,
[
actualWidth
,
actualHeight
],
"
2f
"
);
GPU
.
setProgram
(
"
boundary
"
);
GPU
.
setUniformForProgram
(
"
boundary
"
,
"
u_textureSize
"
,
[
width
,
height
],
"
2f
"
);
var
velocity
=
new
Float32Array
(
width
*
height
*
4
);
// for (var i=0;i<height;i++){
...
...
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