Quick question, I’m trying to implement the dual paraboloid reflection shader in Unity and I’ve bumped with the ObjSpaceViewDir function. Judging from the reference I thought it would’ve given the same result as multiplying the v.vertex with ModelView Matrix, but its not.
So, what would be the difference between:
ObjSpaceViewDir(v.vertex); vs mul ((float3x3)UNITY_MATRIX_MV, v.vertex);
Have justed started with Unity and more posts will come! Thanks for any hint.
One is a direction, and the other is a position.
To quote directly from the documentation:
“float3 ObjSpaceViewDir (float4 v) - returns object space direction (not normalized) from given object space vertex position towards the camera.”
Also, the dual paraboloid reflection shader? Searches the web Ahhhhh, I see.
I never use ObjSpaceViewDir, but the documentation’s wording isn’t clear to me. I wouldn’t bother with it, due to neither the function name nor the description of it providing meaning. Just use a matrix and vector.
One of you ought to provide a link to whatever particular shader you’re talking about. I also don’t under the “the”.
Haha, that was exactly my point. I didn’t know what he was referring to exactly, so I linked to a publication on the subject. Unfortunately it appears that only the first url in a post on this forum is automatically underlined.
If you ever need to know in what direction you can find the camera, in object space (in stead of worldspace), this function is there to help you. Isn’t that what the description says?
No. “not normalized” implies a function called (using Unity’s abbreviation that I wouldn’t) “ObjSpaceViewVec”. If it were actually a direction being returned, it would be normalized. I was confused by that, but the description does provide meaning; it’s just inaccurate.
Also, it shouldn’t take the parameter that it does.
I don’t understand why it shouldn’t take the parameter it does. It ignores the w component, so it might as well ask for a vector3, but this way you can pass an input position without requiring the ‘.xyz’ in the function call. (POSITION input semantic is a float4)
It moves the camera position into object space, I don’t know if the length would still be correct or useful. None of the other functions in UnityCG.cginc end in ‘Vec’, and it does point in the direction of the camera, so it seems consistent to me.
And the good thing is vector isn’t normalized twice, if you end up passing it to a function that normalizes its input anyway. Gives us more control. Why don’t you want to call it a direction if it isn’t normalized?
The “View” vector is established as V, here, i.e. ObjSpaceViewDir(vertexPosition_object):
Name it ObjectSpaceVectorToCamera(float4 point) or similar if it’s intended to take generic points.
Why would it not?
They should, if they return a vector that isn’t guaranteed to be normalized.
A direction is a unit vector.
Are you referring to the ambiguity in the variable name ‘v’ (which is often used instead of ‘vertex’ too)? In that case I agree that a longer variable name would be better.
Are you saying ‘direction’ has a special meaning here? Because I’ve never heard about that being a requirement for a direction. Only the other way around: that a unit vector has a length of one, but still points in the same direction as the vector you derived it from.
Because it is a worldspace length. Is it still meaningful after it has been scaled to objectspace?
No. I’m saying that the “View” vector is an established term that specifically means surface to camera.
Your logic implies that there are infinite vectors that a “direction” function could return. If the return value were not of a meaningful magnitude, there would be no reason not to normalize it before returning.
I am having trouble finding “direction” defined as I learned it in Physics class. This is the closest I’ve found:
http://mathworld.wolfram.com/UnitVector.html
Yes. It gets multiplied by unity_Scale.w.
And that’s exactly what’s calculated. CameraPosition - VertexPosition results in a Vector from vertex to camera. Or are you saying that the vertex isn’t part of the surface?
Yes, exactly (limited by the possible values of the IEEE 754 float, of course), with all of those vectors sharing the same direction, so the most important data is identical. You’ll need to normalize it if you want to do things like projecting, of course.
That link also implies that a direction is independent of magnitude (except for 0): "The unit vector having the same direction as a given (nonzero) vector "
Sorry Toglia3d for letting this go off topic into semantics ^_^. I just find it very interesting to see how Jessy thinks about this.
Super necro post but I agree with Jessy, this name is confusing
I am using this to determine the length of the vertex to the camera and reading my shader with fresh eyes as soon as I see Dir I think Direction and thus normalised. The bug I am seeing makes me think it is normalised as well, so now I don’t know what to think and will just use something else that is clearer so this doesn’t confuse me again