Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8295960

Specular reflection might not be calculated correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • jfx11, jfx19
    • javafx
    • None

      According to the theory, both in online sources and in the `PhongMaterial` class doc, the computation for the specular component should be:
      `R . V` where `V` is the vector to the eye/cam and `R` is the reflection vector computed by `R = 2(N . L)N - L`, or using the a built-in method such as 'reflect' (https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-reflect): `R = -reflect(N, L)`. So the shader files should look something like this:

      float3 refl = reflect(l, n);
      s = ... dot(-refl, e); // e is the vector to the eye, like V

      However, looking at the shader files, already from legacy (https://github.com/openjdk/jfx/blob/c420248b9b459efcfbd3657170d9be0b96b5fb38/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h), the vectors are switched:

      float3 refl = reflect(e, n);
      s = ... dot(-refl, l);

      It looks like the specular computation was wrong from the start. This computation happens both in the D2D and OpenGL pipelines. Initial testing doesn't show that there is much of a visual difference, peculiarly.

            nlisker Nir Lisker
            nlisker Nir Lisker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: