public void RenderBeforeChildren(RenderEventArgs arg) { ICamera camera = arg.Camera; mat4 projectionMat = camera.GetProjectionMatrix(); mat4 viewMat = camera.GetViewMatrix(); mat4 modelMat = this.GetModelMatrix(); ModernRenderUnit unit = this.RenderUnit; RenderMethod method = unit.Methods[0]; ShaderProgram program = method.Program; program.SetUniform("projectionMat", projectionMat); program.SetUniform("mvMat", viewMat * modelMat); program.SetUniform("normalMat", glm.transpose(glm.inverse(viewMat * modelMat))); mat4[] boneMatrixes = this.textureModel.GetBoneMatrixes(); boneMatrixes = null; if (boneMatrixes != null) { program.SetUniform("bones", boneMatrixes); } program.SetUniform("useBones", boneMatrixes != null); Texture tex = this.textureModel.Texture; if (tex != null) { program.SetUniform("textureMap", tex); } program.SetUniform("useDefault", tex != null ? 0.0f : 1.0f); program.SetUniform("light_position", new vec3(1, 1, 1) * 10); method.Render(); }
public void RenderBeforeChildren(RenderEventArgs arg) { // gets mvpMatrix. ICamera camera = arg.Camera; mat4 projectionMat = camera.GetProjectionMatrix(); mat4 viewMat = camera.GetViewMatrix(); mat4 modelMat = this.GetModelMatrix(); mat4 mvpMatrix = projectionMat * viewMat * modelMat; // a render uint wraps everything(model data, shaders, glswitches, etc.) for rendering. ModernRenderUnit unit = this.RenderUnit; // gets render method. // There could be more than 1 method(vertex shader + fragment shader) to render the same model data. Thus we need an method array. RenderMethod method = unit.Methods[0]; // shader program wraps vertex shader and fragment shader. ShaderProgram program = method.Program; //set value for 'uniform mat4 mvpMatrix'; in shader. program.SetUniform("mvpMatrix", mvpMatrix); { program.SetUniform("halfTransparent", true); // render the cube model via OpenGL. method.Render(); } { program.SetUniform("halfTransparent", false); this.polygonModeSwitch.On(); this.lineWidthSwitch.On(); // render the cube model via OpenGL. method.Render(); this.lineWidthSwitch.Off(); this.polygonModeSwitch.Off(); } }
public void RenderBeforeChildren(RenderEventArgs arg) { // gets mvpMatrix. ICamera camera = arg.Camera; mat4 projectionMat = camera.GetProjectionMatrix(); mat4 viewMat = camera.GetViewMatrix(); mat4 modelMat = this.GetModelMatrix(); mat4 mvpMatrix = projectionMat * viewMat * modelMat; // a render uint wraps everything(model data, shaders, glswitches, etc.) for rendering. ModernRenderUnit unit = this.RenderUnit; // gets render method. // There could be more than 1 method(vertex shader + fragment shader) to render the same model data. Thus we need an method array. RenderMethod method = unit.Methods[0]; // shader program wraps vertex shader and fragment shader. ShaderProgram program = method.Program; //set value for 'uniform mat4 mvpMatrix'; in shader. program.SetUniform("mvpMatrix", mvpMatrix); program.SetUniform("color", Color); program.SetUniform("lightDir", LightDir); program.SetUniform("lightColor", LightColor); program.SetUniform("renderMode", (int)renderMode); program.SetUniform("viewPos", arg.Camera.Position); // render the cube model via OpenGL. method.Render(); }
public void RenderBeforeChildren(RenderEventArgs arg) { // gets mvpMatrix. ICamera camera = arg.Camera; mat4 projectionMat = camera.GetProjectionMatrix(); mat4 viewMat = camera.GetViewMatrix(); mat4 modelMat = this.GetModelMatrix(); mat4 mvpMatrix = projectionMat * viewMat * modelMat; // a render uint wraps everything(model data, shaders, glswitches, etc.) for rendering. ModernRenderUnit unit = this.RenderUnit; // gets render method. // There could be more than 1 method(vertex shader + fragment shader) to render the same model data. Thus we need an method array. RenderMethod method = unit.Methods[(int)this.CurrentMethod]; // shader program wraps vertex shader and fragment shader. ShaderProgram program = method.Program; //set value for 'uniform mat4 mvpMatrix'; in shader. program.SetUniform("mvpMatrix", mvpMatrix); switch (this.CurrentMethod) { case MethodType.SingleColor: break; case MethodType.MultiTexture: program.SetUniform("texture0", this.texture0); program.SetUniform("texture1", this.texture1); break; default: break; } // render the cube model via OpenGL. method.Render(); }
public void RenderBeforeChildren(RenderEventArgs arg) { ICamera camera = arg.Camera; mat4 projectionMat = camera.GetProjectionMatrix(); mat4 viewMat = camera.GetViewMatrix(); mat4 modelMat = this.GetModelMatrix(); ModernRenderUnit unit = this.RenderUnit; RenderMethod method = unit.Methods[0]; ShaderProgram program = method.Program; program.SetUniform("mvpMat", projectionMat * viewMat * modelMat); GL.Instance.Clear(GL.GL_DEPTH_BUFFER_BIT); // push this node to top front. method.Render(); }
public void RenderBeforeChildren(RenderEventArgs arg) { ICamera camera = arg.Camera; mat4 projection = camera.GetProjectionMatrix(); mat4 view = camera.GetViewMatrix(); mat4 model = this.GetModelMatrix(); ModernRenderUnit unit = this.RenderUnit; RenderMethod method = this.RenderUnit.Methods[0]; ShaderProgram program = method.Program; program.SetUniform("mvpMat", projection * view * model); program.SetUniform("color", Color); program.SetUniform("renderMode", (int)renderMode); method.Render(); }
public void RenderBeforeChildren(RenderEventArgs arg) { ICamera camera = arg.Camera; mat4 projectionMat = camera.GetProjectionMatrix(); mat4 viewMat = camera.GetViewMatrix(); mat4 modelMat = this.GetModelMatrix(); ModernRenderUnit unit = this.RenderUnit; RenderMethod method = unit.Methods[0]; ShaderProgram program = method.Program; program.SetUniform("mvpMat", projectionMat * viewMat * modelMat); if (this.firstRun) { lastTime = DateTime.Now; this.firstRun = false; } DateTime now = DateTime.Now; float timeInSeconds = (float)(now.Subtract(this.lastTime).TotalSeconds); //this.lastTime = now; Assimp.Scene scene = this.nodePointModel.scene; Assimp.Matrix4x4 transform = scene.RootNode.Transform; transform.Inverse(); mat4[] boneMatrixes = GetBoneMatrixes(scene, timeInSeconds, this.nodePointModel.allBoneInfos); //mat4[] boneMatrixes = null; program.SetUniform("animation", boneMatrixes != null); if (boneMatrixes != null) { program.SetUniform("bones", boneMatrixes); } GL.Instance.Enable(GL.GL_VERTEX_PROGRAM_POINT_SIZE); GL.Instance.Clear(GL.GL_DEPTH_BUFFER_BIT); // push this node to top front. method.Render(); }
public void RenderBeforeChildren(RenderEventArgs arg) { // gets mvpMatrix. //ICamera camera = arg.Camera; //mat4 projectionMat = camera.GetProjectionMatrix(); //mat4 viewMat = camera.GetViewMatrix(); //mat4 modelMat = this.GetModelMatrix(); //mat4 mvpMatrix = projectionMat * viewMat * modelMat; // a render uint wraps everything(model data, shaders, glswitches, etc.) for rendering. ModernRenderUnit unit = this.RenderUnit; // gets render method. // There could be more than 1 method(vertex shader + fragment shader) to render the same model data. Thus we need an method array. RenderMethod method = unit.Methods[0]; // shader program wraps vertex shader and fragment shader. ShaderProgram program = method.Program; //set value for 'uniform mat4 mvpMatrix'; in shader. program.SetUniform("inner0", this.inner0); program.SetUniform("outer0", this.outer0); program.SetUniform("outer1", this.outer1); program.SetUniform("outer2", this.outer2); // render the cube model via OpenGL. method.Render(); }
public void RenderBeforeChildren(RenderEventArgs arg) { ICamera camera = arg.Camera; mat4 projectionMat = camera.GetProjectionMatrix(); mat4 viewMat = camera.GetViewMatrix(); mat4 modelMat = this.GetModelMatrix(); ModernRenderUnit unit = this.RenderUnit; RenderMethod method = unit.Methods[0]; ShaderProgram program = method.Program; program.SetUniform("mvpMat", projectionMat * viewMat * modelMat); program.SetUniform("normalMat", glm.transpose(glm.inverse(modelMat))); program.SetUniform("diffuseColor", this.diffuseColor); { Texture tex = this.model.Texture; if (tex != null) { program.SetUniform("textureMap", tex); } } { angle += 0.01f; vec3 lightDirection = new vec3( (float)Math.Cos(angle), (float)Math.Sin(angle), 1); program.SetUniform("lihtDirection", lightDirection); } if (this.model.container.aiScene.HasAnimations) { if (this.firstRun) { lastTime = DateTime.Now; this.firstRun = false; } DateTime now = DateTime.Now; float timeInSeconds = (float)(now.Subtract(this.lastTime).TotalSeconds); AiScene scene = this.model.container.aiScene; mat4[] boneMatrixes = scene.GetBoneMatrixes(timeInSeconds, this.model.container.GetAllBoneInfos()); if (boneMatrixes != null) { // default pose. program.SetUniform("animation", false); program.SetUniform("transparent", true); this.polygonModeSwitch.On(); method.Render(); this.polygonModeSwitch.Off(); // animation pose. program.SetUniform("animation", boneMatrixes != null); program.SetUniform("transparent", false); program.SetUniform("bones", boneMatrixes); this.polygonModeSwitch.On(); method.Render(); this.polygonModeSwitch.Off(); } else { // no animation found. program.SetUniform("animation", false); this.polygonModeSwitch.On(); method.Render(); this.polygonModeSwitch.Off(); } } else { program.SetUniform("animation", false); this.polygonModeSwitch.On(); method.Render(); this.polygonModeSwitch.Off(); } }