zesterer / openmw-volumetric-clouds

A volumetric clouds mod for OpenMW
80 stars 12 forks source link

Not working on macOS 14.3.1 (23D60) with M1 Pro #32

Open strayer opened 5 months ago

strayer commented 5 months ago

I already saw some reports in Discord and on Reddit, so this is not entirely unexpected, but I wanted to provide some details anyway.

I'm on macOS 14.3.1 (23D60) with a M1 Pro in a 16" MacBook Pro. OpenMW is the 0.48 release version. I followed the One Day Morrowind Moderniation mod list with small differences (Phi's Carefree Leveling instead of NCGDMW, Chocolate UI instead of Monochrome and only these shaders instead of the pack in the mod list – the other shaders simply crash the game)

The shaders menu loads and I can activate the clouds shader, but visually it doesn't seem to do anything. I noticed the following error in the openmw.log:

[22:21:39.644 W] FRAGMENT glCompileShader "main" FAILED
[22:21:39.644 W] FRAGMENT Shader "main" infolog:
[22:21:39.644 W] ERROR: 0:331: 'u' : syntax error: syntax error
[22:21:39.644 W]
[22:21:39.644 W] glLinkProgram 0x600021ab10e0"clouds" FAILED
[22:21:39.644 W] Program "clouds" infolog:
[22:21:39.644 W] ERROR: One or more attached shaders not successfully compiled

Knowing macOS and OpenGL I'm sceptical if this can be fixed, but maybe it helps :)

Edit: Same with OpenMW 0.49 (git ref e7423320358933328af061745728422be584272c, built by myself)

zesterer commented 5 months ago

The version you linked to is out of date, I think. Try installing the latest version as per the instructions in this repository. Let me know if you still hit problems.

strayer commented 5 months ago

Whoops, sorry about that! I didn't realize. Same issue though after cloning this repo instead:

[22:57:05.622 W] FRAGMENT glCompileShader "main" FAILED
[22:57:05.622 W] FRAGMENT Shader "main" infolog:
[22:57:05.622 W] ERROR: 0:331: 'u' : syntax error: syntax error
[22:57:05.622 W]
[22:57:05.622 W] glLinkProgram 0x60000a69f660"clouds" FAILED
[22:57:05.622 W] Program "clouds" infolog:
[22:57:05.622 W] ERROR: One or more attached shaders not successfully compiled
zesterer commented 5 months ago

Could you try the commit I just pushed?

strayer commented 5 months ago

Thanks for taking time to look into this!

Sadly it only ended up with a new error:

[22:52:34.730 W] FRAGMENT glCompileShader "main" FAILED
[22:52:34.730 W] FRAGMENT Shader "main" infolog:
[22:52:34.730 W] ERROR: 0:359: 'mix' : syntax error: syntax error
[22:52:34.730 W]
[22:52:34.730 W] glLinkProgram 0x6000159cc2d0"clouds" FAILED
[22:52:34.730 W] Program "clouds" infolog:
[22:52:34.730 W] ERROR: One or more attached shaders not successfully compiled
strayer commented 5 months ago

Is this a typo? Changing that back to return gives these errors:

