GetWorldSpaceNormalizeViewDir

HLSL
half3 GetWorldSpaceNormalizeViewDir(float3 positionWS)
点击展开查看更多

获取从世界空间中某一点指向相机的归一化视线方向(带透视类型处理)。(也就是Raymarching里的rd


获取相机位置

[!warning|aside-r] 仅URP

HLSL
float3 GetCameraPositionWS()
float3 GetCurrentViewPosition()
点击展开查看更多

这两个函数本质上是为未来的“相机相对渲染”(Camera Relative Rendering)功能预留的抽象层,截至 Unity 6.3,这两个函数仍然只是直接返回


Clip 裁剪

[!warning|aside-r] 仅限片段着色器

在片元着色器阶段对像素进行裁剪(丢弃),如果传入的参数任何分量小于0,则丢弃当前像素

HLSL
clip(0); // 大于等于0,保留
clip(-1); // 小于0,裁剪
点击展开查看更多

案例:画圆⚪,即丢弃圆外的像素

HLSL
// 画圆⚪,即丢弃圆外的像素
float dist = distance(uv, float2(0.5)); // 圆中心(0.5, 0.5)
clip(0.5 - dist); // 半径0.5
点击展开查看更多

版权声明

作者: Cheyne Xie

链接: https://chaim.eu.org/posts/ab7ce9f8/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键