当前位置:网站首页>HDRP Custom Pass Shader Get world coordinates and near clipping plane coordinates
HDRP Custom Pass Shader Get world coordinates and near clipping plane coordinates
2022-08-11 09:25:00 【East Bear in the morning】
获取世界坐标
posInputThe coordinates need to be added to the coordinates of the camera,honey juice pit…
float3 ws = _WorldSpaceCameraPos + posInput.positionWS;
Get the near clipping plane coordinates
用到函数 ComputeWorldSpacePosition().
float3 nearPositionWS = ComputeWorldSpacePosition(posInput.positionNDC, 1, UNITY_MATRIX_I_VP);
nearPositionWS += _WorldSpaceCameraPos;
The internal implementation of this function is of course still usedNDCCoordinates push world space coordinates,But the parameters passed in here are screen coordinatesUV.(Although he named itNDC- -,But it's actually screen coordinatesUV,左下角(0, 0) , 右上角(1, 1))
另外,Here the near plane depth is 1,远平面是0.
This link details how to use itNDCCoordinates and depths derive world space coordinates.上善若水_2019-Reconstructs the coordinates of screen pixels in the world from depth information-简书
Implemented in vertex shader
注释掉引用 CustomPassCommon.hlsl 的那一行,把 CustomPassCommon.hlsl Copy the content inside to your shader,Unlock vertex shader.
Change the code in the vertex shader to look like this
struct Varyings
{
float4 positionCS : SV_POSITION;
// Add a register
float3 positionWS : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings Vert(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
// 注释掉
// output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID, UNITY_RAW_FAR_CLIP_VALUE);
// 改成
float2 uv = float2((input.vertexID << 1) & 2, input.vertexID & 2);
output.positionCS = float4(uv * 2.0 - 1.0, UNITY_RAW_FAR_CLIP_VALUE, 1.0);
float3 nearPositionWS = ComputeWorldSpacePosition(uv, 1, UNITY_MATRIX_I_VP);
nearPositionWS += _WorldSpaceCameraPos;
output.positionWS = nearPositionWS;
return output;
}
边栏推荐
猜你喜欢
A few days ago, Xiaohui went to Guizhou
Jupyter Notebook 插件 contrib nbextension 安装使用
Software custom development - the advantages of enterprise custom development of app software
Segmentation Learning (loss and Evaluation)
The no-code platform helps Zhongshan Hospital build an "intelligent management system" to realize smart medical care
unity shader 测试执行时间
MySQL select count(*) count is very slow, is there any optimization solution?
中国电子学会五级考点详解(一)-string类型字符串
深度学习100例 —— 卷积神经网络(CNN)识别验证码
神经网络图怎么分析,画神经网络结构图
随机推荐
【无标题】超时超时超时超时超时
软件定制开发——企业定制开发app软件的优势
新一代开源免费的轻量级 SSH 终端,非常炫酷好用!
Segmentation Learning (loss and Evaluation)
[UEFI]EFI_DEVICE_PATH_PROTOCOL 结构体初始化的一个例子
excel将数据按某一列值分组并绘制分组折线图
关于ts中的指针问题call,bind, apply
mindspore 执行模型转换为310的mindir文件显示无LRN算子
基于consul的注册发现的微服务架构迁移到servicemesh
模型训练出现NAN
Primavera Unifier 高级公式使用分享
canvas图片操作
idea插件自动填充setter
MySql事务
5分钟快速为OpenHarmony提交PR(Web)
神经网络需要的数学知识,神经网络的数学基础
@RequiredArgsConstructor注解
单元测试系统化讲解之PowerMock
opencv 制作趣图
向日葵安装教程--向日葵远程桌面控制