Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WebGL2 #114

Open
2 of 4 tasks
vorg opened this issue May 10, 2022 · 3 comments
Open
2 of 4 tasks

Add support for WebGL2 #114

vorg opened this issue May 10, 2022 · 3 comments

Comments

@vorg
Copy link
Member

vorg commented May 10, 2022

To make this transition manageable i propose following steps

  • update this repo to ESM
  • port VAO (Add VAO support #85) from 85-vao-temp branch
  • decide on UBO support class/object
  • decouple shader stage parameters from source so we can generate GLSL100 and GLSL300 source code depending on WebGL version
//pex-context@2 for webgl1
ctx.pipeline({
  frag: `....`
})

//pex-context@3 for webgl1/2
ctx.pipeline({
  extensions: [],
  uniforms: [],
  vert: {
    ins: [],
    outs: [],
    src: []
  },
  frag: {    
     outs: []
     src: ``
  }
})

//or more webgl-y
ctx.pipeline({
  extensions: [],
  uniforms: [],
  attributes: [],
  varyings: [],
  outs: [],
  vert: src,
  frag: src
})

The questions is why would we need that?

  • to run on iOS < 15 devices with no WebGL 2 (apparently still about 40% as of 2022-Q1)
  • to ease pain of porting every single PBR/MRT shader as they use extension that is built-in in WebGL2 (draw buffers, derivatives etc)
@vorg
Copy link
Member Author

vorg commented May 10, 2022

Another use case for more structured shader code is similarity to shader graph nodes

module.exports = (node, graph) => {
  const vec3In = node.in("vec3", [1, 1, 1, 1]);
  const xOut = node.out("x", 1);
  const yOut = node.out("y", 1);
  const zOut = node.out("z", 1);

  node.sg = {
    ins: {
      vec3: { type: "vec3", port: vec3In },
    },
    outs: {
      x: { type: "float", port: xOut },
      y: { type: "float", port: yOut },
      z: { type: "float", port: zOut },
    },
    code: (sg) => `
      ${sg.outs.x.type} ${sg.outs.x.var} = ${sg.ins.vec3.var}.x;
      ${sg.outs.y.type} ${sg.outs.y.var} = ${sg.ins.vec3.var}.y;
      ${sg.outs.z.type} ${sg.outs.z.var} = ${sg.ins.vec3.var}.z;
    `,
  };
};

@vorg
Copy link
Member Author

vorg commented May 10, 2022

It looks like BabylonJS doesn't care about this kind of issues and have most shaders still in GLSL100 with some in GLSL300.

@vorg
Copy link
Member Author

vorg commented May 10, 2022

Another thing to consider is not only how you create the source code but also how you provide all those attributes and uniforms (buffers).

In WebGL you have attributes and uniforms
In WebGL2 you have attributes, uniforms and uniform buffers
In WebGPU you have bindings (to uniform buffers, textures and vertex buffers)

dmnsgn added a commit that referenced this issue May 13, 2022
- [x] convert require to import and module.exports to exports
- [x] docs: convert example to esm
- [x] docs: fix examples
- [x] docs: aggregate instancing/batching/shadows example
- [x] fix: handle buffer.length for ArrayBuffer
- [x] fix: debug not working in esm
- [x] fix(webgl2): use gl.MAX_COLOR_ATTACHMENTS instead of "MAX_COLOR_ATTACHMENTS"
- [x] fix(webgl2): handle EXT_disjoint_timer_query_webgl2
- [x] feat: add width/height getters
- [x] feat: set type to webgl2 #114

Closes #66
Closes #38

BREAKING CHANGE: switch to type module
@dmnsgn dmnsgn added this to the 3.0.0 milestone Dec 2, 2022
@dmnsgn dmnsgn removed this from the 3.0.0 milestone May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants