- Home /
Camera.WorldToScreenPoint slightly off?
Hello,
So I have a shader program running on my background in my game, this shader program display a circular light-halo around a ball. The position of the ball is passed in to the shader program by a Vector. My CPU-side code looks like this:
Vector4 v4;
Vector3 v3;
int k;
for (k = 0; k < 1; k++) {
v3 = Camera.main.WorldToScreenPoint(Paddle.balls[k].transform.position);
v4 = new Vector4(v3.x, Camera.main.pixelHeight - v3.y, 0.0f, 0.0f);
renderer.material.SetVector("_BallPoint1", v4);
}
For the y direction, I subtract to the camera's pixel height by the the result of WorldToScreenPoint since Screen starts in the upper left while pixel values start in the lower right.
Anyways, this is what I am getting:
The light green arrow points to the ball, while the red arrow points to the white circle caused by the shader program. The white outline is always off by this fixed amount, regardless of the location of the ball. When my screen size is 453x679, the outline is constantly off by -2.85 in the x axis and +36.26 in the y axis. Why??? What is causing this offset?
Here is what my part of my fragment shader looks like, if it helps:
float dist = sqrt(
((input.pos.x - _BallPoint1.x)*(input.pos.x - _BallPoint1.x)) +
((input.pos.y - _BallPoint1.y)*(input.pos.y - _BallPoint1.y))
);
if (dist < 13.0) finalColor = float4(1.0,1.0,1.0,1.0);
Your answer
![](https://koobas.hobune.stream/wayback/20220613160449im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Material offset relative to other game object 0 Answers
set texture offset inside a shader 0 Answers
How can I move a second set of UVs on an instance of a Skinned Mesh Renderer (not the sharedMesh)? 0 Answers
Dynamically alter shader parameters? 1 Answer
how can i catch the sky box and do a reflection in object 0 Answers