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


C# Cubemap.SetPixel方法代码示例

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


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

示例1: createPlaceHolderCube

 void createPlaceHolderCube()
 {
     if( PlaceHolderCube == null ) {
         PlaceHolderCube = new Cubemap(16,TextureFormat.ARGB32,true);
         for(int face = 0; face < 6; face++) {
             for(int x = 0; x < 16; x++) {
                 for(int y = 0; y < 16; y++) {
                     PlaceHolderCube.SetPixel((CubemapFace)face, x, y, Color.black);
                 }
             }
         }
         PlaceHolderCube.Apply(true);
     }
 }
开发者ID:KieranChandler,项目名称:BritishPoliceSimulator,代码行数:14,代码来源:SetupLux.cs

示例2: GenerateCubemapss

    // Add a mesh collider to each game object that contains collider in its name
    public static void GenerateCubemapss(bool select,int resolution,Color reflectcolor, LayerMask layera)
    {
        if (!System.IO.Directory.Exists("Assets/Textures/cubemaps/"))
        {
            System.IO.Directory.CreateDirectory(Application.dataPath.Substring(0, Application.dataPath.Length - 6) + "Assets/Textures/cubemaps/");
        }

        GameObject[] gos;
        if (select){
            gos = Selection.gameObjects;
        }
        else {
            gos = (GameObject[]) GameObject.FindObjectsOfType(typeof(GameObject));
        }
        EditorUtility.DisplayProgressBar("Initilizing Cubemaps", "Prepering...", 0.0f);

        int j=0;
        int all= gos.Length;
        foreach (GameObject g in gos) {
            // check go.name here

            if (g.GetComponent<Renderer>()!=null){
                foreach (Material item in g.GetComponent<Renderer>().sharedMaterials)
                {
                    if (item.HasProperty("_Cube"))
                    {
                        EditorUtility.DisplayProgressBar("Initilizing Cubemaps", "Processing object " + g.name, 1.0f * j / all);

                        item.SetColor("_ReflectColor", reflectcolor);
                        g.GetComponent<Renderer>().enabled = false;
                        GameObject go = new GameObject("CubemapCamera", typeof(Camera));
                        go.GetComponent<Camera>().transform.position = g.GetComponent<Renderer>().bounds.center;
                        /*if (g.GetComponent(Transform).root.position[1]<1){
                            go.camera.transform.position=go.camera.transform.position+Vector3(0,2);
                        }
                        */
                        go.GetComponent<Camera>().transform.rotation = Quaternion.identity;
                        go.GetComponent<Camera>().cullingMask = layera;
                        go.GetComponent<Camera>().nearClipPlane = 0.01f;
                        Cubemap cubemap = new Cubemap(resolution, TextureFormat.ARGB32, false);
                        for (int i = 0; i < resolution; i++)
                        {
                            for (int k = 0; k < 6; k++)
                            {
                                cubemap.SetPixel((CubemapFace) k, i, j, Color.white);
                            }
                        }

                        go.GetComponent<Camera>().RenderToCubemap(cubemap);

                        GameObject.DestroyImmediate(go);
                        AssetDatabase.CreateAsset(cubemap, "Assets/Textures/cubemaps/" + g.name + "_" + item.name + ".cubemap");
                        g.GetComponent<Renderer>().enabled = true;
                        AssetDatabase.Refresh();
                        Cubemap lm = (Cubemap)Resources.LoadAssetAtPath("Assets/Textures/cubemaps/" + g.name + "_" + item.name + ".cubemap", typeof(Object));
                        //Debug.Log(lm);
                        item.SetTexture("_Cube", lm);
                    }
                }

            }
            j++;
        }
        EditorUtility.ClearProgressBar();
    }
开发者ID:TheHolodeckProject,项目名称:UnityHolodeckProject,代码行数:66,代码来源:GanerateCubemaps.cs

