Beispiel #1
0
        public void SetupSphericalProjectionFilter(int N_theta, int N_phi, CameraFrustum cameraFrustum)
        {
            sphericalWidthRes  = N_theta;
            sphericalHeightRes = N_phi;
            frustum            = cameraFrustum;

            filterCoordinates             = SphericalPixelCoordinates(N_theta, N_phi);
            SphericalProjectionFilterMask = SphericalPixelCoordinatesImage();
        }
        /// <summary>
        /// Checks for when the given mesh render is in the fustrum of the camera
        /// Returns true if in view.
        /// </summary>
        private bool IsMeshInFrustum(GLContext control, GenericPickableMesh mesh)
        {
            if (StayInFustrum)
            {
                return(true);
            }

            var msh = (BfresMeshAsset)mesh;

            msh.BoundingNode.UpdateTransform(Transform.TransformMatrix);
            return(CameraFrustum.CheckIntersection(control.Camera, msh.BoundingNode));
        }
        void Start()
        {
            // Setting User information

            WidthRes /= NrOfCameras;

            float lidarVerticalAngle = VerticalAngle;

            HeightRes     = (int)(WidthRes * Mathf.Tan(lidarVerticalAngle * Mathf.Deg2Rad / 2) / Mathf.Sin(Mathf.PI / NrOfCameras));
            VerticalAngle = Mathf.Rad2Deg * 2 * Mathf.Atan(Mathf.Tan(lidarVerticalAngle * Mathf.Deg2Rad / 2) / Mathf.Cos(Mathf.PI / NrOfCameras));

            NumberOfDepthPixels = (uint)WidthRes * (uint)HeightRes * (uint)NrOfCameras;
            NumberOfLidarPoints = (uint)NrOfLasers * (uint)LidarHorisontalRes * (uint)NrOfCameras;

            // Settup Game objects

            pointCloud = GetComponent <PointCloudManager>();
            pointCloud.SetupPointCloud((int)NumberOfLidarPoints);

            var frustum = new CameraFrustum(WidthRes, MaxDistance, MinDistance, 2 * Mathf.PI / NrOfCameras, lidarVerticalAngle * Mathf.Deg2Rad);

            depthCameras = new DepthCameras(NrOfCameras, frustum, this.transform, lidarShader, "CSMain");
            lidarCameras = depthCameras.cameras;

            projectionFilter = GetComponent <SphericalProjectionFilter>();
            projectionFilter.SetupSphericalProjectionFilter(LidarHorisontalRes, NrOfLasers, frustum);
            pixelCoordinatesBuffer = projectionFilter.filterCoordinates.buffer;

            // Setting up Compute Buffers

            kernelHandle = lidarShader.FindKernel("CSMain");

            lidarShader.SetBuffer(kernelHandle, "sphericalPixelCoordinates", pixelCoordinatesBuffer);
            lidarShader.SetInt("N_theta", LidarHorisontalRes);
            lidarShader.SetInt("N_phi", NrOfLasers);
            lidarShader.SetFloat("rayDropProbability", rayDropProbability);

            UnifiedArray <uint> RandomStateVector = new UnifiedArray <uint>(NrOfCameras * NrOfLasers * LidarHorisontalRes, sizeof(float), "_state_xorshift");

            RandomStateVector.SetBuffer(lidarShader, "CSMain");
            RandomStateVector.SetBuffer(lidarShader, "RNG_Initialize");
            RandomStateVector.SynchUpdate(lidarShader, "RNG_Initialize");

            particleUnifiedArray = new UnifiedArray <Vector3>(NrOfCameras * NrOfLasers * LidarHorisontalRes, sizeof(float) * 3, "lines");
            particleUnifiedArray.SetBuffer(lidarShader, "CSMain");

            lidarDataByte = new UnifiedArray <byte>(NrOfCameras * NrOfLasers * LidarHorisontalRes, sizeof(float) * 6, "LidarData");
            lidarDataByte.SetBuffer(lidarShader, "CSMain");
        }
