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 (BFRES != null && Runtime.shaders["BFRES"].CompiledSuccessfully() && Runtime.shaders["BFRES_PBR"].CompiledSuccessfully()) { if (Runtime.renderPhysicallyBasedRendering == true) { shader = Runtime.shaders["BFRES_PBR"]; GL.UseProgram(shader.programID); GL.Uniform3(shader.getAttribute("difLightColor"), diffuseColor.R, diffuseColor.G, diffuseColor.B); GL.Uniform3(shader.getAttribute("ambLightColor"), ambientColor.R, ambientColor.G, ambientColor.B); } else { shader = Runtime.shaders["BFRES"]; GL.UseProgram(shader.programID); GL.Uniform3(shader.getAttribute("difLightColor"), diffuseColor.R, diffuseColor.G, diffuseColor.B); GL.Uniform3(shader.getAttribute("ambLightColor"), ambientColor.R, ambientColor.G, ambientColor.B); } BFRES.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, Vector2 screenDimensions, bool drawShadow = false) { if (!Checked) { return; } Shader shader; // 3DS MBN shader = OpenTKSharedResources.shaders["Mbn"]; shader.UseProgram(); SetMbnUniforms(camera, shader); // Melee DAT shader = OpenTKSharedResources.shaders["Dat"]; shader.UseProgram(); SetDatUniforms(shader); if (BCH != null) { foreach (BCH_Model mo in BCH.Models.Nodes) { mo.Render(camera.MvpMatrix); } } if (DatMelee != null && OpenTKSharedResources.shaders["Dat"].ProgramCreatedSuccessfully) { DatMelee.Render(camera.MvpMatrix); } LightColor diffuseColor = Runtime.lightSetParam.characterDiffuse.diffuseColor; LightColor ambientColor = Runtime.lightSetParam.characterDiffuse.ambientColor; if (KCL != null && OpenTKSharedResources.shaders["KCL"].ProgramCreatedSuccessfully) { shader = OpenTKSharedResources.shaders["KCL"]; shader.UseProgram(); shader.SetVector3("difLightColor", diffuseColor.R, diffuseColor.G, diffuseColor.B); shader.SetVector3("ambLightColor", ambientColor.R, ambientColor.G, ambientColor.B); KCL.Render(camera.MvpMatrix); } if (BFRES != null && OpenTKSharedResources.shaders["BFRES"].ProgramCreatedSuccessfully && OpenTKSharedResources.shaders["BFRES_PBR"].ProgramCreatedSuccessfully) { if (Runtime.renderPhysicallyBasedRendering == true) { shader = OpenTKSharedResources.shaders["BFRES_PBR"]; } else { shader = OpenTKSharedResources.shaders["BFRES"]; } shader.UseProgram(); shader.SetVector3("difLightColor", diffuseColor.R, diffuseColor.G, diffuseColor.B); shader.SetVector3("ambLightColor", ambientColor.R, ambientColor.G, ambientColor.B); Matrix4 invertedCamera = camera.MvpMatrix.Inverted(); Vector3 lightDirection = new Vector3(0f, 0f, -1f); //Todo. Maybe change direction via AAMP file (configs shader data) shader.SetVector3("lightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized()); shader.SetVector3("specLightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized()); shader.SetVector3("difLightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized()); shader.SetInt("debugOption", (int)Runtime.uvChannel); // This cube map is for a quick test. shader.SetTexture("cmap", RenderTools.dummyTextures[NUD.DummyTextures.StageMapHigh].Id, TextureTarget.TextureCubeMap, 2); BFRES.Render(camera.MvpMatrix); } if (NUD != null && OpenTKSharedResources.shaders["Nud"].ProgramCreatedSuccessfully && OpenTKSharedResources.shaders["NudDebug"].ProgramCreatedSuccessfully) { // Choose the appropriate shader. if (drawShadow) { shader = OpenTKSharedResources.shaders["Shadow"]; } else if (Runtime.renderType != Runtime.RenderTypes.Shaded) { shader = OpenTKSharedResources.shaders["NudDebug"]; } else { shader = OpenTKSharedResources.shaders["Nud"]; } shader.UseProgram(); // Matrices. Matrix4 lightMatrixRef = lightMatrix; shader.SetMatrix4x4("lightMatrix", ref lightMatrixRef); SetCameraMatrixUniforms(camera, shader); SetRenderSettingsUniforms(shader); SetLightingUniforms(shader, camera); shader.SetInt("renderType", (int)Runtime.renderType); shader.SetInt("debugOption", (int)Runtime.uvChannel); shader.SetBoolToInt("drawShadow", Runtime.drawModelShadow); shader.SetTexture("depthMap", depthMap, TextureTarget.Texture2D, 14); SetElapsedDirectUvTime(shader); NUD.Render(VBN, camera, drawShadow, Runtime.drawNudColorIdPass); } }