private static void EqualizeHistogram(IESData iesData) { int num = Mathf.Min((int)iesData.CandelaValues.SelectMany((List <float> v) => v).Max(), 10000); float[] array = new float[num]; float[] array2 = new float[num]; foreach (List <float> list in iesData.NormalizedValues) { foreach (float num2 in list) { array[(int)(num2 * (float)(num - 1))] += 1f; } } float num3 = (float)(iesData.HorizontalAngles.Count * iesData.VerticalAngles.Count); for (int i = 0; i < array.Length; i++) { array[i] /= num3; } for (int j = 0; j < num; j++) { array2[j] = array.Take(j + 1).Sum(); } foreach (List <float> list2 in iesData.NormalizedValues) { for (int k = 0; k < list2.Count; k++) { int num4 = (int)(list2[k] * (float)(num - 1)); list2[k] = array2[num4] * (float)(num - 1) / (float)num; } } }
public Color[] CreateRawCubemap(Texture2D iesTexture, IESData iesData, int resolution) { // Prepare the material. PrepMaterial(iesTexture, iesData); // Create the render textures for the raw cubemap. Viewrect is not compatible with render textures, so render to 6 individual render textures and combine them afterwards. RenderTexture[] renderTargets = new RenderTexture[6]; for (int i = 0; i < 6; i++) { renderTargets[i] = RenderTexture.GetTemporary(resolution, resolution, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); renderTargets[i].filterMode = FilterMode.Trilinear; } // Apply the render target and render each face to the texture. Camera[] faceCameras = transform.GetChild(0).GetComponentsInChildren <Camera>(); for (int i = 0; i < 6; i++) { faceCameras[i].targetTexture = renderTargets[i]; faceCameras[i].Render(); faceCameras[i].targetTexture = null; } // Combine the faces into a single render target. RenderTexture combinedRenderTarget = RenderTexture.GetTemporary(resolution * 6, resolution, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); combinedRenderTarget.filterMode = FilterMode.Trilinear; // Faces have to be flipped horizontally. if (_horizontalMirrorMaterial == null) { _horizontalMirrorMaterial = new Material(Shader.Find("Hidden/IES/HorizontalFlip")); } // Blit each face to a single texture. RenderTexture.active = combinedRenderTarget; for (int i = 0; i < 6; i++) { GL.PushMatrix(); GL.LoadPixelMatrix(0, resolution * 6, 0, resolution); Graphics.DrawTexture(new Rect(i * resolution, 0, resolution, resolution), renderTargets[i], _horizontalMirrorMaterial); GL.PopMatrix(); } // Read back the texture data. Texture2D rawCubemap = new Texture2D(resolution * 6, resolution, TextureFormat.RGBAFloat, false, true) { filterMode = FilterMode.Trilinear }; rawCubemap.ReadPixels(new Rect(0, 0, rawCubemap.width, rawCubemap.height), 0, 0); Color[] pixels = rawCubemap.GetPixels(); // Clean up. RenderTexture.active = null; foreach (var renderTarget in renderTargets) { RenderTexture.ReleaseTemporary(renderTarget); } RenderTexture.ReleaseTemporary(combinedRenderTarget); DestroyImmediate(rawCubemap); return(pixels); }
private static float CalculateHalfSpotlightFovForTopHalf(IESData iesData) { for (int i = 0; i < iesData.VerticalAngles.Count; i++) { int j = 0; while (j < iesData.NormalizedValues.Count) { if (iesData.NormalizedValues[j][i] >= 0.1f) { if (iesData.VerticalType == VerticalType.Top) { if (i > 0) { return(180f - iesData.VerticalAngles[i - 1]); } return(180f - iesData.VerticalAngles[i]); } else { if (i > 0) { return(-iesData.VerticalAngles[i - 1]); } return(-iesData.VerticalAngles[i]); } } else { j++; } } } return(0f); }
private static void NormalizeValues(IESData iesData, bool squashHistogram) { iesData.NormalizedValues = new List <List <float> >(); float num = iesData.CandelaValues.SelectMany((List <float> v) => v).Max(); if (squashHistogram) { num = Mathf.Log(num); } foreach (List <float> list in iesData.CandelaValues) { List <float> list2 = new List <float>(); if (squashHistogram) { for (int i = 0; i < list.Count; i++) { list2.Add(Mathf.Log(list[i])); } } else { list2.AddRange(list); } for (int j = 0; j < list.Count; j++) { List <float> list3 = list2; int index = j; list3[index] /= num; list2[j] = Mathf.Clamp01(list2[j]); } iesData.NormalizedValues.Add(list2); } }
private static void SetVerticalAndHorizontalType(IESData iesData) { if ((iesData.VerticalAngles[0] == 0f && iesData.VerticalAngles[iesData.VerticalAngles.Count - 1] == 90f) || (iesData.VerticalAngles[0] == -90f && iesData.VerticalAngles[iesData.VerticalAngles.Count - 1] == 0f)) { iesData.VerticalType = VerticalType.Bottom; } else if (iesData.VerticalAngles[iesData.VerticalAngles.Count - 1] == 180f && iesData.VerticalAngles[0] == 90f) { iesData.VerticalType = VerticalType.Top; } else { iesData.VerticalType = VerticalType.Full; } if (iesData.HorizontalAngles.Count == 1) { iesData.HorizontalType = HorizontalType.None; return; } if (iesData.HorizontalAngles[iesData.HorizontalAngles.Count - 1] - iesData.HorizontalAngles[0] == 90f) { iesData.HorizontalType = HorizontalType.Quadrant; return; } if (iesData.HorizontalAngles[iesData.HorizontalAngles.Count - 1] - iesData.HorizontalAngles[0] == 180f) { iesData.HorizontalType = HorizontalType.Half; return; } iesData.HorizontalType = HorizontalType.Full; if (iesData.HorizontalAngles[iesData.HorizontalAngles.Count - 1] != 360f) { ParseIES.StitchHorizontalAssymetry(iesData); } }
public void CreateSpotlightCookie(Texture2D iesTexture, IESData iesData, int resolution, bool applyVignette, bool flipVertically, out Texture2D cookie) { // Create regular spotlight cookies using the designated shader which handles symmetry and vignetting. if (iesData.PhotometricType != PhotometricType.TypeA) { // Init the material. if (_spotlightMaterial == null) { _spotlightMaterial = new Material(Shader.Find("Hidden/IES/IESToSpotlightCookie")); } CalculateAndSetSpotHeight(iesData); SetShaderKeywords(iesData, applyVignette); cookie = CreateTexture(iesTexture, resolution, flipVertically); } // Blit automotive photometry straight from the prepared ies texture onto a texture of the target cookie size. A vignette may be applied to prevent sharp cookie edges. else { // Init the material. if (_fadeSpotlightEdgesMaterial == null) { _fadeSpotlightEdgesMaterial = new Material(Shader.Find("Hidden/IES/FadeSpotlightCookieEdges")); } // Calculate the position of the vertical center in the cookie. float verticalCenter = applyVignette ? CalculateCookieVerticalCenter(iesData) : 0; // Create the cookie using the aspect of the cookie (automotive data is most often in a wide horizontal aspect). Vector2 fadeEllipse = applyVignette ? CalculateCookieFadeEllipse(iesData) : Vector2.zero; cookie = BlitToTargetSize(iesTexture, resolution, fadeEllipse.x, fadeEllipse.y, verticalCenter, applyVignette, flipVertically); } }
/// <summary> /// To make optimal usage of the spot light, the ies cookie is filled to fit the field of view of the spot. /// </summary> private void CalculateAndSetSpotHeight(IESData iesData) { // The spot height is defined by the max spot angle over the radius of the uv plane (0.5). float spotHeight = 0.5f / Mathf.Tan(iesData.HalfSpotlightFov * Mathf.Deg2Rad); _spotlightMaterial.SetFloat("_SpotHeight", spotHeight); }
private float CalculateCookieVerticalCenter(IESData iesData) { float normalizedTop = 1f - (float)iesData.PadBeforeAmount / iesData.NormalizedValues[0].Count; float normalizedCenter = (float)(iesData.NormalizedValues[0].Count - iesData.PadBeforeAmount - iesData.PadAfterAmount) / iesData.NormalizedValues.Count / 2f; return(normalizedTop - normalizedCenter); }
/// <summary> /// Converts an IES file to either a point or spot light cookie. /// </summary> public void ConvertIES(string filePath, string targetPath, bool createSpotlightCookies, bool rawImport, bool applyVignette, out Cubemap pointLightCookie, out Texture2D spotlightCookie, out EXRData exrData, out string targetFilename) { // Parse the ies data. IESData iesData = ParseIES.Parse(filePath, rawImport ? NormalizationMode.Linear : NormalizationMode); // Create a texture from the normalized IES data. _iesTexture = IESToTexture.ConvertIesData(iesData); // Regular import - creates cookies that are directly usable within Unity. if (!rawImport) { exrData = default(EXRData); RegularImport(filePath, targetPath, createSpotlightCookies, applyVignette, out pointLightCookie, out spotlightCookie, out targetFilename, iesData); } // Raw import - creates a .exr import of the IES data instead, to give the user full control. else { pointLightCookie = null; spotlightCookie = null; RawImport(iesData, filePath, targetPath, createSpotlightCookies, out exrData, out targetFilename); } // Clean up. if (_iesTexture != null) { #if UNITY_EDITOR DestroyImmediate(_iesTexture); #else Destroy(_iesTexture); #endif } }
private float CalculateCookieVerticalCenter(IESData iesData) { float num = 1f - (float)iesData.PadBeforeAmount / (float)iesData.NormalizedValues[0].Count; float num2 = (float)(iesData.NormalizedValues[0].Count - iesData.PadBeforeAmount - iesData.PadAfterAmount) / (float)iesData.NormalizedValues.Count / 2f; return(num - num2); }
private void PrepMaterial(Texture2D iesTexture, IESData iesData) { if (this._iesMaterial == null) { this._iesMaterial = base.GetComponent <Renderer>().sharedMaterial; } this._iesMaterial.mainTexture = iesTexture; this.SetShaderKeywords(iesData, this._iesMaterial); }
private static void DiscardHalf(IESData iesData, int start, int range) { iesData.VerticalAngles.RemoveRange(start, range); for (int i = 0; i < iesData.CandelaValues.Count; i++) { iesData.CandelaValues[i].RemoveRange(start, range); iesData.NormalizedValues[i].RemoveRange(start, range); } }
private void PrepMaterial(Texture2D iesTexture, IESData iesData) { if (_iesMaterial == null) { _iesMaterial = GetComponent <Renderer>().sharedMaterial; } _iesMaterial.mainTexture = iesTexture; SetShaderKeywords(iesData, _iesMaterial); }
/// <summary> /// The given ies file may have vertical angles from 0 to 180, but only one half actually contains light. /// If this is the case, the unused half is discarded, and a spot light cookie can be created. /// </summary> private static void DiscardUnusedVerticalHalf(IESData iesData) { if (iesData.VerticalAngles[0] != 0 || iesData.VerticalAngles[iesData.VerticalAngles.Count - 1] != 180) { return; } // Check bottom half. for (int i = 0; i < iesData.VerticalAngles.Count; i++) { // There is light in the bottom half. if (iesData.NormalizedValues.Any(slice => slice[i] > SpotlightCutoff)) { break; } // There is no light in the bottom half. Discard it. if (iesData.VerticalAngles[i] == 90) { DiscardBottomHalf(iesData); return; } // There was no fixed 90 degree value - this can only happen in an improperly formatted file. else if (iesData.VerticalAngles[i] > 90) { iesData.VerticalAngles[i] = 90; DiscardBottomHalf(iesData); return; } } // Check top half. for (int i = iesData.VerticalAngles.Count - 1; i >= 0; i--) { // There is light in the top half. if (iesData.NormalizedValues.Any(slice => slice[i] > SpotlightCutoff)) { break; } // There is no light in the top half. Discard it. if (iesData.VerticalAngles[i] == 90) { DiscardTopHalf(iesData); return; } // There was no fixed 90 degree value - this can only happen in an improperly formatted file. else if (iesData.VerticalAngles[i] < 90) { iesData.VerticalAngles[i] = 90; DiscardTopHalf(iesData); return; } } }
private static float CalculateHalfSpotFov(IESData iesData) { if (iesData.VerticalType == VerticalType.Bottom && iesData.VerticalAngles[0] == 0f) { return(ParseIES.CalculateHalfSpotlightFovForBottomHalf(iesData)); } if (iesData.VerticalType == VerticalType.Top || (iesData.VerticalType == VerticalType.Bottom && iesData.VerticalAngles[0] == -90f)) { return(ParseIES.CalculateHalfSpotlightFovForTopHalf(iesData)); } return(-1f); }
private static void DiscardBottomHalf(IESData iesData) { int num = 0; int num2 = 0; while (num2 < iesData.VerticalAngles.Count && iesData.VerticalAngles[num2] != 90f) { num++; num2++; } ParseIES.DiscardHalf(iesData, 0, num); }
private Vector2 CalculateCookieFadeEllipse(IESData iesData) { if (iesData.HorizontalAngles.Count > iesData.VerticalAngles.Count) { return(new Vector2(0.5f, 0.5f * ((float)(iesData.NormalizedValues[0].Count - iesData.PadBeforeAmount - iesData.PadAfterAmount) / (float)iesData.NormalizedValues[0].Count))); } if (iesData.HorizontalAngles.Count < iesData.VerticalAngles.Count) { return(new Vector2(0.5f * (iesData.HorizontalAngles.Max() - iesData.HorizontalAngles.Min()) / (iesData.VerticalAngles.Max() - iesData.VerticalAngles.Min()), 0.5f)); } return(new Vector2(0.5f, 0.5f)); }
public void CreateSpotlightCookie(Texture2D iesTexture, IESData iesData, int resolution, out Texture2D cookie) { // Init the material. if (_material == null) { _material = new Material(Shader.Find("Hidden/IES/IESToSpotlightCookie")); } CalculateAndSetSpotHeight(iesData); SetShaderKeywords(iesData); cookie = CreateTexture(iesTexture, resolution); }
public static IESData Parse(string path, bool squashHistogram) { // Find the line containing the number of vertical and horizontal angles. string[] lines = File.ReadAllLines(path); int lineNumber = 0; FindNumberOfAnglesLine(lines, ref lineNumber); if (lineNumber == lines.Length - 1) { throw new IESParseException("No line containing number of angles found."); } // Read the number of vertical and horizontal angles. int numberOfVerticalAngles, numberOfHorizontalAngles; PhotometricType photometricType; ReadProperties(lines, ref lineNumber, out numberOfVerticalAngles, out numberOfHorizontalAngles, out photometricType); // Read the vertical angles. List <float> verticalAngles = ReadValues(lines, numberOfVerticalAngles, ref lineNumber); // Read the horizontal angles. List <float> horizontalAngles = ReadValues(lines, numberOfHorizontalAngles, ref lineNumber); // Read the candela values for all vertical slices for each horizontal angle. List <List <float> > values = new List <List <float> >(); for (int i = 0; i < numberOfHorizontalAngles; i++) { values.Add(ReadValues(lines, numberOfVerticalAngles, ref lineNumber)); } IESData iesData = new IESData() { VerticalAngles = verticalAngles, HorizontalAngles = horizontalAngles, CandelaValues = values, PhotometricType = photometricType }; // Normalize the candela values, applying the enhanced mode if requested. // The normalized values will also be used to discard practically unlit areas from spot light cookies. NormalizeValues(iesData, squashHistogram); DiscardUnusedVerticalHalf(iesData); SetVerticalAndHorizontalType(iesData); iesData.HalfSpotlightFov = CalculateHalfSpotFov(iesData); return(iesData); }
private void RawImport(IESData iesData, string filePath, string targetPath, bool createSpotlightCookie, out EXRData exrData, out string targetFilename) { if ((createSpotlightCookie && iesData.VerticalType != VerticalType.Full) || iesData.PhotometricType == PhotometricType.TypeA) { Texture2D texture2D = null; base.GetComponent <IESToSpotlightCookie>().CreateSpotlightCookie(this._iesTexture, iesData, this.Resolution, false, true, out texture2D); exrData = new EXRData(texture2D.GetPixels(), this.Resolution, this.Resolution); UnityEngine.Object.DestroyImmediate(texture2D); } else { exrData = new EXRData(base.GetComponent <IESToCubemap>().CreateRawCubemap(this._iesTexture, iesData, this.Resolution), this.Resolution * 6, this.Resolution); } this.BuildTargetFilename(Path.GetFileNameWithoutExtension(filePath), targetPath, false, true, NormalizationMode.Linear, iesData, out targetFilename); }
private static void PadToSquare(IESData iesData) { if (Mathf.Abs(iesData.HorizontalAngles.Count - iesData.VerticalAngles.Count) <= 1) { return; } int num = Mathf.Max(iesData.HorizontalAngles.Count, iesData.VerticalAngles.Count); if (iesData.HorizontalAngles.Count < num) { ParseIES.PadHorizontal(iesData, num); return; } ParseIES.PadVertical(iesData, num); }
public static IESData Parse(string path, NormalizationMode normalizationMode) { string[] array = File.ReadAllLines(path); int num = 0; ParseIES.FindNumberOfAnglesLine(array, ref num); if (num == array.Length - 1) { throw new IESParseException("No line containing number of angles found."); } int numberOfValuesToFind; int num2; PhotometricType photometricType; ParseIES.ReadProperties(array, ref num, out numberOfValuesToFind, out num2, out photometricType); List <float> verticalAngles = ParseIES.ReadValues(array, numberOfValuesToFind, ref num); List <float> horizontalAngles = ParseIES.ReadValues(array, num2, ref num); List <List <float> > list = new List <List <float> >(); for (int i = 0; i < num2; i++) { list.Add(ParseIES.ReadValues(array, numberOfValuesToFind, ref num)); } IESData iesdata = new IESData { VerticalAngles = verticalAngles, HorizontalAngles = horizontalAngles, CandelaValues = list, PhotometricType = photometricType }; ParseIES.NormalizeValues(iesdata, normalizationMode == NormalizationMode.Logarithmic); if (normalizationMode == NormalizationMode.EqualizeHistogram) { ParseIES.EqualizeHistogram(iesdata); } if (photometricType != PhotometricType.TypeA) { ParseIES.DiscardUnusedVerticalHalf(iesdata); ParseIES.SetVerticalAndHorizontalType(iesdata); iesdata.HalfSpotlightFov = ParseIES.CalculateHalfSpotFov(iesdata); } else { ParseIES.PadToSquare(iesdata); } return(iesdata); }
private void SetShaderKeywords(IESData iesData, bool applyVignette) { // Enable or disable the vignette. if (applyVignette) { _spotlightMaterial.EnableKeyword("VIGNETTE"); } else { _spotlightMaterial.DisableKeyword("VIGNETTE"); } // Set the appropriate keyword for whether or not the top half of the sphere is used. if (iesData.VerticalType == VerticalType.Top) { _spotlightMaterial.EnableKeyword("TOP_VERTICAL"); } else { _spotlightMaterial.DisableKeyword("TOP_VERTICAL"); } // Also set the approrpiate keyword for horizontal symmetry. if (iesData.HorizontalType == HorizontalType.None) { _spotlightMaterial.DisableKeyword("QUAD_HORIZONTAL"); _spotlightMaterial.DisableKeyword("HALF_HORIZONTAL"); _spotlightMaterial.DisableKeyword("FULL_HORIZONTAL"); } else if (iesData.HorizontalType == HorizontalType.Quadrant) { _spotlightMaterial.EnableKeyword("QUAD_HORIZONTAL"); _spotlightMaterial.DisableKeyword("HALF_HORIZONTAL"); _spotlightMaterial.DisableKeyword("FULL_HORIZONTAL"); } else if (iesData.HorizontalType == HorizontalType.Half) { _spotlightMaterial.DisableKeyword("QUAD_HORIZONTAL"); _spotlightMaterial.EnableKeyword("HALF_HORIZONTAL"); _spotlightMaterial.DisableKeyword("FULL_HORIZONTAL"); } else if (iesData.HorizontalType == HorizontalType.Full) { _spotlightMaterial.DisableKeyword("QUAD_HORIZONTAL"); _spotlightMaterial.DisableKeyword("HALF_HORIZONTAL"); _spotlightMaterial.EnableKeyword("FULL_HORIZONTAL"); } }
private void SetShaderKeywords(IESData iesData, Material iesMaterial) { if (iesData.VerticalType == VerticalType.Bottom) { iesMaterial.EnableKeyword("BOTTOM_VERTICAL"); iesMaterial.DisableKeyword("TOP_VERTICAL"); iesMaterial.DisableKeyword("FULL_VERTICAL"); } else if (iesData.VerticalType == VerticalType.Top) { iesMaterial.EnableKeyword("TOP_VERTICAL"); iesMaterial.DisableKeyword("BOTTOM_VERTICAL"); iesMaterial.DisableKeyword("FULL_VERTICAL"); } else { iesMaterial.DisableKeyword("TOP_VERTICAL"); iesMaterial.DisableKeyword("BOTTOM_VERTICAL"); iesMaterial.EnableKeyword("FULL_VERTICAL"); } if (iesData.HorizontalType == HorizontalType.None) { iesMaterial.DisableKeyword("QUAD_HORIZONTAL"); iesMaterial.DisableKeyword("HALF_HORIZONTAL"); iesMaterial.DisableKeyword("FULL_HORIZONTAL"); return; } if (iesData.HorizontalType == HorizontalType.Quadrant) { iesMaterial.EnableKeyword("QUAD_HORIZONTAL"); iesMaterial.DisableKeyword("HALF_HORIZONTAL"); iesMaterial.DisableKeyword("FULL_HORIZONTAL"); return; } if (iesData.HorizontalType == HorizontalType.Half) { iesMaterial.DisableKeyword("QUAD_HORIZONTAL"); iesMaterial.EnableKeyword("HALF_HORIZONTAL"); iesMaterial.DisableKeyword("FULL_HORIZONTAL"); return; } if (iesData.HorizontalType == HorizontalType.Full) { iesMaterial.DisableKeyword("QUAD_HORIZONTAL"); iesMaterial.DisableKeyword("HALF_HORIZONTAL"); iesMaterial.EnableKeyword("FULL_HORIZONTAL"); } }
public Color[] CreateRawCubemap(Texture2D iesTexture, IESData iesData, int resolution) { this.PrepMaterial(iesTexture, iesData); RenderTexture[] array = new RenderTexture[6]; for (int i = 0; i < 6; i++) { array[i] = RenderTexture.GetTemporary(resolution, resolution, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); array[i].filterMode = FilterMode.Trilinear; } Camera[] componentsInChildren = base.transform.GetChild(0).GetComponentsInChildren <Camera>(); for (int j = 0; j < 6; j++) { componentsInChildren[j].targetTexture = array[j]; componentsInChildren[j].Render(); componentsInChildren[j].targetTexture = null; } RenderTexture temporary = RenderTexture.GetTemporary(resolution * 6, resolution, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); temporary.filterMode = FilterMode.Trilinear; if (this._horizontalMirrorMaterial == null) { this._horizontalMirrorMaterial = new Material(Shader.Find("Hidden/IES/HorizontalFlip")); } RenderTexture.active = temporary; for (int k = 0; k < 6; k++) { GL.PushMatrix(); GL.LoadPixelMatrix(0f, (float)(resolution * 6), 0f, (float)resolution); Graphics.DrawTexture(new Rect((float)(k * resolution), 0f, (float)resolution, (float)resolution), array[k], this._horizontalMirrorMaterial); GL.PopMatrix(); } Texture2D texture2D = new Texture2D(resolution * 6, resolution, TextureFormat.RGBAFloat, false, true) { filterMode = FilterMode.Trilinear }; texture2D.ReadPixels(new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), 0, 0); Color[] pixels = texture2D.GetPixels(); RenderTexture.active = null; RenderTexture[] array2 = array; for (int l = 0; l < array2.Length; l++) { RenderTexture.ReleaseTemporary(array2[l]); } RenderTexture.ReleaseTemporary(temporary); UnityEngine.Object.DestroyImmediate(texture2D); return(pixels); }
private void SetShaderKeywords(IESData iesData, Material iesMaterial) { // Fill either the entire sphere or only the bottom of top half, depending on the vertical angles described in the file. if (iesData.VerticalType == VerticalType.Bottom) { iesMaterial.EnableKeyword("BOTTOM_VERTICAL"); iesMaterial.DisableKeyword("TOP_VERTICAL"); iesMaterial.DisableKeyword("FULL_VERTICAL"); } else if (iesData.VerticalType == VerticalType.Top) { iesMaterial.EnableKeyword("TOP_VERTICAL"); iesMaterial.DisableKeyword("BOTTOM_VERTICAL"); iesMaterial.DisableKeyword("FULL_VERTICAL"); } else { iesMaterial.DisableKeyword("TOP_VERTICAL"); iesMaterial.DisableKeyword("BOTTOM_VERTICAL"); iesMaterial.EnableKeyword("FULL_VERTICAL"); } // Also set the approrpiate keyword for horizontal symmetry. if (iesData.HorizontalType == HorizontalType.None) { iesMaterial.DisableKeyword("QUAD_HORIZONTAL"); iesMaterial.DisableKeyword("HALF_HORIZONTAL"); iesMaterial.DisableKeyword("FULL_HORIZONTAL"); } else if (iesData.HorizontalType == HorizontalType.Quadrant) { iesMaterial.EnableKeyword("QUAD_HORIZONTAL"); iesMaterial.DisableKeyword("HALF_HORIZONTAL"); iesMaterial.DisableKeyword("FULL_HORIZONTAL"); } else if (iesData.HorizontalType == HorizontalType.Half) { iesMaterial.DisableKeyword("QUAD_HORIZONTAL"); iesMaterial.EnableKeyword("HALF_HORIZONTAL"); iesMaterial.DisableKeyword("FULL_HORIZONTAL"); } else if (iesData.HorizontalType == HorizontalType.Full) { iesMaterial.DisableKeyword("QUAD_HORIZONTAL"); iesMaterial.DisableKeyword("HALF_HORIZONTAL"); iesMaterial.EnableKeyword("FULL_HORIZONTAL"); } }
public void CreateCubemap(Texture2D iesTexture, IESData iesData, int resolution, out Cubemap cubemap) { if (_iesMaterial == null) { _iesMaterial = GetComponent <Renderer>().sharedMaterial; } _iesMaterial.mainTexture = iesTexture; SetShaderKeywords(iesData, _iesMaterial); CreateCubemap(resolution, out cubemap); // Clean up. _iesMaterial.mainTexture = null; DestroyImmediate(iesTexture); }
private static void DiscardBottomHalf(IESData iesData) { int range = 0; for (int i = 0; i < iesData.VerticalAngles.Count; i++) { if (iesData.VerticalAngles[i] == 90) { break; } range++; } DiscardHalf(iesData, 0, range); }
private static void DiscardTopHalf(IESData iesData) { int num = 0; for (int i = 0; i < iesData.VerticalAngles.Count; i++) { if (iesData.VerticalAngles[i] == 90f) { num = i + 1; break; } } int range = iesData.VerticalAngles.Count - num; ParseIES.DiscardHalf(iesData, num, range); }
private static void PadVertical(IESData iesData, int longestSide) { int totalPadAmount = longestSide - iesData.VerticalAngles.Count; // If the sign of the highest and lowest angle are equal, just use the halfway point as center point. if (Mathf.Sign(iesData.VerticalAngles[0]) == Math.Sign(iesData.VerticalAngles[iesData.VerticalAngles.Count - 1])) { int halfPadAmount = totalPadAmount / 2; iesData.PadBeforeAmount = halfPadAmount; iesData.PadAfterAmount = totalPadAmount - halfPadAmount; foreach (var verticalSlice in iesData.NormalizedValues) { verticalSlice.InsertRange(0, new List <float>(new float[halfPadAmount])); verticalSlice.AddRange(new List <float>(new float[totalPadAmount - halfPadAmount])); } } // Otherwise, keep 0 degrees on the horizon. else { // Calculate the amount of entries to add at the top (angle > 0) int topPadAmount = longestSide / 2 - iesData.VerticalAngles.Count(v => v >= 0); // If vertical angles start negative... if (iesData.VerticalAngles[0] < 0) { iesData.PadBeforeAmount = totalPadAmount - topPadAmount; iesData.PadAfterAmount = topPadAmount; foreach (var verticalSlice in iesData.NormalizedValues) { verticalSlice.InsertRange(0, new List <float>(new float[totalPadAmount - topPadAmount])); verticalSlice.AddRange(new List <float>(new float[topPadAmount])); } } // Else, if the vertical angles start positive... else { iesData.PadBeforeAmount = topPadAmount; iesData.PadAfterAmount = totalPadAmount - topPadAmount; foreach (var verticalSlice in iesData.NormalizedValues) { verticalSlice.InsertRange(0, new List <float>(new float[topPadAmount])); verticalSlice.AddRange(new List <float>(new float[totalPadAmount - topPadAmount])); } } } }