Пример #1
0
    void selectSamplesToBroadcast(List <Samples.singleSampleObject> localSampleList, int deviceID)
    {
        //maxSampleNetwork: maximum number of samples the network CAN send.
        //numLocalSamples: number of samples in the frame.
        //numSamplesToSend: number of samples chosen by the user/app

        int numLocalSamples = localSampleList.Count;

        numSamplesToSend = clientLOS.LIM_NUM_SAMPLES_TO_SEND;

        //Assign the  numSamplesToSend = min(maxSampleCount, maxSamples, numSamplesToSend);
        numSamplesToSend = maxSampleNetwork < numSamplesToSend ? maxSampleNetwork : numSamplesToSend;
        numSamplesToSend = numLocalSamples < numSamplesToSend ? numLocalSamples : numSamplesToSend;

        samplesToSend = new Samples.singleSampleObject[numSamplesToSend];
        Samples.singleSampleObject[] localSampleArray = new Samples.singleSampleObject[localSampleList.Count];
        for (int i = 0; i < numSamplesToSend; i++)
        {
            samplesToSend[i] = localSampleList[i];
        }

        // Populating the local sample's list with samples generated
        for (int i = 0; (i < localSampleList.Count) && (i < clientLOS.LIM_SAMPLES_PER_LOCAL_LIST); i++)
        {
            localSampleArray[i] = localSampleList[i];
        }

        //Add to own list if not receiving it from server
        clientList.Add(localSampleArray);
        clientLOS.timestamps.Add(CurrentTimeMillis());
        clientLOS.deviceIDs.Add(deviceID);
        return;
    }
