예제 #1
0
        virtual public Mesh[] GetTransformedMeshes(Camera camera, out Matrix4x4 matrix, int vertexCount, bool volume)
        {
            if (camera != null)
            {
                matrix = GetMatrix(camera);
            }
            else
            {
                matrix = Matrix4x4.identity;
            }

            CachedMeshSet cachedMeshSet;
            int           hash = vertexCount;

            if (volume)
            {
                hash = -hash;
            }

            if (!cache.TryGetValue(hash, out cachedMeshSet))
            {
                cache[hash] = cachedMeshSet = new CachedMeshSet(CreateMeshes(vertexCount, volume));
            }
            else
            {
                cachedMeshSet.Update();
            }

            return(cachedMeshSet.meshes);
        }
예제 #2
0
        override public Mesh[] GetTransformedMeshes(Camera camera, out Matrix4x4 matrix, int vertexCount, bool volume)
        {
            int pixelWidth  = camera.pixelWidth;
            int pixelHeight = camera.pixelHeight;

            CachedMeshSet cachedMeshSet;
            int           hash           = pixelHeight | (pixelWidth << 16);
            Vector3       cameraPosition = camera.transform.position;

            matrix     = Matrix4x4.identity;
            matrix.m03 = cameraPosition.x;
            matrix.m13 = 0.0f;
            matrix.m23 = cameraPosition.z;

            float verticesPerPixel = (float)vertexCount / (pixelWidth * pixelHeight);

            water.WaterMaterial.SetMatrix("_InvViewMatrix", camera.cameraToWorldMatrix);
            water.WaterBackMaterial.SetMatrix("_InvViewMatrix", camera.cameraToWorldMatrix);

            if (!cache.TryGetValue(hash, out cachedMeshSet))
            {
                cache[hash] = cachedMeshSet = new CachedMeshSet(CreateMeshes(Mathf.RoundToInt(pixelWidth * verticesPerPixel), Mathf.RoundToInt(pixelHeight * verticesPerPixel)));
            }

            return(cachedMeshSet.meshes);
        }