private static void RenderPresetsToFiles() { using (GameWindow gameWindow = OpenTKSharedResources.CreateGameWindowContext(width, height)) { // Resource creation. screenVao = ScreenDrawing.CreateScreenTriangleVao(); shader = OpenTKSharedResources.shaders["NudSphere"]; // Skip thumbnail generation if the shader didn't compile. if (!shader.ProgramCreatedSuccessfully) { return; } // HACK: This isn't a very clean way to pass resources around. NudMatSphereDrawing.LoadMaterialSphereTextures(); Dictionary <NUD.DummyTextures, Texture> dummyTextures = RenderTools.CreateNudDummyTextures(); CreateNudSphereShader(); foreach (string file in Directory.EnumerateFiles(MainForm.executableDir + "\\materials", "*.nmt", SearchOption.AllDirectories)) { NUD.Material material = NUDMaterialEditor.ReadMaterialListFromPreset(file)[0]; string presetName = Path.GetFileNameWithoutExtension(file); RenderMaterialPresetToFile(presetName, material, dummyTextures); } } }
public static void InitializeSharedResources() { // Only setup once. This is checked multiple times to prevent crashes. if (setupStatus == SharedResourceStatus.Initialized) { return; } try { // Make a permanent context to share resources. GraphicsContext.ShareContexts = true; dummyResourceWindow = CreateGameWindowContext(); if (Runtime.enableOpenTKDebugOutput) { EnableOpenTKDebugOutput(); } RenderTools.LoadTextures(); ScreenDrawing.screenQuadVbo = ScreenDrawing.CreateScreenQuadBuffer(); GetOpenGLSystemInfo(); ShaderTools.SetupShaders(); setupStatus = SharedResourceStatus.Initialized; } catch (AccessViolationException) { // Context creation failed. setupStatus = SharedResourceStatus.Failed; } }
private static Framebuffer DrawTextureToNewFbo(Texture2D texture, int width, int height, bool r, bool g, bool b, bool a) { BufferObject screenVbo = ScreenDrawing.CreateScreenQuadBuffer(); Framebuffer framebuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height, PixelInternalFormat.Rgba); framebuffer.Bind(); // Draw the specified color channels. GL.Viewport(0, 0, width, height); ScreenDrawing.DrawTexturedQuad(texture.Id, 1, 1, r, g, b, a); return(framebuffer); }
public static void DrawNudMaterialSphere(Shader shader, NUD.Material material, Mesh3D screenTriangle, Dictionary <NUD.DummyTextures, Texture> dummyTextures) { if (!shader.ProgramCreatedSuccessfully) { return; } shader.UseProgram(); // Use the same uniforms as the NUD shader. GenericMaterial genericMaterial = new GenericMaterial(); NudUniforms.SetMaterialPropertyUniforms(genericMaterial, material); genericMaterial.SetShaderUniforms(shader); NUD.SetStageLightingUniforms(shader, 0); ModelContainer.SetRenderSettingsUniforms(shader); nudSphereCamera.UpdateMatrices(); ModelContainer.SetLightingUniforms(shader, nudSphereCamera); ModelContainer.SetCameraMatrixUniforms(nudSphereCamera, shader); // Use default textures rather than textures from the NUT. NudUniforms.SetTextureUniformsNudMatSphere(shader, material, dummyTextures); // These values aren't needed in the shader currently. shader.SetVector3("cameraPosition", 0, 0, 0); shader.SetFloat("zBufferOffset", 0); shader.SetFloat("bloomThreshold", Runtime.bloomThreshold); bool isTransparent = (material.srcFactor > 0) || (material.dstFactor > 0) || (material.alphaFunction > 0) || (material.alphaTest > 0); shader.SetBoolToInt("isTransparent", isTransparent); // Set texture uniforms for the mesh attributes. shader.SetTexture("normalTex", sphereNrmTex.Id, TextureTarget.Texture2D, 15); shader.SetTexture("uvTex", sphereUvTex.Id, TextureTarget.Texture2D, 16); shader.SetTexture("tanTex", sphereTanTex.Id, TextureTarget.Texture2D, 17); shader.SetTexture("bitanTex", sphereBitanTex.Id, TextureTarget.Texture2D, 18); // Draw full screen "quad" (big triangle) ScreenDrawing.DrawScreenTriangle(shader, screenTriangle); }