public AddDirectionalLight ( Vector3 direction, Color color, float intensity ) : void | ||
direction | Vector3 | |
color | Color | |
intensity | float | |
Résultat | void |
void SHAddPointLight(Vector3 probePosition, Vector3 position, float range, Color color, float intensity, ref SphericalHarmonicsL2 sh) { // From the point of view of an SH probe, point light looks no different than a directional light, // just attenuated and coming from the right direction. Vector3 probeToLight = position - probePosition; float attenuation = 1.0F / (1.0F + 25.0F * probeToLight.sqrMagnitude / (range * range)); sh.AddDirectionalLight(probeToLight.normalized, color, intensity * attenuation); }
void CalcAmbientLight(Cubemap TempCube){ //AMBIENT LIGHT CALCULATION string path = AssetDatabase.GetAssetPath(TempCube); TextureImporter ti = TextureImporter.GetAtPath(path) as TextureImporter; bool OldIsReadable = false; int OldMaxSize = 1; if (ti!=null){ OldIsReadable = ti.isReadable; ti.isReadable = true; OldMaxSize = ti.maxTextureSize; ti.maxTextureSize = 32; AssetDatabase.ImportAsset(path); } //CubeResize = new Texture2D(70,70,TextureFormat.ARGB32,false); //Color[] colors = new Color[(int)(CubeResize.width*CubeResize.height)]; Cubemap UseCube = TempCube; int MipmapLevel = 0; try { TempCube.GetPixel(CubemapFace.PositiveX,0,0); } catch { UseCube = defaultBackCube; } int i = 1; if (UseCube.height>4){ for (i=1;i<9;i++){ bool Continue = false; try { Continue = false; Color[] colors2 = UseCube.GetPixels(CubemapFace.PositiveX,i); if (colors2!=null&&colors2.Length>1) Continue = true; } catch{ Continue = false; } // Debug.Log(Continue); if (!Continue) break; } } MipmapLevel = i-1; // Debug.Log(MipmapLevel); Color PosXo = UseCube.GetPixel(CubemapFace.PositiveX,0,0); Color NegXo = UseCube.GetPixel(CubemapFace.NegativeX,0,0); Color PosYo = UseCube.GetPixel(CubemapFace.PositiveY,0,0); Color NegYo = UseCube.GetPixel(CubemapFace.NegativeY,0,0); Color PosZo = UseCube.GetPixel(CubemapFace.PositiveZ,0,0); Color NegZo = UseCube.GetPixel(CubemapFace.NegativeZ,0,0); if (MipmapLevel!=0){ PosXo = UseCube.GetPixels(CubemapFace.PositiveX,MipmapLevel)[0]; NegXo = UseCube.GetPixels(CubemapFace.NegativeX,MipmapLevel)[0]; PosYo = UseCube.GetPixels(CubemapFace.PositiveY,MipmapLevel)[0]; NegYo = UseCube.GetPixels(CubemapFace.NegativeY,MipmapLevel)[0]; PosZo = UseCube.GetPixels(CubemapFace.PositiveZ,MipmapLevel)[0]; NegZo = UseCube.GetPixels(CubemapFace.NegativeZ,MipmapLevel)[0]; } Color PosX = Color.Lerp(PosXo,NegYo,0.5f); Color NegX = Color.Lerp(NegXo,NegYo,0.5f); Color PosY = Color.Lerp(PosYo,PosXo,0.2f); Color NegY = Color.Lerp(NegYo,NegXo,0.2f); Color PosZ = Color.Lerp(PosZo,NegYo,0.5f); Color NegZ = Color.Lerp(NegZo,NegYo,0.5f); #if UNITY_5 SphericalHarmonicsL2 L = new SphericalHarmonicsL2(); L.AddDirectionalLight(new Vector3(1,0,0),PosX,ToGreyscale(PosX)); L.AddDirectionalLight(new Vector3(0,1,0),PosY,ToGreyscale(PosY)); L.AddDirectionalLight(new Vector3(0,0,1),PosZ,ToGreyscale(PosZ)); L.AddDirectionalLight(new Vector3(-1,0,0),NegX,ToGreyscale(NegX)); L.AddDirectionalLight(new Vector3(0,-1,0),NegY,ToGreyscale(NegY)); L.AddDirectionalLight(new Vector3(0,0,-1),NegZ,ToGreyscale(NegZ)); (previewCam.GetComponent("PreviewCameraSet") as PreviewCameraSet).NewAmbient = L; #endif Color C = (PosX/6f)+(NegX/6f)+(PosY/6f)+(NegY/6f)+(PosZ/6f)+(NegZ/6f); //Debug.Log(C); (previewCam.GetComponent("PreviewCameraSet") as PreviewCameraSet).NewAmbientColor = C; //L.AddDirectionalLight(new Vector3(0,0,1),new Color(0.5f,0,0),1f); //Debug.Log(ToGreyscale(new Color(0.5f,0,0))); //CubeResize.SetPixels(colors); //CubeResize.Apply(false,false); if (ti!=null){ ti.isReadable = OldIsReadable; ti.maxTextureSize = OldMaxSize; AssetDatabase.ImportAsset(path); } }