Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- // North Star Calibration Utilities
- // Screen UV to Rectilinear Coefficients
- float left_uv_to_rect_x[16] = { -0.7530364531010308, 0.8806592947908687, -0.8357813137161849, 0.3013989721607643, 0.9991764544369446, -0.2578159567698274, 0.3278667335649757, -0.4602577277109663, -0.23980700925448195, -0.056891370605734376, -0.1248008903440144, 0.7641381600051023, 0.20935445281014292, -0.06256983016261788, 0.25844580123833516, -0.5098143951663658 };
- float left_uv_to_rect_y[16] = { 0.5612597403791647, -1.1899589356849427, 0.4652815794139322, -0.2737933233160801, 0.3774305703820774, -0.8110333901413378, 1.2705775357104372, -0.7461290557575936, -0.19222925521894155, 0.936404121235537, -1.7109388784623627, 0.9147182510080394, 0.33073407860855586, -1.1463700238163494, 1.4965795269835196, -0.7090919632511286 };
- float right_uv_to_rect_x[16] = { -0.2117125319456463, -0.432262579698108, 0.41675063901331316, -0.14650788483832153, 1.0941580384494245, -0.30628109185189906, 0.109119134429531, 0.11642874201014344, -0.2761527408488216, -0.4335709010559027, 0.9626491769528918, -0.5572405188216735, 0.18342869894719088, 0.37981945016058366, -0.8718621504058989, 0.5218968716935535 };
- float right_uv_to_rect_y[16] = { 1.0129568069314265, -2.110976542118192, 1.4108474581893895, -0.7746290913232183, -0.746419837008027, 1.747642287758405, - 1.5753294007072252, 0.7143402603200871, 0.5607717274125551, -1.5019493985594772, 1.2539128525783017, -0.42999735712430215, -0.21517910830152714, 0.5965062719847273, -0.5664205050494074, 0.18545738302854597};
- struct Functions
- {
- // Evaluate a 2D polynomial from its coefficients
- float polyval2d(float X, float Y, float C[16])
- {
- float X2 = X * X; float X3 = X2 * X;
- float Y2 = Y * Y; float Y3 = Y2 * Y;
- return (((C[ 0] ) + (C[ 1] * Y) + (C[ 2] * Y2) + (C[ 3] * Y3)) +
- ((C[ 4] * X ) + (C[ 5] * X * Y) + (C[ 6] * X * Y2) + (C[ 7] * X * Y3)) +
- ((C[ 8] * X2) + (C[ 9] * X2 * Y) + (C[10] * X2 * Y2) + (C[11] * X2 * Y3)) +
- ((C[12] * X3) + (C[13] * X3 * Y) + (C[14] * X3 * Y2) + (C[15] * X3 * Y3)));
- }
- // Calculate the direction a ray takes exiting the eye on its way towards this screen UV
- float3 uvToRayDirection(float2 uv, float left_uv_to_rect_x[16], float left_uv_to_rect_y[16],
- float right_uv_to_rect_x[16], float right_uv_to_rect_y[16])
- {
- float2 screenUV = float2(fmod((2.0 * (1.0-uv.x)), 1.0), uv.y); // Calculate the Screen-Space UV
- float xCoeffs[16] = left_uv_to_rect_x; if(uv.x < 0.5) { xCoeffs = right_uv_to_rect_x; }
- float yCoeffs[16] = left_uv_to_rect_y; if(uv.x < 0.5) { yCoeffs = right_uv_to_rect_y; }
- return float3(polyval2d(screenUV.x, screenUV.y, xCoeffs),
- polyval2d(screenUV.x, screenUV.y, yCoeffs), 1.0);
- }
- // Calculate the origin of a ray given a shader UV
- float3 uvToRayOrigin(float2 uv)
- {
- return float3(0.032 * ((uv.x > 0.5) ? -1.0 : 1.0), 0.0, 0.0);
- }
- float4 Out()
- {
- // Calculate the ray origin and direction
- float3 ray_origin = uvToRayOrigin(uv);
- float3 ray_dir = uvToRayDirection(uv, left_uv_to_rect_x,
- left_uv_to_rect_y,
- right_uv_to_rect_x,
- right_uv_to_rect_y);
- // Get the point on a virtual plane 15cm away
- float3 plane_pos = ray_origin + ray_dir * 0.15;
- // Create a Checkerboard Pattern
- float2 Pos = floor(plane_pos.xy * 100.0);
- float PatternMask = fmod(Pos.x + fmod(Pos.y, 2.0), 2.0);
- return float4(float3(PatternMask, PatternMask, PatternMask),1.0);
- }
- };
- Functions f;
- return f.Out();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement