Exemple #1
0
        internal static void Index2EntryPointKernel(
            Index2 index,
            ArrayView <int> output,
            Index2 extent)
        {
            var linearIndex = index.ComputeLinearIndex(extent);

            output[linearIndex] = linearIndex;
        }
        static void NearFieldKernel1(
            Index2 index,      // Contains (sample, line)  First dimension changes fastest
            int target_line,   // row within the 128 x 128 target patch
            int target_sample, // column
            int slope_idx_start,
            int slope_idx_stop,

            ArrayView <short> gpu_terrain,
            ArrayView <float> gpu_range,
            ArrayView <float> gpu_slope,
            ArrayView <float> gpu_rise,
            ArrayView <int> gpu_range_limit)
        {
            var flip = -LonFactor;

            // From ILGPU source code: public int ComputeLinearIndex(Index2 dimension) => Y * dimension.X + X;
            var rise_idx = index.ComputeLinearIndex(Dimension);
            var rise     = gpu_rise[rise_idx];

            var center_line   = target_line + index.Y;
            var center_sample = target_sample + index.X;
            var center_idx    = center_line * TerrainSize + center_sample;
            var center_height = 0.5f * gpu_terrain[center_idx];

            GetVector3d(center_line, center_sample, center_height, out float center_x, out float center_y, out float center_z);
            center_z *= flip;

            for (var slope_idx = slope_idx_start; slope_idx < slope_idx_stop; slope_idx++)
            {
                var slope = gpu_slope[slope_idx];

                // Work out the direction vector
                var ray_rad = XMath.PI * 2f * slope_idx / cpu_slope_size; // 0 deg in ME frame points toward the earth
                var ray_cos = XMath.Cos(ray_rad);                         // varies the line
                var ray_sin = XMath.Sin(ray_rad);                         // varies the sample

                // iterate over the ranges
                var range_limit = gpu_range_limit[slope_idx];
                for (var range_idx = 0; range_idx < range_limit; range_idx++)
                {
                    var range         = gpu_range[range_idx];
                    var caster_line   = center_line + ray_sin * range;
                    var caster_sample = center_sample + ray_cos * range;

                    var x1 = (int)caster_sample;  // Calculate the caster point by interpolating between four points from the points array
                    var y1 = (int)caster_line;
                    int x2 = x1 + 1;
                    int y2 = y1 + 1;

                    var q11_idx = y1 * TerrainSize + x1;
                    var q11     = gpu_terrain[q11_idx];

                    var q12_idx = q11_idx + TerrainSize;
                    var q12     = gpu_terrain[q12_idx];

                    // First interpolation across rows (line)
                    var q1_line = q11 + (caster_line - y1) * (q12 - q11);

                    var q21_idx = q11_idx + 1;
                    var q21     = gpu_terrain[q21_idx];

                    var q22_idx = q11_idx + TerrainSize + 1;
                    var q22     = gpu_terrain[q22_idx];

                    // Second interpolation across rows
                    var q2_line = q21 + (caster_line - y1) * (q22 - q21);

                    // Interpolate across samples and convert to meters
                    var caster_height = q1_line + (caster_sample - x1) * (q2_line - q1_line);
                    caster_height *= 0.5f;

                    GetVector3d(caster_line, caster_sample, caster_height, out float caster_x, out float caster_y, out float caster_z);
                    caster_z *= flip;

                    var dx = caster_x - center_x;
                    var dy = caster_y - center_y;
                    var d  = XMath.Sqrt(dx * dx + dy * dy);             // horizontal distance in moon radius units

                    var light_ray_height = caster_z - slope * d;        // negative slope gets higher as light ray goes toward the center
                    var ray_rise_height  = light_ray_height - center_z; // moon radius units
                    var ray_rise_meters  = ray_rise_height * 1000f;

                    // Alternative
                    //var dInMeters = d * 1000f;
                    //var deltaHeightInMeters = (caster_z - center_z) * 1000f;
                    //var rise2 = deltaHeightInMeters - dInMeters * slope;

                    rise = XMath.Max(rise, ray_rise_meters);
                }
            }

            gpu_rise[rise_idx] = rise;
        }
Exemple #3
0
            public void InstanceKernel(Index2 index, ArrayView <int> output, Index2 extent)
            {
                var linearIndex = index.ComputeLinearIndex(extent);

                output[linearIndex] = NestedFunction(linearIndex);
            }