Hi guys,
I am trying to get a picked point under mouse cursor using vertex shader…
my cpu implementation is just fine and working …
this is my code for GPU picking in vertex shader … whcih is not giving me desired result …
float r = 0.5f; //imaginary sphere around a vertex of terrain radius
float4 VertexPos = mul(output.WorldPosition, worldMatrix);
float3 PosToRayOrigin = VertexPos.xyz - RayPosition.xyz;
float ProjectionOnRay = dot(PosToRayOrigin, RayDirection.xyz);
float PosRayOriginLenSq = dot(PosToRayOrigin, PosToRayOrigin);
float r2 = r * r;
float m2 = PosRayOriginLenSq - ProjetionOnRay * ProjetionOnRay;
bool RayOriginoutSideSphere = PosRayOriginLenSq > r2;
bool sphereBehindRayOrigin = ProjectionOnRay < 0.0f;
bool noIntersection = RayOriginoutSideSphere && sphereBehindRayOrigin;
bool RayMisSphere = m2 > r2;
if (!noIntersection && !RayMisSphere)
output.PickedPointGpu = VertexPos;
r = 0.5f because terrain vertex are 1.0f units apart on xz plane.
kindly help as i am not getting desired result, and dont know where I am making mistake …