private static void SetSharedUniforms(Camera c, Shader shader) { shader.SetMatrix4x4("mvpMatrix", c.MvpMatrix); OpenTK.Matrix4 sphereMatrix = c.ModelViewMatrix; sphereMatrix.Invert(); sphereMatrix.Transpose(); shader.SetMatrix4x4("sphereMatrix", sphereMatrix); shader.SetInt("renderType", (int)Runtime.renderType); shader.SetTexture("UVTestPattern", RenderTools.uvTestPattern, 10); shader.SetBoolToInt("renderR", Runtime.renderR); shader.SetBoolToInt("renderG", Runtime.renderG); shader.SetBoolToInt("renderB", Runtime.renderB); shader.SetBoolToInt("renderAlpha", Runtime.renderAlpha); bool alphaOverride = Runtime.renderAlpha && !Runtime.renderR && !Runtime.renderG && !Runtime.renderB; shader.SetBoolToInt("alphaOverride", alphaOverride); shader.SetBoolToInt("renderNormalMap", Runtime.renderNormalMap); shader.SetBoolToInt("renderDiffuse", Runtime.renderDiffuse); shader.SetBoolToInt("renderSpecular", Runtime.renderSpecular); }
// Parse meta data from image Json public static void ParseImageDescriptor(string imagemetapath, out Dictionary <string, object> meta, out OpenTK.Matrix4 invview) { meta = null; invview = OpenTK.Matrix4.Identity; if (!File.Exists(imagemetapath)) { return; } StreamReader sr = new StreamReader(new FileStream(imagemetapath, FileMode.Open, FileAccess.Read)); dynamic json = JsonConvert.DeserializeObject(sr.ReadToEnd()); sr.Close(); try { meta = ((JObject)json.variables).ToObject <Dictionary <string, object> >(); } catch {} if (json["lookat"] != null) { float[] lookat = json["lookat"].ToObject <float[]>(); if (lookat.Length == 9) { invview = OpenTK.Matrix4.LookAt(lookat[0], lookat[1], lookat[2], -lookat[3], lookat[4], lookat[5], lookat[6], lookat[7], lookat[8]).Inverted(); //EDIT: -lookat[3] or lookat[3] ??? } } else if (json["theta-phi-xyz"] != null) { float[] theta_phi_xyz = json["theta-phi-xyz"].ToObject <float[]>(); if (theta_phi_xyz.Length == 5) { invview = OpenTK.Matrix4.CreateTranslation(-theta_phi_xyz[2], theta_phi_xyz[3], -theta_phi_xyz[4]); invview *= OpenTK.Matrix4.CreateRotationY(theta_phi_xyz[0]); invview *= OpenTK.Matrix4.CreateRotationX(-theta_phi_xyz[1]); invview.Invert(); } } }