当前位置: 首页>>代码示例>>C#>>正文


C# Cubemap.GetPixels方法代码示例

本文整理汇总了C#中UnityEngine.Cubemap.GetPixels方法的典型用法代码示例。如果您正苦于以下问题:C# Cubemap.GetPixels方法的具体用法?C# Cubemap.GetPixels怎么用?C# Cubemap.GetPixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Cubemap的用法示例。


在下文中一共展示了Cubemap.GetPixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyTextureCube

        private void CopyTextureCube(string texturePath, Cubemap cubemap, BabylonTexture babylonTexture)
        {
            if (!babylonScene.AddTextureCube(texturePath))
            {
                return;
            }

            try
            {
                foreach (CubemapFace face in Enum.GetValues(typeof(CubemapFace)))
                {
                    var faceTexturePath = Path.Combine(babylonScene.OutputPath, Path.GetFileNameWithoutExtension(texturePath));

                    switch (face)
                    {
                        case CubemapFace.PositiveX:
                            faceTexturePath += "_px.jpg";
                            break;
                        case CubemapFace.NegativeX:
                            faceTexturePath += "_nx.jpg";
                            break;
                        case CubemapFace.PositiveY:
                            faceTexturePath += "_py.jpg";
                            break;
                        case CubemapFace.NegativeY:
                            faceTexturePath += "_ny.jpg";
                            break;
                        case CubemapFace.PositiveZ:
                            faceTexturePath += "_pz.jpg";
                            break;
                        case CubemapFace.NegativeZ:
                            faceTexturePath += "_nz.jpg";
                            break;
                        default:
                            continue;
                    }

                    var tempTexture = new Texture2D(cubemap.width, cubemap.height, TextureFormat.RGB24, false);

                    tempTexture.SetPixels(cubemap.GetPixels(face));
                    tempTexture.Apply();

                    // Flip faces in cube texture.
                    tempTexture = FlipTexture(tempTexture);

                    File.WriteAllBytes(faceTexturePath, tempTexture.EncodeToJPG());
                }

            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }

            var textureName = Path.GetFileNameWithoutExtension(texturePath);
            babylonTexture.name = textureName;
            babylonTexture.isCube = true;
            babylonTexture.level = exportationOptions.ReflectionDefaultLevel;
            babylonTexture.coordinatesMode = 3;
        }
开发者ID:CreateAppAdmin,项目名称:Babylon.js,代码行数:60,代码来源:SceneBuilder.Materials.cs

示例2: CreateSubMips

		public static void CreateSubMips(Cubemap cube) {
			AssetDatabase.StartAssetEditing();
			int faceSize = cube.width;
			string cubePath = AssetDatabase.GetAssetPath(cube);

			//load all sub-assets
			UnityEngine.Object[] mips = AssetDatabase.LoadAllAssetRepresentationsAtPath(cubePath);
			if(mips != null) {
				for(int i=0; i<mips.Length; ++i) {
					if( mips[i] != null && AssetDatabase.IsSubAsset(mips[i]) ) UnityEngine.Object.DestroyImmediate(mips[i], true);
				}
			}
			AssetDatabase.Refresh();

			// skip mip level 0, its in the cubemap itself
			faceSize = faceSize >> 1;
			for( int mip = 1; faceSize > 0; ++mip ) {
				// extract mipmap faces from a cubemap and add them as textures in the sub image
				Texture2D tex = new Texture2D(faceSize, faceSize*6,TextureFormat.ARGB32,false);
				tex.name = "mip"+mip;
				for( int face = 0; face<6; ++face ) {
					tex.SetPixels(0, face*faceSize, faceSize, faceSize, cube.GetPixels((CubemapFace)face,mip));
				}
				tex.Apply();
				AssetDatabase.AddObjectToAsset(tex, cubePath);
				AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(tex));
				faceSize = faceSize >> 1;
			}
			AssetDatabase.StopAssetEditing();
			AssetDatabase.Refresh();
		}
开发者ID:keyward,项目名称:EnemyOfMyEnemy,代码行数:31,代码来源:CubeMipProcessor.cs

示例3: GetPixels

    private static Color[] GetPixels(Cubemap c, CubemapFace f)
    {
        var pixels = c.GetPixels(f);
        var halfH  = c.height / 2;

        for (var y = 0; y < halfH; y++)
        {
            var o = c.width * y;
            var n = c.width * (c.height - y - 1);

            for (var x = 0; x < c.width; x++)
            {
                var a = pixels[o + x];
                var b = pixels[n + x];

                pixels[o + x] = b;
                pixels[n + x] = a;
            }
        }

        return pixels;
    }
开发者ID:JasonSlingsCode,项目名称:Mindjammer,代码行数:22,代码来源:SgtExtractCubemap.cs

示例4: FilterCubefacesBF

