Requesting Help Troubleshooting PBRTerrain Bug

In a recent thread, this graphical display bug was reported to occurr when running Jmonkey’s PBR Terrain examples:

I am trying to work on figuring out the cause still, so I made this thread to see if any other JME users can try to run these 2 PBRTerrain test cases and let me know your device specs and if you experience this error or not. (unfortunately my device does not reproduce this error so I cannot troubleshoot it myself by trial/error like I normally would)

I have a few ideas as to what the issue can be, but I want to collect some more information and look into it more before I begin changing things. Right now I think the most likely cause could be that I forgot to normalize a value or something somewhere throughout the normals or tangents calculation, but in that case I’d have expected some strange display glitches on my device too.

Any ideas, as well as any help running the test cases to see if you also experience this display bug (or any similar bugs with the pbr terrains) on your device would be greatly appreciated. :slightly_smiling_face:

3 Likes

I ran PBRTerrainTest.java on master. Didn’t see any problems with or without triplanar mapping.

Specs:

INFO: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: NVIDIA GeForce GTX 1060 6GB/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 545.29.06
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core
1 Like

Strange bug. Hard to track down without beeing able to run it. Div/0 would come i to my mind, but that should fail on most devices. Or a wrong texture access in the non triplanar path. Something subtile wrong that more culant drivers ignore. Div/int instead of Div/float. Maybe on the texture array index. Guesses in the wild

1 Like

One of the things I really love about graphics development is that even the bugs are often spectacular. :slight_smile:

5 Likes

Can I hop on this thread? I just ran the PBRTerrainTest and AdvancedPBRTerrainTest on my machine and the geometry is completely black. I have confirmed that the geometry and lights all exist, by applying a simple (Lighting) material instead of the PBR one. PBR produces nothing visible.

Thoughts?

1 Like

Do you have a light probe in your scene?

PBR has 100% black ambient without a light probe.

2 Likes

Yup, there’s a light. Its exactly the code in PBRTerrainTest.java.

Note that a “light” and a “light probe” are not the same thing.

…but I’ll assume this test is setup correctly else others would have complained.

What version of JME are you running? 3.6 or the latest 3.7 beta?

Thanks @pspeed, really appreciate you looking into this.
I realize that if there were a defect in the test, others would have complained. I 100% expect this to be a problem on my end, I’m just not sure where to look :stuck_out_tongue:

I’m on JME 3.6.1. See below for the renderer info and a screenshot.

Oct 09, 2024 11:07:56 A.M. com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information

  • Vendor: Apple
  • Renderer: Apple M3 Max
  • OpenGL Version: 4.1 Metal - 89.3
  • GLSL Version: 4.10
  • Profile: Core

1 Like

Thanks for running the tests and reporting your device specs here!

Could you also confirm if you are able to render jme’s stock PBR shader (PBRLighting.j3md)? You could confirm this by running another other Test in jme3-examples called “TestPBRLighting” (or by running any jme project that uses PBRLighting.j3md)

If that test using PBRLighthing.frag with a standard geometry works, then that should confirm that the issue is specific to the PBR terrain shaders.

ahahahah is the ‘apple’ a known issue?

Ran TestPBRLighting on my machine. Rendered textured geometry very briefly then crashed:
Oct. 09, 2024 1:02:39 P.M. com.jme3.system.lwjgl.LwjglContext initOpenCL
INFO: Initialize OpenCL with LWJGL2
Oct. 09, 2024 1:02:39 P.M. com.jme3.system.lwjgl.LwjglContext initOpenCL
INFO: Available OpenCL platforms:

  • Platform 1
  • Name: Apple
  • Vendor: Apple
  • Version: OpenCL 1.2 (Aug 3 2024 13:56:49)
  • Profile: FULL_PROFILE
  • Supports interop: false
  • Available devices:
    • Device 1
    • Name: Apple M3 Max
    • Vendor: Intel
    • Version: OpenCL 1.2
    • Profile: FULL_PROFILE
    • Compiler version: OpenCL C 1.2
    • Device type: CPU
    • Compute units: 14
    • Work group size: 1024
    • Global memory: 103079215104B
    • Local memory: 32768B
    • Constant memory: 65536B
    • Supports double: true
    • Supports half floats: false
    • Supports writable 3d images: true
    • Supports interop: false
    • Device 2
    • Name: Apple M3 Max
    • Vendor: Apple
    • Version: OpenCL 1.2
    • Profile: FULL_PROFILE
    • Compiler version: OpenCL C 1.2
    • Device type: GPU
    • Compute units: 30
    • Work group size: 256
    • Global memory: 77309411328B
    • Local memory: 32768B
    • Constant memory: 1073741824B
    • Supports double: false
    • Supports half floats: false
    • Supports writable 3d images: true
    • Supports interop: false
      Oct. 09, 2024 1:02:39 P.M. com.jme3.system.lwjgl.LwjglContext initOpenCL
      INFO: chosen platform: Apple
      Oct. 09, 2024 1:02:39 P.M. com.jme3.system.lwjgl.LwjglContext initOpenCL
      INFO: chosen devices: [Apple M3 Max]
      Oct. 09, 2024 1:02:39 P.M. com.jme3.system.lwjgl.LwjglContext initOpenCL
      INFO: OpenCL context created
      Oct. 09, 2024 1:02:39 P.M. com.jme3.system.lwjgl.LwjglContext printContextInitInfo
      INFO: LWJGL 2.9.5 context running on thread jME3 Main
  • Graphics Adapter: null
  • Driver Version: null
  • Scaling Factor: 1
    Oct. 09, 2024 1:02:39 P.M. com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
    INFO: OpenGL Renderer Information
  • Vendor: Apple
  • Renderer: Apple M3 Max
  • OpenGL Version: 2.1 Metal - 89.3
  • GLSL Version: 1.20
  • Profile: Compatibility
