Ejemplo n.º 1
0
        public static Color GetColorBilinear(GTextureNativeDataDescriptor <Color32> tex, ref Vector2 uv)
        {
            Vector2 pixelCoord = new Vector2(
                Mathf.Lerp(0, tex.width - 1, uv.x),
                Mathf.Lerp(0, tex.height - 1, uv.y));
            //apply a bilinear filter
            int xFloor = Mathf.FloorToInt(pixelCoord.x);
            int xCeil  = Mathf.CeilToInt(pixelCoord.x);
            int yFloor = Mathf.FloorToInt(pixelCoord.y);
            int yCeil  = Mathf.CeilToInt(pixelCoord.y);

            Color f00 = tex.data[To1DIndex(ref xFloor, ref yFloor, ref tex.width)];
            Color f01 = tex.data[To1DIndex(ref xFloor, ref yCeil, ref tex.width)];
            Color f10 = tex.data[To1DIndex(ref xCeil, ref yFloor, ref tex.width)];
            Color f11 = tex.data[To1DIndex(ref xCeil, ref yCeil, ref tex.width)];

            Vector2 unitCoord = new Vector2(
                pixelCoord.x - xFloor,
                pixelCoord.y - yFloor);

            Color color =
                f00 * (1 - unitCoord.x) * (1 - unitCoord.y) +
                f01 * (1 - unitCoord.x) * unitCoord.y +
                f10 * unitCoord.x * (1 - unitCoord.y) +
                f11 * unitCoord.x * unitCoord.y;

            return(color);
        }
Ejemplo n.º 2
0
        internal GCreateVertexJob GetCreateVertexJob(
            int meshBaseResolution,
            int meshResolution,
            int lod,
            int displacementSeed,
            float displacementStrength,
            bool smoothNormal,
            bool useSmoothNormalMask,
            GTextureNativeDataDescriptor <Color32> maskMap,
            GAlbedoToVertexColorMode albedoToVertexColor,
            GTextureNativeDataDescriptor <Color32> albedoMap,
            GTextureNativeDataDescriptor <Color32>[] hm)
        {
            InitMeshDataNativeContainers(albedoToVertexColor);

            Vector3          terrainSize = Terrain.TerrainData.Geometry.Size;
            Rect             uvRect      = GetUvRange();
            float            texelSize   = 1.0f / Terrain.TerrainData.Geometry.HeightMapResolution;
            GCreateVertexJob job         = new GCreateVertexJob()
            {
                nodes         = subdivNodeNativeArray,
                creationState = subdivNodeCreationState,

                hmC  = hm[4],
                hmL  = hm[3],
                hmT  = hm[7],
                hmR  = hm[5],
                hmB  = hm[1],
                hmBL = hm[0],
                hmTL = hm[6],
                hmTR = hm[8],
                hmBR = hm[2],

                vertices  = vertexNativeArray,
                uvs       = uvsNativeArray,
                normals   = normalsNativeArray,
                triangles = trianglesNativeArray,
                colors    = vertexColorsNativeArray,
                metadata  = generationMetadata,

                meshBaseResolution = meshBaseResolution,
                meshResolution     = meshResolution,
                lod = lod,
                displacementSeed     = displacementSeed,
                displacementStrength = displacementStrength,
                smoothNormal         = smoothNormal,
                useSmoothNormalMask  = useSmoothNormalMask,

                albedoToVertexColorMode = albedoToVertexColor,
                albedoMap = albedoMap,
                maskMap   = maskMap,

                terrainSize        = terrainSize,
                chunkUvRect        = uvRect,
                chunkLocalPosition = transform.localPosition,
                texelSize          = texelSize
            };

            return(job);
        }
        public static Color GetColorPoint(GTextureNativeDataDescriptor <Color32> tex, Vector2 uv)
        {
            Vector2 pixelCoord = new Vector2(
                Mathf.Lerp(0, tex.width - 1, uv.x),
                Mathf.Lerp(0, tex.height - 1, uv.y));

            int xFloor = Mathf.FloorToInt(pixelCoord.x);
            int yFloor = Mathf.FloorToInt(pixelCoord.y);

            return(tex.data[To1DIndex(ref xFloor, ref yFloor, ref tex.width)]);
        }
Ejemplo n.º 4
0
        internal GSplitBaseTreeForDynamicPolygonJob GetSplitBaseTreeForDynamicPolygonJob(
            int meshBaseResolution, int meshResolution, int lod,
            GTextureNativeDataDescriptor <Color32> subdivMap)
        {
            Rect uvRect = GetUvRange();
            GSplitBaseTreeForDynamicPolygonJob job = new GSplitBaseTreeForDynamicPolygonJob()
            {
                baseTree       = subdivNodeNativeArray,
                creationState  = subdivNodeCreationState,
                vertexMarker   = vertexMarkerNativeArray,
                subdivMap      = subdivMap,
                baseResolution = meshBaseResolution,
                resolution     = meshResolution,
                lod            = lod,
                uvRect         = uvRect
            };

            return(job);
        }
Ejemplo n.º 5
0
 public static Color GetColorBilinear(GTextureNativeDataDescriptor <Color32> tex, Vector2 uv)
 {
     return(GetColorBilinear(tex, ref uv));
 }