mirror of
https://github.com/PavelDoGreat/WebGL-Fluid-Simulation.git
synced 2025-10-04 09:51:38 +02:00
experiment with ga
This commit is contained in:
26
script.js
26
script.js
@@ -17,7 +17,7 @@ let config = {
|
||||
let pointers = [];
|
||||
let splatStack = [];
|
||||
|
||||
const { gl, ext, support_linear_float } = getWebGLContext(canvas);
|
||||
const { gl, ext } = getWebGLContext(canvas);
|
||||
startGUI();
|
||||
|
||||
function getWebGLContext (canvas) {
|
||||
@@ -40,7 +40,7 @@ function getWebGLContext (canvas) {
|
||||
const internalFormat = isWebGL2 ? gl.RGBA16F : gl.RGBA;
|
||||
const internalFormatRG = isWebGL2 ? gl.RG16F : gl.RGBA;
|
||||
const formatRG = isWebGL2 ? gl.RG : gl.RGBA;
|
||||
const texType = isWebGL2 ? gl.HALF_FLOAT : halfFloat.HALF_FLOAT_OES;
|
||||
const halfFloatTexType = isWebGL2 ? gl.HALF_FLOAT : halfFloat.HALF_FLOAT_OES;
|
||||
|
||||
return {
|
||||
gl,
|
||||
@@ -48,9 +48,9 @@ function getWebGLContext (canvas) {
|
||||
internalFormat,
|
||||
internalFormatRG,
|
||||
formatRG,
|
||||
texType
|
||||
},
|
||||
support_linear_float
|
||||
halfFloatTexType,
|
||||
support_linear_float
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ initFramebuffers();
|
||||
const clearProgram = new GLProgram(baseVertexShader, clearShader);
|
||||
const displayProgram = new GLProgram(baseVertexShader, displayShader);
|
||||
const splatProgram = new GLProgram(baseVertexShader, splatShader);
|
||||
const advectionProgram = new GLProgram(baseVertexShader, support_linear_float ? advectionShader : advectionManualFilteringShader);
|
||||
const advectionProgram = new GLProgram(baseVertexShader, ext.support_linear_float ? advectionShader : advectionManualFilteringShader);
|
||||
const divergenceProgram = new GLProgram(baseVertexShader, divergenceShader);
|
||||
const curlProgram = new GLProgram(baseVertexShader, curlShader);
|
||||
const vorticityProgram = new GLProgram(baseVertexShader, vorticityShader);
|
||||
@@ -410,10 +410,10 @@ function initFramebuffers () {
|
||||
const iFormat = ext.internalFormat;
|
||||
const iFormatRG = ext.internalFormatRG;
|
||||
const formatRG = ext.formatRG;
|
||||
const texType = ext.texType;
|
||||
const texType = ext.halfFloatTexType;
|
||||
|
||||
density = createDoubleFBO(0, textureWidth, textureHeight, iFormat , gl.RGBA , texType, support_linear_float ? gl.LINEAR : gl.NEAREST);
|
||||
velocity = createDoubleFBO(2, textureWidth, textureHeight, iFormatRG, formatRG, texType, support_linear_float ? gl.LINEAR : gl.NEAREST);
|
||||
density = createDoubleFBO(0, textureWidth, textureHeight, iFormat , gl.RGBA , texType, ext.support_linear_float ? gl.LINEAR : gl.NEAREST);
|
||||
velocity = createDoubleFBO(2, textureWidth, textureHeight, iFormatRG, formatRG, texType, ext.support_linear_float ? gl.LINEAR : gl.NEAREST);
|
||||
divergence = createFBO (4, textureWidth, textureHeight, iFormatRG, formatRG, texType, gl.NEAREST);
|
||||
curl = createFBO (5, textureWidth, textureHeight, iFormatRG, formatRG, texType, gl.NEAREST);
|
||||
pressure = createDoubleFBO(6, textureWidth, textureHeight, iFormatRG, formatRG, texType, gl.NEAREST);
|
||||
@@ -435,6 +435,10 @@ function createFBO (texId, w, h, internalFormat, format, type, param) {
|
||||
gl.viewport(0, 0, w, h);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
|
||||
const status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
|
||||
if (status != gl.FRAMEBUFFER_COMPLETE)
|
||||
ga('send', 'event', 'app', 'init', status);
|
||||
|
||||
return [texture, fbo, texId];
|
||||
}
|
||||
|
||||
@@ -449,7 +453,7 @@ function createDoubleFBO (texId, w, h, internalFormat, format, type, param) {
|
||||
get second () {
|
||||
return fbo2;
|
||||
},
|
||||
swap: () => {
|
||||
swap () {
|
||||
let temp = fbo1;
|
||||
fbo1 = fbo2;
|
||||
fbo2 = temp;
|
||||
@@ -542,10 +546,10 @@ function update () {
|
||||
gl.uniform2f(pressureProgram.uniforms.texelSize, 1.0 / textureWidth, 1.0 / textureHeight);
|
||||
gl.uniform1i(pressureProgram.uniforms.uDivergence, divergence[2]);
|
||||
pressureTexId = pressure.first[2];
|
||||
gl.uniform1i(pressureProgram.uniforms.uPressure, pressureTexId);
|
||||
gl.activeTexture(gl.TEXTURE0 + pressureTexId);
|
||||
for (let i = 0; i < config.PRESSURE_ITERATIONS; i++) {
|
||||
gl.bindTexture(gl.TEXTURE_2D, pressure.first[0]);
|
||||
gl.uniform1i(pressureProgram.uniforms.uPressure, pressureTexId);
|
||||
blit(pressure.second[1]);
|
||||
pressure.swap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user