Beispiel #4
0
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     // Set background color and enable depth testing
     GLES20.GlClearColor(1f, 1f, 1f, 1.0f);
     GLES20.GlEnable(GLES20.GlDepthTest);
     resetModelMatCalculator();
     mCameraFrustum        = new CameraFrustum();
     mFloorGrid            = new Grid();
     mCameraFrustumAndAxis = new CameraFrustumAndAxis();
     mTrajectory           = new Trajectory(3);
     // Construct the initial view matrix
     Matrix.SetIdentityM(mViewMatrix, 0);
     Matrix.SetLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
     mCameraFrustumAndAxis.ModelMatrix = ModelMatCalculator.ModelMatrix;
 }
Beispiel #5
0
        private void CameraSetup()
        {
            CameraFrustum frustums = new CameraFrustum(PixelWidth, PixelHeight, FarPlane, NearPlane, focalLengthMilliMeters, pixelSizeInMicroMeters);

            _cameraBuffer = new RenderTexture(PixelWidth / ImageCrop, PixelHeight / ImageCrop, (int)DepthBufferPrecision, renderTextureFormat, 0);

            camera = gameObject.GetComponent <Camera>();
            camera.usePhysicalProperties = false;
            camera.targetTexture         = _cameraBuffer;

            camera.aspect = frustums._aspectRatio;                          //Mathf.Tan(Mathf.PI / numbers) / Mathf.Tan(frustums._verticalAngle / 2.0f);
            Debug.Log("Aspect Ratio RGB: " + frustums._aspectRatio.ToString());
            camera.fieldOfView   = frustums._verticalAngle * Mathf.Rad2Deg; //Camera.HorizontalToVerticalFieldOfView(360.0f / numbers, cam.aspect);
            camera.farClipPlane  = frustums._farPlane;
            camera.nearClipPlane = frustums._nearPlane;
            //camera.enabled = false;
        }
        public void DistanceAndFrustumCulling(CameraFrustum frustum)
        {
            var viewPoint = frustum.ViewPoint;
            var halfSize  = _clusterDimensions / 2;

            var minVisiblePosX = viewPoint.x - _cullingDistance;
            var minVisiblePosZ = viewPoint.z - _cullingDistance;
            var maxVisiblePosX = minVisiblePosX + _cullingDistance * 2;
            var maxVisiblePosZ = minVisiblePosZ + _cullingDistance * 2;

            int curVisibleStartX = Mathf.FloorToInt(minVisiblePosX / _clusterSize) + halfSize;
            int curVisibleStartZ = Mathf.FloorToInt(minVisiblePosZ / _clusterSize) + halfSize;
            int curVisibleEndX   = Mathf.CeilToInt(maxVisiblePosX / _clusterSize) + halfSize;
            int curVisibleEndZ   = Mathf.CeilToInt(maxVisiblePosZ / _clusterSize) + halfSize;

            bool enoughRoom = true;

            for (int i = _lastVisibleStartX; i < _lastVisibleEndX; ++i)
            {
                for (int j = _lastVisibleStartZ; j < _lastVisibleEndZ; ++j)
                {
                    if (i >= 0 && i < _clusterDimensions && j >= 0 && j < _clusterDimensions)
                    {
                        var cluster = _nodeClusters[i, j];
                        if (cluster == null)
                        {
                            continue;
                        }

                        var node = cluster.DistanceAndFrustumCulling(viewPoint, enoughRoom);
                        if (node != null && enoughRoom)
                        {
                            _curInstantiatingNode = node;
                            enoughRoom            = false;
                        }
                    }
                }
            }

            if (_lastVisibleStartX != curVisibleStartX || _lastVisibleEndX != curVisibleEndX ||
                _lastVisibleStartZ != curVisibleStartZ || _lastVisibleEndZ != curVisibleEndZ)
            {
                for (int i = curVisibleStartX; i < curVisibleEndX; ++i)
                {
                    for (int j = curVisibleStartZ; j < curVisibleEndZ; ++j)
                    {
                        if (i >= 0 && i < _clusterDimensions && j >= 0 && j < _clusterDimensions)
                        {
                            var cluster = _nodeClusters[i, j];
                            if (cluster == null)
                            {
                                continue;
                            }

                            var node = cluster.DistanceAndFrustumCulling(viewPoint, enoughRoom);
                            if (node != null && enoughRoom)
                            {
                                _curInstantiatingNode = node;
                                enoughRoom            = false;
                            }
                        }
                    }
                }

                _lastVisibleStartX = curVisibleStartX;
                _lastVisibleEndX   = curVisibleEndX;
                _lastVisibleStartZ = curVisibleStartZ;
                _lastVisibleEndZ   = curVisibleEndZ;
            }

            if (!enoughRoom)
            {
                _curInstantiatingNode.SetInstantiating();
                _curInstantiatingNode.Node.BuildBuffer(_curInstantiatingNode.HeightBuffer());
            }

            for (int i = 0; i < _cachedNodesActualLength; ++i)
            {
                var node = _cachedNodes[i];
                if (node != null && node.IsInstantiated)
                {
                    node.IsActive = frustum.IsNodeVisible(node);
                }
            }
        }