示例3: Capture

	IEnumerator Capture(Cubemap cubemap,CubemapFace face,Camera cam)
	{
		var width = Screen.width;
		var height = Screen.height;

		Texture2D tex = new Texture2D(height, height, TextureFormat.ARGB32, false);
		int cubeSize = cubemap.height;
		
		cam.transform.localRotation = Rotation(face);
		
		yield return new WaitForEndOfFrame();

		tex.ReadPixels(new Rect((width-height)/2, 0, height, height), 0, 0);
		tex.Apply();
		tex = Resize(tex, cubeSize,cubeSize,false);

		Color cubeCol;
		for (int y = 0; y < cubeSize; y++)
		{
			for (int x = 0; x < cubeSize; x++)
			{

				cubeCol = tex.GetPixel(cubeSize + x, (cubeSize - 1) - y);

				cubemap.SetPixel(face, x, y, cubeCol);

			}
		}

		cubemap.Apply();

		DestroyImmediate(tex);
	}
开发者ID:ArieLeo,项目名称:AntonovSuit,代码行数:33,代码来源:AntonovSuitProbe.cs

示例4: ConvolveIrradianceEnvironmentMap


//.........这里部分代码省略.........
		    //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];

				    // read normalvector and pass it to EvalSHBasis to get SHdir
				    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);

				    // set color values
				    double R = 0.0;
				    double G = 0.0;
				    double B = 0.0;
				
				    for (int i = 0; i < 25; ++i)
				    {
					    R += (SHr[i] * SHdir[i] * SHBandFactor[i]);
					    G += (SHg[i] * SHdir[i] * SHBandFactor[i]);
					    B += (SHb[i] * SHdir[i] * SHBandFactor[i]);
				    }
				    // Lux needs alpha!
				    irrCubeMap.SetPixel((CubemapFace)iFaceIdx, x, y, new Color((float)R,(float)G,(float)B, 1.0f ));
			    }
		    }
	    }
	    irrCubeMap.Apply();
    }
开发者ID:Backman,项目名称:Hellbound,代码行数:101,代码来源:LuxCubeProcessor.cs

示例5: computeFilteredCubeMap

	// This function computes a diffuse environment map in 
	// "filteredCubemap" of the same dimensions as "originalCubemap"
	// by integrating -- for each texel of "filteredCubemap" -- 
	// the diffuse illumination from all texels of "originalCubemap" 
	// for the surface normal vector corresponding to the direction 
	// of each texel of "filteredCubemap".
	private Cubemap computeFilteredCubeMap()
	{
		Cubemap filteredCubeMap = new Cubemap(originalCubeMap.width, 
		                                      originalCubeMap.format, true);
		
		int filteredSize = filteredCubeMap.width;
		int originalSize = originalCubeMap.width;
		
		// Compute all texels of the diffuse environment cube map 
		// by itterating over all of them
		for (int filteredFace = 0; filteredFace < 6; filteredFace++) 
			// the six sides of the cube
		{
			for (int filteredI = 0; filteredI < filteredSize; filteredI++)
			{
				for (int filteredJ = 0; filteredJ < filteredSize; filteredJ++)
				{
					Vector3 filteredDirection = 
						getDirection(filteredFace, 
						             filteredI, filteredJ, filteredSize).normalized;
					float totalWeight = 0.0f;
					Vector3 originalDirection;
					Vector3 originalFaceDirection;
					float weight;
					Color filteredColor = new Color(0.0f, 0.0f, 0.0f);
					
					// sum (i.e. integrate) the diffuse illumination 
					// by all texels in the original environment map
					for (int originalFace = 0; originalFace < 6; originalFace++)
					{
						originalFaceDirection = getDirection(
							originalFace, 1, 1, 3).normalized; 
						//the normal vector of the face
						
						for (int originalI = 0; originalI < originalSize; originalI++)
						{
							for (int originalJ = 0; originalJ < originalSize; originalJ++)
							{
								originalDirection = getDirection(
									originalFace, originalI, 
									originalJ, originalSize); 
								// direction to the texel 
								// (i.e. light source)
								weight = 1.0f 
									/ originalDirection.sqrMagnitude; 
								// take smaller size of more 
								// distant texels into account
								originalDirection = 
									originalDirection.normalized;
								weight = weight * Vector3.Dot(
									originalFaceDirection, 
									originalDirection); 
								// take tilt of texel compared 
								// to face into account
//								weight = weight * Mathf.Max(0.0f, 
//								                            Vector3.Dot(filteredDirection, 
//								            originalDirection)); 
								// directional filter 
								// for diffuse illumination
								weight = weight * Mathf.Pow(Mathf.Max(0.0f, 
								                                      Vector3.Dot(filteredDirection, originalDirection)), 50.0f); 
								//directional filter for specular illumination
								totalWeight = totalWeight + weight; 
								// instead of analytically 
								// normalization, we just normalize 
								// to the potential max illumination
								filteredColor = filteredColor + weight 
									* originalCubeMap.GetPixel(
										(CubemapFace)originalFace, 
										originalI, originalJ); // add the 
								// illumination by this texel 
							}
						}
					}
					filteredCubeMap.SetPixel(
						(CubemapFace)filteredFace, filteredI, 
						filteredJ, filteredColor / totalWeight); 
					// store the diffuse illumination of this texel
				}
			}
		}
		
		// Avoid seams between cube faces: average edge texels 
		// to the same color on each side of the seam
		int maxI = filteredCubeMap.width - 1;
		for (int i = 0; i < maxI; i++)
		{
			setFaceAverage(ref filteredCubeMap, 
			               0, i, 0, 2, maxI, maxI - i);
			setFaceAverage(ref filteredCubeMap, 
			               0, 0, i, 4, maxI, i);
			setFaceAverage(ref filteredCubeMap, 
			               0, i, maxI, 3, maxI, i);
			setFaceAverage(ref filteredCubeMap, 
//.........这里部分代码省略.........
开发者ID:sasuke010101,项目名称:UnityShader,代码行数:101,代码来源:ComputeDiffuseEnvironmentMap.cs

示例6: setCornerAverage

	private void setCornerAverage(ref Cubemap filteredCubeMap, 
	                              int a, int b, int c, int d, int e, int f, int g, int h, int i)
	{
		Color average = 
			(filteredCubeMap.GetPixel((CubemapFace)a, b, c) 
			 + filteredCubeMap.GetPixel((CubemapFace)d, e, f) 
			 + filteredCubeMap.GetPixel((CubemapFace)g, h, i)) / 3.0f;
		filteredCubeMap.SetPixel((CubemapFace)a, b, c, average);
		filteredCubeMap.SetPixel((CubemapFace)d, e, f, average);
		filteredCubeMap.SetPixel((CubemapFace)g, h, i, average);
	}
开发者ID:sasuke010101,项目名称:UnityShader,代码行数:11,代码来源:ComputeDiffuseEnvironmentMap.cs

示例7: setFaceAverage

	private void setFaceAverage(ref Cubemap filteredCubeMap, 
	                            int a, int b, int c, int d, int e, int f)
	{
		Color average = 
			(filteredCubeMap.GetPixel((CubemapFace)a, b, c) 
			 + filteredCubeMap.GetPixel((CubemapFace)d, e, f)) / 2.0f;
		filteredCubeMap.SetPixel((CubemapFace)a, b, c, average);
		filteredCubeMap.SetPixel((CubemapFace)d, e, f, average);
	}
开发者ID:sasuke010101,项目名称:UnityShader,代码行数:9,代码来源:ComputeDiffuseEnvironmentMap.cs

示例8: 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

示例9: Snapshot

    IEnumerator Snapshot(Cubemap cubemap, CubemapFace face, Camera cam)
    {
        int width = Screen.width;
        int height = Screen.height;
        Texture2D tex = new Texture2D(height, height, textureFormat, mipmap);

        cam.transform.localRotation = Rotation(face);
        yield return new WaitForEndOfFrame();

        tex.ReadPixels(new Rect((width - height) / 2, 0, height, height), 0, 0);
        tex.Apply();
        tex = Scale(tex, this.size, this.size);

        Color[] colors = tex.GetPixels();
        for (int i = 0; i < colors.Length; i++)
        {
            cubemap.SetPixel(face, this.size - (i % this.size) - 1, (int)Mathf.Floor(i / this.size), colors[colors.Length - i - 1]);
        }
    }
开发者ID:MedStarSiTEL,项目名称:UnityTrauma,代码行数:19,代码来源:CubeManager.cs


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