Skip to content

Easy to use planar reflections for Unity's Universal Render Pipeline.

License

Notifications You must be signed in to change notification settings

draftPRD/URP_PlanarReflections

Repository files navigation

License

Planar Reflections in Unity's URP

Full .unitypackage here: https://github.com/Macleodsolutions/URP_PlanarReflections/releases/download/v0.2/URP_PlanarReflections.unitypackage

Requires Entities Package.

FAST, easy to use planar reflections for Unity's Universal Render Pipeline. Example scenes provided demonstrate ShaderGraph setup and Min/Max settings. Using DOTS, optimized for the URP. Experimental support for recursive reflections. Based on the Boat Attack Demo located here: https://github.com/Verasl/BoatAttack


Basic Setup (No Recursion, Best Performance)

Assuming the user has no use for recursion, setup can be greatly simplified by simply adding individual reflection scripts to the main camera, one for each direction you intend to have reflections come from.

The reflection script ultimately outputs to a global shader property, which needs to be caught on any materials you intent to have reflections. An example set of shaders designed to replicate the standard unity ones can be found for each corrosponding direction, demonstrating how to recieve the reflection textures within the shadergraph.

Basic Example

Using the shader property "_PlanarGround", which is already being caught in the Ground Planar Reflection shader variation, we can easily assign all materials catching "_PlanarGround" to reflect at a normal angle of 0,1,0, or up.



Resulting in:


Well, the skybox is clearly being reflected, but no objects anywhere in sight. By simply adjusting the "Clip Plane Offset" option, we can find the optimal reflection offset for your scene.


Now, we have our objects reflecting! Still, something seems off. We have a number of post processing effects available to more closely match our original objects:



Excellent! Last but not least, lets talk about multiple reflection angles. Simply set up another Reflection Script on the same camera with the desired reflection angle, and feed it to a material property with a global shader call. Several direction materials are available in the example scene.



Advanced Setup (Recursion, Questionable Performance, Experimental)

If the user does however require recursion, experimental support is provided via the Recursion Control script:



In the first inspector diagram above, we see a Recursive Reflection Control script, with no active layers, but with the same settings filled in as in the previous "_PlanarGround" example.

NOTE: At this point it it imperative that "Recursive Reflection" is enabled, and that "Levels Of Recursion" is at least 2.

After clicking the first direction icon under step #4 (the direction indicated as the green side of the cube) we arrive at the second inspector diagram, where the reflection layer is now active. To edit this reflection layer now, you must click the same direction icon again to remove it, then readd with desired values. This is not optimal behaviour and will be addressed in a future update.



Finally, we see the same settings as our previous example, running in a recursive fashion. Even with the advantages that DOTS brings this is still a costly operation.

Questions? Feature Requests? PRs? Get it touch! I'm also available at contact@wmacleod.me, and you can check out more of my work at https://www.wmacleod.me

About

Easy to use planar reflections for Unity's Universal Render Pipeline.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages