freezy / VisualPinball.Engine

:video_game: Visual Pinball Engine for Unity
https://docs.visualpinball.org
GNU General Public License v3.0
396 stars 62 forks source link

Create VPE specific shaders #223

Open Pandelii opened 3 years ago

Pandelii commented 3 years ago

In testing the metals i found a few workflow issues with the default shader that will create a lot of texture/download size bloat for tables. A new shader could reduce this by encouraging re-use of textures.

Since tables share so many materials with only slight variations, the material and texture workflow can be simplified by introducing a VPE specific shader graph.

This shader would provide a simplified interface, hopefully easier code based access and more flexibility for custom texture usage while at the same time providing more opportunity for reuse of shared textures. Using a graph for this instead of a traditional shader also improves the odds of future compatability with render pipelines, and provides creators with something less complex than manual code editing if they need a variation that falls outside the scope of the default.

Base functionality: Albedo map and color. To allow for greyscale albedo + tinting. Metalness value map + remap.
Smoothness/Ambient occlusion map + remap Wear map + remap.
Transmission Profile Transmission map Normal map Texture placement: UVx, Planar, Triplanar UV tiling + offset + rotation. Anisotrophy

Special layered shader can be used to combine materials with simple masking.

Code entry points: Tex2d inputs: _Albedo _Metalness _SmoothAO _Wear _Normal

Float inputs _MetalLow _MetalHigh _SmoothLow _SmoothHigh _AOMultiplier _WearAmount _NormalAmount _RotationAmount _Anisotrophy

Vector2 Inputs _UVTile _UVOffset

Vector3 inputs _WorldScale _WorldOffset

Vector4 inputs _AlbedoColor

freezy commented 3 years ago

So besides user friendliness, how much will this impact performance and how would it compare to HDRP's lit shader in terms of visuals?

Pandelii commented 3 years ago

In terms of rendering visuals they will be equivalent. In terms of table appearance it should be slightly better through less texture jank. Performance should be slightly lower overall due to additional texture samples, but may be better in other areas due to more reuse. Tradeoff is being more versatile/easy to use with lower average download sizes vs more performant. Performance can be increased with channel packing, but channel packing means more duplicate textures. There is also a performance unknown in shader graph vs raw shaders. I havent profiled them yet but usually they are slightly less efficient, but not appreciably.

Pandelii commented 3 years ago

Oh, the other advantage is that we can make a 1:1 mapping fir URP and HDRP, ensuring that on the material end creators will not have to make their own variants in the event it doesn't translate precisely. The value of this may depreciate as the two pipelines become more in line with each other.

freezy commented 3 years ago

Oh yeah that would be awesome.

By the way, if you can have a look at our standard elements and auto-assign the new materials to them, that would be cool as well. For instance, creating a new table via the toolbox adds a new playfield mesh with no material at all. Getting something nice here out of the box (even though at least the texture would be replaced later on by the author), would be nice.

Pandelii commented 3 years ago

Sure thing