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

Enable Shader API does not function without changing underwater appearance #1145

Closed
2 tasks done
Revmatek opened this issue Mar 30, 2024 · 20 comments
Closed
2 tasks done
Labels
Milestone

Comments

@Revmatek
Copy link

Revmatek commented Mar 30, 2024

Is there an existing issue for this?

  • I have searched the existing issues.

Have you checked the documentation to resolve your problem?

  • I have read the linked documentation and could not resolve my issue.

Current Behavior

Enable Shader API moves the command buffer to/from before/after forward alpha which enables transparent shaders to render after the fog. While this is desirable, it does not seem like it works with the rest of the features (the docs say this is in "Preview This feature is in preview and may change in the future.")
_camera.AddCommandBuffer(_enableShaderAPI ? CameraEvent.BeforeForwardAlpha : CameraEvent.AfterForwardAlpha, _underwaterEffectCommandBuffer);

I have been unable to use this feature because it alters the appearance of the surface / underwater rendering while in an ocean environment, not a mask / contained area with limited settings or short view distance.

Expected Behavior

Enabling the Shader API should not alter the appearance of the ocean shader, lighting, or create artifacts.

Steps To Reproduce

  1. Open Main.unity
  2. Play
  3. Go underwater
  4. Turn on the shader api
  5. Adjust settings to see a bit further
image
  1. Observer on / off behavior of shader api

Off:
image

On:
image

Unity Version

2021.3.26

Crest Version

4.19

Render Pipeline

Built-In

Editor or Standalone

Editor (Edit Mode), Editor (Play Mode)

Environment

No response

Anything else?

You can sorta work around the API problem by using custom rendering for transparent shaders that have issues using the command buffer and not using the Enable Shader API feature. This does not always work though nor is it desirable.

@daleeidd
Copy link
Collaborator

daleeidd commented Apr 4, 2024

These are two separate issues if you could kindly make a new one for one of the issues.

@Revmatek Revmatek changed the title Enable Shader API does not function without altering surface, lighting, and / or creating artifacts Enable Shader API does not function Apr 4, 2024
@Revmatek
Copy link
Author

Revmatek commented Apr 4, 2024

These are two separate issues if you could kindly make a new one for one of the issues.

I am not really sure which two separate issues you mean specifically of the various problems with the shader API mentioned. The primary issue is that the Shader API is non-functional any other information I have provided is for context. I can update the title to more accurately reflect the problem.

@Revmatek
Copy link
Author

Revmatek commented Apr 4, 2024

There may be several distinct problems here, but I am not sure where the lines are or if they are all the same thing.

  1. Support for transparent shaders underwater does not seem to work because other things stop working (it does actually allow transparency with the underwater fog)
  2. Artifacts appear, which I did not originally know, I included it here because I noticed it when I went to make sure it was reproducible in the demo scene.
  3. Lighting on the surface appears to change
  4. The transparency on the surface of the water looks different

Do you want me to create 4 issues? I am fine if you break this up however you need to and I can sub to the other issues.

@daleeidd
Copy link
Collaborator

daleeidd commented Apr 5, 2024

Making a new issue for the artefacts should be enough. The other issues are tied to Depth Fog Density Factor?

@Revmatek Revmatek changed the title Enable Shader API does not function Enable Shader API does not function without changing underwater appearance Apr 5, 2024
@Revmatek
Copy link
Author

Revmatek commented Apr 5, 2024

Making a new issue for the artefacts should be enough.

I have create this issue #1146

The other issues are tied to Depth Fog Density Factor?

I don't think it is required, I did that to help illustrate the extreme difference in appearance. For my settings you can see far underwater so it is immediately apparent when enabled because it changes all the visuals of the underwater perspective and makes it harder to see the surface. I did confirm that without changing the setting is still occurs by examining the shader example in the example scene where it is masked as a sphere, you can zoom in on it and look around underwater and toggle the api and see the same visual changes, it is just much more apparent when you can see a bit further in the fog how much it affects everything.

@daleeidd
Copy link
Collaborator

daleeidd commented Apr 5, 2024

Thanks.

It looks like the Depth Fog Density Factor and the portals feature currently do not work with the Shader API. I was unable to see any differences when either of these are not used.

Does this sound correct? If it affects it without those features used, can you provide an example?

@Revmatek
Copy link
Author

Revmatek commented Apr 5, 2024

Thanks.

It looks like the Depth Fog Density Factor and the portals feature currently do not work with the Shader API. I was unable to see any differences when either of these are not used.

Does this sound correct? If it affects it without those features used, can you provide an example?

That does sound correct in terms of Depth Fog Density Factor. I may be able to get the visuals I want by directly modifying Depth Fog Density vs Depth Fog Density Factor. It was not clear to me this transparency was independent of the surface (though maybe that was not intended) I will have to investigate a new implementation though.

I am not currently concerned with portals so I have no information on that.

I played around with it at runtime and it looks the same on/off in the demo main scene. I tried this in my setup as well and I only see very minor differences, I will have to investigate them though with a task to refactor how the underwater stuff works to accommodate this new information (unless you have an easy fix to make these features play nice).

Here is what I see if it is helpful, there may be other settings at play though. Ignore any floating particles or jellyfish you see in terms of transparency, the support I added for them underwater does not work with me toggling the API back and forth.

Original with Depth Fog Density Factor in play:
image

Manually tweaking shader values at runtime Factor = 1 (which I assume is what you mean by disable):
image
So far near identical...

Enabling shader API with Depth Fog Density changes on the shader:
image
Now I do start to see some differences in the distance where the transparency is near the geometry of the ocean tiles and the docs I have in the image on the left.

It is more apparent in the shadows

