SebLague / Geographical-Adventures

Home Page:https://sebastian.itch.io/geographical-adventures

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Atmosphere is Flipped on Linux

maltejur opened this issue · comments

In the Linux build the atmosphere seems to be flipped horizontally. Everything looks fine on Windows/Wine.

Screenshot_20220502_142518

I suspect this has something to do with https://github.com/SebLague/Geographical-Adventures/blob/main/Assets/Post%20Processing/Atmosphere/Atmosphere.shader#L58.

Yup I can confirm this. Running the game on Ubuntu Budge and have the same issue

Thanks for the report. I'd greatly appreciate if someone with a linux device could try fixing this -- I thought I had addressed it by flipping the uvs (in the code maltejur linked), but apparently not!

I'm not familiar with Unity projects, but I'd like to help in any way I can — are there compilation instructions available somewhere?

Just did a bit of experimenting and I think i made it work by moving the UV code to the DrawSky shader instead of the Atmosphere shader. The code in the Atmosphere shader actually just makes things worse and the code in the DrawSky seems to fix the issue.

--- a/Assets/Post Processing/Atmosphere/Atmosphere.shader	
+++ b/Assets/Post Processing/Atmosphere/Atmosphere.shader	
@@ -55,11 +55,6 @@
 			}
 
 			float3 getAtmoCol(float2 uv, float3 originalCol, float viewLength, float3 viewDir) {
-				// Account for flipped y on some platforms (not quite sure where this needs to be used, will need to test...)
-				#if !UNITY_UV_STARTS_AT_TOP
-					uv = float2(uv.x, 1-uv.y);
-				#endif
-
 				float3 outputCol = originalCol;
 				float nonlin_depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
 				float sceneDepth = LinearEyeDepth(nonlin_depth) * viewLength;
--- a/Assets/Post Processing/Atmosphere/DrawSky.shader	
+++ b/Assets/Post Processing/Atmosphere/DrawSky.shader	
@@ -36,6 +36,12 @@ Shader "Hidden/DrawSky"
 				v2f o;
 				o.vertex = UnityObjectToClipPos(v.vertex);
 				o.uv = v.uv;
+
+				// Account for flipped y on some platforms
+				#if !UNITY_UV_STARTS_AT_TOP
+					o.uv = float2(o.uv.x, 1-o.uv.y);
+				#endif
+
 				float3 viewVector = mul(unity_CameraInvProjection, float4(v.uv.xy * 2 - 1, 0, -1));
 				o.viewVector = mul(unity_CameraToWorld, float4(viewVector,0));
 				return o;

Not sure about the correct placement in the DrawSky shader though, I just hacked it in for now.

Edit: On a second look, the placement in the DrawSky shader is definitely wrong because now the stars are flipped.

So after trying out things a bit more, the only place this flip is needed seems to be the tex2D(Sky....

--- a/Assets/Post Processing/Atmosphere/Atmosphere.shader	
+++ b/Assets/Post Processing/Atmosphere/Atmosphere.shader	
@@ -55,11 +55,6 @@
 			}
 
 			float3 getAtmoCol(float2 uv, float3 originalCol, float viewLength, float3 viewDir) {
-				// Account for flipped y on some platforms (not quite sure where this needs to be used, will need to test...)
-				#if !UNITY_UV_STARTS_AT_TOP
-					uv = float2(uv.x, 1-uv.y);
-				#endif
-
 				float3 outputCol = originalCol;
 				float nonlin_depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
 				float sceneDepth = LinearEyeDepth(nonlin_depth) * viewLength;
--- a/Assets/Post Processing/Atmosphere/DrawSky.shader	
+++ b/Assets/Post Processing/Atmosphere/DrawSky.shader	
@@ -84,7 +84,11 @@ Shader "Hidden/DrawSky"
 				float3 viewDir = normalize(i.viewVector);
 				float3 dirToSun = _WorldSpaceLightPos0;
 
+#if UNITY_UV_STARTS_AT_TOP
 				float3 skyLum = tex2D(Sky, i.uv).rgb;
+#else
+				float3 skyLum = tex2D(Sky, float2(i.uv.x, 1-i.uv.y)).rgb;
+#endif
 				float3 sunDisc = sunDiscWithBloom(viewDir, dirToSun);
 				float3 transmittance = sampleSunTransmittanceLUT(_WorldSpaceCameraPos, viewDir);
 				skyLum += sunDisc * transmittance;

Thanks for the fix maltejur, much appreciated!

this is amazing, thanks so much. are the any instructions on how to implement this fix perhaps?

I've merged the fix, so you just need to pull the latest changes / redownload the project.

Just downloaded and it works perfectly. I found a small bug in the pick and drop off displays, but I will test further and report if it happens again. So so so brilliant. I am so stoked at stublimg accross the first video and have been following you since then, and now I have an awesome game that I actually enjoy playing.

I'm happy you're enjoying it! Is the display issue you experienced the same one mentioned in #33 ?

Howdy, yeah it is, However its only happened once to me. There was a glitch where the next location was slightly to the left. Once I dropped that package off it reset the location, however it never removed the original location. I will try it again tomorrow and report on that issue in that thread for you