[22:56:31.795 W] FRAGMENT glCompileShader "main" FAILED
[22:56:31.795 W] FRAGMENT Shader "main" infolog:
[22:56:31.795 W] ERROR: 0:330: '^' does not operate on 'int' and 'int'
[22:56:31.795 W] ERROR: 0:331: Use of undeclared identifier 'n'
[22:56:31.795 W] ERROR: 0:371: Structure has no field named simlationTime
[22:56:31.795 W] ERROR: 0:378: Use of undeclared identifier 'time'
[22:56:31.795 W] ERROR: 0:382: Use of undeclared identifier 'mist_base'
[22:56:31.795 W] ERROR: 0:389: Use of undeclared identifier 'time'
[22:56:31.795 W] ERROR: 0:395: Use of undeclared identifier 'time'
[22:56:31.795 W] ERROR: 0:399: Use of undeclared identifier 'mist_base'
[22:56:31.795 W] ERROR: 0:401: Use of undeclared identifier 'hfactor'
[22:56:31.795 W] ERROR: 0:401: Use of undeclared identifier 'hfactor'
[22:56:31.795 W] ERROR: 0:402: Use of undeclared identifier 'hfactor'
[22:56:31.795 W] ERROR: 0:402: Use of undeclared identifier 'hfactor2'
[22:56:31.795 W] ERROR: 0:402: Use of undeclared identifier 'hfactor2'
[22:56:31.795 W] ERROR: 0:402: Use of undeclared identifier 'hfactor'
[22:56:31.795 W] ERROR: 0:404: Use of undeclared identifier 'mist_nz'
[22:56:31.795 W] ERROR: 0:405: Use of undeclared identifier 'hfactor'
[22:56:31.795 W] ERROR: 0:407: Use of undeclared identifier 'cull_dist'
[22:56:31.795 W] ERROR: 0:415: Use of undeclared identifier 'cull_dist'
[22:56:31.795 W] ERROR: 0:415: Use of undeclared identifier 'MIN_CLOUD_DIST'
[22:56:31.795 W] ERROR: 0:416: Use of undeclared identifier 'time'
[22:56:31.795 W] ERROR: 0:419: Use of undeclared identifier 'time'
[22:56:31.795 W] ERROR: 0:420: Use of undeclared identifier 'cloud_f'
[22:56:31.795 W] ERROR: 0:422: Use of undeclared identifier 'cloud_f2'
[22:56:31.795 W] ERROR: 0:422: Use of undeclared identifier 'time'
[22:56:31.795 W] ERROR: 0:425: Use of undeclared identifier 'cloud_f'
[22:56:31.795 W] ERROR: 0:425: Use of undeclared identifier 'cloud_f2'
[22:56:31.795 W] ERROR: 0:427: Use of undeclared identifier 'dyn_clouds'
[22:56:31.795 W] ERROR: 0:431: Use of undeclared identifier 'cloud_large'
[22:56:31.795 W] ERROR: 0:433: Use of undeclared identifier 'time'
[22:56:31.795 W] ERROR: 0:434: Use of undeclared identifier 'time'
[22:56:31.795 W] ERROR: 0:436: Use of undeclared identifier 'cloud_large'
[22:56:31.795 W] ERROR: 0:438: Use of undeclared identifier 'cf'
[22:56:31.795 W] ERROR: 0:438: Use of undeclared identifier 'cf'
[22:56:31.795 W] ERROR: 0:439: Use of undeclared identifier 'cf'
[22:56:31.795 W] ERROR: 0:439: Use of undeclared identifier 'cf2'
[22:56:31.795 W] ERROR: 0:439: Use of undeclared identifier 'cf2'
[22:56:31.795 W] ERROR: 0:439: Use of undeclared identifier 'cf'
[22:56:31.795 W] ERROR: 0:440: Use of undeclared identifier 'cf'
[22:56:31.795 W] ERROR: 0:441: Use of undeclared identifier 'cloud_factor'
[22:56:31.795 W] ERROR: 0:445: Use of undeclared identifier 'cull_dist'
[22:56:31.795 W] ERROR: 0:445: Use of undeclared identifier 'MIN_CLOUD_DIST'
[22:56:31.795 W] ERROR: 0:445: Use of undeclared identifier 'MIN_CLOUD_DIST'
[22:56:31.795 W] ERROR: 0:450: Use of undeclared identifier 'dyn_clouds'
[22:56:31.795 W] ERROR: 0:452: Use of undeclared identifier 'cloud_f'
[22:56:31.795 W] ERROR: 0:452: Use of undeclared identifier 'cloud_f2'
[22:56:31.795 W] ERROR: 0:453: Use of undeclared identifier 'dyn_clouds'
[22:56:31.795 W] ERROR: 0:453: Use of undeclared identifier 'dyn_clouds'
[22:56:31.795 W] ERROR: 0:453: Use of undeclared identifier 'cloud_factor'
[22:56:31.795 W] ERROR: 0:453: Use of undeclared identifier 'cloud_factor'
[22:56:31.795 W] ERROR: 0:454: Use of undeclared identifier 'cloud_factor'
[22:56:31.795 W] ERROR: 0:530: Use of undeclared identifier 'MIN_CLOUD_DIST'
[22:56:31.795 W] 
[22:56:31.795 W] glLinkProgram 0x600016c3d680"clouds" FAILED
[22:56:31.795 W] Program "clouds" infolog:
[22:56:31.795 W] ERROR: One or more attached shaders not successfully compiled
strayer commented 5 months ago

