Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebGL Tutorial
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
최형택
WebGL Tutorial
Commits
cde9ba5a
Commit
cde9ba5a
authored
4 years ago
by
Hyung-Taik Choi
Browse files
Options
Downloads
Patches
Plain Diff
Refactor code
parent
13ad84ad
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
script.js
+101
-202
101 additions, 202 deletions
script.js
with
101 additions
and
202 deletions
script.js
+
101
−
202
View file @
cde9ba5a
/*
MIT License
Copyright (c) 2021 Hyung-Taik Choi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'
use strict
'
;
// Mobile promo section
// const promoPopup = document.getElementsByClassName('promo')[0];
// const promoPopupClose = document.getElementsByClassName('promo-close')[0];
// if (isMobile()) {
// setTimeout(() => {
// promoPopup.style.display = 'table';
// }, 20000);
// }
// promoPopupClose.addEventListener('click', e => {
// promoPopup.style.display = 'none';
// });
// const appleLink = document.getElementById('apple_link');
// appleLink.addEventListener('click', e => {
// ga('send', 'event', 'link promo', 'app');
// window.open('https://apps.apple.com/us/app/fluid-simulation/id1443124993');
// });
// const googleLink = document.getElementById('google_link');
// googleLink.addEventListener('click', e => {
// ga('send', 'event', 'link promo', 'app');
// window.open('https://play.google.com/store/apps/details?id=games.paveldogreat.fluidsimfree');
// });
// Simulation section
const
canvas
=
document
.
getElementsByTagName
(
'
canvas
'
)[
0
];
...
...
@@ -113,8 +62,6 @@ if (!ext.supportLinearFiltering) {
config
.
SUNRAYS
=
false
;
}
// startGUI();
function
getWebGLContext
(
canvas
)
{
const
params
=
{
alpha
:
true
,
depth
:
false
,
stencil
:
false
,
antialias
:
false
,
preserveDrawingBuffer
:
false
};
...
...
@@ -140,21 +87,17 @@ function getWebGLContext (canvas) {
let
formatRG
;
let
formatR
;
if
(
isWebGL2
)
{
if
(
isWebGL2
)
{
formatRGBA
=
getSupportedFormat
(
gl
,
gl
.
RGBA16F
,
gl
.
RGBA
,
halfFloatTexType
);
formatRG
=
getSupportedFormat
(
gl
,
gl
.
RG16F
,
gl
.
RG
,
halfFloatTexType
);
formatR
=
getSupportedFormat
(
gl
,
gl
.
R16F
,
gl
.
RED
,
halfFloatTexType
);
}
else
{
else
{
formatRGBA
=
getSupportedFormat
(
gl
,
gl
.
RGBA
,
gl
.
RGBA
,
halfFloatTexType
);
formatRG
=
getSupportedFormat
(
gl
,
gl
.
RGBA
,
gl
.
RGBA
,
halfFloatTexType
);
formatR
=
getSupportedFormat
(
gl
,
gl
.
RGBA
,
gl
.
RGBA
,
halfFloatTexType
);
}
// ga('send', 'event', isWebGL2 ? 'webgl2' : 'webgl', formatRGBA == null ? 'not supported' : 'supported');
return
{
gl
,
ext
:
{
...
...
@@ -167,12 +110,9 @@ function getWebGLContext (canvas) {
};
}
function
getSupportedFormat
(
gl
,
internalFormat
,
format
,
type
)
{
if
(
!
supportRenderTextureFormat
(
gl
,
internalFormat
,
format
,
type
))
{
switch
(
internalFormat
)
{
function
getSupportedFormat
(
gl
,
internalFormat
,
format
,
type
)
{
if
(
!
supportRenderTextureFormat
(
gl
,
internalFormat
,
format
,
type
))
{
switch
(
internalFormat
)
{
case
gl
.
R16F
:
return
getSupportedFormat
(
gl
,
gl
.
RG16F
,
gl
.
RG
,
type
);
case
gl
.
RG16F
:
...
...
@@ -205,41 +145,6 @@ function supportRenderTextureFormat (gl, internalFormat, format, type) {
return
status
==
gl
.
FRAMEBUFFER_COMPLETE
;
}
// function startGUI () {
// var gui = new dat.GUI({ width: 300 });
// gui.add(config, 'DYE_RESOLUTION', { 'high': 1024, 'medium': 512, 'low': 256, 'very low': 128 }).name('quality').onFinishChange(initFramebuffers);
// gui.add(config, 'SIM_RESOLUTION', { '32': 32, '64': 64, '128': 128, '256': 256 }).name('sim resolution').onFinishChange(initFramebuffers);
// gui.add(config, 'DENSITY_DISSIPATION', 0, 4.0).name('density diffusion');
// gui.add(config, 'VELOCITY_DISSIPATION', 0, 4.0).name('velocity diffusion');
// gui.add(config, 'PRESSURE', 0.0, 1.0).name('pressure');
// gui.add(config, 'CURL', 0, 50).name('vorticity').step(1);
// gui.add(config, 'SPLAT_RADIUS', 0.01, 1.0).name('splat radius');
// gui.add(config, 'SHADING').name('shading').onFinishChange(updateKeywords);
// gui.add(config, 'COLORFUL').name('colorful');
// gui.add(config, 'PAUSED').name('paused').listen();
// gui.add({ fun: () => {
// splatStack.push(parseInt(Math.random() * 20) + 5);
// } }, 'fun').name('Random splats');
// let bloomFolder = gui.addFolder('Bloom');
// bloomFolder.add(config, 'BLOOM').name('enabled').onFinishChange(updateKeywords);
// bloomFolder.add(config, 'BLOOM_INTENSITY', 0.1, 2.0).name('intensity');
// bloomFolder.add(config, 'BLOOM_THRESHOLD', 0.0, 1.0).name('threshold');
// let sunraysFolder = gui.addFolder('Sunrays');
// sunraysFolder.add(config, 'SUNRAYS').name('enabled').onFinishChange(updateKeywords);
// sunraysFolder.add(config, 'SUNRAYS_WEIGHT', 0.3, 1.0).name('weight');
// let captureFolder = gui.addFolder('Capture');
// captureFolder.addColor(config, 'BACK_COLOR').name('background color');
// captureFolder.add(config, 'TRANSPARENT').name('transparent');
// captureFolder.add({ fun: captureScreenshot }, 'fun').name('take screenshot');
// if (isMobile())
// gui.close();
// }
function
isMobile
()
{
return
/Mobi|Android/i
.
test
(
navigator
.
userAgent
);
}
...
...
@@ -323,8 +228,7 @@ class Material {
hash
+=
hashCode
(
keywords
[
i
]);
let
program
=
this
.
programs
[
hash
];
if
(
program
==
null
)
{
if
(
program
==
null
)
{
let
fragmentShader
=
compileShader
(
gl
.
FRAGMENT_SHADER
,
this
.
fragmentShaderSource
,
keywords
);
program
=
createProgram
(
this
.
vertexShader
,
fragmentShader
);
this
.
programs
[
hash
]
=
program
;
...
...
@@ -881,18 +785,15 @@ const blit = (() => {
gl
.
enableVertexAttribArray
(
0
);
return
(
target
,
clear
=
false
)
=>
{
if
(
target
==
null
)
{
if
(
target
==
null
)
{
gl
.
viewport
(
0
,
0
,
gl
.
drawingBufferWidth
,
gl
.
drawingBufferHeight
);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
null
);
}
else
{
else
{
gl
.
viewport
(
0
,
0
,
target
.
width
,
target
.
height
);
gl
.
bindFramebuffer
(
gl
.
FRAMEBUFFER
,
target
.
fbo
);
}
if
(
clear
)
{
if
(
clear
)
{
gl
.
clearColor
(
0.0
,
0.0
,
0.0
,
1.0
);
gl
.
clear
(
gl
.
COLOR_BUFFER_BIT
);
}
...
...
@@ -979,8 +880,7 @@ function initBloomFramebuffers () {
bloom
=
createFBO
(
res
.
width
,
res
.
height
,
rgba
.
internalFormat
,
rgba
.
format
,
texType
,
filtering
);
bloomFramebuffers
.
length
=
0
;
for
(
let
i
=
0
;
i
<
config
.
BLOOM_ITERATIONS
;
i
++
)
{
for
(
let
i
=
0
;
i
<
config
.
BLOOM_ITERATIONS
;
i
++
)
{
let
width
=
res
.
width
>>
(
i
+
1
);
let
height
=
res
.
height
>>
(
i
+
1
);
...
...
@@ -1468,8 +1368,7 @@ canvas.addEventListener('touchmove', e => {
window
.
addEventListener
(
'
touchend
'
,
e
=>
{
const
touches
=
e
.
changedTouches
;
for
(
let
i
=
0
;
i
<
touches
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
touches
.
length
;
i
++
)
{
let
pointer
=
pointers
.
find
(
p
=>
p
.
id
==
touches
[
i
].
identifier
);
if
(
pointer
==
null
)
continue
;
updatePointerUpData
(
pointer
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment