Giter Site home page Giter Site logo

Comments (8)

typpo avatar typpo commented on June 10, 2024

Thanks for the report. I'm on Mac Firefox and am able to see the rings. So I suspect it may be some combination of OS+GPU.

Here is an old but potentially related issue. However, my ring shader doesn't return any structs. So I'm not sure the fix is directly applicable.

from spacekit.

Postrediori avatar Postrediori commented on June 10, 2024

So I suspect it may be some combination of OS+GPU.

Yes, this happens to be a Windows-specific issue. Ubuntu 18.04 on the same machine (using Live USB) renders rings as intended.

from spacekit.

Postrediori avatar Postrediori commented on June 10, 2024

However, my ring shader doesn't return any structs.

It seems that the version of RING_SHADER_FRAGMENT from src/shaders.js is not called from anywhere in the Saturn demo. Instead the shader is in build/spacekit.js.

Warning: D3D shader compilation failed with default flags.

I've found out the similar error in the TensorFlow JS library (tensorflow/tfjs#1337). It's not directly aplicable to this case, but the solution for that bug (tensorflow/tfjs-core#1646) showed that there might be flaws hidden deep in a valid and working code because of the GPU drivers (like an inability to handle integer division correctly in TensorFlow case).

So I've checked the ring's frament shader for suspicious things. There is the following calculation of the pixel's colour:

  void main(void) {
	gl_FragColor = color() * vec4(lights() * shadow(), 1.0);
  }

The color() function contains discard option as the conditional path.

  vec4 color() {
    ...
    if (...) {
      discard;
    }
    ...
  }

Commenting this out (or replacing with return vec4(0.0)) fixes the problem (and renders rings wrong of course).

My guess is that the driver on Windows cannot handle variable deallocation correctly. When an operand of the multiplication operation (color() function) calls discard it does not discard the multiplication operation as a whole. Light and shadow components are calculated anyway and when the second operand vec4(...) is calculated it tries to multiply the result by the left operand that has already been discarded and the driver crashes (hence the vague 'unbound variable' text in the error log).

Switching the operands of the final multiplication allows rings to be rendered:

	gl_FragColor = vec4(lights() * shadow(), 1.0) * color();

Also, saving light&shadow components to a temporary vector also works fine as right value is already known when discard in color() is executed:

        vec3 lightAndShadow = lights() * shadow();
	gl_FragColor = color() * vec4(lightAndShadow , 1.0);

This is just my first look on the problem and I'm not sure this is the final or 'proper' way to fix this.

P.S. The following version also works for some mysterious reason:

  void main(void) {
        vec3 foo = lights();
        vec3 bar = shadow();
	gl_FragColor = color() * vec4(lights() * shadow(), 1.0);
  }

from spacekit.

typpo avatar typpo commented on June 10, 2024

@Postrediori Thanks so much for the detailed debugging help! I've made one of your suggested changes:

gl_FragColor = vec4(lights() * shadow(), 1.0) * color();

This means the example should load correctly (you may have to hard refresh): https://typpo.github.io/spacekit/examples/saturn/index.html. How does it look?

from spacekit.

Postrediori avatar Postrediori commented on June 10, 2024

Rings are rendered correctly:

Saturn

Checked on Win10 & 8.1, Firefox and Chromium.

Thanks!

from spacekit.

typpo avatar typpo commented on June 10, 2024

Thank you again for the help!

from spacekit.

Postrediori avatar Postrediori commented on June 10, 2024

FYI Maybe a bit late, I reported this issue to Chromium bugtracker: https://bugs.chromium.org/p/chromium/issues/detail?id=1192924. It was labeled as Wont Fix though, because is is a bug somewhere in legacy DirectX dll.

from spacekit.

typpo avatar typpo commented on June 10, 2024

This is interesting, thanks so much for following up. I've run into strange issues with ANGLE before.

from spacekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.