- Home /
What is the value of unity_ProjectorClip ?
Hi
Unity's Projector is a very powerful tool, but it is hard to find documentation about its internal implementation.
I am trying to build my own projector, actually something that projects several images from several positions. For this I need to "reproduce" Unity's projector. I don't want to use Unity's projector, and instead I'm putting a Camera component with basically the same projection values as what I would have written in the Projector component.
Somehow I managed to decipher the value of unity_Projector matrix, which is:
k_ProjectorOffsetMatrix * camera.projectionMatrix * camera.worldToCameraMatrix
Where the k_ProjectorOffsetMatrix is the following linear transformation magic value:
k_ProjectorOffsetMatrix = Matrix4x4.TRS ( Vector3.one * .5f, Quaternion.identity, -Vector3.one * .5f);
(Hope this will help someone)
But regarding the second matrix unity_ProjectorClip, I'm stuck. I know this is something that takes into account the near/far clip planes, and maybe also the side boundaries, but I just can't manage to reverse-engineer its value. This matrix is needed for sampling the "falloff" texture that prevents projected image from appearing beyond the projection frustum, and is used in the following way, based on the ProjectorMultiply.shader code:
v2f vert(appdata_tan v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv_Main = mul (_Projector, v.vertex);
**o.uv_Clip = mul (_ProjectorClip, v.vertex);**
return o;
}
half4 frag (v2f i) : COLOR
{
half4 tex = tex2Dproj(_ShadowTex, i.uv_Main);
**half4 falloff = tex2D(_FalloffTex, i.uv_Clip.xy);
tex = lerp(float4(1,1,1,1),tex,falloff.a);**
return tex;
}
For the falloff texture, it can be a one-dimentional white texture where just the last pixel is black. Somehow, i.e. with the right unity_ProjectorClip value, it will cause the alpha value of the pixel to be white on the far clip plane and beyond.
I have all the bricks, but a little help to get to the arrival line would be much appreciated.
Michael
I am also attempting to reverse-engineer this $$anonymous$$atrix, but am stuck.
From what I can gather, it exists as an additional Transformation on top of the Projector's $$anonymous$$VP matrix, which is why you can simply take the object-space vertex position and multiply it by this matrix to get the result.
It seems to take the z value of that vertex in "clip-space" and maps it to the 'u' coordinate of the provided ramp texture. But it actually appears to "cut off" outside of the frustum.
Hi, following the thread. I can't help to decode the function matrix, apart from saying that the legacy _Projector and _ProjectorClip functions are automatically replaced on import (2017.x) and seem broken: The unity_Projector function fails to discard the "shadow" texture on its side at certain distances, whatever the alpha provided in the "shadow" texture, resulting in the horrible bleeding seen in almost every projector implementation! I'd like to learn more too, but, my 2 cents contribution is: each function has a different TEXCOORD. I guess the coordinates belong to the projector where texcoord(0) is the base projection plane and texcoord(1) the pyramidal shape...