static public RenderTextureFormat GetFourierRenderTextureFormat() { RenderTextureFormat fmt = RenderTextureFormat.Default; if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat)) { fmt = RenderTextureFormat.ARGBFloat; } else if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)) { fmt = RenderTextureFormat.ARGBHalf; } Debug.Log("FourierTextureFormat = " + fmt.ToString()); return(fmt); }
public void SetTextureFormat(RenderTextureFormat fmt) { switch (fmt) { case RenderTextureFormat.RHalf: _textureFormat = TexFormat.RHalf; break; case RenderTextureFormat.RGHalf: _textureFormat = TexFormat.RGHalf; break; case RenderTextureFormat.ARGBHalf: _textureFormat = TexFormat.RGBAHalf; break; default: Debug.LogError("Unsupported texture format for readback: " + fmt.ToString(), this); break; } }
void CreateTextureQuad(RenderTextureFormat format, Vector3 pos) { if ((int)format >= 0) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad); Transform t = go.GetComponent <Transform> (); MeshRenderer mr = go.GetComponent <MeshRenderer> (); Material mat = new Material(_shader); TextureFormat tf = TextureFormat.Alpha8; bool isFormat = false; string s = format.ToString(); try { tf = (TextureFormat)Enum.Parse(typeof(TextureFormat), s); isFormat = true; } catch (ArgumentException e) { isFormat = false; } Texture2D tex = null; if (SystemInfo.SupportsRenderTextureFormat(format) && isFormat) { Debug.Log("Texture supported " + format.ToString()); tex = new Texture2D(widthheight, widthheight, tf, false); Graphics.CopyTexture(refTexture, tex); LabelMaker.MakeLabel(format.ToString(), Color.green, t); } else { Debug.LogWarning("Texture not supported on platform of CopyTexture " + format.ToString()); tex = errorTexture; LabelMaker.MakeLabel(format.ToString(), Color.red, t); } tex.filterMode = FilterMode.Point; mat.mainTexture = tex; mat.name = format.ToString(); mr.material = mat; tex.wrapMode = TextureWrapMode.Repeat; go.name = format.ToString(); t.SetParent(transform); t.position = pos; } }
/// <summary> /// Select vertex indexes contained within a rect. /// </summary> /// <param name="camera"></param> /// <param name="pickerRect"></param> /// <param name="selection"></param> /// <param name="doDepthTest"></param> /// <param name="renderTextureWidth"></param> /// <param name="renderTextureHeight"></param> /// <returns>A dictionary of pb_Object selected vertex indexes.</returns> public static Dictionary <ProBuilderMesh, HashSet <int> > PickVerticesInRect( Camera camera, Rect pickerRect, IList <ProBuilderMesh> selection, bool doDepthTest, int renderTextureWidth = -1, int renderTextureHeight = -1) { Dictionary <uint, SimpleTuple <ProBuilderMesh, int> > map; Dictionary <ProBuilderMesh, HashSet <int> > selected = new Dictionary <ProBuilderMesh, HashSet <int> >(); #if PB_RENDER_PICKER_TEXTURE List <Color> rectImg = new List <Color>(); #endif Texture2D tex = RenderSelectionPickerTexture(camera, selection, doDepthTest, out map, renderTextureWidth, renderTextureHeight); Color32[] pix = tex.GetPixels32(); int ox = System.Math.Max(0, Mathf.FloorToInt(pickerRect.x)); int oy = System.Math.Max(0, Mathf.FloorToInt((tex.height - pickerRect.y) - pickerRect.height)); int imageWidth = tex.width; int imageHeight = tex.height; int width = Mathf.FloorToInt(pickerRect.width); int height = Mathf.FloorToInt(pickerRect.height); UObject.DestroyImmediate(tex); SimpleTuple <ProBuilderMesh, int> hit; HashSet <int> indexes = null; HashSet <uint> used = new HashSet <uint>(); for (int y = oy; y < System.Math.Min(oy + height, imageHeight); y++) { for (int x = ox; x < System.Math.Min(ox + width, imageWidth); x++) { uint v = DecodeRGBA(pix[y * imageWidth + x]); #if PB_RENDER_PICKER_TEXTURE rectImg.Add(pix[y * imageWidth + x]); #endif if (used.Add(v) && map.TryGetValue(v, out hit)) { if (selected.TryGetValue(hit.item1, out indexes)) { indexes.Add(hit.item2); } else { selected.Add(hit.item1, new HashSet <int>() { hit.item2 }); } } } } var coincidentSelection = new Dictionary <ProBuilderMesh, HashSet <int> >(); // workaround for picking vertices that share a position but are not shared foreach (var meshSelection in selected) { var positions = meshSelection.Key.positionsInternal; var sharedVertices = meshSelection.Key.sharedVerticesInternal; var positionHash = new HashSet <int>(meshSelection.Value.Select(x => VectorHash.GetHashCode(positions[sharedVertices[x][0]]))); var collected = new HashSet <int>(); for (int i = 0, c = sharedVertices.Length; i < c; i++) { var hash = VectorHash.GetHashCode(positions[sharedVertices[i][0]]); if (positionHash.Contains(hash)) { collected.Add(i); } } coincidentSelection.Add(meshSelection.Key, collected); } selected = coincidentSelection; #if PB_RENDER_PICKER_TEXTURE if (width > 0 && height > 0) { Texture2D img = new Texture2D(width, height); img.SetPixels(rectImg.ToArray()); img.Apply(); System.IO.File.WriteAllBytes("Assets/rect_" + s_RenderTextureFormat.ToString() + ".png", img.EncodeToPNG()); #if UNITY_EDITOR UnityEditor.AssetDatabase.Refresh(); #endif UObject.DestroyImmediate(img); } #endif return(selected); }
void append(StringBuilder sb, RenderTextureFormat fmt) { sb.Append(fmt.ToString() + "\t\t" + SystemInfo.SupportsRenderTextureFormat(fmt) + "\n"); }
internal bool ValidateFormat(RenderTextureFormat format) { if (SystemInfo.SupportsRenderTextureFormat(format)) { return(true); } else { Debug.LogError(String.Format("RenderTexture creation failed. '{0}' is not supported on this platform. Use 'SystemInfo.SupportsRenderTextureFormat' C# API to check format support.", format.ToString()), this); return(false); } }
private static TextureFormat GetBest2DFormat(RenderTextureFormat formatRT) { switch (formatRT) { case RenderTextureFormat.Default: case RenderTextureFormat.DefaultHDR: return TextureFormat.ARGB32; default: return formatRT.ToString().Contains("A") ? TextureFormat.ARGB32 : TextureFormat.RGB24; } }
internal bool ValidateFormat(RenderTextureFormat format) { bool flag = SystemInfo.SupportsRenderTextureFormat(format); bool result; if (flag) { result = true; } else { Debug.LogError(string.Format("RenderTexture creation failed. '{0}' is not supported on this platform. Use 'SystemInfo.SupportsRenderTextureFormat' C# API to check format support.", format.ToString()), this); result = false; } return(result); }