public void fromBuffer(CubeBuffer src) { clear(); faceSize = src.faceSize; pixels = new Color[src.pixels.Length]; pixelCopy(ref pixels, 0, src.pixels, 0, pixels.Length); }
private void gatherLights(ref mset.CubeBuffer cube) { ps.lights = new Color[cube.pixels.Length]; mset.CubeBuffer.pixelCopy(ref ps.lights, 0, cube.pixels, 0, cube.pixels.Length); ps.lightCount = (ulong)ps.lights.LongLength; ulong faceSize = (ulong)cube.faceSize; ps.lightDirs = new mset.DirLookup[ps.lightCount]; Vector3 vec = new Vector3(); for (ulong face = 0; face < 6; ++face) { for (ulong y = 0; y < faceSize; ++y) { for (ulong x = 0; x < faceSize; ++x) { ulong i = face * faceSize * faceSize + y * faceSize + x; mset.Util.invCubeLookup(ref vec, ref ps.lightDirs[i].weight, face, x, y, faceSize); ps.lights[i] *= ps.lightDirs[i].weight; ps.lightDirs[i].weight = 1f; ps.lightDirs[i].x = vec.x; ps.lightDirs[i].y = vec.y; ps.lightDirs[i].z = vec.z; } } } }
public CubemapGUI(Type _type, bool _inspector) { type = _type; mipmapped = type == Type.SIM; inputPath = ""; clear(); inspector = _inspector; buffers = new CubeBuffer[4]; for (int i = 0; i < buffers.Length; ++i) { buffers[i] = new CubeBuffer(); } 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; } } }
public void resampleToBuffer(ref CubeBuffer dst) { int dstFaceLength = dst.faceSize * dst.faceSize; for (int face = 0; face < 6; ++face) { resampleFace(ref dst.pixels, face * dstFaceLength, face, dst.faceSize, false); } }
public void resampleToBuffer(ref CubeBuffer dst, float exposureMult) { int dstFaceLength = dst.faceSize * dst.faceSize; for (int face = 0; face < 6; ++face) { resampleFace(ref dst.pixels, face * dstFaceLength, face, dst.faceSize, false); dst.applyExposure(exposureMult); } }
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 void init() { CONVO = new CubeBuffer(); IN = new CubeBuffer(); }
public void updatePreview() { if (locked || !input) { return; } int previewFaceSize = previewWidth / 4; int previewHeight = previewFaceSize; switch (previewLayout) { case Layout.ROW: previewHeight = previewFaceSize; break; case Layout.CROSS: previewHeight = 3 * previewFaceSize; break; case Layout.PANO: previewHeight = 2 * previewFaceSize; break; } ; if (!preview) { preview = new Texture2D(previewWidth, previewHeight, TextureFormat.ARGB32, false, true); preview.hideFlags |= HideFlags.DontSave; //do not save this and do not clear it coming back from play mode } else if (preview.width != previewWidth || preview.height != previewHeight) { preview.Resize(previewWidth, previewHeight); } if (previewLayout == Layout.CROSS) { Util.clearTo2D(ref preview, Color.black); } int faceSize = buffers[0].faceSize; //many input formats don't have mipmapped buffers, sample high mip bool splitMips = mipmapped && faceSize > 8 && !buffers[1].empty() && !buffers[2].empty() && !buffers[3].empty(); float gamma = 1f; if (!assetLinear) //renderLinear) { //if linear-space rendering, we're expecting a gamma curve to be applied to the image before display { gamma *= Gamma.toSRGB; } if (previewLayout == Layout.PANO) { ulong w = (ulong)previewWidth; ulong h = (ulong)previewHeight; Color pixel = new Color(); for (ulong x = 0; x < w; ++x) { for (ulong y = 0; y < h; ++y) { float u = 0f; float v = 0f; ulong face = 0; Util.latLongToCubeLookup(ref u, ref v, ref face, x, y, w, h); int mip = 0; if (splitMips) { mip = (int)(x * 4 / w); } buffers[mip].sample(ref pixel, u, v, (int)face); pixel.r = Mathf.Clamp01(pixel.r); pixel.g = Mathf.Clamp01(pixel.g); pixel.b = Mathf.Clamp01(pixel.b); if (gamma != 1f) { Util.applyGamma(ref pixel, gamma); } preview.SetPixel((int)x, (int)y, pixel); } } preview.Apply(); } else { Color[] facePixels = new Color[previewFaceSize * previewFaceSize]; int faceCount; if (previewLayout == Layout.CROSS) { faceCount = 6; } else { faceCount = 4; } for (int face = 0; face < faceCount; ++face) { int mip = 0; if (splitMips) { mip = face; if (face >= 4) { mip = 1; } } int sampleFace = face; switch (face) { case 0: sampleFace = (int)CubemapFace.NegativeX; break; case 1: sampleFace = (int)CubemapFace.PositiveZ; break; case 2: sampleFace = (int)CubemapFace.PositiveX; break; case 3: sampleFace = (int)CubemapFace.NegativeZ; break; case 4: sampleFace = (int)CubemapFace.PositiveY; break; case 5: sampleFace = (int)CubemapFace.NegativeY; break; } ; if (buffers[mip].pixels == null) { Debug.LogError("null pixels on mip " + mip); } buffers[mip].resampleFace(ref facePixels, sampleFace, previewFaceSize, true); CubeBuffer.encode(ref facePixels, facePixels, ColorMode.RGB8, false); if (gamma != 1f) { Util.applyGamma(ref facePixels, gamma); } if (previewLayout == Layout.CROSS) { if (face < 4) { preview.SetPixels(previewFaceSize * face, 1 * previewFaceSize, previewFaceSize, previewFaceSize, facePixels); } else if (face == 4) { preview.SetPixels(previewFaceSize * 1, 2 * previewFaceSize, previewFaceSize, previewFaceSize, facePixels); } else if (face == 5) { preview.SetPixels(previewFaceSize * 1, 0, previewFaceSize, previewFaceSize, facePixels); } } else { preview.SetPixels(previewFaceSize * face, 0, previewFaceSize, previewFaceSize, facePixels); } } preview.Apply(); } }