pex-gl / pex-shaders

MIT License
3 stars 0 forks source link

Provide aliases for patchES300 #10

Open vorg opened 5 months ago

vorg commented 5 months ago

Current approach is verbose and error prone

ctx.pipeline({
   vert: parser.patchES300("..."),
   frag: parser.patchES300("...", "fragment")
})

The alternative approach is much more readable

ctx.pipeline({
   vert: parser.patchVert("..."),
   frag: parser.patchFrag("...")
})

Downsides:

But for comparision i don't think this is better

ctx.pipeline({
   vert: parser.patchVertES300("..."),
   frag: parser.patchFragES300("...")
})

Maybe it should be the parser that is typed?

import { parser } from "pex-shaders";

to

import { es3000Parser as parser } from "pex-shaders";

then you could switch language by switching import (in my dreams..)

vorg commented 5 months ago

One could as why do we even have to bother and why pex-context is not auto-upgrading it for us?

vorg commented 5 months ago

Another option build a online tool when we can upgrade our code by copy paste and stop using parser.

What do you think @dmnsgn

dmnsgn commented 5 months ago

I think parser.patchES300 is purposely verbose as it should be a relic from the past by now and we are willing to remove it entirely.

The current solution (as of Jan 2024) is:

That works beautifully in pex-renderer v4 alpha and has the following pros:

And cons:

That's for current status.

We reached the conclusion that –now that Safari caught up– WebGL 2 has enough worldwide support so we should entirely drop WebGL1. In a soonish future that means:

PS: I still don't see any obvious GLSL -> WGSL bridge without DSL extracting shader variables and providing different body like I did in dgel:

https://github.com/dmnsgn/dgel/blob/b3a213d636a3327eb80a89a93344a4f852c25db2/examples/cube.js#L159-L194

vorg commented 5 months ago

Ok. I missed that defines SOTA. It kind of brings back the question of Shift from framework to library #9 as those defines are in final shaders that could be in pex-renderer instead of here.

Re. glsl/wgsl we could got further into thi.ng/umbrella and copy ThreeJS approach with DSL in JS/TS. https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast. There is no WGSL front end yet, only glsl.

const sinc = (x: FloatTerm, k: FloatTerm) =>
    div(sin(mul(x,k)), mul(x, k));

Not sure how does it feel to write whole PBR shader in this though... Seems like 6 months project.