Hello.
I want to get the screen position of a point on the skybox and display text there.
For example, here is the code
Shader "CustomSkybox/Sun"
{
Properties {
_BGColor ("Background Color", Color) = (0.7, 0.7, 1, 1)
_SunColor ("Color", Color) = (1, 0.8, 0.5, 1)
_SunDir ("Sun Direction", Vector) = (0, 0.5, 1, 0)
_SunStrength("Sun Strengh", Range(0, 300)) = 12
}
SubShader
{
Tags
{
"RenderType"="Background"
"Queue"="Background"
"PreviewType"="SkyBox"
}
Pass
{
ZWrite Off
Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed3 _BGColor;
fixed3 _SunColor;
float3 _SunDir;
float _SunStrength;
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 viewDir : TEXCOORD0;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.viewDir = -WorldSpaceViewDir(v.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float3 sunDir = normalize(_SunDir);
float3 dir = normalize(i.viewDir);
float angle = dot(dir, sunDir);
fixed3 c = _BGColor + _SunColor * pow(max(0.0, angle), _SunStrength);
return fixed4(c, 1.0);
}
ENDCG
}
}
}
This shader specifies the position of the sun in 3D coordinates from the inspector, normalizes it on a sphere, and draws the sun by dot product with the world space view vector.
What I want to do is to get the screen position of the pixel whose dot product is zero.
If I can get those coordinates I would be able to draw the text. However, I do not know how to do that.
Ultimately this is what I would like to do. If there is a way to achieve this outside of shaders, please let me know.
Thank you in advance.