public override float Evaluate(Representation representation) { RepresentationMesh repre = representation as RepresentationMesh; if (repre == null) { return(0); } Vector4 structMinMax = getStructureSize(repre.goList); Vector2 minPoint = new Vector2(structMinMax.x, structMinMax.y); Vector2 maxPoint = new Vector2(structMinMax.z, structMinMax.w); Vector2 structSize = maxPoint - minPoint; float cameraSize = Mathf.Max(structSize.x, structSize.y) / 2f; Vector3 cameraPosition = (maxPoint + minPoint) / 2f; cameraPosition.z = -10f; int texSize = 64; RenderTexture renderTexture = new RenderTexture(texSize, texSize, 0); RenderTexture renderTextureTemp = null; GameObject camera = new GameObject("Camera"); camera.transform.position = cameraPosition; camera.AddComponent <Camera> (); camera.GetComponent <Camera> ().clearFlags = CameraClearFlags.Color; camera.GetComponent <Camera> ().backgroundColor = Color.white; camera.GetComponent <Camera> ().orthographic = true; camera.GetComponent <Camera> ().orthographicSize = cameraSize; camera.GetComponent <Camera> ().targetTexture = renderTexture; camera.AddComponent <GrayscaleBinary> (); camera.GetComponent <GrayscaleBinary> ().shader = Shader.Find("Hidden/GrayscaleBinary"); renderTextureTemp = RenderTexture.active; RenderTexture.active = renderTexture; camera.GetComponent <Camera> ().Render(); Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false); texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); texture.Apply(); TextureCount.Count(texture); RenderTexture.active = renderTextureTemp; GameObject.DestroyImmediate(camera); return((float)TextureCount.boxCount / (float)(texSize * texSize)); }
public virtual TextureHandler GetTexture(Enum id, out Vector2 scale) { uint pos = Convert.ToUInt32(id); uint File = GetEntry(id).File; //check if we set a custom file and we have a pos more then set entriespertexture if (File == 0 && EntriesPerTexture > 0 && pos > EntriesPerTexture) { File = (uint)(pos / EntriesPerTexture); } if (File > 0) { uint j = (uint)TextureCount.Sum(); if (File >= j) { File %= j; } } scale = Scale[File]; return(Textures[(int)File]); }
protected virtual void InitTextures(ArchiveWorker aw = null) { if (Textures == null) { Textures = new List <TextureHandler>(TextureCount.Sum()); } if (Textures.Count <= 0) { if (aw == null) { aw = new ArchiveWorker(ArchiveString); } TEX tex; Scale = new Dictionary <uint, Vector2>(TextureCount.Sum()); int b = 0; for (int j = 0; j < TextureCount.Length; j++) { for (uint i = 0; i < TextureCount[j]; i++) { string path = aw.GetListOfFiles().First(x => x.ToLower().Contains(string.Format(TextureFilename[j], i + TextureStartOffset))); tex = new TEX(ArchiveWorker.GetBinaryFile(ArchiveString, path)); if (TextureBigFilename != null && FORCE_ORIGINAL == false && b < TextureBigFilename.Length && b < TextureBigSplit.Length) { TextureHandler th = new TextureHandler(TextureBigFilename[b], tex, 2, TextureBigSplit[b++] / 2); Textures.Add(th); Scale[i] = Vector2.One;//th.GetScale(); } else { TextureHandler th = new TextureHandler(path, tex); Textures.Add(th); Scale[i] = th.GetScale(); } } } } }
public override string ToString() { return(String.Format("ColorCount: {0} | TextureCount: {1} | Normal Format: {2} [Data: {3}] ", ColorCount.ToString(), TextureCount.ToString(), NormalFormat.ToString(), (int)_data)); }
public override float Evaluate(Representation representation) { RepresentationMesh repre = representation as RepresentationMesh; if (repre == null) { return(0); } Vector4 structSize = getStructureSize(repre.goList); Vector2 minPoint = new Vector2(structSize.x, structSize.y); Vector2 maxPoint = new Vector2(structSize.z, structSize.w); Vector2 ivySize = maxPoint - minPoint; float cameraSize = Mathf.Max(ivySize.x, ivySize.y) / 2f; Vector3 cameraPosition = (maxPoint + minPoint) / 2f; cameraPosition.z = -10f; int texSize = 1024; float boxSize = 1f / (float)texSize; RenderTexture renderTexture = new RenderTexture(texSize, texSize, 0); RenderTexture renderTextureTemp = null; GameObject camera = new GameObject("Camera"); camera.transform.position = cameraPosition; camera.AddComponent <Camera> (); camera.GetComponent <Camera> ().backgroundColor = Color.white; camera.GetComponent <Camera> ().orthographic = true; camera.GetComponent <Camera> ().orthographicSize = cameraSize; camera.GetComponent <Camera> ().targetTexture = renderTexture; camera.AddComponent <GrayscaleBinary> (); camera.GetComponent <GrayscaleBinary> ().shader = Shader.Find("Hidden/GrayscaleBinary"); renderTextureTemp = RenderTexture.active; RenderTexture.active = renderTexture; camera.GetComponent <Camera> ().Render(); Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false); texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); texture.Apply(); TextureCount.Count(texture); List <Vector2> logValues = new List <Vector2> (); logValues.Add(new Vector2(Mathf.Log10(1f / boxSize), Mathf.Log10((float)TextureCount.boxCount))); while (texture.width > 8) { TextureScale.Half(texture); boxSize *= 2; if (TextureScale.newBoxCount == 0) { UnityEditor.EditorApplication.isPlaying = false; } logValues.Add(new Vector2(Mathf.Log10(1f / boxSize), Mathf.Log10((float)TextureScale.newBoxCount))); } float averageSlope = 0f; for (int i = 0; i < logValues.Count - 1; i++) { averageSlope += (logValues[i].y - logValues[i + 1].y) / (logValues[i].x - logValues[i + 1].x); } averageSlope /= (logValues.Count - 1); RenderTexture.active = renderTextureTemp; GameObject.DestroyImmediate(camera); return(averageSlope); }
public void Map() { var lastCamera = Camera.Current; var lights = Game.World.Scene.GetLights(); var light = lights[0]; for (int i = 0; i < Shader.ProgramsList.Length; i++) { var s = Shader.ProgramsList[i]; if (!s.Compiled) { continue; } s.Use(); s.SetUniform("GridSizeX", GridSizeX); s.SetUniform("GridSizeY", GridSizeY); s.SetUniform("GridSizeZ", GridSizeZ); s.SetUniform("BoxSize", BoxSize); s.SetUniform("MapPosition", -MapPosition); light.SetUniforms(); light.BindShadowMap(20, 21); SetUniforms(); BindTexture(TextureUnit.Texture25); } TextureRed.Clear(); TextureGreen.Clear(); TextureBlue.Clear(); TextureCount.Clear(); //TextureResolved.Clear(); FBO.Use(); GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); TextureRed.BindImageUnit(6, TextureAccess.ReadWrite, SizedInternalFormat.R32ui); TextureGreen.BindImageUnit(1, TextureAccess.ReadWrite, SizedInternalFormat.R32ui); TextureBlue.BindImageUnit(2, TextureAccess.ReadWrite, SizedInternalFormat.R32ui); TextureCount.BindImageUnit(3, TextureAccess.ReadWrite, SizedInternalFormat.R32ui); /* * TextureNormalX.BindImageUnit(7, TextureAccess.ReadWrite, SizedInternalFormat.R32i); * TextureNormalY.BindImageUnit(8, TextureAccess.ReadWrite, SizedInternalFormat.R32i); * TextureNormalZ.BindImageUnit(9, TextureAccess.ReadWrite, SizedInternalFormat.R32i); */ // Camera.Current = RenderingCameraX; // RenderWorld(); Camera.Current = RenderingCameraX; RenderingCameraX.SetOrientation(XForward); RenderingCameraX.Update(); RenderingCameraX.Transformation.ClearModifiedFlag(); RenderWorld(); Camera.Current = RenderingCameraY; RenderingCameraY.SetOrientation(YForward); RenderingCameraY.Update(); RenderingCameraY.Transformation.ClearModifiedFlag(); RenderWorld(); Camera.Current = RenderingCameraZ; RenderingCameraZ.SetOrientation(ZForward); RenderingCameraZ.Update(); RenderingCameraZ.Transformation.ClearModifiedFlag(); RenderWorld(); // Camera.Current = RenderingCameraZ; // RenderWorld(); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); TextureResolvedMipMaps[0].BindImageUnit(4, TextureAccess.WriteOnly, SizedInternalFormat.Rgba16f); TextureRed.Use(TextureUnit.Texture0); TextureGreen.Use(TextureUnit.Texture1); TextureBlue.Use(TextureUnit.Texture2); TextureCount.Use(TextureUnit.Texture3); TextureResolverShader.Use(); TextureResolverShader.Dispatch(GridSizeX / 16, GridSizeY / 8, GridSizeZ / 8); GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); /* * TextureNormalX.Use(TextureUnit.Texture0); * TextureNormalY.Use(TextureUnit.Texture1); * TextureNormalZ.Use(TextureUnit.Texture2); * TextureCount.Use(TextureUnit.Texture3); * TextureNormalResolved.BindImageUnit(10, TextureAccess.ReadWrite, SizedInternalFormat.Rgba16f); * * TextureResolverNormalShader.Use(); * TextureResolverNormalShader.Dispatch(GridSize / 16, GridSize / 8, GridSize / 8); */ TextureMipmapShader.Use(); for (int i = 0; i < TextureResolvedMipMaps.Count - 1; i++) { TextureResolvedMipMaps[i].Use(TextureUnit.Texture0); TextureResolvedMipMaps[i + 1].BindImageUnit(4, TextureAccess.WriteOnly, SizedInternalFormat.Rgba16f); TextureMipmapShader.Dispatch(TextureResolvedMipMaps[i + 1].SizeX / 8, TextureResolvedMipMaps[i + 1].SizeY / 8, TextureResolvedMipMaps[i + 1].SizeZ / 8); GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); } Camera.Current = lastCamera; }