borismus / webvr-boilerplate

A starting point for web-based VR experiences that work on all VR headsets.
Apache License 2.0
1.8k stars 451 forks source link

Declare non-constant fragment shader variables inside main #96

Closed brianchirls closed 8 years ago

brianchirls commented 8 years ago

I'm getting the following warning in Chrome when compiling the BarrelDistortionFragment (v2) shader:

WARNING: 0:22: '=' : global variable initializers should be constant expressions (uniforms and globals are allowed in global initializers for legacy compatibility)

It's on the declaration of projectionRight and unprojectionRight. If you move those declarations inside of main, the warning goes away. I'm not sure, but I suspect this might break on certain devices. There's some discussion of it and a proper reference to the spec on Stack Overflow.

borismus commented 8 years ago

Not sure... I'd stick to spec and deal with the warning rather than risk breakage. @toji what do you think?

On Thu, Dec 31, 2015, 7:21 AM Brian Chirls notifications@github.com wrote:

I'm getting the following warning in Chrome when compiling the BarrelDistortionFragment (v2) shader:

WARNING: 0:22: '=' : global variable initializers should be constant expressions (uniforms and globals are allowed in global initializers for legacy compatibility)

It's on the declaration of projectionRight and unprojectionRight. If you move those declarations inside of main, the warning goes away. I'm not sure, but I suspect this might break on certain devices. There's some discussion of it and a proper reference to the spec on Stack Overflow http://stackoverflow.com/questions/28076568/is-it-ever-reasonable-to-do-computations-outside-of-main-in-an-opengl-shader

.

You can view, comment on, or merge this pull request online at:

https://github.com/borismus/webvr-boilerplate/pull/96 Commit Summary

  • Declare non-constant fragment shader variables inside main

File Changes

Patch Links:

— Reply to this email directly or view it on GitHub https://github.com/borismus/webvr-boilerplate/pull/96.

brianchirls commented 8 years ago

As I read it, placing the declarations inside of main does both stick to the spec and gets rid of the warning. Everybody wins.

toji commented 8 years ago

I think what @brianchirls was saying is "I suspect [leaving these variables where they currently are] might break on certain devices." And I agree, it feels awkward to do computation outside of a function. Moving the declarations inside main should be harmless and get rid of the warning.