Skip to content

Commit

Permalink
google pixel strange behaviour fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaraush committed Sep 8, 2023
1 parent a21b53c commit 72bf0d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ let W, H
const resize = () => {
const sz = Math.min(700, Math.min(canvasParent.clientWidth, canvasParent.clientHeight) * .9)
canvas.style.width = canvas.style.height = sz + 'px'
canvas.width = W = sz * window.devicePixelRatio
canvas.height = H = sz * window.devicePixelRatio
canvas.width = W = Math.floor(sz * window.devicePixelRatio)
canvas.height = H = Math.floor(sz * window.devicePixelRatio)
}
window.onresize = resize
resize()
Expand Down Expand Up @@ -71,7 +71,7 @@ const genBuffer = () => {

const compileShader = async (type, path) => {
const shader = gl.createShader(type)
gl.shaderSource(shader, await (await fetch(path)).text())
gl.shaderSource(shader, await (await fetch(path)).text() + '\n//' + Math.random())
gl.compileShader(shader)
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
throw 'compile shader error:\n' + gl.getShaderInfoLog(shader)
Expand All @@ -81,9 +81,6 @@ const compileShader = async (type, path) => {

const init = async () => {

transformFeedback = gl.createTransformFeedback()
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, transformFeedback)

genBuffer()

const vertexShader = await compileShader(gl.VERTEX_SHADER, './vertex.glsl')
Expand All @@ -96,6 +93,8 @@ const init = async () => {
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw 'program link error:\n' + gl.getProgramInfoLog(program)
}
gl.deleteShader(vertexShader)
gl.deleteShader(fragmentShader)

timeHandle = gl.getUniformLocation(program, 'time')
deltaTimeHandle = gl.getUniformLocation(program, 'deltaTime')
Expand Down Expand Up @@ -165,6 +164,14 @@ const loop = () => {
gl.vertexAttribPointer(3, 1, gl.FLOAT, false, 24, 20)
gl.enableVertexAttribArray(3)
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, buffer[1 - bufferIndex])
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 24, 0)
gl.enableVertexAttribArray(0)
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 24, 8)
gl.enableVertexAttribArray(1)
gl.vertexAttribPointer(2, 1, gl.FLOAT, false, 24, 16)
gl.enableVertexAttribArray(2)
gl.vertexAttribPointer(3, 1, gl.FLOAT, false, 24, 20)
gl.enableVertexAttribArray(3)
gl.beginTransformFeedback(gl.POINTS)
gl.drawArrays(gl.POINTS, 0, GUI.particlesCount)
gl.endTransformFeedback()
Expand All @@ -173,6 +180,7 @@ const loop = () => {

bufferIndex = 1 - bufferIndex
stats.end();

requestAnimationFrame(loop)
}

Expand Down
2 changes: 2 additions & 0 deletions vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@ void main() {
gl_Position = vec4((position / size * 2.0 - vec2(1.0)), 0.0, 1.0);
alpha = sin(particleTime * 3.14) * (.3 + .7 * rand(vec2(gl_VertexID)));
}

// @dkaraush

0 comments on commit 72bf0d8

Please sign in to comment.