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); }
static void scale(ref mset.SHEncoding sh, float s) { for (int i = 0; i < 27; ++i) { sh.c[i] *= s; } }
//script instance is destroyed private void OnDestroy() { SH = null; _blackCube = null; specularCube = null; skyboxCube = null; }
//on enable or activate private void OnEnable() { //finalize or allocate serialized properties here if (SH == null) { SH = new mset.SHEncoding(); } SH.copyToBuffer(); }
//script instance is destroyed private void OnDestroy() { UnityEngine.Object.DestroyImmediate(_skyboxMaterial, false); SH = null; _skyboxMaterial = null; _blackCube = null; diffuseCube = null; specularCube = null; skyboxCube = null; }
//on enable or activate private void OnEnable() { //finalize or allocate serialized properties here if (SH == null) { SH = new mset.SHEncoding(); } if (this.CustomSH != null) { SH.copyFrom(this.CustomSH.SH); } SH.copyToBuffer(); SceneManager.sceneLoaded += SceneStart; }
public static void projectCubeBuffer(ref mset.SHEncoding sh, CubeBuffer cube) { sh.clearToBlack(); float totalarea = 0f; ulong faceSize = (ulong)cube.faceSize; float[] dc = new float[9]; Vector3 u = Vector3.zero; for (ulong face = 0; face < 6; ++face) { 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 = face * faceSize * faceSize + y * faceSize + x; Color rgba = cube.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); }
public static void convolve(ref mset.SHEncoding sh, float conv0, float conv1, float conv2) { for (int i = 0; i < 27; ++i) { if (i < 3) { sh.c[i] *= conv0; } else if (i < 12) { sh.c[i] *= conv1; } else { sh.c[i] *= conv2; } } }
//on enable or activate private void OnEnable() { //finalize or allocate serialized properties here if(SH == null) SH = new mset.SHEncoding(); if(this.CustomSH != null) SH.copyFrom(this.CustomSH.SH); SH.copyToBuffer(); }
public static void convolve(ref mset.SHEncoding sh) { convolve(ref sh, 1f, 2f / 3f, 0.25f); }
public void OnEnable() { clear(); hideFlags |= HideFlags.HideAndDontSave; if (lightGizmo == null) { lightGizmo = Resources.Load("light") as Texture2D; } if (pickerIcon == null) { if (EditorGUIUtility.isProSkin) { pickerIcon = Resources.Load("white_picker") as Texture2D; } else { pickerIcon = Resources.Load("picker") as Texture2D; } } //NOTE: buffers are now allocated along with The CubemapGUI, what's internal to the buffers is still controlled strictly /*if (buffers == null) { buffers = new CubeBuffer[4]; for (int i = 0; i < buffers.Length; ++i) { buffers[i] = new CubeBuffer(); } }*/ if(SH == null) SH = new mset.SHEncoding(); setType(type, inspector); //updates path, buffers, and preview reloadReference(); }
public void freeMem() { if(locked) return; UnityEngine.Object.DestroyImmediate(preview,false); UnityEngine.Object.DestroyImmediate(tempTexture,false); preview = null; tempTexture = null; cube = null; RT = null; input = null; srInput = null; SH = null; foreach(CubeBuffer buffer in buffers) { buffer.clear(); } }