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

Various features added for Shell Lit #10

Closed
wants to merge 13 commits into from
Closed

Conversation

jiaozi158
Copy link
Contributor

@jiaozi158 jiaozi158 commented Apr 26, 2022

Edited:

Hi, if you would like to try the changes mentioned below, you can still find it here


Commit into Shell (Lit) because it is the most performant one among three.

Changes:

1. Add "DepthNormals" Pass (For forward renderer, stores normal only).

  • "_CameraNormalsTexture"
    Fur-DepthNormals

  • Now SSAO (Depth Normal mode) works. (Should enable "After Opaque" in URP 12)

  • URP 12 Depth Priming (Depth pre-pass) works.

2. Adding specular scattering. (No effect on front face)

3. Controlling fur length using one texture (Red channel).

  • Should be black and white, using red channel if it's color texture.
    Fur-Length

4. Fixed issues when using Depth Priming on URP 12.

  • Depth Priming avoids rendering pixels that are occluded by front pixels [probably] which improves performance
    Fur-DepthPriming

5. Fixed MainLight Shadow issue on URP 12. (Shell Lit only)

6. Add XR single pass instance support for both Shell Lit and Unlit.

7. Increase maximum Shell Amount (13 to 52). (Optional)

  • Using geometry shader instancing, so it requires "#pragma target 4.6". (Equivalent to OpenGL 4.1)

  • If the device does not support "#pragma target 4.6", it will fall back to 13 shells maximum. (No error should occur)

  • The Shell Step is now being replaced by Total Shell Step.

  • so that no matter how many shells are using, fall back fur appearance should not change too much.

  • You may control it more from the comments in Shell's "Lit.hlsl".
    Fur-50Shells
    Fur-13Shells

  • The performance should still be better than the other two method. (Also please try Depth Priming)

  • If your fur is "toooo long", you will meet Camera Frustum Culling issue at the edges of view, you can try increasing mesh bounds and that should solve the problem. (Other two fur methods should also meet this issue if "toooo long")

8. Add disable fur shadow option. (Mesh Shadow Only)

  • Sometimes, the correct shapes of shadow can be less important (hard to notice? it depends...).
    Fur-MeshShadowOnly

Quick tested on Unity 2020.3.23, no visible problem [probably]:
Tested on Unity2020

1. A "DepthNormals" Pass (For forward renderer)

2. Adding specular scattering from "maajor"'s https://github.com/maajor/Marschner-Hair-Unity, licensed under MIT.

3. Controlling the length of fur using a texture (R channel).

4. Fixed issues when using Depth Priming on URP 12. (Depth Priming avoids rendering pixels that are occluded [probably] which improves performance)
@jiaozi158
Copy link
Contributor Author

Notes:

The scatter light won't be obvious if smoothness is very low.
Fur-Smoothness

Should also disable "Specular Highlights" to avoid flickering.
Fur-SpecularHighlights

Don't know why I disabled it. Did not mention "Light Layer" on UPR12 because it does not support Specular Scattering, will add support (later...).
I used a wrong uv to sample the BaseMap.
Just realized it because scaling the BaseMap is not common (except testing scene)
@jiaozi158
Copy link
Contributor Author

I am quite confused now.

I heard that negative "light.direction" should be used in shaders, but maajor is using a positive "light.direction". (and looks fine? Did not see upside down lighting in the demo)

MaajorLightDir

  • And "light.dir" does not have negative in default:

UnityLightDir

So positive / negative, which one is correct?
Or I just use positive because it looks OK?

@jiaozi158
Copy link
Contributor Author

jiaozi158 commented Apr 28, 2022

Edited: positive should be correct

Well I think negative direction (green one) is correct. (sadly)

But seems that positive direction can fake the scattering by keeping the "factor" low.
LightDir3

1. Add XR single pass instance support for both Shell Lit and Shell Unlit.

2. Increase maximum shell amount. (requires "#pragma target 4.6", or will fall back to 13 shells.)

3. Add option to disable fur shadow (show original mesh shadow only).
@hecomi
Copy link
Owner

hecomi commented May 2, 2022

Thank you for the pull request. I am willing to accept the DepthNormals (I would be happy to receive another pull request!), but I am not willing to accept the other changes. This repository is not a practical library of fur shaders, but rather a sample that comes with the article (https://tips.hecomi.com/entry/2019/10/27/152520) to showcase the implementation, and I want to keep it as simple as possible.

As for the light direction, sorry, I have not read that library so I do not know the detailed implementation. But whether it is positive or negative depends on the internal implementation; I recommend comparing the calculation in the official Unity shader with the Marschner-Hair-Unity calculation (FurBxDF()).

@jiaozi158
Copy link
Contributor Author

Thank you for the pull request. I am willing to accept the DepthNormals (I would be happy to receive another pull request!), but I am not willing to accept the other changes. This repository is not a practical library of fur shaders, but rather a sample that comes with the article (https://tips.hecomi.com/entry/2019/10/27/152520) to showcase the implementation, and I want to keep it as simple as possible.

As for the light direction, sorry, I have not read that library so I do not know the detailed implementation. But whether it is positive or negative depends on the internal implementation; I recommend comparing the calculation in the official Unity shader with the Marschner-Hair-Unity calculation (FurBxDF()).

Thanks for checking this PR! I will try to make another PR (DepthNormals, Shadow and XR)

Just to confirm, another PR would be something like this or?

  • DepthNormals: SSAO, and Depth Priming fix (depth normal mode)
  • MainLight shadow fix (from cdibbs's PR)
  • XR single pass instance support

@jiaozi158 jiaozi158 closed this May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants