/// <summary> /// Renders a unit capsule to the given context /// </summary> public static void DrawRectangularPrism(Camera Camera, Vector3 Position, Vector3 Size, Matrix4 Transform) { if (UnitPrism == null) { UnitPrism = new RectangularPrism(); } var shader = ShaderManager.GetShader("Prism"); shader.UseProgram(); Matrix4 mvp = Camera.MvpMatrix; shader.SetMatrix4x4("mvp", ref mvp); shader.SetVector4("color", 1, 0, 0, 1); shader.SetMatrix4x4("transform", ref Transform); shader.SetVector3("size", Size); shader.SetVector3("offset", Position); GL.LineWidth(5f); UnitPrism.Draw(shader); }
public static void RenderSkyBox(Camera camera, TextureCubeMap cubemap, int mipLevel = 0) { if (UnitSkyBox == null) { UnitSkyBox = new SkyBox(); } var shader = ShaderManager.GetShader("CubeMap"); shader.UseProgram(); shader.SetInt("mipLevel", mipLevel); Matrix4 view = camera.ModelViewMatrix; var mat = new Matrix3(view); view = new Matrix4(mat); shader.SetMatrix4x4("view", ref view); var projection = Matrix4.CreatePerspectiveFieldOfView(1.3f, camera.RenderWidth / (float)camera.RenderHeight, 0.1f, 100.0f); shader.SetMatrix4x4("projection", ref projection); shader.SetTexture("skybox", cubemap, 0); cubemap.MagFilter = TextureMagFilter.Nearest; UnitSkyBox.Draw(shader); }
public void SetShader(Type shaderType, ShaderProperties properties) { ShaderProperties p = new ShaderProperties(properties); p.SetProperty("DEFAULT", true); SetShader(ShaderManager.GetShader(shaderType, p)); }
public void SetShader(Type shaderType) { UpdateShaderProperties(); g_shaderProperties.SetProperty("DEFAULT", true); SetShader(ShaderManager.GetShader(shaderType, g_shaderProperties)); g_shaderProperties.SetProperty("DEFAULT", false); }
public RenderBuffer(ShaderManager.ShaderType shaderType) { this.shader = ShaderManager.GetShader(shaderType); meshesToAdd = new ConcurrentBag <Mesh>(); meshesToRemove = new ConcurrentBag <Mesh>(); }
private void NrmGenerator_Load(object sender, EventArgs e) { Mesh quadMesh = MeshFactory.CreateQuad(); quadGeom = new Geometry(quadMesh); quadGeom.SetShader(ShaderManager.GetShader(typeof(NormalMapShader))); MtlViewerGame mtlPreview = new MtlViewerGame(); mtlPreview.Rotate = false; mtlPreview.Camera.Enabled = false; mtlPreview.Camera.Width = 256; mtlPreview.Camera.Height = 256; // mtlPreview.Camera = new ApexEngine.Rendering.Cameras.OrthoCamera(-2, 2, -2, 2, -2, 2); mtlPreview.Camera.Translation = new ApexEngine.Math.Vector3f(0, 0, -3); mtlPreview.RootNode.AddChild(quadGeom); ApexEngineControl mtlViewer = new ApexEngineControl(mtlPreview); mtlViewer.Framerate = 50; mtlViewer.Dock = DockStyle.Fill; pnlObj.Controls.Add(mtlViewer); quadGeom.Material.SetValue("delta_value", 5.0f); //mtlPreview.RenderManager.PostProcessor.PostFilters.Add(new BlurPostFilter(true)); //mtlPreview.RenderManager.PostProcessor.PostFilters.Add(new BlurPostFilter(false)); }
private void CheckForShaderChanges() { if (_shaderManagerReference.GetShaderHasChanged(_shaderIndex)) { _shader = _shaderManagerReference.GetShader(_shaderIndex); Initialize(); } }
public void Load(ShaderManager shaderManager, string shaderPath) { _shaderIndex = shaderManager.AddShader(shaderPath); _shader = shaderManager.GetShader(_shaderIndex); _shaderManagerReference = shaderManager; }
public void RenderRenderableModel(RenderableModel model, Matrix4 vpmatrix) { var shader = ShaderManager.GetShader(model.ShaderName); shader.Start(); shader.LoadModelViewMatrix(vpmatrix); GL.BindVertexArray(model.VaoID); GL.EnableVertexArrayAttrib(model.VaoID, 0); GL.DrawElements(PrimitiveType.Triangles, model.Indicies.Count, DrawElementsType.UnsignedInt, 0); GL.DisableVertexArrayAttrib(model.VaoID, 0); GL.BindVertexArray(0); shader.Stop(); }
private void Load(ShaderManager shaderManager, string shaderPath) { //"Shaders/Deferred/DeferredPointLight" _shaderIndex = shaderManager.AddShader(shaderPath); _pointLightShader = shaderManager.GetShader(_shaderIndex); _shaderManagerReference = shaderManager; }
public void RenderShader(Camera camera) { GL.LineWidth(1f); if (bonePrism == null) { bonePrism = new BonePrism(); } var boneShader = ShaderManager.GetShader("Bone"); boneShader.UseProgram(); boneShader.SetMatrix4x4("mvpMatrix", camera.MvpMatrix); var color = Tools.CrossMath.ColorToVector(ApplicationSettings.BoneColor); var selcolor = Tools.CrossMath.ColorToVector(ApplicationSettings.SelectedBoneColor); boneShader.SetMatrix4x4("rotation", ref prismRotation); foreach (var b in Bones) { if (b.Selected) { boneShader.SetVector4("color", selcolor); } else { boneShader.SetVector4("color", color); } Matrix4 transform = b.AnimatedWorldTransform; boneShader.SetMatrix4x4("bone", ref transform); boneShader.SetInt("hasParent", b.Parent != null ? 1 : 0); if (b.Parent != null) { Matrix4 parenttransform = b.Parent.AnimatedWorldTransform; boneShader.SetMatrix4x4("parent", ref parenttransform); } bonePrism.Draw(boneShader); // leaf node boneShader.SetInt("hasParent", 0); bonePrism.Draw(boneShader); } if (ApplicationSettings.RenderBoneNames) { foreach (var b in Bones) { TextRenderer.Draw(camera, b.Name, b.AnimatedWorldTransform); } } }
private Shader GetShader() { if (ApplicationSettings.UseDebugShading) { return(ShaderManager.GetShader("UltimateModelDebug")); } else { return(ShaderManager.GetShader("UltimateModel")); } }
public void SetDefaultShader() { if (mesh.GetSkeleton() != null) { g_shaderProperties.SetProperty("SKINNING", true).SetProperty("NUM_BONES", mesh.GetSkeleton().GetNumBones()); } g_shaderProperties.SetProperty("DEFAULT", true); g_shaderProperties.SetProperty("NORMALS", false); g_shaderProperties.SetProperty("DEPTH", false); SetShader(ShaderManager.GetShader(typeof(Rendering.Shaders.DefaultShader), g_shaderProperties)); g_shaderProperties.SetProperty("DEFAULT", false); }
public static void RenderTexture(Texture renderTexture, bool displayR, bool displayG, bool displayB, bool displayA, int LOD, bool IsSrgb = false) { if (triangle == null) { triangle = new ScreenTriangle(); } // Texture unit 0 should be reserved for image preview. var shader = ShaderManager.GetShader("Texture"); shader.UseProgram(); if (renderTexture != null) { shader.SetTexture("image", renderTexture, 0); } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Nearest); // The colors need to be converted back to sRGB gamma. shader.SetBoolToInt("isSrgb", IsSrgb); bool monoChannel = false; if (displayR && !displayG && !displayB && !displayA) { monoChannel = true; } if (!displayR && displayG && !displayB && !displayA) { monoChannel = true; } if (!displayR && !displayG && displayB && !displayA) { monoChannel = true; } if (!displayR && !displayG && !displayB && displayA) { monoChannel = true; } shader.SetBoolToInt("enableR", displayR); shader.SetBoolToInt("enableG", displayG); shader.SetBoolToInt("enableB", displayB); shader.SetBoolToInt("enableA", displayA); shader.SetBoolToInt("monoChannel", monoChannel); shader.SetInt("LOD", LOD); triangle.Draw(shader); }
public void RenderShader(Camera camera) { GL.LineWidth(1f); if (bonePrism == null) { bonePrism = new BonePrism(); } var boneShader = ShaderManager.GetShader("Bone"); boneShader.UseProgram(); boneShader.SetVector4("boneColor", new Vector4(ApplicationSettings.BoneColor.R / 255f, ApplicationSettings.BoneColor.G / 255f, ApplicationSettings.BoneColor.B / 255f, ApplicationSettings.BoneColor.A / 255f)); boneShader.SetMatrix4x4("rotation", ref prismRotation); foreach (var b in Bones) { Matrix4 transform = b.AnimatedWorldTransform; boneShader.SetMatrix4x4("bone", ref transform); boneShader.SetInt("hasParent", b.Parent != null ? 1 : 0); if (b.Parent != null) { Matrix4 parenttransform = b.Parent.AnimatedWorldTransform; boneShader.SetMatrix4x4("parent", ref parenttransform); } bonePrism.Draw(boneShader, camera); // leaf node boneShader.SetInt("hasParent", 0); bonePrism.Draw(boneShader, null); } if (ApplicationSettings.RenderBoneNames) { foreach (var b in Bones) { TextRenderer.Draw(camera, b.Name, b.AnimatedWorldTransform); } } }
public static void RenderTexture(Texture renderTexture, bool IsSrgb = false) { if (triangle == null) { triangle = new ScreenTriangle(); } // Texture unit 0 should be reserved for image preview. var shader = ShaderManager.GetShader("Texture"); shader.UseProgram(); if (renderTexture != null) { shader.SetTexture("image", renderTexture, 0); } // The colors need to be converted back to sRGB gamma. shader.SetBoolToInt("isSrgb", IsSrgb); triangle.Draw(shader, null); }
/// <summary> /// Renders a unit capsule to the given context /// </summary> public static void DrawCapsule(Camera Camera, float Size, Matrix4 bone1, Matrix4 bone2) { if (UnitCapsule == null) { UnitCapsule = new Capsule(); } var shader = ShaderManager.GetShader("Capsule"); shader.UseProgram(); Matrix4 mvp = Camera.MvpMatrix; shader.SetMatrix4x4("mvp", ref mvp); shader.SetVector4("Color", 1, 0, 0, 1); Vector3 position1 = Vector3.TransformPosition(Vector3.Zero, bone1); Vector3 position2 = Vector3.TransformPosition(Vector3.Zero, bone2); Vector3 to = position2 - position1; to.NormalizeFast(); Vector3 axis = Vector3.Cross(Vector3.UnitY, to); float omega = (float)System.Math.Acos(Vector3.Dot(Vector3.UnitY, to)); Matrix4 rotation = Matrix4.CreateFromAxisAngle(axis, omega); Matrix4 transform1 = rotation * Matrix4.CreateTranslation(position1); Matrix4 transform2 = rotation * Matrix4.CreateTranslation(position2); shader.SetMatrix4x4("transform1", ref transform1); shader.SetMatrix4x4("transform2", ref transform2); shader.SetFloat("Size", Size); GL.PointSize(5f); UnitCapsule.Draw(shader); }
public override void RenderShader(Camera camera) { var shader = ShaderManager.GetShader("HSD"); if (ApplicationSettings.UseDebugShading) { shader = ShaderManager.GetShader("HSDDebug"); } if (!shader.LinkStatusIsOk) { return; } shader.UseProgram(); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); Matrix4 sphereMatrix = camera.ModelViewMatrix; sphereMatrix.Invert(); sphereMatrix.Transpose(); shader.SetMatrix4x4("sphereMatrix", ref sphereMatrix); shader.SetBoolToInt("renderDiffuse", ApplicationSettings.EnableDiffuse); shader.SetBoolToInt("renderSpecular", ApplicationSettings.EnableSpecular); shader.SetBoolToInt("renderAlpha", true); shader.SetBoolToInt("renderNormalMap", ApplicationSettings.RenderNormalMaps); shader.SetInt("renderMode", (int)ApplicationSettings.ShadingMode); shader.SetVector3("cameraPos", camera.Position); shader.SetMatrix4x4("mvp", camera.MvpMatrix); // Bones if (Skeleton != null) { //boneBinds = Skeleton.GetBindTransforms(); var bones = Skeleton.Bones; if (bones.Length > boneTransforms.Length) { boneTransforms = new Matrix4[bones.Length]; boneBinds = new Matrix4[bones.Length]; } for (int i = 0; i < bones.Length; i++) { boneTransforms[i] = bones[i].AnimatedWorldTransform; boneBinds[i] = bones[i].AnimatedBindMatrix; } } int blockIndex2 = GL.GetUniformBlockIndex(shader.Id, "BoneTransforms"); boneTransformUniformBuffer.BindBase(BufferRangeTarget.UniformBuffer, blockIndex2); boneTransformUniformBuffer.SetData(boneTransforms, BufferUsageHint.DynamicDraw); //TODO update sf grapics so it can be used to bind this shader.SetMatrix4x4("binds", boneBinds); List <SBHsdMesh> sortedMesh = new List <SBHsdMesh>(); List <SBHsdMesh> opaqueMesh = new List <SBHsdMesh>(); for (int i = Mesh.Count - 1; i >= 0; i--) { var m = Mesh[i]; if (m.ParentBone == null || m.ParentBone == "") { opaqueMesh.Add(m); } else { sortedMesh.Add(m); } } sortedMesh = sortedMesh.OrderBy(c => { Matrix4 transform = Skeleton[c.ParentBone].WorldTransform * camera.MvpMatrix; var v = Vector3.TransformPosition(c.BoundingSphere.Position, transform); v = Vector3.TransformPosition(c.BoundingSphere.Position, camera.MvpMatrix); return(v.Z + c.BoundingSphere.Radius); }).ToList(); opaqueMesh.AddRange(sortedMesh); // TODO: sort opaque mesh foreach (var rm in opaqueMesh) { if (!rm.Visible) { continue; } shader.SetBoolToInt("renderWireframe", ApplicationSettings.EnableWireframe || rm.Selected); rm.Draw(this, shader); } base.RenderShader(camera); // render zones /*if(HSDFile != null && HSDFile.Roots.Count > 1 && HSDFile.Roots[1].Node is KAR_GrModel model) * { * foreach( var el in model.MainModel.ModelUnk1.GroupsUnk1_1.Elements) * { * var min = new Vector3(el.UnkFloat1, el.UnkFloat2, el.UnkFloat3); * var max = new Vector3(el.UnkFloat4, el.UnkFloat5, el.UnkFloat6); * var mid = (max + min) / 2; * var size = max - min; * Rendering.Shapes.RectangularPrism.DrawRectangularPrism(camera, mid, size, Matrix4.Identity); * } * }*/ }
public void SetShader(Type shaderType, ShaderProperties properties) { properties.SetProperty("DEFAULT", true); SetShader(ShaderManager.GetShader(shaderType, properties)); properties.SetProperty("DEFAULT", false); }
public void SetShader(Type shaderType) { SetShader(ShaderManager.GetShader(shaderType, new ShaderProperties().SetProperty("DEFAULT", true))); }
static SimplexTerrainChunkNode() { terrainShader = ShaderManager.GetShader(typeof(TerrainShader), new ShaderProperties().SetProperty("DEFAULT", true)); }