0
votes

In my vertex shader I pass through positions in world space for each vertex. I use a uniform to pass the position of the cameras in world coordinates to the fragment shader. I need both of the values there independent of the answer of the question.

now what is better practice: calulate a vec3 cameraToSurface ( world space ) in vertex shader and pass it to the fragment shader and let it be interpolated in that process? Or should I just recalculate that vector for each fragment in the fragment shader? which would be a simple ( vec3 a - vec3 b ) operation.

Basically: should I pass a vec3 from vertex to fragment shader or recalulate it there, if it is a simple difference operation? whats the cost of interpolating a vec3 between vertex and fragment shader?

1

1 Answers

1
votes

Calculate in the vertex shader, let the interpolation hardware do its job.

However since the camera location is fixed and is the same for all vertices, I don't see a reason why to calculate in the shader at all. Calculate on the CPU and use a uniform. The relation between camera and vertex in world space is simply the vertex view space position so whatever you're calculating right now, it probably can be simplified.