// brute force: no look up table used

    void FilterCubefacesBF (Cubemap RadianceCubeMap, int mipLevel, float a_FilterConeAngle, float a_SpecularPower)
    {
	    // Read the first CubeFace
	    Color[] InputCubeFacePixels = RadianceCubeMap.GetPixels(CubemapFace.PositiveX, mipLevel);
	    // Get its dimensions
	    int faceLength = InputCubeFacePixels.Length;
	    int a_Size = (int)Mathf.Sqrt(faceLength);
	    // Create new array for all Faces
	    Color[] PixelsOfAllFaces = new Color[faceLength * 6];
	    // Copy first face
	    InputCubeFacePixels.CopyTo(PixelsOfAllFaces, 0);
	    // Copy all other Faces
	    for (int readFace = 1; readFace < 6; readFace++ ) {
		    InputCubeFacePixels = RadianceCubeMap.GetPixels((CubemapFace)readFace, mipLevel);
		    InputCubeFacePixels.CopyTo(PixelsOfAllFaces, faceLength * readFace);
	    }
	    InputCubeFacePixels = null;

	    // declare jagged output array and init its child arrays
	    Color[][] OutputCubeFacePixels = new Color[6][];
	    OutputCubeFacePixels[0] = new Color[faceLength];
	    OutputCubeFacePixels[1] = new Color[faceLength];
	    OutputCubeFacePixels[2] = new Color[faceLength];
	    OutputCubeFacePixels[3] = new Color[faceLength];
	    OutputCubeFacePixels[4] = new Color[faceLength];
	    OutputCubeFacePixels[5] = new Color[faceLength];


	    // FilterCubeSurfaces
	    float srcTexelAngle;
        float dotProdThresh;
        int filterSize;
	    //angle about center tap to define filter cone
	    float filterAngle;
	    //min angle a src texel can cover (in degrees)
	    srcTexelAngle = (180.0f / CP_PI) * Mathf.Atan2(1.0f, (float)a_Size);  
	    //filter angle is 1/2 the cone angle
        filterAngle = a_FilterConeAngle / 2.0f;
        //ensure filter angle is larger than a texel
        if(filterAngle < srcTexelAngle)
        {
            filterAngle = srcTexelAngle;    
        }
        //ensure filter cone is always smaller than the hemisphere
        if(filterAngle > 90.0f)
        {
            filterAngle = 90.0f;
        }

	    // The maximum number of texels in 1D the filter cone angle will cover
	    // Used to determine bounding box size for filter extents
	    filterSize = (int)Mathf.Ceil(filterAngle / srcTexelAngle);
	    // Ensure conservative region always covers at least one texel
        if(filterSize < 1)
        {
            filterSize = 1;
        }

	    // dotProdThresh threshold based on cone angle to determine whether or not taps 
	    // Reside within the cone angle
	    dotProdThresh = Mathf.Cos( (CP_PI / 180.0f) * filterAngle );

	    // Process required faces
	    for (int a_FaceIdx = 0; a_FaceIdx < 6; a_FaceIdx++)
	    {
		    // Iterate over dst cube map face texel
		    for (int a_V  = 0; a_V < a_Size; a_V++)
		    {
			    for (int a_U = 0; a_U < a_Size; a_U++)
			    {
				    Vector4 Sample = new Vector4();
				    Color tempCol = new Color();
				
				    // get center tap direction
				    Vector3 centerTapDir = TexelToVect(a_FaceIdx, (float)a_U, (float)a_V, a_Size);

				    //--------------------------------------------------------------------------------------
				    //	ProcessFilterExtents 

				    float weightAccum = 0.0f;

				    // Iterate over cubefaces
				    for(int iFaceIdx = 0; iFaceIdx < 6; iFaceIdx++ )
				    {
					    for(int v = 0; v < a_Size; v++)
					    {
						    for(int u = 0; u < a_Size; u++)
						    {
							    // CP_FILTER_TYPE_COSINE_POWER
							    // Pointer to direction in cube map associated with texel
							    Vector3 texelVect = TexelToVect(iFaceIdx, (float)u, (float)v, a_Size);
							    // Check dot product to see if texel is within cone
							    float tapDotProd = Vector3.Dot(texelVect, centerTapDir);


							    float weight = 0.0f;
							    if( tapDotProd >= dotProdThresh && tapDotProd > 0.0f )
							    {
//.........这里部分代码省略.........
开发者ID:Backman,项目名称:Hellbound,代码行数:101,代码来源:LuxCubeProcessor.cs

示例5: ConvolveIrradianceEnvironmentMap

    //--------------------------------------------------------------------------------------
    // Irridiance Convolution based on SH

    void ConvolveIrradianceEnvironmentMap(Cubemap irrCubeMap)
    {
	    int a_Size = irrCubeMap.width;

	    Vector4[] m_NormCubeMapArray = new Vector4[a_Size*a_Size*6];
	    BuildNormalizerSolidAngleArray(a_Size, ref m_NormCubeMapArray);

	    //This is a custom implementation of D3DXSHProjectCubeMap to avoid to deal with LPDIRECT3DSURFACE9 pointer
	    //Use Sh order 2 for a total of 9 coefficient as describe in http://www.cs.berkeley.edu/~ravir/papers/envmap/
	    //accumulators are 64-bit floats in order to have the precision needed 
	    //over a summation of a large number of pixels 
	    double[] SHr = new double[25]; // NUM_SH_COEFFICIENT
	    double[] SHg = new double[25];
	    double[] SHb = new double[25];
	    double[] SHdir = new double[25];

	    double weightAccum = 0.0;
	    double weight = 0.0;

	    int startFacePtr = 0;

	    for (int iFaceIdx = 0; iFaceIdx < 6; iFaceIdx++) {

		    // read pixels of m_NormCubeMap
		    //var m_NormCubeMap_pixels  = new Color[m_NormCubeMap.width*m_NormCubeMap.height];
		    //m_NormCubeMap_pixels = m_NormCubeMap.GetPixels((CubemapFace)iFaceIdx);

		    // Pointer to the start of the given face in m_NormCubeMapArray 
		    startFacePtr = a_Size*a_Size*iFaceIdx;

		    // read all pixels of irrCubeMap
            var cubeMap_pixels = new Color[irrCubeMap.width * irrCubeMap.height];
		    cubeMap_pixels = irrCubeMap.GetPixels((CubemapFace)iFaceIdx);


			    for (int y = 0; y < a_Size; y++) {
				    for (int x = 0; x < a_Size; x++) {

					    // read normalCube single pixel
					    Vector4 m_NormCubeMap_pixel = m_NormCubeMapArray[startFacePtr + y*a_Size + x];

					    // read originalCube single pixel
					    Color cubeMap_pixel = cubeMap_pixels[y*a_Size + x];

					    // solid angle stored in 4th channel of normalizer/solid angle cube map
					    weight = m_NormCubeMap_pixel[3];
					    //weight = TexelCoordSolidAngle(iFaceIdx, (float)x, (float)y, a_Size);

					    // pointer to direction and solid angle in cube map associated with texel
					    Vector3 texelVect;
					    texelVect.x = m_NormCubeMap_pixel[0];
					    texelVect.y = m_NormCubeMap_pixel[1];
					    texelVect.z = m_NormCubeMap_pixel[2];
					    //texelVect = TexelToVect(iFaceIdx, (float)x, (float)y, a_Size);
	
					    EvalSHBasis(texelVect, ref SHdir);

					    // read original colors and convert to float64
					    double R = cubeMap_pixel[0];
					    double G = cubeMap_pixel[1];
					    double B = cubeMap_pixel[2];

					    for (int i = 0; i < 25; i++)
					    {
						    SHr[i] += R * SHdir[i] * weight;
						    SHg[i] += G * SHdir[i] * weight;
						    SHb[i] += B * SHdir[i] * weight;
					    }
					    weightAccum += weight;
			    }
		    }
	    }
	    // Normalization - The sum of solid angle should be equal to the solid angle of the sphere (4 PI), so
	    // Normalize in order our weightAccum exactly match 4 PI.
	    for (int i = 0; i < 25; ++i)
	    {
		    SHr[i] *= 4.0 * CP_PI / weightAccum;
		    SHg[i] *= 4.0 * CP_PI / weightAccum;
		    SHb[i] *= 4.0 * CP_PI / weightAccum;
	    }

	    // Second step - Generate cubemap from SH coefficient

	    // Normalized vectors per cubeface and per-texel solid angle
	    // Why do we do it a 2nd time????
	    BuildNormalizerSolidAngleArray(a_Size, ref m_NormCubeMapArray);

	    for (int iFaceIdx = 0; iFaceIdx < 6; iFaceIdx++) {

		    // Pointer to the start of the given face in m_NormCubeMapArray 
		    startFacePtr = a_Size*a_Size*iFaceIdx;

		    for (int y = 0; y < a_Size; y++) {
			    for (int x = 0; x < a_Size; x++) {
				    // read normalCube pixel
				    Vector4 m_NormCubeMap_pixel = m_NormCubeMapArray[startFacePtr + y*a_Size + x];

//.........这里部分代码省略.........
开发者ID:Backman,项目名称:Hellbound,代码行数:101,代码来源:LuxCubeProcessor.cs

示例6: RenderCube

    public IEnumerator RenderCube(GameObject lightShapeObjTemp, GameObject lightShapeObjTempAlt, GameObject groundShapeObjTemp, Material gMat, Material lsMat, Material alsMat)
    {
        yield return new WaitForEndOfFrame();
        var cubeCamera = new GameObject( "CubemapCamera", typeof(Camera) ) as GameObject;
        cubeCamera.hideFlags = HideFlags.HideInHierarchy;
        var cubeCam = cubeCamera.GetComponent("Camera") as Camera;
        var tempFull = new Cubemap (LightShapeProbe.LightShapeManager.CubeMapSize, TextureFormat.RGB24, LightShapeProbe.LightShapeManager.hasMips) as Cubemap;
        yield return new WaitForEndOfFrame();
        cubeCam.nearClipPlane = 0.001f;
        cubeCam.aspect = 1.0f;

        if(LightShapeProbe.LightShapeManager.worldCamera)
        {
            if(!RenderSettings.skybox)
            {
                if(!LightShapeProbe.overrideCameraColor)
                {
                    cubeCam.backgroundColor = LightShapeProbe.LightShapeManager.worldCamera.backgroundColor;
                }

                if(LightShapeProbe.overrideCameraColor)
                {
                    cubeCam.backgroundColor = LightShapeProbe.BGColor;
                }
            }

                if(RenderSettings.skybox)
                {
                    if(!LightShapeProbe.overrideCameraColor)
                    {
                        cubeCam.clearFlags = CameraClearFlags.Skybox;
                    }
                    if(LightShapeProbe.overrideCameraColor)
                    {
                        cubeCam.clearFlags = CameraClearFlags.SolidColor;
                        cubeCam.backgroundColor = LightShapeProbe.BGColor;
                    }
                }
        }

        cubeCam.fov = 90;
        cubeCam.cullingMask = 1 << 0;
        cubeCamera.transform.position = transform.position;

        cubeCamera.transform.eulerAngles = new Vector3(0, 90, 0);
        Texture2D tex = new Texture2D (LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize, TextureFormat.RGB24, false);

        yield return new WaitForEndOfFrame();
        tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
        yield return new WaitForEndOfFrame();
        tex.Apply ();
        CubeMapColors = tex.GetPixels();

        Color [,] bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors[i];
        }

        Color [,] flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
            {
                flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
        }

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
        }

        tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveX);
        tempFull.Apply();

        cubeCamera.transform.eulerAngles = new Vector3(0, 270, 0);
        yield return new WaitForEndOfFrame();
        tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
        yield return new WaitForEndOfFrame();
        tex.Apply ();
        CubeMapColors = tex.GetPixels();

        bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors[i];
        }
//.........这里部分代码省略.........
开发者ID:ifty420,项目名称:Traffic-Racer-2-3d,代码行数:101,代码来源:AltMethod.cs

示例7: Convert

    ///<summary>
    /// Convert an environment map into an array of SH coefficients.
    ///</summary>
    static float[] Convert(Cubemap cubemap)
    {
        // Initialize arrays.
        double[] SHr = new double[NUM_SH_COEFFICIENT];
        double[] SHg = new double[NUM_SH_COEFFICIENT];
        double[] SHb = new double[NUM_SH_COEFFICIENT];
        double[] SHdir = new double[NUM_SH_COEFFICIENT];
        Vector4[, ,] CubeInfo = new Vector4[6, cubemap.width, cubemap.height];

        // Loop all texels of a cubemap to calculate every texel's direction and area.
        // Loop 6 faces.
        for (int CubeFace = 0; CubeFace < 6; CubeFace++)
        {
            // Loop every texel of a face.
            for (int v = 0; v < cubemap.height; v++)
                for (int u = 0; u < cubemap.width; u++)
            {
                // Compute direction.
                Vector3 vect = TexelCoordToVect(CubeFace, u, v, cubemap.width);
                // Compute area.
                float area = TexelCoordSolidAngle(CubeFace, u, v, cubemap.width);

                CubeInfo[CubeFace, u, v] = new Vector4(vect.x, vect.y, vect.z, area);

            }
        }

        // Loop all texels of a cubemap to compute SH coefficients.

        double weightAccum = 0.0;
        double weight = 0.0;
        Texture2D temp = new Texture2D(cubemap.width, cubemap.height, cubemap.format, false);

        for (int CubeFace = 0; CubeFace < 6; CubeFace++)
        {
            // Get color data from  a cubemap.
            switch (CubeFace)
            {
            case 0:
                temp.SetPixels(cubemap.GetPixels(CubemapFace.PositiveX));
                break;
            case 1:
                temp.SetPixels(cubemap.GetPixels(CubemapFace.NegativeX));
                break;
            case 2:
                temp.SetPixels(cubemap.GetPixels(CubemapFace.PositiveY));
                break;
            case 3:
                temp.SetPixels(cubemap.GetPixels(CubemapFace.NegativeY));
                break;
            case 4:
                temp.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ));
                break;
            case 5:
                temp.SetPixels(cubemap.GetPixels(CubemapFace.NegativeZ));
                break;
            }

            // Loop every texel of a face.
            for (int u = 0; u < cubemap.width; u++)
                for (int v = 0; v < cubemap.height; v++)
            {

                // Evaluate the SH basis functions.
                weight = (double)(CubeInfo[CubeFace, u, v].w);
                Vector4 texelVect = CubeInfo[CubeFace, u, v];
                EvalSHBasis(texelVect, SHdir);
                Color rgb = temp.GetPixel(u, v);
                // Accumulate SH coefficients.
                for (int i = 0; i < NUM_SH_COEFFICIENT; i++)
                {
                    SHr[i] += rgb.r * SHdir[i] * weight;
                    SHg[i] += rgb.g * SHdir[i] * weight;
                    SHb[i] += rgb.b * SHdir[i] * weight;
                }
                weightAccum += weight;
            }
        }

        // Normalization - The sum of solid angle should be equal to the solid angle of the sphere (4 PI).
        for (int i = 0; i < NUM_SH_COEFFICIENT; ++i)
        {

            SHr[i] *= 4.0 / (weightAccum);
            SHg[i] *= 4.0 / (weightAccum);
            SHb[i] *= 4.0 / (weightAccum);
        }

        for (int i = 0; i < NUM_SH_COEFFICIENT; ++i)
        {
            SHr[i] = (SHr[i] * SHBandFactor[i]);
            SHg[i] = (SHg[i] * SHBandFactor[i]);
            SHb[i] = (SHb[i] * SHBandFactor[i]);
        }

        float[] output = new float[NUM_SH_COEFFICIENT * 3];

//.........这里部分代码省略.........
开发者ID:shuhuai,项目名称:IndirectLighting_Unity,代码行数:101,代码来源:AddEnvironmentToSH.cs

示例8: convolve_internal

        private void convolve_internal(Texture dstTex, Texture srcCube, bool dstRGBM, bool srcRGBM, bool linear, Camera cam, Material skyMat, Matrix4x4 matrix)
        {
            bool prevHDR = cam.hdr;
            CameraClearFlags prevFlags = cam.clearFlags;
            int prevMask = cam.cullingMask;
            cam.clearFlags = CameraClearFlags.Skybox;
            cam.cullingMask = 0;
            cam.hdr = !dstRGBM; // might need HDR camera buffer when we're not rendering to RGBM encoded pixels

            skyMat.name = "Internal Convolve Skybox";
            skyMat.shader = Shader.Find("Hidden/Marmoset/RGBM Convolve");

            //toggleKeywordPair("MARMO_LINEAR", "MARMO_GAMMA", linear);
            toggleKeywordPair("MARMO_RGBM_INPUT_ON", "MARMO_RGBM_INPUT_OFF", srcRGBM);
            toggleKeywordPair("MARMO_RGBM_OUTPUT_ON", "MARMO_RGBM_OUTPUT_OFF", dstRGBM);

            skyMat.SetMatrix("_SkyMatrix", matrix);
            skyMat.SetTexture("_CubeHDR", srcCube);
            bindRandomValueTable(skyMat,"_PhongRands", srcCube.width);

            Material prevSkyMat = UnityEngine.RenderSettings.skybox;
            UnityEngine.RenderSettings.skybox = skyMat;

            Cubemap dstCube = dstTex as Cubemap;
            RenderTexture dstRT = dstTex as RenderTexture;

            if( dstCube ) {
                if( generateMipChain ) {
                    int mipCount = mset.QPow.Log2i(dstCube.width) - 1;
                    int mip = highestMipIsMirror ? 1 : 0;
                    for( ; mip<mipCount; ++mip ) {
                        int mipSize = 1 << (mipCount-mip);
                        float mipExp = mset.QPow.clampedDownShift(this.maxExponent, highestMipIsMirror ? (mip-1) : mip, 1);
                        skyMat.SetFloat("_SpecularExp", mipExp);
                        skyMat.SetFloat ("_SpecularScale", this.convolutionScale);
                        Cubemap mipCube = new Cubemap(mipSize, dstCube.format, false);
                        cam.RenderToCubemap(mipCube);

                        for(int f=0; f<6; ++f) {
                            CubemapFace face = (CubemapFace)f;
                            dstCube.SetPixels(mipCube.GetPixels(face), face, mip);
                        }
                        Cubemap.DestroyImmediate(mipCube);
                    }
                    dstCube.Apply(false);
                } else {
                    skyMat.SetFloat("_SpecularExp", this.maxExponent);
                    skyMat.SetFloat ("_SpecularScale", this.convolutionScale);
                    cam.RenderToCubemap(dstCube);
                }
            } else if(dstRT) {
                skyMat.SetFloat("_SpecularExp", this.maxExponent);
                skyMat.SetFloat ("_SpecularScale", this.convolutionScale);
                cam.RenderToCubemap(dstRT);
            }

            cam.clearFlags = prevFlags;
            cam.cullingMask = prevMask;
            cam.hdr = prevHDR;
            UnityEngine.RenderSettings.skybox = prevSkyMat;
        }
开发者ID:elephantatwork,项目名称:Secret-Game,代码行数:61,代码来源:SkyProbe.cs

示例9: UseColor

    void UseColor()
    {
        var othersCube = new Cubemap (LightShapeProbe.LightShapeManager.CubeMapSize, TextureFormat.RGB24, false) as Cubemap;

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.PositiveX);

        for(var rXp = 0; rXp < CubeMapColorsR.Length; rXp++)
        {
            CubeMapColorsR[rXp] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.PositiveX);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.NegativeX);
        for(var rXn = 0; rXn < CubeMapColorsR.Length; rXn++)
        {
            CubeMapColorsR[rXn] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.NegativeX);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.PositiveY);
        for(var rYp = 0; rYp < CubeMapColorsR.Length; rYp++)
        {
            CubeMapColorsR[rYp] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.PositiveY);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.NegativeY);
        for(var rYn = 0; rYn < CubeMapColorsR.Length; rYn++)
        {
            CubeMapColorsR[rYn] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.NegativeY);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.PositiveZ);
        for(var rZp = 0; rZp < CubeMapColorsR.Length; rZp++)
        {
            CubeMapColorsR[rZp] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.PositiveZ);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.NegativeZ);
        for(var rZn = 0; rZn < CubeMapColorsR.Length; rZn++)
        {
            CubeMapColorsR[rZn] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.NegativeZ);
        othersCube.Apply();

        GameObject[] wObjects = LightShapeProbe.LightShapeManager.cubeProbes;

        foreach(GameObject o in wObjects)
        {
            var oo = o.GetComponent("LightShapeProbe") as LightShapeProbe;

            foreach(GameObject ooo in oo.myObjects)
            {
                var tempMat = ooo.GetComponent<MeshRenderer>();

         				tempMat.sharedMaterial.SetTexture("_Cube", othersCube);
            }
        }
    }
开发者ID:ifty420,项目名称:Traffic-Racer-2-3d,代码行数:73,代码来源:AltMethod.cs

示例10: ConvolveSpecularCubeMap

	IEnumerator ConvolveSpecularCubeMap()
	{
		int size = 0;
		int samples = 0;
		size = CubeSizeSetup(false);
		samples = qualitySetup(false);

		if(radianceModel == radianceEnum.BlinnPhong)
		{
			convolveSpecularSkybox = new Material(Shader.Find("Hidden/Antonov Suit/Radiance/Blinn"));
		}

		if(radianceModel == radianceEnum.GGX)
		{
			convolveSpecularSkybox = new Material(Shader.Find("Hidden/Antonov Suit/Radiance/GGX"));
		}

		convolveSpecularSkybox.SetInt("_specSamples",samples);
		convolveSpecularSkybox.SetInt("_specularSize", size);
		convolveSpecularSkybox.SetTexture("_SpecCubeIBL", specularCube);

		UnityEngine.RenderSettings.skybox = convolveSpecularSkybox;

		Cubemap tempCube = new Cubemap(size, TextureFormat.ARGB32, true);

		for(int mip = 0; (size >> mip) > 0; mip++)
		{

			// v0.035 better way to get exponent with different cubemap size
			float minExponent = 0.005f;

			float exponent = Mathf.Max( (float)specularExponent / (float)size * (float)mip, minExponent );

			/*
			float[] expVal = new float [] {
				0.01f,0.1f,0.2f,0.3f,0.4f,0.5f,0.6f,0.7f,0.8f,0.9f,1.0f
			};

			float exponent = expVal[mip];

			convolveSpecularSkybox.SetFloat("_Shininess", exponent );
			*/

			if( mip == 0 )
			{
				convolveSpecularSkybox.SetFloat("_Shininess", minExponent);
			}
			if( mip != 0 && radianceModel == radianceEnum.GGX)
			{
				convolveSpecularSkybox.SetFloat("_Shininess", exponent + 0.05f);
			}
			if( mip != 0 && radianceModel == radianceEnum.BlinnPhong)
			{
				convolveSpecularSkybox.SetFloat("_Shininess", exponent);
			}

			int cubeSize = Mathf.Max(1, tempCube.width >> mip );

			Cubemap mipCube = new Cubemap(cubeSize, TextureFormat.ARGB32, false);

			if( hasPro == true )
			{		
				cubeCamera.RenderToCubemap(mipCube);

				for(int f=0; f<6; ++f) 
				{
					CubemapFace face = (CubemapFace)f;
					tempCube.SetPixels(mipCube.GetPixels(face), face, mip);
				}

			}
			else
			{
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.PositiveZ, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.PositiveX, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.NegativeX, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.NegativeZ, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.PositiveY, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.NegativeY, cubeCamera,mip));
			}
		}

		// v0.035 this fix the ugly mipmap transition
		tempCube.filterMode = FilterMode.Trilinear;
		tempCube.wrapMode = TextureWrapMode.Clamp;

		if (SystemInfo.graphicsShaderLevel != 50)
		{
			tempCube.SmoothEdges(smoothEdge);
		}

		tempCube.Apply(false);

		specularCube = tempCube;

		string convolvedSpecularPath = GetOutPutPath(specularCube,false);
	
		AssetDatabase.CreateAsset(specularCube, convolvedSpecularPath);
		SerializedObject serializedCubemap = new SerializedObject(specularCube);
		SetLinearSpace(ref serializedCubemap, false);
//.........这里部分代码省略.........
开发者ID:ArieLeo,项目名称:AntonovSuit,代码行数:101,代码来源:AntonovSuitProbe.cs

示例11: MakeSnapshot

	IEnumerator MakeSnapshot(Cubemap c, CubemapFace face, CubemapNode node)
	{
		// We should only read the screen buffer after rendering is complete
		yield return new WaitForEndOfFrame();

		int width = Screen.width;
		int height = Screen.height;
	
		//Create the blank texture container
		Texture2D snapshot = new Texture2D(width, height, textureFormat, useMipMaps);
		snapshot.wrapMode = TextureWrapMode.Clamp;
	
		// Rectangle Area from the Camera
		Rect copyRect = new Rect((camera.pixelWidth * 0.5f) - (snapshot.width * 0.5f), (camera.pixelHeight * 0.5f) - (snapshot.height * 0.5f), snapshot.width, snapshot.height);
		
		//Read the current render into the texture container, snapshot
		snapshot.ReadPixels(copyRect, 0, 0, false);
		
		yield return null;
		
		snapshot.Apply();
		
		// Resize our Texture
		snapshot = Scale(snapshot, nodeResolution, nodeResolution);
		
		// Write mirrored pixels from our Texture to Cubemap
		Color cubemapColor;
		for (int y = 0; y<nodeResolution; y++)
        {
            for (int x = 0; x<nodeResolution; x++)
            {
				cubemapColor = snapshot.GetPixel(nodeResolution + x, (nodeResolution-1) - y);
				c.SetPixel(face, x, y, cubemapColor);
            }
        }
        c.Apply();	 
		 
		// Optional PNG generation. Double-check it with overriding Node setting
		if(makePNG && node.allowGeneratePNG)
		{
			// Mirror the snapshot image for our PNG in order to be identical with the cubemap faces
			snapshot.SetPixels32( MirrorColor32( c.GetPixels(face) ) );
			snapshot.Apply();
			
			// Convert to PNG file
			byte[] bytes = snapshot.EncodeToPNG();
			
			// Save the file			
			string path = Application.dataPath + "/" + pathCubemapPNG + "/" + sceneName + "_" + node.name + "_" + face.ToString() + ".png";
			//System.IO.File.WriteAllBytes(path, bytes); // deprecated because not available on Webplayer
			System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
			System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
			bw.Write(bytes);
			bw.Close();
			fs.Close();

            // Fix compression state
            string finalImagePath = "Assets/" + pathCubemapPNG + "/" + sceneName + "_" + node.name + "_" + face.ToString() + ".png";
            if (finalImagePath.Contains("//"))
                finalImagePath = finalImagePath.Replace("//", "/");

            AssetDatabase.Refresh(); // refresh necessary before we can use the textureimporter

            TextureImporter textureImporter = AssetImporter.GetAtPath(finalImagePath) as TextureImporter;
            if (textureImporter != null)
            {
                textureImporter.textureFormat = TextureImporterFormat.RGB24;
                AssetDatabase.ImportAsset(finalImagePath);
            }
		}
		
		// Delete our screenshot texture as clean up
		DestroyImmediate(snapshot);
		
		yield return null;
	}
开发者ID:fengqk,项目名称:Art,代码行数:76,代码来源:Cubemapper.cs

示例12: CopyTextureCube

        private void CopyTextureCube(string texturePath, Cubemap cubemap, BabylonTexture babylonTexture, bool hdr = false)
        {
            if (!babylonScene.AddTextureCube(texturePath))
            {
                return;
            }
            ExporterWindow.ReportProgress(1, "Parsing texture cube: " + texturePath);
            var srcTexturePath = AssetDatabase.GetAssetPath(cubemap);
            bool textureNotExistsMode = (SceneController != null && SceneController.skyboxOptions.textureFile == BabylonTextureExport.IfNotExists);
            bool png = (exportationOptions.DefaultImageFormat == (int)BabylonImageFormat.PNG);
            string fext = (png == true) ? ".png" : ".jpg";
            try
            {
                if (hdr)
                {
                    var hdrTexturePath = Path.Combine(babylonScene.OutputPath, Path.GetFileName(texturePath));
                    bool writeHdrTexture = true;
                    string textureHdrName = Path.GetFileName(hdrTexturePath);
                    if (textureNotExistsMode && File.Exists(hdrTexturePath))
                    {
                        writeHdrTexture = false;
                        ExporterWindow.ReportProgress(1, "Texture hdr cube item exists: " + textureHdrName);
                    }
                    if (writeHdrTexture)
                    {
                        ExporterWindow.ReportProgress(1, "Copying hdr texture cube item: " + textureHdrName);
                        File.Copy(srcTexturePath, hdrTexturePath, true);
                    }
                }
                else
                {
                    var importTool = new BabylonTextureImporter(srcTexturePath);
                    bool isReadable = importTool.IsReadable();
                    if (!isReadable) importTool.SetReadable();
                    try
                    {
                        foreach (CubemapFace face in Enum.GetValues(typeof(CubemapFace)))
                        {
                            var faceTexturePath = Path.Combine(babylonScene.OutputPath, Path.GetFileNameWithoutExtension(texturePath));
                            switch (face)
                            {
                                case CubemapFace.PositiveX:
                                    faceTexturePath += ("_px" + fext);
                                    break;
                                case CubemapFace.NegativeX:
                                    faceTexturePath += ("_nx" + fext);
                                    break;
                                case CubemapFace.PositiveY:
                                    faceTexturePath += ("_py" + fext);
                                    break;
                                case CubemapFace.NegativeY:
                                    faceTexturePath += ("_ny" + fext);
                                    break;
                                case CubemapFace.PositiveZ:
                                    faceTexturePath += ("_pz" + fext);
                                    break;
                                case CubemapFace.NegativeZ:
                                    faceTexturePath += ("_nz" + fext);
                                    break;
                                default:
                                    continue;
                            }
                            bool writeFaceTexture = true;
                            string textureFaceName = Path.GetFileName(faceTexturePath);
                            if (textureNotExistsMode && File.Exists(faceTexturePath))
                            {
                                writeFaceTexture = false;
                                ExporterWindow.ReportProgress(1, "Texture cube item exists: " + textureFaceName);
                            }
                            if (writeFaceTexture)
                            {
                                ExporterWindow.ReportProgress(1, "Exporting texture cube item: " + textureFaceName);
                                var tempTexture = new Texture2D(cubemap.width, cubemap.height, TextureFormat.ARGB32, false);

                                Color[] pixels = cubemap.GetPixels(face);
                                tempTexture.SetPixels(pixels);
                                tempTexture.Apply();

                                // Flip faces in cube texture.
                                tempTexture = FlipTexture(tempTexture);

                                // Encode cube face texture
                                if (png)
                                {
                                    File.WriteAllBytes(faceTexturePath, tempTexture.EncodeToPNG());
                                }
                                else
                                {
                                    File.WriteAllBytes(faceTexturePath, tempTexture.EncodeToJPG(exportationOptions.DefaultQualityLevel));
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (!isReadable) importTool.ForceUpdate();
                    }
                }
            }
            catch (Exception ex)
//.........这里部分代码省略.........
开发者ID:Temechon,项目名称:Babylon.js,代码行数:101,代码来源:SceneBuilder.Materials.cs

示例13: projectCube

		public static void projectCube(ref mset.SHEncoding sh, Cubemap cube, int mip, bool hdr) {
			sh.clearToBlack();
			float totalarea = 0f;

			ulong faceSize = (ulong)cube.width;
			mip = Mathf.Min(mset.QPow.Log2i(faceSize)+1, mip);
			faceSize = (ulong)(faceSize >> mip);
			float[] dc = new float[9];
			Vector3 u = Vector3.zero;

			for(ulong face=0; face<6; ++face) {
				Color rgba = Color.black;
				Color[] pixels = cube.GetPixels((CubemapFace)face, mip);
				for(ulong y=0; y<faceSize; ++y)
				for(ulong x=0; x<faceSize; ++x) {
					//compute cube direction
					float areaweight = 1f;
					mset.Util.invCubeLookup(ref u, ref areaweight, face, x, y, faceSize);				
					float shscale = 4f / 3f;
					ulong index = y*faceSize + x;
					if(hdr) mset.RGB.fromRGBM(ref rgba, pixels[index], true);
					else 	rgba = pixels[index];

					//project on basis functions, and accumulate					
					dc[0] = project_l0_m0(u);
					
					dc[1] = project_l1_mneg1(u);
					dc[2] = project_l1_m0(u);
					dc[3] = project_l1_m1(u);
					
					dc[4] = project_l2_mneg2(u);
					dc[5] = project_l2_mneg1(u);
					dc[6] = project_l2_m0(u);
					dc[7] = project_l2_m1(u);
					dc[8] = project_l2_m2(u);
					for(int i=0; i<9; ++i ) {
						sh.c[3*i + 0] += shscale * areaweight * rgba[0] * dc[i];
						sh.c[3*i + 1] += shscale * areaweight * rgba[1] * dc[i];
						sh.c[3*i + 2] += shscale * areaweight * rgba[2] * dc[i];
					}
					totalarea += areaweight;
				}
			}
			
			//complete the integration by dividing by total area
			scale( ref sh, 16f / totalarea );
		}
开发者ID:keyward,项目名称:EnemyOfMyEnemy,代码行数:47,代码来源:SHUtil.cs

示例14: CopyCubemapFace

    private void CopyCubemapFace(CubemapFace face, Cubemap source, ref Cubemap target)
    {
        //Create the blank texture container
        Texture2D snapshot = new Texture2D(source.width, source.height, source.format, m_useMipMaps, false);
        snapshot.wrapMode = TextureWrapMode.Clamp;

        // Read Face Pixels into the Texture
        snapshot.SetPixels(source.GetPixels(face), 0);

        // Resize to new size
        snapshot = Scale(snapshot, m_resolution, m_resolution);

        // Finally write the contents to the new Cubemap
        target.SetPixels(snapshot.GetPixels(), face, 0);
        target.Apply();
    }
开发者ID:fengqk,项目名称:Art,代码行数:16,代码来源:CubemapToolPropertyModifier.cs

示例15: ProjectCubeIntoSH3Func

 public SphericalHarmonicsL2 ProjectCubeIntoSH3Func(Cubemap src, int miplevel)
 {
     Vector4[] array = new Vector4[]
     {
         new Vector4(0f, 0f, -1f, 0f),
         new Vector4(0f, -1f, 0f, 0f),
         new Vector4(-1f, 0f, 0f, 0f),
         new Vector4(0f, 0f, 1f, 0f),
         new Vector4(0f, -1f, 0f, 0f),
         new Vector4(1f, 0f, 0f, 0f),
         new Vector4(1f, 0f, 0f, 0f),
         new Vector4(0f, 0f, 1f, 0f),
         new Vector4(0f, -1f, 0f, 0f),
         new Vector4(1f, 0f, 0f, 0f),
         new Vector4(0f, 0f, -1f, 0f),
         new Vector4(0f, 1f, 0f, 0f),
         new Vector4(1f, 0f, 0f, 0f),
         new Vector4(0f, -1f, 0f, 0f),
         new Vector4(0f, 0f, -1f, 0f),
         new Vector4(-1f, 0f, 0f, 0f),
         new Vector4(0f, -1f, 0f, 0f),
         new Vector4(0f, 0f, 1f, 0f)
     };
     Quaternion rotation = base.gameObject.transform.rotation;
     Matrix4x4 matrix4x = this.QuaternionToMatrix(rotation);
     for (int i = 0; i < 6; i++)
     {
         array[i] = matrix4x * array[i];
     }
     Shader.SetGlobalMatrix("_SkyRotation", matrix4x);
     float num = 0f;
     SphericalHarmonicsL2 sphericalHarmonicsL = default(SphericalHarmonicsL2);
     sphericalHarmonicsL.Clear();
     for (int j = 0; j < 6; j++)
     {
         Vector3 a = array[j * 3];
         Vector3 a2 = -array[j * 3 + 1];
         Vector3 a3 = -array[j * 3 + 2];
         Color[] pixels = src.GetPixels((CubemapFace)j, miplevel);
         int num2 = src.width >> miplevel;
         if (num2 < 1)
         {
             num2 = 1;
         }
         float num3 = -1f + 1f / (float)num2;
         float num4 = 2f * (1f - 1f / (float)num2) / ((float)num2 - 1f);
         for (int k = 0; k < num2; k++)
         {
             float num5 = (float)k * num4 + num3;
             for (int l = 0; l < num2; l++)
             {
                 Color a4 = pixels[l + k * num2];
                 float num6 = (float)l * num4 + num3;
                 float num7 = 1f + num6 * num6 + num5 * num5;
                 float num8 = 4f / (Mathf.Sqrt(num7) * num7);
                 Vector3 a5 = a3 + a * num6 + a2 * num5;
                 a5.Normalize();
                 Color color = a4 * a4.a * 8f;
                 sphericalHarmonicsL.AddDirectionalLight(-a5, (QualitySettings.activeColorSpace != ColorSpace.Linear) ? color : color.linear, num8 * 0.5f);
                 num += num8;
             }
         }
     }
     float rhs = 4f / num;
     sphericalHarmonicsL *= rhs;
     return sphericalHarmonicsL;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:67,代码来源:ProjectCubeIntoSH3.cs


注:本文中的UnityEngine.Cubemap.GetPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。