SetPixel() public method

public SetPixel ( CubemapFace face, int x, int y, Color color ) : void
face CubemapFace
x int
y int
color Color
return void
コード例 #1
0
 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);
     }
 }
コード例 #2
0
 static public int SetPixel(IntPtr l)
 {
     try {
         UnityEngine.Cubemap     self = (UnityEngine.Cubemap)checkSelf(l);
         UnityEngine.CubemapFace a1;
         checkEnum(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         System.Int32 a3;
         checkType(l, 4, out a3);
         UnityEngine.Color a4;
         checkType(l, 5, out a4);
         self.SetPixel(a1, a2, a3, a4);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #3
0
 static public int SetPixel(IntPtr l)
 {
     try{
         UnityEngine.Cubemap     self = (UnityEngine.Cubemap)checkSelf(l);
         UnityEngine.CubemapFace a1;
         checkEnum(l, 2, out a1);
         System.Int32 a2;
         checkType(l, 3, out a2);
         System.Int32 a3;
         checkType(l, 4, out a3);
         UnityEngine.Color a4;
         checkType(l, 5, out a4);
         self.SetPixel(a1, a2, a3, a4);
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #4
0
 static public int SetPixel(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Cubemap     self = (UnityEngine.Cubemap)checkSelf(l);
         UnityEngine.CubemapFace a1;
         a1 = (UnityEngine.CubemapFace)LuaDLL.luaL_checkinteger(l, 2);
         System.Int32 a2;
         checkType(l, 3, out a2);
         System.Int32 a3;
         checkType(l, 4, out a3);
         UnityEngine.Color a4;
         checkType(l, 5, out a4);
         self.SetPixel(a1, a2, a3, a4);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #5
0
    // 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();
    }
コード例 #6
0
	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);
	}
コード例 #7
0
ファイル: LuxCubeProcessor.cs プロジェクト: Backman/Hellbound
    //--------------------------------------------------------------------------------------
    // 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];

				    // 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();
    }
コード例 #8
0
	// 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, 
			               0, maxI, i, 5, 0, i);
			
			setFaceAverage(ref filteredCubeMap, 
			               1, i, 0, 2, 0, i);
			setFaceAverage(ref filteredCubeMap, 
			               1, 0, i, 5, maxI, i);
			setFaceAverage(ref filteredCubeMap, 
			               1, i, maxI, 3, 0, maxI - i);
			setFaceAverage(ref filteredCubeMap, 
			               1, maxI, i, 4, 0, i);
			
			setFaceAverage(ref filteredCubeMap, 
			               2, i, 0, 5, maxI - i, 0);
			setFaceAverage(ref filteredCubeMap, 
			               2, i, maxI, 4, i, 0);
			setFaceAverage(ref filteredCubeMap, 
			               3, i, 0, 4, i, maxI);
			setFaceAverage(ref filteredCubeMap, 
			               3, i, maxI, 5, maxI - i, maxI);
		}
		
		// Avoid seams between cube faces: 
		// average corner texels to the same color 
		// on all three faces meeting in one corner
		setCornerAverage(ref filteredCubeMap, 
		                 0, 0, 0, 2, maxI, maxI, 4, maxI, 0);
		setCornerAverage(ref filteredCubeMap, 
		                 0, maxI, 0, 2, maxI, 0, 5, 0, 0);
		setCornerAverage(ref filteredCubeMap, 
		                 0, 0, maxI, 3, maxI, 0, 4, maxI, maxI);
		setCornerAverage(ref filteredCubeMap, 
		                 0, maxI, maxI, 3, maxI, maxI, 5, 0, maxI);
		setCornerAverage(ref filteredCubeMap, 
		                 1, 0, 0, 2, 0, 0, 5, maxI, 0);
		setCornerAverage(ref filteredCubeMap, 
		                 1, maxI, 0, 2, 0, maxI, 4, 0, 0);
		setCornerAverage(ref filteredCubeMap, 
		                 1, 0, maxI, 3, 0, maxI, 5, maxI, maxI);
		setCornerAverage(ref filteredCubeMap, 
		                 1, maxI, maxI, 3, 0, 0, 4, 0, maxI);
		
		filteredCubeMap.Apply(); //apply all SetPixel(..) commands
		
		return filteredCubeMap;
	}
コード例 #9
0
	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);
	}
コード例 #10
0
	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);
	}
コード例 #11
0
ファイル: Cubemapper.cs プロジェクト: fengqk/Art
	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;
	}
コード例 #12
0
    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]);
        }
    }