Oct. 09, 2024 1:02:40 P.M. com.jme3.material.Material checkTextureParamColorSpace
WARNING: The texture Textures/Sky/Path.hdr has linear color space, but the material parameter Texture specifies no color space requirement, this may lead to unexpected behavior.
Check if the image was not set to another material parameter with a linear color space, or that you did not set the ColorSpace to Linear using texture.getImage.setColorSpace().
Oct. 09, 2024 1:02:41 P.M. com.jme3.material.Material checkTextureParamColorSpace
WARNING: The texture Models/Tank/Tank_Occ_Rough_Metal.png has linear color space, but the material parameter LightMap specifies no color space requirement, this may lead to unexpected behavior.
Check if the image was not set to another material parameter with a linear color space, or that you did not set the ColorSpace to Linear using texture.getImage.setColorSpace().
Oct. 09, 2024 1:02:41 P.M. com.jme3.renderer.opengl.GLRenderer updateShaderSourceData
WARNING: Bad compile of:
1	#version 110
2	#define SRGB 1
3	#define FRAGMENT_SHADER 1
4	
5	uniform samplerCube m_CubeMap;
6	
7	varying vec3 Reflect_refVec;
8	
9	void main() {
10			vec4 Global_color = vec4(1.0);
11	
12	
13		//EnvMapping : Begin
14		vec3 EnvMapping_refVec;
15		EnvMapping_refVec = Reflect_refVec;
16		vec4 EnvMapping_color;
17	
18	        //@input vec3 EnvMapping_refVec the reflection vector
19	    //@input samplerCube m_CubeMap the cube map
20	    //@output vec4 EnvMapping_color the output EnvMapping_color
21	
22	    #ifdef GL_ES
23	        #ifdef GL_EXT_shader_texture_lod
24	            EnvMapping_color = textureCubeLodEXT(m_CubeMap, EnvMapping_refVec, 0.0);
25	        #else
26	            EnvMapping_color = textureCube(m_CubeMap, EnvMapping_refVec);
27	        #endif
28	    #else
29	        EnvMapping_color = textureCubeLod(m_CubeMap, EnvMapping_refVec, 0.0);
30	    #endif
31		Global_color = EnvMapping_color;
32		//EnvMapping : End
33	
34		gl_FragColor = Global_color;
35	}

Oct. 09, 2024 1:02:41 P.M. com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,6,main]
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Default.frag, defines, type=Fragment, language=GLSL100]
ERROR: 0:29: Invalid call of undeclared identifier 'textureCubeLod'

	at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1581)
	at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1608)
	at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1673)
	at com.jme3.material.logic.DefaultTechniqueDefLogic.render(DefaultTechniqueDefLogic.java:96)
	at com.jme3.material.Technique.render(Technique.java:167)
	at com.jme3.material.Material.render(Material.java:1052)
	at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:682)
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:273)
	at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:312)
	at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:961)
	at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:855)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1223)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1287)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:278)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:160)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:225)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:242)
	at java.base/java.lang.Thread.run(Thread.java:840)

I’m guessing there’s some kind of shader incompatibility with my apple hardware. Oh well :frowning:

1 Like

I don’t know… but Apple always makes things harder for some reason. So I usually get suspicious.

1 Like

It sounds like the PBR shader worked, and the crash error you reported is related to some other stuff related to generating LightProbes on the GPU in that test-case/example.

In hindsight I probably shouldn’t have recommended running that test-case since it also does light probe generation, however it does not appear that JME has a PBR example using a pre-generated probe. (there is one other pbr example called TestPBRSimple.java you could try, but that also appears to generate the light probe at run-time as well)

So I suspect that you could get PBRLighting.j3md to work on your apple device if you load and attach a pre-generated lightProbe (and the black rendering for the PBR terrains is likely a gpu-specific mistake I made that I will still need to fix)

But as @pspeed mentioned, apple has a tendency to cause some unexpected difficulties with jme, and I personally don’t have an apple device so I am not entirely sure how many jme features actually support apple devices or how many other issues you may run into. If possible, I’d recommend using jme with windows or linux (and for my game, personally, I kind of gave up on trying to support apple since I know it will be difficult). But hopefully someone with more experience using apple devices with jme can chime in to provide more info.

Thanks @yaRnMcDonuts ! My next step was going to be working through the PBRTerrain shader to see if I can determine where the problem may be occurring. I’ll let this thread know if I find anything.

1 Like

…except it apparently isn’t that shader that is the problem.

Can you try with a core profile selected?

settings.setRenderer(AppSettings.LWJGL_OPENGL41);

i think osx supports 4.1 but i am not 100% sure on the compability matrix for osx

Thanks @zzuegg . Tried that, same behaviour.

Verified that the core porfile loaded and the shader in question does not start with
#version 110?

Just to make sure