private void CreateFromEmissiveTexture(Texture2D emissionTexture2D) { // Calculate points that are bright for (int x = 0; x < emissionTexture2D.width; x += sample) { for (int y = 0; y < emissionTexture2D.height; y += sample) { var color = emissionTexture2D.GetPixel(x, y); if (color.Equals(Color.black)) { continue; } var pos = new Vector2(x, y); var uvPos = new Vector2((float)x / emissionTexture2D.width, (float)y / emissionTexture2D.height); MapParticleData m = new MapParticleData(); m.color = color; m.texPosition = pos; m.uvPosition = uvPos; m.position = UvTo3D(uvPos); // How to?? m.normal = FindNormal(m.position);// normals[0]; if (_mapParticleDatas.Contains(m)) { continue; } _mapParticleDatas.Add(m); } } InstantiateFromMapParticleData(); }
private void IterateUvs(Texture2D emissionTexture2D) { for (var uvX = 0f; uvX <= 1f; uvX += uvPresicion) { for (var uvY = 0f; uvY <= 1f; uvY += uvPresicion) { var uvCoordinate = new Vector2(uvX, uvY); var x = uvX * emissionTexture2D.width; var y = uvY * emissionTexture2D.height; var color = emissionTexture2D.GetPixel((int)x, (int)y); if (color.Equals(Color.black)) { continue; } MapParticleData m = new MapParticleData(); m.color = color; m.texPosition = new Vector2(x, y); m.uvPosition = uvCoordinate; m.position = UvTo3D(uvCoordinate); // How to?? m.normal = FindNormal(m.position);//normals[0]; if (_mapParticleDatas.Contains(m)) { continue; } _mapParticleDatas.Add(m); } } InstantiateFromMapParticleData(); }