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

Support webgl2 and GLSL 3.00 #13692

Closed

Conversation

yoshikiohshima
Copy link
Contributor

Another attempt to support WebGL2RenderingContext and GLSL 3.00.

  • WebGLRenderer.js parameter may specify to call getContext() with argument 'webgl2'.
  • Such a renderer allows to use GLSL 3.00.
  • The share code in ShaderChunk and ShaderLib has #ifdef to switch between "varying/attribute" vs. "in/out".
  • Multiple Render Target can be specified from the client code.
  • extensions natively supported by WebGL2RenderingContext are handled.

(For our project, we have a GPGPU framework that uses GLSL3.00 features such as texelFetch and new buffer types such as R32F. This patch allows integrating the framework with Three.js. It's been working well for our purpose, and hopefully it is useful for others who are trying a similar stuff.)

@takahirox
Copy link
Collaborator

Do you wanna join the discussion here? #12250

@takahirox
Copy link
Collaborator

And #9965 is for WebGL2.0.

@yoshikiohshima yoshikiohshima mentioned this pull request Mar 26, 2018
@mrdoob
Copy link
Owner

mrdoob commented Mar 26, 2018

Rather than adding ifdefs macros everywhere... I would, instead, change the relevant varying to in directly in the .glsl files.

Then I would add a convertToGLSL1() function which would replace in with varying . That same function could also remove out vec4 glFragColor; and replace glFragColor = to gl_FragColor = .

Seems like sooner or later we would need this anyway.

@mrdoob mrdoob added this to the r92 milestone Mar 26, 2018
@yoshikiohshima
Copy link
Contributor Author

Great! When I started, I was not sure if all of those changes can be done mechanically. In the end, it was the case (I think).

By following some code in WebGLProgram.js, it may not be too hard to provide the source to source translation (without really parsing the GLSL code.)

@mrdoob
Copy link
Owner

mrdoob commented Mar 27, 2018

That's what I hope!
Would you like to give a go to my suggestion?

@yoshikiohshima
Copy link
Contributor Author

I just would like to check with you on the style of my JS, and how much assumptions I can have on the GLSL code. Basically my convertToGLSL1() would look like:

https://gist.github.com/yoshikiohshima/7083198c6eb7efdc82627de11e351f72

On my computer, it seems to be working. (The function is kind of long, but not too long.)

One thing I wonder about is that a use of glFragColor such as:

gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );

can't go multiple lines. So far I don't see a case like that so it maybe okay but somehow it'd have to be understood.

If this is good enough, I'll double check things (hopefully tomorrow) and make another pull request.

@yoshikiohshima
Copy link
Contributor Author

Superceded by #13701.

@mrdoob mrdoob closed this Mar 27, 2018
@mrdoob mrdoob removed this from the r92 milestone Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants