UnityURPUnlitScreenSpaceDecalShader icon indicating copy to clipboard operation
UnityURPUnlitScreenSpaceDecalShader copied to clipboard

Why should we make a "viewRay z division" to viewRayOS?

Open wqaetly opened this issue 3 years ago • 2 comments

Good guy, I have some doubts when studying the code, why do we need to do perspective division on the ray from the model space camera to the vertex? In my cognition, perspective division is only to get the NDC coordinates, and there are some unclear meanings here.

大佬好,在研究代码的时候有一些疑惑,为什么要对模型空间相机到顶点的射线做透视除法,在我的认知里透视除法只是为了得到NDC坐标,而这里让我有些摸不到头脑

i.viewRayOS.xyz = i.viewRayOS.xyz / i.viewRayOS.w;

wqaetly avatar Apr 01 '21 08:04 wqaetly

after i.viewRayOS.xyz /= i.viewRayOS.w; i.viewRayOS.xyz is now an object space view direction with view space depth = 1 (not a unit vector). cameraPosOS.xyz + i.viewRayOS.xyz * linearEyeDepth = reconstruct scene position in object space from depth texture

ColinLeung-NiloCat avatar Apr 01 '21 17:04 ColinLeung-NiloCat

Okay, thank you for your reply, I think I already understand why, as shown below

image

In addition, I wrote a technical blog to analyze this project, hoping to help those who want to understand the principles of the project,https://www.lfzxb.top/screen-space-decal-in-urp-study/

wqaetly avatar Apr 02 '21 09:04 wqaetly