You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This seems to be related to the comments because if I remove all of them, it no longer hangs for 8 seconds!
//@flowimportReactfrom"react";import{Uniform,Shaders,Node,GLSL,NearestCopy}from"gl-react";import{Surface}from"gl-react-dom";importtimeLoopfrom"../../HOC/timeLoop";exportconstshaders=Shaders.create({InitGameOfLife: {// returns white or black randomlyfrag: GLSL`precision highp float;varying vec2 uv;float random (vec2 uv) { return fract(sin(dot(uv, vec2(12.9898,78.233))) * 43758.5453);}void main() { gl_FragColor = vec4(vec3(step(0.5, random(uv))), 1.0);}`},GameOfLife: {// implement Game Of Life.frag: GLSL`precision highp float;varying vec2 uv;uniform float size;uniform sampler2D t; // the previous world statevoid main() { float prev = step(0.5, texture2D(t, uv).r); float c = 1.0 / size; float sum = step(0.5, texture2D(t, uv + vec2(-1.0, -1.0)*c).r) + step(0.5, texture2D(t, uv + vec2(-1.0, 0.0)*c).r) + step(0.5, texture2D(t, uv + vec2(-1.0, 1.0)*c).r) + step(0.5, texture2D(t, uv + vec2( 0.0, 1.0)*c).r) + step(0.5, texture2D(t, uv + vec2( 1.0, 1.0)*c).r) + step(0.5, texture2D(t, uv + vec2( 1.0, 0.0)*c).r) + step(0.5, texture2D(t, uv + vec2( 1.0, -1.0)*c).r) + step(0.5, texture2D(t, uv + vec2( 0.0, -1.0)*c).r); float next = prev==1.0 && sum >= 2.0 && sum <= 3.0 || sum == 3.0 ? 1.0 : 0.0; gl_FragColor = vec4(vec3(next), 1.0);}`}});constrefreshEveryTicks=20;exportconstGameOfLife=({ tick })=>{// Changing size is "destructive" and will reset the Game of Life stateconstsize=16*(1+Math.floor(tick/refreshEveryTicks));// However, we can conditionally change shader/uniforms,// React reconciliation will preserve the same <Node> instance,// and our Game of Life state will get preserved!returntick%refreshEveryTicks===0
? <Nodeshader={shaders.InitGameOfLife}width={size}height={size}backbuffering// makes Node holding 2 fbos that get swapped each draw timesync// force <Node> to draw in sync each componentDidUpdate time/>
: <Nodeshader={shaders.GameOfLife}width={size}height={size}backbufferingsyncuniforms={{t: Uniform.Backbuffer,// Use previous frame buffer as a texture
size
}}/>;};constGameOfLifeLoop=timeLoop(GameOfLife,{refreshRate: 20});exportdefault()=>(<Surfacewidth={384}height={384}><NearestCopy><GameOfLifeLoop/></NearestCopy></Surface>);
The text was updated successfully, but these errors were encountered:
Thanks for reporting, the performance issue should be fixed now. (Though the Node tags are still not highlighted since Prism does not support comments in those.)
This seems to be related to the comments because if I remove all of them, it no longer hangs for 8 seconds!
The text was updated successfully, but these errors were encountered: