Code Monkey home page Code Monkey logo

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

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.