// Uniforms can be of multiple types - mat, int, float.. public bool SetUniform(OpenGL gl, string key, object value) { bool ret = false; // Find the ID of the uniform int id = GetUniformID(gl, key); // Find the type of the uniform if (value.GetType() == typeof(int)) { gl.Uniform1(id, (int)Convert.ToInt32(value)); } else if (value.GetType() == typeof(float)) { gl.Uniform1(id, (float)Convert.ToDecimal(value)); } else if (value.GetType() == typeof(vec3)) { vec3 v = (vec3)Convert.ChangeType(value, typeof(vec3)); gl.Uniform3(id, v.x, v.y, v.z); } else if (value.GetType() == typeof(vec4)) { vec4 v = (vec4)Convert.ChangeType(value, typeof(vec4)); gl.Uniform4(id, v.x, v.y, v.z, v.w); } else if (value.GetType() == typeof(mat3)) { mat3 m = (mat3)Convert.ChangeType(value, typeof(mat3)); gl.UniformMatrix4(id, 1, false, m.to_array()); } else if (value.GetType() == typeof(mat4)) { mat4 m = (mat4)Convert.ChangeType(value, typeof(mat4)); gl.UniformMatrix4(id, 1, false, m.to_array()); } else { throw new Exception("Unimplemented Uniform Type"); } return(ret); }
public void SetUniformMat3(string name, mat3 v) { int location = getUniformLocation(name); Gl.UniformMatrix3(location, false, v.to_array()); }
public void Draw_Wrapped(OpenGL gl) { //shaderProgram.SetUniform1 Projectile.jp.ProcessStartingData(); float rads = (StaticSettings.S.AngleOfView / 360.0f) * (float)Math.PI * 2.0f; projectionMatrix = glm.perspective(rads, width / height, 0.1f, 1000.0f); // Create a view matrix to move us back a bit. viewMatrix = glm.translate(new mat4(1.0f), new vec3(-SS.env.player.coords.Player_precise_position.x, -SS.env.player.coords.Player_precise_position.y, -SS.env.player.coords.Player_precise_position.z)); rotMatrix = glm.scale(new mat4(1.0f), new vec3(1.0f)) * glm.rotate(-SS.env.player.coords.Player_rotational_view.y, new vec3(1.0f, 0.0f, 0.0f)) * glm.rotate(-SS.env.player.coords.Player_rotational_view.x, new vec3(0.0f, 1.0f, 0.0f)) * glm.rotate(0, new vec3(0.0f, 0.0f, 1.0f)); playerMatrix_veced[0] = Sun.S.player_pos; playerMatrix_veced[1] = Sun.S.player_stepback; playerMatrix_veced[2] = Sun.S.player_stepback - Sun.S.player_look; StaticShadow.Sh.ShadowProtocol(); playerMatrix = new mat3(playerMatrix_veced); // Clear the scene. gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT); Time.time.GetSkyColor(gl); if (StaticSettings.S.Compass) { StaticCompass.C.Draw_Compas(gl, (int)StaticAccess.FMOS.openGLControl.Width / 2, (int)(0 + StaticCompass.C.r * 2 + 2)); } // Bind the shader, set the matrices. shaderProgram.Bind(gl); shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array()); shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array()); shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array()); shaderProgram.SetUniformMatrix4(gl, "rotMatrix", rotMatrix.to_array()); shaderProgram.SetUniform3(gl, "SunPosition", StaticShadow.Sh.SunPosition.x, StaticShadow.Sh.SunPosition.y, StaticShadow.Sh.SunPosition.z); shaderProgram.SetUniformMatrix3(gl, "playerMatrix", playerMatrix.to_array()); sunMatrix = new mat3(new vec3(-(float)Time.time.GetTotalRadianTime(), 0, 0), new vec3(0, DataForDraw.localed_range * Sun.LocalSun.Sun_Height, 0),//new vec3(0, (float)+DataForDraw.localed_range * 100, 0), new vec3(StaticSettings.S.SunStatus.x, 0, StaticSettings.S.PointOfViewCuterEnabled)); shaderProgram.SetUniformMatrix3(gl, "sunMatrix", sunMatrix.to_array()); shaderProgram.SetUniform1(gl, "settingsTransparency", 1.0f); shaderProgram.SetUniform1(gl, "TimeTotalSeconds", (float)Time.time.GetTotalSeconds()); shaderProgram.SetUniform1(gl, "settingsTHIS_IS_EXPLOSION", 0.0f); shaderProgram.SetUniform3(gl, "viewparameters", (float)(StaticSettings.S.RangeOfView_Old - 1) * 16, StaticSettings.S.PointOfViewCoefOfDifference, StaticSettings.S.SunSidedCoef ); // Bind the out vertex array. SS.Main.scene_info.vertexBufferArray.Bind(gl); // Draw the square. gl.DrawArrays(OpenGL.GL_POINTS, 0, SS.Main.Quantity() / 3); // Unbind our vertex array and shader. SS.Main.scene_info.vertexBufferArray.Unbind(gl); shaderProgram.Unbind(gl); if (StaticSettings.S.Secondary_SceneInfo_is_Activated) { shaderProgram_secondary.Bind(gl); shaderProgram_secondary.SetUniform3(gl, "SunPosition", StaticShadow.Sh.SunPosition.x, StaticShadow.Sh.SunPosition.y, StaticShadow.Sh.SunPosition.z); shaderProgram_secondary.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array()); shaderProgram_secondary.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array()); shaderProgram_secondary.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array()); shaderProgram_secondary.SetUniformMatrix4(gl, "rotMatrix", rotMatrix.to_array()); shaderProgram_secondary.SetUniformMatrix3(gl, "playerMatrix", playerMatrix.to_array()); sunMatrix = new mat3(new vec3(-(float)Time.time.GetTotalRadianTime(), 0, 0), new vec3(0, DataForDraw.localed_range * Sun.LocalSun.Sun_Height, 0),//new vec3(0, (float)+DataForDraw.localed_range * 100, 0), new vec3(StaticSettings.S.SunStatus.x, 1.0f, 0.0f)); shaderProgram_secondary.SetUniformMatrix3(gl, "sunMatrix", sunMatrix.to_array()); shaderProgram_secondary.SetUniform1(gl, "settingsTransparency", 1.0f); shaderProgram_secondary.SetUniform1(gl, "TimeTotalSeconds", (float)Time.time.GetGameTotalSeconds()); shaderProgram_secondary.SetUniform1(gl, "settingsTHIS_IS_EXPLOSION", 0.0f); //shaderProgram_secondary.SetUniform1(gl, "TimePauseForExplosion", Projectile.jp.TimePauseUntilExplosion); shaderProgram_secondary.SetUniform3(gl, "viewparameters", (float)(StaticSettings.S.RangeOfView_Old - 1) * 16, StaticSettings.S.PointOfViewCoefOfDifference, StaticSettings.S.SunSidedCoef ); SS.FreshlyPlacedList.scene_info.vertexBufferArray.Bind(gl); gl.DrawArrays(OpenGL.GL_POINTS, 0, SS.FreshlyPlacedList.Quantity() / 3); SS.FreshlyPlacedList.scene_info.vertexBufferArray.Unbind(gl); if (!newThread.IsAlive && !DoWork_IsAlive) { if (Explosion.exp.StartingFirst) { Music.wav_player.SaySoundEffect("Explosion"); //Music.wav_player.SaySoundEffect("Explosion"); //Interface.Time_pause(900); //TimeSpan timeItTook = (DateTime.Now - start); //Time.time.SetTotalSeconds((DateTime.Now - start_independent).TotalSeconds); //Time.time.TimeIncrease(timeItTook.TotalMilliseconds * Time.time.Time_Speed); //start = DateTime.Now; Explosion.exp.StartingFirst = false; Explosion.exp.StartingFirstStarted = true; Explosion.exp.StartingShiftForLoeading = (float)Time.time.GetGameTotalSeconds() - Explosion.exp.StartingTime; } } if (Explosion.exp.StartingFirstStarted) { shaderProgram_secondary.SetUniform1(gl, "TimeTotalSeconds", (float)Time.time.GetGameTotalSeconds() - (Explosion.exp.StartingShiftForLoeading));// - Explosion.exp.StartingShiftForLoeading); shaderProgram_secondary.SetUniform1(gl, "settingsTHIS_IS_EXPLOSION", 1.0f); SS.ExplosionList.scene_info.vertexBufferArray.Bind(gl); gl.DrawArrays(OpenGL.GL_POINTS, 0, SS.ExplosionList.Quantity() / 3); SS.ExplosionList.scene_info.vertexBufferArray.Unbind(gl); shaderProgram_secondary.SetUniform1(gl, "settingsTHIS_IS_EXPLOSION", 0.0f); } shaderProgram_secondary.SetUniform1(gl, "TimeTotalSeconds", (float)Time.time.GetGameTotalSeconds()); shaderProgram_secondary.SetUniform1(gl, "settingsTransparency", (float)(0.4 + 0.2 * Math.Abs(Math.Sin(Time.time.GetTotalRadianTime() * 200.0)))); SS.Ghost.scene_info.vertexBufferArray.Bind(gl); gl.DrawArrays(OpenGL.GL_POINTS, 0, SS.Ghost.Quantity() / 3); SS.Ghost.scene_info.vertexBufferArray.Unbind(gl); sunMatrix = new mat3(new vec3(-(float)Time.time.GetTotalRadianTime(), 0, 0), new vec3(0, DataForDraw.localed_range * Sun.LocalSun.Sun_Height, 0),//new vec3(0, (float)+DataForDraw.localed_range * 100, 0), new vec3(1.0f, 1.0f, 0.0f)); shaderProgram_secondary.SetUniformMatrix3(gl, "sunMatrix", sunMatrix.to_array()); if (Projectile.jp.Loaded && !Projectile.jp.Launched) { shaderProgram_secondary.SetUniform1(gl, "settingsTransparency", 0.3f); Projectile.jp.NotEveryTimeRealoder(); SS.TrajectoryPath.scene_info.vertexBufferArray.Bind(gl); gl.DrawArrays(OpenGL.GL_POINTS, 0, SS.TrajectoryPath.Quantity() / 3); SS.TrajectoryPath.scene_info.vertexBufferArray.Unbind(gl); } sunMatrix = new mat3(new vec3(-(float)Time.time.GetTotalRadianTime(), 0, 0), new vec3(0, DataForDraw.localed_range * Sun.LocalSun.Sun_Height, 0),//new vec3(0, (float)+DataForDraw.localed_range * 100, 0), new vec3(1.0f, 1.0f, 0.25f)); //Второе значений 3 строки отключает Point Of view если больше 0.5 в геом шейдере. //Третье пусть отключит вращение. shaderProgram_secondary.SetUniformMatrix3(gl, "sunMatrix", sunMatrix.to_array()); shaderProgram_secondary.SetUniform1(gl, "settingsTransparency", 1.0f); //shaderProgram_sunandmoon.SetUniformMatrix3(gl, "sunMatrix", sunMatrix.to_array()); SS.SunAndMoon.scene_info.vertexBufferArray.Bind(gl); gl.DrawArrays(OpenGL.GL_POINTS, 0, SS.SunAndMoon.Quantity() / 3); SS.SunAndMoon.scene_info.vertexBufferArray.Unbind(gl); //shaderProgram_sunandmoon.Unbind(gl); shaderProgram_secondary.Unbind(gl); } if (Projectile.jp.Loaded) { shaderProgram_projectile.Bind(gl); shaderProgram_projectile.SetUniform3(gl, "SunPosition", StaticShadow.Sh.SunPosition.x, StaticShadow.Sh.SunPosition.y, StaticShadow.Sh.SunPosition.z); shaderProgram_projectile.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array()); shaderProgram_projectile.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array()); shaderProgram_projectile.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array()); shaderProgram_projectile.SetUniformMatrix4(gl, "rotMatrix", rotMatrix.to_array()); shaderProgram_projectile.SetUniformMatrix3(gl, "playerMatrix", playerMatrix.to_array()); sunMatrix = new mat3(new vec3(-(float)Time.time.GetTotalRadianTime(), 0, 0), new vec3(0, DataForDraw.localed_range * Sun.LocalSun.Sun_Height, 0),//new vec3(0, (float)+DataForDraw.localed_range * 100, 0), new vec3(StaticSettings.S.SunStatus.x, 1.0f, 0.0f)); shaderProgram_projectile.SetUniformMatrix3(gl, "sunMatrix", sunMatrix.to_array()); shaderProgram_projectile.SetUniform1(gl, "settingsTransparency", 1.0f); shaderProgram_projectile.SetUniform1(gl, "TimeTotalSeconds", (float)Time.time.GetGameTotalSeconds() - (Explosion.exp.StartingShiftForLoeading));// - Explosion.exp.StartingShiftForLoeading); shaderProgram_projectile.SetUniform3(gl, "viewparameters", (float)(StaticSettings.S.RangeOfView_Old - 1) * 16, StaticSettings.S.PointOfViewCoefOfDifference, StaticSettings.S.SunSidedCoef ); if (Explosion.exp.StartingFirstStarted) { shaderProgram_projectile.SetUniform1(gl, "settingsTHIS_IS_EXPLOSION", 1.0f); } else { shaderProgram_projectile.SetUniform1(gl, "settingsTHIS_IS_EXPLOSION", 0.5f); } //shaderProgram_projectile.SetUniform1(gl, "TimePauseForExplosion", Projectile.jp.TimePauseUntilExplosion); shaderProgram_projectile.SetUniformMatrix3(gl, "projectileMatrix", Projectile.jp.GetProjectileMatrix().to_array()); SS.ProjectileList.scene_info.vertexBufferArray.Bind(gl); gl.DrawArrays(OpenGL.GL_POINTS, 0, SS.ProjectileList.Quantity() / 3); SS.ProjectileList.scene_info.vertexBufferArray.Unbind(gl); shaderProgram_projectile.Unbind(gl); } //SS.OpenGLDraw(gl, modelMatrix * rotMatrix * viewMatrix);//projectionMatrix * rotMatrix * viewMatrix * ); }
/// <summary> /// Converts NormalMatrix to a float[]. /// </summary> /// <returns>A float[] containing all the values from the initial matrix.</returns> public float[] ToArray() { return(_normalMatrix.to_array()); }