Screen Space Reflection Implemented in Vulkan

Share

Introduction

An important part of real-time rendering is computing indirect lighting. There are many ways to implement indirect lighting, and screen space reflection is one of them. I will try to implement screen space reflection and add it to my renderer.

Principle

22-1

The principle is simple ray marching in view space.

For any point ( p ) on screen:

  1. According to the camera direction ( L ) and the normal ( N ) of the current point ( p ), compute the reflection direction ( RDir = reflect(L,N) ).
  2. Starting from point ( p ), march along the reflected direction: ( rayPos = p + step * RDir ), where step is the marching length.
  3. For each step, compare ( rayPos ) with the screen-space ( z ) value corresponding to ( rayPos.xy ). If the difference is smaller than a threshold ( eps ), an intersection occurs, and that point’s color is used as the reflection value for ( p ). Otherwise, return to step 2 and continue the loop.

The principle is very simple, but the direct result is not ideal. It needs attenuation based on ray-marching distance, roughness at the sample point, and other factors. Since this is also an iterative marching algorithm, the time cost is large, so acceleration techniques such as binary search and Hi-Z need to be considered.

Implementation

  1. The most primitive SSR result I first implemented is shown below. The step size is 0.2.
ssr_0png
  1. Adjusting the step size can improve the result. When the step size is changed to 0.02, the result looks better, but the performance cost becomes high.
ssr_1
  1. Adding attenuation based on marching distance improves the result further. The attenuation formula I used is ( weight = e^{-distance * attenuation} ), where ( distance ) is the ray-marching length and ( attenuation ) is the attenuation coefficient.
ssr_2-1
  1. I tried using binary search to find the intersection point, but the improvement did not seem obvious.
  2. I tried determining attenuation based on metallic and roughness values, applying another attenuation by the coefficient ( metal * rough ). I changed to another scene here. The floor is non-metallic with roughness 0.5, and most of the model is metallic. From the image, some color bleeding can be seen.
ssr_3 ssr_4
Rendering result SSR texture

References

[OpenGL] Screen Space Reflection effect

Unity URP screen space reflection implementation

Read more

可多路视频播放的VisionOS 媒体查看器开发

可多路视频播放的VisionOS 媒体查看器开发

开发一款能够同时播放多个视频的vision pro媒体查看器。 0:00 /0:40 1× 缘起 Vision Pro 发布时我就特别想买,毕业工作后终于有资金购入并加入Apple开发者计划,从今年五月到现在也用了快小半年,用起来确实挺爽。 但是有些痛点还是很难受,其中一个痛点就是无法同时播放多个视频音频(实际上VisionOS提供了同时播放音频的API,但是似乎我用的APP都是不遵守🤣 导致都在抢占),因此为了满足我自己的这个痛点,也学习一下Vision OS 的应用开发,甚至完成度足够的话考虑上架App Store,便有了这个目标是多视频同时播放的媒体查看器项目。 现有工作 我购买了4XVR、Infuse、Moon Player、ES 文件助手(这款只有iPad OS版,不是专供Vision OS的),这几个月体验下来,全都存在我提到的和其他APP抢占音频通道,无法同时播放的问题,其他的我的主观的体验如下: 4XVR:使用最多,用起来最舒服,格式支持很全,VR视频也能看,号称全v

By Feiran Yu