Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underwater + Metal has some issues #192

Closed
jelmerS2 opened this issue Feb 20, 2019 · 6 comments
Closed

Underwater + Metal has some issues #192

jelmerS2 opened this issue Feb 20, 2019 · 6 comments
Labels

Comments

@jelmerS2
Copy link

jelmerS2 commented Feb 20, 2019

Hi

First wanted to say that I'm super impressed by this project. I'm using it for a mobile app (iOS), stunned that it runs so smoothly.

I did notice the following visual problem when I enabled the Underwater option in Ocean.mat in the standard scene (main.scene), with Metal enabled under player settings.
screen shot 2019-02-20 at 11 21 11
If underwater is disabled, all looks (very) good.

@jelmerS2 jelmerS2 changed the title Underwater + metal doesn't work Underwater + Metal has some issues Feb 20, 2019
@huwb
Copy link
Contributor

huwb commented Feb 20, 2019

Ha thats cool, thanks for that feedback. We've been giving it a bit of a push to make it run well on switch which I'm sure has helped mobile too!

Thats a very odd result. Could you attach the log file from running it? Also are there any errors or warnings when making the build from unity? When stuff looks completely wrong like this its usually something failing to load, and in this case i might be using shader features that arent supported on mobile.

@huwb huwb added the Bug label Feb 20, 2019
@jelmerS2
Copy link
Author

It happens both on MacOS and iOS. I have Metal as graphics API in the editor and builds, and I have it as the only graphics API in the project (Because of linear colour space, Unity says I can only have Metal on iOS at least).
In Player.log from my MacOS build, I read the following:
_Begin MonoManager ReloadAssembly

  • Completed reload, in 0.071 seconds
    Metal RecreateSurface[0x10c58eaf0]: surface size 3360x2100
    WARNING: Shader Unsupported: 'Standard' - Pass 'META' has no vertex shader
    WARNING: Shader Unsupported: 'Standard' - Pass 'META' has no vertex shader

    UnloadTime: 0.931800 ms
    Setting up 6 worker threads for Enlighten._

It's important to note that all works fine if Underwater is not enabled. Then it looks like this and everything seems fine (also foam, even though not shown here):
crest

@huwb
Copy link
Contributor

huwb commented Feb 23, 2019

I reckon those warnings are unrelated to crest: https://issuetracker.unity3d.com/issues/unity-outputs-a-warning-in-a-windows-64bit-standalone-player-when-using-built-in-shaders

Does the wireframe option work (top left on the debug gui)? If so could i see a screenshot of the issue with wireframe turned on?

It looks like the curtain geometry that renders the underwater effect is dominating the screen. The curtain shoudl turn off completely when the camera is not close to the surface. I assume it stays like that when the camera is raised further? How does it look when the camera is moved under the surface? Ideally with sea floor visible so i can see if the underwater effects are working.

The curtain is enabled/disabled based on a water height query which comes from reading back the displacement textures from the gpu. Maybe the readbacks dont work on metal. There should be a rowboat in that scene that is doing height queries for physics - is it happily bobbing away on the water surface? (this test assumes you havent overridden the collision source to e.g. CPU gerstner waves).

@huwb
Copy link
Contributor

huwb commented Mar 22, 2019

Hi there, thought I'd check in. Any luck with the above?

I start to suspect "SV_IsFrontFace" does not work on metal (hence it thinks your underwater all the time).

There's a different attribute i guess for opengl called VFACE, and maybe the cross compiling is broken for metal.

In addition to the above, could you also try forcing underwater to false in ocean.shader:

half4 Frag(const Varyings input, const bool i_isFrontFace : SV_IsFrontFace) : SV_Target
{
	const bool underwater = false; 
	...

Thanks in advance

@jelmerS2
Copy link
Author

Hi thanks for checking up :)
For now I haven't looked into it much further, because my AR experience takes place above the water. It's only when the user would move the camera below the surface that underwater could be a nice extra.
To uncheck "underwater" in the inspector is enough to make it run by the way :) (no need to force it off afaik).

@huwb
Copy link
Contributor

huwb commented Mar 23, 2019

I think I found the issue - it seems like the VFACE attribute is flipped on metal, so the shader thinks its underwater when you're above. someone reports this here: https://answers.unity.com/questions/1262709/shader-semantics-vface-error-in-ios-metal.html . if this is the issue i'll report it to unity.

I've just pushed a speculative fix (commit ref'd above), could i trouble you for a confirmation that this works for you?

@huwb huwb closed this as completed Mar 30, 2019
huwb added a commit that referenced this issue Apr 4, 2019
Underwater should be working on metal now.
ShadowTeolog pushed a commit to ShadowTeolog/crest-oceanrender that referenced this issue Apr 26, 2019
Underwater should be working on metal now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants