public void Render(Camera camera, int depthmap, Matrix4 lightMatrix, Matrix4 modelMatrix, bool specialWireFrame = false) { if (!Checked) { return; } Shader shader; if (Runtime.renderType != Runtime.RenderTypes.Shaded) { shader = Runtime.shaders["NUD_Debug"]; } else { shader = Runtime.shaders["NUD"]; } GL.UseProgram(shader.programID); int renderType = (int)Runtime.renderType; Matrix4 mvpMatrix = camera.mvpMatrix; GL.UniformMatrix4(shader.getAttribute("mvpMatrix"), false, ref mvpMatrix); // Perform the calculations here to reduce render times in shader Matrix4 modelViewMatrix = camera.modelViewMatrix; Matrix4 sphereMapMatrix = modelViewMatrix; sphereMapMatrix.Invert(); sphereMapMatrix.Transpose(); GL.UniformMatrix4(shader.getAttribute("modelViewMatrix"), false, ref modelViewMatrix); GL.UniformMatrix4(shader.getAttribute("sphereMapMatrix"), false, ref sphereMapMatrix); Matrix4 rotationMatrix = camera.rotationMatrix; GL.UniformMatrix4(shader.getAttribute("rotationMatrix"), false, ref rotationMatrix); shader = Runtime.shaders["MBN"]; GL.UseProgram(shader.programID); if (Runtime.cameraLight) { GL.Uniform3(shader.getAttribute("difLightDirection"), Vector3.TransformNormal(new Vector3(0f, 0f, -1f), camera.mvpMatrix.Inverted()).Normalized()); } else { GL.Uniform3(shader.getAttribute("difLightDirection"), Runtime.lightSetParam.characterDiffuse.direction); } shader = Runtime.shaders["DAT"]; GL.UseProgram(shader.programID); LightColor diffuseColor = Runtime.lightSetParam.characterDiffuse.diffuseColor; LightColor ambientColor = Runtime.lightSetParam.characterDiffuse.ambientColor; GL.Uniform3(shader.getAttribute("difLightColor"), diffuseColor.R, diffuseColor.G, diffuseColor.B); GL.Uniform3(shader.getAttribute("ambLightColor"), ambientColor.R, ambientColor.G, ambientColor.B); if (BCH != null) { foreach (BCH_Model mo in BCH.Models.Nodes) { mo.Render(camera.mvpMatrix); } } if (DAT_MELEE != null && Runtime.shaders["DAT"].CompiledSuccessfully()) { DAT_MELEE.Render(camera.mvpMatrix); } if (NUD != null && Runtime.shaders["NUD"].CompiledSuccessfully() && Runtime.shaders["NUD_Debug"].CompiledSuccessfully()) { if (Runtime.renderType != Runtime.RenderTypes.Shaded) { shader = Runtime.shaders["NUD_Debug"]; } else { shader = Runtime.shaders["NUD"]; } GL.UseProgram(shader.programID); SetRenderSettingsUniforms(shader); SetLightingUniforms(shader, camera); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.TextureCubeMap, RenderTools.dummyTextures[NUD.DummyTextures.StageMapHigh]); GL.Uniform1(shader.getAttribute("cmap"), 2); GL.Uniform1(shader.getAttribute("renderType"), renderType); GL.Uniform1(shader.getAttribute("debugOption"), (int)Runtime.uvChannel); SetElapsedDirectUvTime(shader); GL.UniformMatrix4(shader.getAttribute("modelMatrix"), false, ref modelMatrix); if (specialWireFrame) { Runtime.renderModelWireframe = true; Runtime.renderModel = false; } NUD.Render(VBN, camera); } }
public void Render(Camera camera, int depthmap, Matrix4 lightMatrix, Matrix4 modelMatrix, Vector2 screenDimensions, bool specialWireFrame = false) { if (!Checked) { return; } Shader shader; if (Runtime.renderType != Runtime.RenderTypes.Shaded) { shader = Runtime.shaders["NudDebug"]; } else { shader = Runtime.shaders["Nud"]; } GL.UseProgram(shader.programId); int renderType = (int)Runtime.renderType; SetCameraMatrixUniforms(camera, shader); shader = Runtime.shaders["Mbn"]; GL.UseProgram(shader.programId); if (Runtime.cameraLight) { GL.Uniform3(shader.GetVertexAttributeUniformLocation("difLightDirection"), Vector3.TransformNormal(new Vector3(0f, 0f, -1f), camera.mvpMatrix.Inverted()).Normalized()); } else { GL.Uniform3(shader.GetVertexAttributeUniformLocation("difLightDirection"), Runtime.lightSetParam.characterDiffuse.direction); } shader = Runtime.shaders["Dat"]; GL.UseProgram(shader.programId); LightColor diffuseColor = Runtime.lightSetParam.characterDiffuse.diffuseColor; LightColor ambientColor = Runtime.lightSetParam.characterDiffuse.ambientColor; GL.Uniform3(shader.GetVertexAttributeUniformLocation("difLightColor"), diffuseColor.R, diffuseColor.G, diffuseColor.B); GL.Uniform3(shader.GetVertexAttributeUniformLocation("ambLightColor"), ambientColor.R, ambientColor.G, ambientColor.B); if (BCH != null) { foreach (BCH_Model mo in BCH.Models.Nodes) { mo.Render(camera.mvpMatrix); } } if (DAT_MELEE != null && Runtime.shaders["Dat"].ProgramCreatedSuccessfully()) { DAT_MELEE.Render(camera.mvpMatrix); } if (NUD != null && Runtime.shaders["Nud"].ProgramCreatedSuccessfully() && Runtime.shaders["NudDebug"].ProgramCreatedSuccessfully()) { if (Runtime.renderType != Runtime.RenderTypes.Shaded) { shader = Runtime.shaders["NudDebug"]; } else { shader = Runtime.shaders["Nud"]; } GL.UseProgram(shader.programId); SetRenderSettingsUniforms(shader); SetLightingUniforms(shader, camera); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.TextureCubeMap, RenderTools.dummyTextures[NUD.DummyTextures.StageMapHigh]); GL.Uniform1(shader.GetVertexAttributeUniformLocation("cmap"), 2); GL.Uniform1(shader.GetVertexAttributeUniformLocation("renderType"), renderType); GL.Uniform1(shader.GetVertexAttributeUniformLocation("debugOption"), (int)Runtime.uvChannel); // Used for wireframe shader. GL.Uniform2(shader.GetVertexAttributeUniformLocation("windowSize"), screenDimensions); SetElapsedDirectUvTime(shader); GL.UniformMatrix4(shader.GetVertexAttributeUniformLocation("modelMatrix"), false, ref modelMatrix); if (specialWireFrame) { Runtime.renderModelWireframe = true; Runtime.renderModel = false; } NUD.Render(VBN, camera); } }