Пример #2
0
    /*
     * Input parameter includes the u,v texture samples, this method
     * will collect the radiance samples from the pixel values corresponding to
     * cubemap face.
     */
    void generateRadianceSamples(List <Samples.singleSampleObject> samples)
    {
        // Initialize variables
        Ray        ray;
        RaycastHit hit;
        Vector3    outDirection;

        float hitLength = 5.0f;
        float u, v; // Sample generation variables from respective cubemap.
        int   screen_i, screen_j;
        int   numHitRays = 0;

        List <float> deviations = new List <float>();

        // Radiance Sampling
        //BEGIN SPIRAL COORDS
        int x, y, dx, dy;
        int X = probeSampleSize;
        int Y = probeSampleSize;

        x = y = dx = 0;
        // initialized to -1 because first pixel delta corresponds to -1 to 0
        dy = -1;
        int t    = probeSampleSize;
        int maxI = t * t;       // max # pixels.

        int counter = 0;

        //Color32 pixeltemp = pixels[(iii + (probeSampleSize - jjj - 1) * probeSampleSize)];
        for (int ii = 0; ii < maxI && numHitRays < clientLOS.LIM_SAMPLES_PER_LOCAL_LIST; ii = ii + 1)
        {
            // Check corresponding locations for spiral effect of pixel center.
            if ((x == y) || ((x < 0) && (x == -y)) || ((x > 0) && (x == 1 - y)))
            {
                t  = dx;    // Accumulated texture size.
                dx = -dy;   // Increment the delta x
                dy = t;     // Y is the texture size 'tracker'
            }
            // Assign new pixel index of x & y.
            x += dx;
            y += dy;
            // I and J assigned respective rows/columns of 'WIP' texture.
            int i = x + probeSampleSize / 2;
            int j = y + probeSampleSize / 2 - 1;
            //END SPIRAL COORDS
            // float spx = colWebTexPos.x + screen_i - (((probeSampleSize / 2 - camwidth / 2) / calcratio) + mainCamPixWidth / 2);
            // float spy = colWebTexPos.y + screen_j - (((probeSampleSize / 2 - camheight / 2) / calcratio) + mainCamPixHeight / 2);
            float spx = x + samplePosX + probeSampleSize / 2;
            float spy = samplePosY + probeSampleSize / 2 - y;
            // Sampling space with respect to collider position (depth z)
            Vector3 newCoord = new Vector3(spx, spy, colWebTexPos.z);

            // Raycasting from screen pixel
            Vector3 rayCoordinateOnScreen = newCoord;
            // Shoot ray from sample space with respect to collider position.
            ray = sampleCamera.ScreenPointToRay(rayCoordinateOnScreen);
            // Check if screen space sample pixel collides with reflective probe.
            bool coll = probeCollider.Raycast(ray, out hit, hitLength);
            if (coll) // If raycast collides with the collider
            {
                if ((i + (probeSampleSize - 1 - j) * probeSampleSize) >= pixels.Length || (i + (probeSampleSize - 1 - j) * probeSampleSize) < 0)
                {
                }
                else
                {
                    //Color32 pixel = new Color32((byte)(i * 255.0f / probeSampleSize), (byte)(j * 255.0f / probeSampleSize), 0, 255);//
                    Color32 pixel = pixels[(i + (probeSampleSize - 1 - j) * probeSampleSize)]; // Generating samples
                    // We have angle of incidence, here we calculate the angle from environment.
                    outDirection = Vector3.Reflect(ray.direction, hit.normal);

                    // Point on cube is calculated by taking respective vector on iteration to scale into set of
                    // weighted distance.
                    Vector3 pointOnCube = new Vector3(outDirection.x / Mathf.Max(Mathf.Abs(outDirection.x), Mathf.Abs(outDirection.y), Mathf.Abs(outDirection.z)),
                                                      outDirection.y / Mathf.Max(Mathf.Abs(outDirection.x), Mathf.Abs(outDirection.y), Mathf.Abs(outDirection.z)),
                                                      outDirection.z / Mathf.Max(Mathf.Abs(outDirection.x), Mathf.Abs(outDirection.y), Mathf.Abs(outDirection.z)));
                    dev = calcDeviations(-outDirection, transform.position - sampleCamera.transform.position);
                    //if (dev > 120.0f)
                    //continue;
                    if (pointOnCube.x >= .99f)
                    {
                        face = CubemapFace.PositiveX;
                        u    = (-(pointOnCube.z) + 1) / 2;
                        v    = ((pointOnCube.y) + 1) / 2;
                    }
                    else if (pointOnCube.x <= -.99f)
                    {
                        face = CubemapFace.NegativeX;
                        u    = ((pointOnCube.z) + 1) / 2;
                        v    = ((pointOnCube.y) + 1) / 2;
                    }
                    else if (pointOnCube.y >= .99f)
                    {
                        face = CubemapFace.PositiveY;
                        u    = ((pointOnCube.x) + 1) / 2;
                        v    = (-(pointOnCube.z) + 1) / 2;
                    }
                    else if (pointOnCube.y <= -.99f)
                    {
                        face = CubemapFace.NegativeY;
                        u    = ((pointOnCube.x) + 1) / 2;
                        v    = ((pointOnCube.z) + 1) / 2;
                    }
                    else if (pointOnCube.z >= .99f)
                    {
                        face = CubemapFace.PositiveZ;
                        u    = ((pointOnCube.x) + 1) / 2;
                        v    = ((pointOnCube.y) + 1) / 2;
                    }
                    else if (pointOnCube.z <= -.99f)
                    {
                        face = CubemapFace.NegativeZ;
                        u    = (-(pointOnCube.x) + 1) / 2;
                        v    = ((pointOnCube.y) + 1) / 2;
                    }
                    else
                    {
                        face = CubemapFace.PositiveX;
                        u    = 0;
                        v    = 0;
                    }
                    Samples.singleSampleObject sample = new Samples.singleSampleObject();
                    //text = text + dev + "\n";
                    ////pixel = Color.Lerp(pixel, Color.black, dev/150.0f);
                    //pixel.r = (byte)((1 - (dev / 180.0f)) * pixel.r);
                    //pixel.g = (byte)((1 - (dev / 180.0f)) * pixel.g);
                    //pixel.b = (byte)((1 - (dev / 180.0f)) * pixel.b);

                    //pixel = new Color32();
                    pixel.a = (byte)((1 - ((dev / 180.0f) * (dev / 180.0f))) * 255);
                    //pixel.r = (byte)(i * 255.0f / probeSampleSize);
                    //pixel.g = (byte)(j * 255.0f / probeSampleSize);
                    //pixel.b = 0;
                    //sample.alpha = (short)((1 - (dev / 180.0f)) * 255);
                    sample.face = face;
                    sample.u    = u;
                    sample.v    = v;
                    sample.pix  = pixel;
                    samples.Add(sample);
                    numHitRays++;
                    counter++;
                }
            }
        }
        //writeToFile("./rawData.txt", text, false);
        return;
    }