当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
DataGrip配置OceanBase
VoLTE基础自学系列 | 3GPP规范解读之Rx接口(上集)
数组、字符串、日期笔记【蓝桥杯】
snapshot standby switch
Redis的客户端连接的可视化管理工具
WooCommerce电子商务WordPress插件-赚美国人的钱
持续集成/持续部署(2)Jenkins & SonarQube
基于PSO在满足可靠性的基础上实现费用最优MATLAB仿真(含完整matlab代码)
UNITY gameobject代码中setacvtive(false)与面板中直接去掉勾 效果不一样
利用mindspore下面mindzoo里面的yolov3-darknet53进行目标识别,模型训练不收敛
三次握手与四次挥手
mindspore 执行模型转换为310的mindir文件显示无LRN算子
中移链EOSJS实战使用
CreateJS加速地址
wordpress插件开发03-简单的all in one seo 插件开发
IPQ4019/IPQ4029 support WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz MT7915 MT7975
Inventorying Four Entry-Level SSL Certificates
canvas图像阴影处理
HDRP shader 获取阴影(Custom Pass)
What should I do if the mysql data query causes the cup to be full because the query time span is too large