Off:
image

On:
image

Off:
image

On:
image

This also changes the surface from above to be near non existent, extremely transparent, not what I am going for. The settings in the main scene are different and seem darker so you can't see very far still and there is nothing out there to render over, not really sure the differences.

Normal:
image

Shader changes / Factor 1:
image
Not really ok. So not something I can work around with I guess. The primary issue is that Depth Fog Density Factor is not working with the Shader API as you described.

@Revmatek
Copy link
Author

Revmatek commented Apr 5, 2024

If you play around in the boat wake scene you can sort see some of the differences:
Off:
image

On:
image

It is sorta difficult to see with these screenshots even side by side, you really need to switch back and forth to see the differences. Though I have lowered the density to an extreme here to obtain the desired affect. 0.01

@daleeidd daleeidd added this to the Next milestone Apr 6, 2024
@daleeidd
Copy link
Collaborator

daleeidd commented Apr 6, 2024

Thanks. That should be all fixed now with latest.

@Revmatek
Copy link
Author

Revmatek commented Apr 6, 2024

Thanks. That should be all fixed now with latest.

I will check it out.

@Revmatek
Copy link
Author

Revmatek commented Apr 6, 2024

The water surface definitely looks correct now with Shader API enabled.

I am noticing a couple issues with a lowered Depth Fog Density which I can repro by changing settings in the main scene
image

Shader API Off:
image

On:
image
These 2 white lines are a tile being culled very close when shader api is on, but it does not do so for off.
image
It is much more apparent in my setup, I am trying to determine the differences. The surface lighting seems to be an issue with my version of the ocean, maybe I am missing a commit or something recent. The tile culling does seem like a problem with latest though.

Both On:
image
image

@Revmatek
Copy link
Author

Revmatek commented Apr 6, 2024

I am very perplexed by what I am seeing. I cannot seem to determine the cause of the lighting change. I went so far as to re-integrate with the crest project where the lighting change does not occur. As far as I can tell all the code is the same (with the exception of things that are changed that are not running in the demo scene, like 3rd party fog, even taking that out has no effect). It almost seems like there is something stuck somewhere. I can copy the entire scene to the working project and everything works fine without changes... I will try rebuilding Library.

Demo scene in my project:

Off:
image

On:
image

@Revmatek
Copy link
Author

Revmatek commented Apr 6, 2024

Rebuilding the library has no effect on the lighting problem, however disabling the directional light in the scene and creating a new one completely eliminates the lighting problem. It is not clear to me why. Must be some sort of corruption, if it was corrupted it should not have worked when loaded into another project. If I duplicate the light in the scene it remains broken.

Off:
image

On:
image

Wonderful!

I'm not really sure what to make of this, but I have seen this happen before with lights being corrupted somehow. Idk if that means I need to destroy mine and make a new set with the same settings and everything will work then. Some sort of bug.

So the tile culling is the only thing that remains maybe.

@Revmatek
Copy link
Author

Revmatek commented Apr 6, 2024

It is working though (minus the tile culling), I will have to test this out in my next build, I have other issues I need to address first.

close to defaults:
image

lower depth fog density factor:
image
image

@Revmatek
Copy link
Author

Revmatek commented Apr 6, 2024

It seems that the act of changing the color of the light causes this issue. But only in this project... Does not occur in latest project, which is the same code as I mentioned early.

image

image

Copying my entire crest directory into a clean unity project makes the problem vanish... something is doing something.

@Revmatek
Copy link
Author

Revmatek commented Apr 6, 2024

It appears to be caused by the color space settings in the project, it works with Linear but not Gamma. Can support be added for Gamma?

@daleeidd
Copy link
Collaborator

daleeidd commented Apr 7, 2024

Latest has it fixed for gamma. The line issue is probably related to #1146 instead?

@Revmatek
Copy link
Author

Revmatek commented Apr 7, 2024

Latest has it fixed for gamma.

Fix looks good! I will check it out more when I implement it later.
image

The line issue is probably related to #1146 instead?

I think this is a separate issue as it occurs because a tile is missing, not from a horizon artifact of some sort. It happens with MSAA off and
image

image
image

It is difficult to get a good look at what it is, but I am fairly certain it is some sort of tile gap
image
image
image
image
image
Disabling it manually
image
image
I cannot observe it up close when paused
image
Camera perspective
image
image
Requires a certain angle
image
image

Having said all that I don't see that in my project, only the example scene (which means I may see it later)

Side note:
I do see the bounds of the ocean tiles being culled on the sides of the screen though, which I fixed in my scene by increasing the size of the tile renderer bounds arbitrarily.
image
image
This can manifest to more extremes when above the ocean, just an FYI. I may have mentioned previously, I don't recall where.

@Revmatek
Copy link
Author

Revmatek commented Apr 7, 2024

I am still seeing an issue with shadows when shader api is on, you can recreate this in the main scene by adding a giant cube above the water or other object that should make the water dark.

Off:
image
image

On:
image
image

This is what appears to be causing shadow / lighting issues with previous images of the docks

Off:
image

On:
image

Some other thoughts on this, I may need to disable tiling culling or something to prevent transparent objects over the ocean from becoming visible when tiles are culled. When the tiles are culled it seems more like objects above the surface (clouds or smoke for example) become part of the ocean because they are no longer masked by the surface. Or be forced to hide such objects.

ON:
image
Off:
image

@daleeidd
Copy link
Collaborator

daleeidd commented Apr 7, 2024

I will look at the shadow one but fixing it requires recalculating the scattering term a second time which could be a bit of a performance hit.

In regards to culling, please open new reports for separate issues to reduce noise in this one.

And yeah that makes sense re disabling underwater culling.

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