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

Problem with LUTPass and WebGL1 #21502

Closed
nilsrydell opened this issue Mar 23, 2021 · 10 comments · Fixed by #21531
Closed

Problem with LUTPass and WebGL1 #21502

nilsrydell opened this issue Mar 23, 2021 · 10 comments · Fixed by #21531
Labels

Comments

@nilsrydell
Copy link

Describe the bug

The LUTPass is not rendering output when used in a WebGL1 context (Safari and IOS). I have tried both the example (https://threejs.org/examples/?q=post#webgl_postprocessing_3dlut) and my own code with no luck.
Chrome and WebGL2 seems to work fine. Safari on desktop and on IOS produce the same errors to console:

WebGL: ERROR: 0:115: 'sampler3D' : Illegal use of reserved word
WebGL: ERROR: 0:115: 'sampler3D' : syntax error
THREE.WebGLProgram: shader error:
WebGL: INVALID_OPERATION: useProgram: program not valid

To Reproduce

Run this demo in Safari or IOS Safari: https://threejs.org/examples/?q=post#webgl_postprocessing_3dlut

Platform:

  • Device: Desktop and Mobile
  • OS: MacOS 10.15.7 (19H2) and iOS 14.4
  • Browser: Safari 14.0 and IOS Safari
  • Three.js version: 127dev and r126
@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 23, 2021

/ping @gkjohnson

@gkjohnson
Copy link
Collaborator

WebGL: ERROR: 0:115: 'sampler3D' : Illegal use of reserved word
WebGL: ERROR: 0:115: 'sampler3D' : syntax error

It seems Safari is complaining about this line using sampler3d in WebGL1 even though it's excluded through a disabled define flag...

#if USE_3DTEXTURE
uniform sampler3D lut3d;
#else

I'm not sure what the WebGL spec dictates but it seems like some weird behavior from Safari. Either way I think a solution is to update the ShaderMaterial fragment shader to manually exclude that line if using WebGL1 / 2D LUT rather than a #define.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 23, 2021

This is no Safari specific issue. When I use WebGL1Renderer in webgl_postprocessing_3dlut with Chrome, I get the same runtime error.

If LUTPass is supposed to support WebGL 1, then this issue is a bug.

@nilsrydell
Copy link
Author

#if USE_3DTEXTURE
uniform sampler3D lut3d;
#else
I made some further research into it. It works on WebGL1 (Safari) if the shader is striped from all mentions of sampler3D and the if-statements.

I'm not sure what the WebGL spec dictates but it seems like some weird behavior from Safari. Either way I think a solution is to update the ShaderMaterial fragment shader to manually exclude that line if using WebGL1 / 2D LUT rather than a #define.

Yes, I guess this would be a good way to implement it, without changing to much. There is also the option of having 2 shaders and have the LUTPass pick the appropriate one. I guess that would render a lot of code, though.

@gkjohnson
Copy link
Collaborator

gkjohnson commented Mar 23, 2021

This is no Safari specific issue. When I use WebGL1Renderer in webgl_postprocessing_3dlut with Chrome, I get the same runtime error.

Oh I missed that! I must have changed that since I originally tested with WebGL1.

@nilsrydell

Yes, I guess this would be a good way to implement it, without changing to much.

My plan was to make a function that would conditionally include the snippets currently inside the USE_3DTEXTURE and update the fragment shader rather than the material defines. Would you like to make a PR with the change? Otherwise I'll be able to look into it in the next week.

@nilsrydell
Copy link
Author

I have this solution currently working in both WebGL1 and 2 (Safari and Chrome):
https://github.com/nilsrydell/three.js/blob/7936ca7f6e16c4bed2f1d1a171b6741dd27fccaa/examples/jsm/postprocessing/LUTPass.js

Should I make a Pull Request for this one? I don't know if it is up to the coding standards, I just did it my way. Need this feature working tomorrow in a showcase. :). I have also made changes to the html of the example. Just fixed a variable spelling error in the parameters.

@Mugen87 Mugen87 changed the title Problem with LUTPass on WebGL1 (Safari and IOS) Problem with LUTPass with WebGL1 Mar 24, 2021
@Mugen87 Mugen87 changed the title Problem with LUTPass with WebGL1 Problem with LUTPass and WebGL1 Mar 24, 2021
@mrdoob
Copy link
Owner

mrdoob commented Mar 24, 2021

Here's the diff: nilsrydell@7936ca7?w=1

@gkjohnson
Copy link
Collaborator

I'll take a look at the diff and make a PR with updated formatting this weekend if that sounds good @nilsrydell.

Thanks!

@Mugen87 Mugen87 added the Bug label Mar 24, 2021
@nilsrydell
Copy link
Author

@gkjohnson Yes, sure sound great :).

@vanruesc
Copy link
Contributor

It seems Safari is complaining about this line using sampler3d in WebGL1 even though it's excluded through a disabled define flag...

I think this issue might actually be caused by this line which occurs outside of the preprocessor directives.

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 a pull request may close this issue.

5 participants