I got the shader to work with this patch:

diff --git a/shaders/clouds.omwfx b/shaders/clouds.omwfx
index 05500a2..78ca34d 100644
--- a/shaders/clouds.omwfx
+++ b/shaders/clouds.omwfx
@@ -320,14 +320,10 @@ fragment main {
         }
     }

-    #define M1 204766743
-    #define M2 388370683
-    #define M3 396128171
-
-    // Replace this function with the one below it if your GPU can't handle bitwise ops
-    float hash_one(int q) {
-        int n = ((M3 * q) ^ M2) * M1;
-        return float(n) * (1.0 / float(0xffffffff));
+    #define M 43758.5453
+
+    float hash_one(float n) {
+        return fract(sin(n) * M);
     }

     float noise_2d(vec2 pos) {
@@ -355,7 +351,7 @@ fragment main {
         int z = int(floor(pos.z));
         vec2 offs0 = vec2(hash_one(z), hash_one(z + 73));
         vec2 offs1 = vec2(hash_one(z + 1), hash_one(z + 1 + 73));
-        retrn mix(
+        return mix(
             billow_noise_2d(pos.xy + offs0),
             billow_noise_2d(pos.xy + offs1),
             fract(pos.z)
@@ -363,15 +359,15 @@ fragment main {
     }

     const float MIN_MIST_DIST = 100.0;
-    const float MIN_CLOD_DIST = 10000.0;
+    const float MIN_CLOUD_DIST = 10000.0;

-    vec2 fog_at(vec3 wpos, float cll_dist, vec3 dir, in float dyn_clods, in float dyn_mist) {
+    vec2 fog_at(vec3 wpos, float cull_dist, vec3 dir, in float dyn_clouds, in float dyn_mist) {
         wpos.z = max(wpos.z, 0);
-        vec3 time = vec3(omw.simlationTime * 0.1, 0, 0);
+        vec3 time = vec3(omw.simulationTime * 0.1, 0, 0);

         float mist = 0.0;

-        if (mist_enabled && cll_dist > MIN_MIST_DIST) {
+        if (mist_enabled && cull_dist > MIN_MIST_DIST) {
             float mist_base = omw.waterHeight
                 + mist_alt
                 + (noise_2d(wpos.xy * 0.000003 + time.xy * 0.03) - 0.6) * 3000;

Disclaimer: The hash_one function was generated by GPT-4, so it is probably completely wrong… but I don't know anything about OpenGL so I had to improvise 😰

There were some typos with missing us in the code that I kind of fixed.

Not sure if it looks right, but here is a screenshot:

grafik
zesterer commented 5 months ago

Nice work! I'm not entirely sure how the typos crept in. Any chance you could open a PR?

strayer commented 5 months ago

Sure! Can you give any insight into the hash_one function? As mentioned I don't have any experience with OpenGL so I don't really know if what GPT-4 generated there makes any sense at all.

strayer commented 5 months ago

Added PR #33 first to fix the typos to avoid people on Windows/Linux running into issues with the current main branch. I'll open another one with the hash_one function later with your feedback (and I'll also do some more testing myself, though as said - no experience with OpenGL).

zesterer commented 5 months ago

The hash_one implementation seems... sufficient. Thankfully, sin is pretty quick on most modern hardware so there's probably not an appreciable difference in performance.

strayer commented 5 months ago

Still feels bad to change it in this way for a niche platform that probably doesn't really have much usage anyway. Is it maybe possible to differentiate operating systems with something like the preprocessor stuff in C++ to only use this code for macOS?

zesterer commented 5 months ago

Not that I'm aware of. It should be possible to express the original code in a way that makes sense to more GLSL implementations though. That said, I'm not really that bothered: the function in question is just a simple PRNG and the exact output values are not really meaningful provided the function has good entropy (which trig functions modulated in this way generally do), so the new implementation will do fine.