castle-engine / castle-model-viewer

Viewer for many 3D and 2D model formats: glTF, X3D, VRML, Collada, 3DS, MD3, Wavefront OBJ, STL, Spine JSON, sprite sheets in Cocos2D and Starling XML formats
https://castle-engine.io/castle-model-viewer
92 stars 19 forks source link

Error when initializing GLSL shader for ScreenEffects #32

Closed elmkni closed 3 years ago

elmkni commented 3 years ago

Hi Michalis,

its me, Elmar.

I discovered that recent view3dscene win64 compiles (view3dscene-3.19.0-win64-x86_64.zip - 24-Jan-2021 19:59 - 6573059) show an GLSL shader compile error in the logfile (see attached/zipped view3dscene.log) for all built-in effect shaders,

Warning: GLSL: Error when initializing GLSL shader for ScreenEffect[Visualize Depth]: Fragment shader not compiled:
Fragment shader failed to compile with the following errors:
ERROR: 0:247: error(#132) Syntax error: ")" parse error
ERROR: error(#273) 1 compilation errors.  No code generated

that didn't occur with older versions of view3dscene (like: view3dscene_3.19.0-win64-x86_64 - 23-Oct-2020 08:00), so that the built-in effect shaders can't be activated from the menu (e.g.: View->Screen Effects->Visualize Depth) anymore, no matter if used with or without --debug-enable-fixed-function

Effect shaders within loaded x3d/x3dv-files (example included in zip file) seem to work, as far I can tell.

Please help...

Yours, Elmar

view3dscene_log_plus_example_x3dv.zip

michaliskambi commented 3 years ago

Thank you for catching this! It was always occurring when you have "Anti-Aliasing" selected in view3dscene options. We did a trivial mistake in shader code change recently.

Fixed.

Allow a few hours for the Jenkins to rebuild Castle Game Engine and then view3dscene, and the problem will disappear in latest "snapshot" version from the top of https://castle-engine.io/view3dscene.php .

Note about your attached example: on my current GPU (Mesa DRI Intel(R) UHD Graphics 630 (Coffeelake 3x8 GT2) on Linux) it required an extra fix, reporting compilation error initially:

VRML/X3D: Cannot use GLSL shader for shape "Box": Fragment shader not compiled:
0:31(17): error: no matching function for call to `mix(int, int, float)'; candidates are:
0:31(17): error:    float mix(float, float, float)
0:31(17): error:    vec2 mix(vec2, vec2, float)
0:31(17): error:    vec3 mix(vec3, vec3, float)
0:31(17): error:    vec4 mix(vec4, vec4, float)
0:31(17): error:    vec2 mix(vec2, vec2, vec2)
0:31(17): error:    vec3 mix(vec3, vec3, vec3)
0:31(17): error:    vec4 mix(vec4, vec4, vec4)
0:31(11): error: cannot construct `vec3' from a non-numeric data type
0:31(2): error: no matching function for call to `star(vec3, error, vec2, float)'; candidates are:
0:31(2): error:    void star(vec3, vec3, vec2, float)
0:32(8): warning: `c' used uninitialized

To fix, change the line

star( c, vec3( mix( -20,2, rand( i ))), f, 0.3 ); /* stars */

to

star( c, vec3( mix( -20.0,2.0, rand( i ))), f, 0.3 ); /* stars */

That is, add .0 to two constant values, to make them float. In GLSL, automatic promotion from integer->float is not allowed, unlike in most other languages.

elmkni commented 3 years ago

Hi Michalis,

it's me, Elmar.

Thank you very much for the quick fix and also for the info about my mistake ;)

I had actually fixed the int-to-float issue in most of my files, but accidentally send one of the un-fixed... (Murphy's Law)

Best regards, Elmar