Skip to content

Instantly share code, notes, and snippets.

@Chikanut
Chikanut / SeeThroughMask.hlsl
Last active September 20, 2022 01:22
This is HLSL code of See Through feature, all parameters of shader must be globally seted.
float2 WorldToScreenPos(float3 pos){
pos = normalize(pos - _WorldSpaceCameraPos)*(_ProjectionParams.y + (_ProjectionParams.z - _ProjectionParams.y))+_WorldSpaceCameraPos;
float2 uv =0;
float3 toCam = mul(unity_WorldToCamera, pos);
float camPosZ = toCam.z;
float height = 2 * camPosZ / unity_CameraProjection._m11;
float width = _ScreenParams.x / _ScreenParams.y * height;
uv.x = (toCam.x + width / 2)/width;
uv.y = (toCam.y + height / 2)/width;
return uv;