public static PropertyNameMap LoadPropertyNameMap(string shaderName) { string content = ManifestResourceLoader.LoadTextFile(string.Format( "{0}.{0}.PropertyNameMap.xml", shaderName)); PropertyNameMap result = PropertyNameMap.Parse(XElement.Parse(content)); return(result); }
private void LoadModel() { string datafilePrefix = @"data\floordata"; int noneZeroItemCount = 0; bool minSet = false, maxSet = false; float min = 0, max = 0; char[] separator = new char[] { ' ', '\t', '\r', '\n' }; for (int i = 0; i < 20; i++) { string filename = datafilePrefix + (i + 1).ToString() + ".txt"; //using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) using (var sr = new StreamReader(filename)) { while (!sr.EndOfStream) { var line = sr.ReadLine(); var parts = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (var part in parts) { float value; if (float.TryParse(part, out value)) { if (value != 0.0f) { noneZeroItemCount++; } if (!minSet) { min = value; minSet = true; } if (!maxSet) { max = value; maxSet = true; } if (value < min) { min = value; } if (max < value) { max = value; } } else { throw new Exception(); } } } } } ColorBar colorBar = ColorBar.GetDefault(); int xSize = 921, ySize = 921, zSize = 20; int vertexIndex = 0; List <vec3> positionList = new List <vec3>(); List <vec3> colorList = new List <vec3>(); for (int i = 0; i < 20; i++) { string filename = datafilePrefix + (i + 1).ToString() + ".txt"; using (var sr = new StreamReader(filename)) { while (!sr.EndOfStream) { var line = sr.ReadLine(); var parts = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); foreach (var part in parts) { float value; if (float.TryParse(part, out value)) { if (value != 0.0f) { vec3 color = colorBar.GetColor(min, max, value); //vec3 color = new vec3(1, 1, 1); colorList.Add(color); float x = vertexIndex % xSize; float y = (vertexIndex % (xSize * ySize)) / ySize; float z = vertexIndex / ySize / xSize; if (vertexIndex != x + y * xSize + z * ySize * xSize) { Console.WriteLine("asdf"); } vec3 position = new vec3(x - xSize / 2, y - ySize / 2, z - zSize / 2); position = position / 10; positionList.Add(position); } vertexIndex++; } else { throw new Exception(); } } } } } RadarModel model = new RadarModel(positionList, colorList); CodeShader[] codeShaders = new CodeShader[2]; codeShaders[0] = new CodeShader(File.ReadAllText("Radar.vert"), CodeShader.GLSLShaderType.VertexShader); codeShaders[1] = new CodeShader(File.ReadAllText("Radar.frag"), CodeShader.GLSLShaderType.FragmentShader); PropertyNameMap propertyNameMap = PropertyNameMap.Parse(XElement.Load("Radar.PropertyNameMap.xml")); UniformNameMap uniformNameMap = UniformNameMap.Parse(XElement.Load("Radar.UniformNameMap.xml")); this.modelRenderer = new ModernRenderer(model, codeShaders, propertyNameMap, uniformNameMap); this.modelRenderer.SwitchList.Add(new PointSpriteSwitch()); this.modelRenderer.Initialize();//不在此显式初始化也可以。 this.modelRenderer.SetUniformValue("canvasWidth", (float)this.glCanvas1.Width); this.modelRenderer.SetUniformValue("canvasHeight", (float)this.glCanvas1.Height); this.modelRenderer.SetUniformValue("brightness", 1.0f); Texture2D texture = new Texture2D(); texture.Initialize(new Bitmap("cloud30.png")); this.modelRenderer.SetUniformValue("cloudTexture", new samplerValue(texture.Name, ActiveTextureIndex.Texture0)); }