Giter Site home page Giter Site logo

colinleung-nilocat / unityurp-mobilescreenspaceplanarreflection Goto Github PK

View Code? Open in Web Editor NEW
980.0 21.0 150.0 632.76 MB

Reusable RendererFeature of MobileScreenSpacePlanarReflection

License: MIT License

C# 75.46% ShaderLab 18.38% HLSL 6.16%
unity urp mobile planarreflection reflection screenspace shader render

unityurp-mobilescreenspaceplanarreflection's Introduction

UnityURP-MobileScreenSpacePlanarReflection

A simple and fast ScreenSpacePlanarReflection(SSPR) as a standalone reusable RendererFeature in URP.
Can run on PC/console/vulkan android, other platforms not tested but should work if compute shader is supported.

SSPR ON screenshot SSPR OFF screenshot SSPR ON screenshot SSPR OFF screenshot

On Adreno630 GPU android mobile device(almost all 2018/2019 flagship android mobiles), Toggle SSPR ON/OFF:

  • cost <1ms to update 128 height SSPR RT
  • cost <1ms to update 256 height SSPR RT
  • cost 1~2ms to update 512 height SSPR RT

On Adreno612 GPU android mobile device(Samsung Galaxy A70), Toggle SSPR ON/OFF:

  • cost <1ms to update 128 height SSPR RT
  • cost 1~2ms to update 256 height SSPR RT
  • cost 4~5ms to update 512 height SSPR RT

On Adreno506 GPU android mobile device(Lenovo S5), Toggle SSPR ON/OFF:

  • cost ~1ms to update 128 height SSPR RT
  • cost 3~4ms to update 256 height SSPR RT
  • cost 8~9ms to update 512 height SSPR RT

Where are the important files?

There are only 4 important code files, all inside a folder "Assets \ _MobileSSPR \ ReusableCore".
https://github.com/ColinLeung-NiloCat/UnityURP-MobileScreenSpacePlanarReflection/tree/master/Assets/_MobileSSPR/ReusableCore
Other files are for demo only, not important.

Can it run on mobile?

Tested on ~10 android devices(all support Vulkan). If your android device support Vulkan, result should be correct and rendering should be fast enough. (OpenGLES3.2 is not enough, must support Vulkan!)

*We have received a report that this SSPR is not working on MaliT760 GPU android (Galaxy S6), but we don't have this device to reproduce it

How to try this inside my own URP project?

  • copy "Assets \ _MobileSSPR \ ReusableCore" folder to your project (contains 4 important code files)

  • turn on "Depth Texture" in all your project's URP's setting

  • turn on "Opaque Texture" in all your project's URP's setting

  • Add MobileSSPRRendererFeature(RendererFeature) to your forward renderer asset

  • create a new plane game object in your scene (set world space pos y = 0.01)

  • create a material using MobileSSPRExampleShader.shader

  • assign this material to your new plane

  • DONE! You should see correct reflection both in scene and game window

I can see some small flickering in reflection / can't see any reflection

It is not expected! Please report your device name in Issues, thanks!

Notes

It is not safe to use InterlockedMin() and RenderTexture color format "RInt" on android/iOS compute shader(see -> https://zhuanlan.zhihu.com/p/150890059). Instead, we will use RenderTexture color format RFloat / ARGBHalf to produce similar result.

Editor

2020.3.33f1 LTS

Implementation reference

Change log

  • 2020-08-23: add iOS/OSX support (with the help of MusouCrow)
  • 2022-05-02: upgrade project to Unity2020.3.33f1, merged a bug fix in MobileSSPRComputeShader.compute

unityurp-mobilescreenspaceplanarreflection's People

Contributors

colinleung-nilocat avatar firdiansyah-ramadhan-programmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unityurp-mobilescreenspaceplanarreflection's Issues

No reflection on macOS (Metal)

@ColinLeung-NiloCat Thank you very much for fixing the reflection when changing the height of the plane. Reflections now work perfectly on Windows and Android with Vulkan.

Screenshot 2022-12-03 at 14 54 12

Unfortunately reflections are missing on the M1 MacBook Air using Metal. Enabling them gives this error:

CommandBuffer: temporary render texture _MobileSSPR_PackedDataRT not found while executing SSPR (SetComputeTextureParam)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

I get the same error in my own project as well as a clone of this repo. The error occurs in the latest Unity 2021 LTS (2021.3.15f1) as well as the latest Unity 2020 LTS (2020.3.42f1).

How to use SSPR in AR scene?

Now Unity URP project of AR Foundation works well and Unity URP SSPR project works well too. But when I add the two Renderer Features in Pipeline_Renderer, there is no reflection of the ground. Do you know why? Are the two Renderer Features conflict? How to reslove this?

Does not work for webgl

Great work, but after downloading same project and just building for webgl whole screen turns black when mobile screen space reflections are turned on.

Black texture and low quality

I have a 50*4 scale plane. I added this script to it, but the quality is very poor and the base texture become black.

Transparency will render under reflective surface

Hi! I tried to use the reflection shader on a flat surface, and it worked well, but as soon as I popped some particles on top of it they were rendered behind the reflective surface. Is there any way to fix that? Thanks!

Unity 219.4.16f1 (LTS)

Screenshot 2021-01-29 114211

Depth bug when using OpenGLES graphics API

If change the graphics API whatever in editor or android runtime, the effect will be like this.

image

which height looks like not correct ,but the real reason is the depth is not corrct.
Because the depth range in opengl i [-1,1], dx and vulkan is [0,1].
so add this code is enough.
image

image

Have transparency support in the shader

Hi, Is it possible to have base texture as transparent one, so it will blend with background color, like floor/plane edges will be blended with background color due to the smooth transparency in the edge of texture/base map.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.