Beispiel #7
0
 // Use this for initialization
 void Start()
 {
     camPivot = GameObject.Find("camPivot");
     _cameraFrustrum = GameObject.Find("mainCam").GetComponent<CameraFrustum>();
 }
Beispiel #8
0
    // Use this for initialization
    void Start()
    {
        if(usefullData.lowTechnologie)
        {
        _cameraFrustrum = GameObject.Find("mainCam").GetComponent<CameraFrustum>();
        Mesh mesh = GetComponent<MeshFilter> ().mesh;
        Vector3[] vertices = mesh.vertices;
        Vector2[] uvs = new Vector2[vertices.Length];
        int i = 0;
        while (i < uvs.Length) {
            uvs[i] = new Vector2 (vertices[i].x, vertices[i].z);
            //Debug.Log("mask Start : "+uvs[i]);
            i++;
        }
        mesh.uv = uvs;

        if(textureApply!=null)
        {
            textureApply.wrapMode = TextureWrapMode.Repeat;
            GetComponent<Renderer>().material.SetTexture ("_MainTex", textureApply);
            _guiText = GameObject.Find ("backgroundImage").GetComponent<GUITexture>();
        }
        mc = GameObject.Find("maskCam").GetComponent<MaskCreator>();
        }
        else
        {
            string originalShaderName = transform.GetComponent<Renderer>().material.shader.name;
            if (originalShaderName.Contains("inverse"))
            {
                Shader shad = (Shader)Resources.Load("shaders/"+"Pointcube_maskInverse");
                transform.GetComponent<Renderer>().material.shader = shad;
            }
            else
            {
                Shader shad = (Shader)Resources.Load("shaders/"+"Pointcube_mask");
                transform.GetComponent<Renderer>().material.shader = shad;
            }
        }
    }
Beispiel #9
0
    //-----------------------------------------------------
    // Use this for initialization
    void Start()
    {
        // if(m_grassSky == null)      Debug.LogError(DEBUGTAG+"Grass Sky"+PC.MISSING_REF);
        if(m_grassGround == null)   Debug.LogError(DEBUGTAG+"Grass Ground"+PC.MISSING_REF);

        cam = Camera.main;
        startHeight = cam.transform.position.y;
        mainNode = GameObject.Find("MainNode");
        mainScene = GameObject.Find("MainScene");
        grid = GameObject.Find("grid");
        avatar = GameObject.Find("_avatar");
        _cameraFrustrum = GameObject.Find("mainCam").GetComponent<CameraFrustum>();

        _iosShadows = GameObject.Find("iosShadows");

        sceneCenter = grid.transform.position;
        //		dist = Mathf.Abs(cam.transform.localPosition.z)/2;

        init();
    }