Exemplo n.º 1
0
        private static void RenderPresetsToFiles()
        {
            using (GameWindow gameWindow = OpenTKSharedResources.CreateGameWindowContext(width, height))
            {
                // Resource creation.
                screenTriangle = ScreenDrawing.CreateScreenTriangle();
                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);
                }
            }
        }
Exemplo n.º 2
0
        private static Framebuffer DrawTextureToNewFbo(Texture2D texture, int width, int height, bool r, bool g, bool b, bool a)
        {
            Mesh3D      screenTriangle = ScreenDrawing.CreateScreenTriangle();
            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, screenTriangle, r, g, b, a);
            return(framebuffer);
        }
Exemplo n.º 3
0
        public static void DrawQuadGradient(Vector3 topColor, Vector3 bottomColor, Mesh3D screenTriangle)
        {
            // draw RGB and alpha channels of texture to screen quad
            Shader shader = OpenTKSharedResources.shaders["Gradient"];

            shader.UseProgram();

            EnableAlphaBlendingWhiteBackground();

            shader.SetVector3("topColor", topColor);
            shader.SetVector3("bottomColor", bottomColor);

            DrawScreenTriangle(shader, screenTriangle);
        }
Exemplo n.º 4
0
        public static void DrawScreenQuadPostProcessing(int texture0, int texture1, Mesh3D screenTriangle)
        {
            // Draws RGB and alpha channels of texture to screen quad.
            Shader shader = OpenTKSharedResources.shaders["ScreenQuad"];

            shader.UseProgram();

            shader.SetTexture("image0", texture0, TextureTarget.Texture2D, 0);
            shader.SetTexture("image1", texture1, TextureTarget.Texture2D, 1);

            shader.SetBoolToInt("renderBloom", Runtime.renderBloom);
            shader.SetFloat("bloomIntensity", Runtime.bloomIntensity);

            ShaderTools.SystemColorVector3Uniform(shader, Runtime.backgroundGradientBottom, "backgroundBottomColor");
            ShaderTools.SystemColorVector3Uniform(shader, Runtime.backgroundGradientTop, "backgroundTopColor");

            // Draw full screen "quad" (big triangle)
            DrawScreenTriangle(shader, screenTriangle);
        }
Exemplo n.º 5
0
        public static void DrawTexturedQuad(Texture texture, int width, int height, Mesh3D screenTriangle,
                                            bool renderR         = true, bool renderG     = true, bool renderB = true, bool renderA = false,
                                            bool keepAspectRatio = false, float intensity = 1, int currentMipLevel = 0)
        {
            // Draws RGB and alpha channels of texture to screen quad.
            Shader shader = OpenTKSharedResources.shaders["Texture"];

            shader.UseProgram();

            EnableAlphaBlendingWhiteBackground();

            // Single texture uniform.
            shader.SetTexture("image", texture, 0);

            // Channel toggle uniforms.
            shader.SetBoolToInt("renderR", renderR);
            shader.SetBoolToInt("renderG", renderG);
            shader.SetBoolToInt("renderB", renderB);
            shader.SetBoolToInt("renderAlpha", renderA);

            shader.SetFloat("intensity", intensity);

            bool alphaOverride = renderA && !renderR && !renderG && !renderB;

            shader.SetBoolToInt("alphaOverride", alphaOverride);

            // Perform aspect ratio calculations in shader.
            // This only displays correctly if the viewport is square.
            shader.SetBoolToInt("preserveAspectRatio", keepAspectRatio);
            shader.SetFloat("width", width);
            shader.SetFloat("height", height);

            // Display certain mip levels.
            shader.SetInt("currentMipLevel", currentMipLevel);

            // Draw full screen "quad" (big triangle)
            DrawScreenTriangle(shader, screenTriangle);
        }
Exemplo n.º 6
0
        public static void DrawNudMaterialSphere(Shader shader, NUD.Material material, Mesh3D screenTriangle, Dictionary <NudEnums.DummyTexture, Texture> dummyTextures)
        {
            if (!shader.LinkStatusIsOk)
            {
                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);

            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, 15);
            shader.SetTexture("uvTex", sphereUvTex, 16);
            shader.SetTexture("tanTex", sphereTanTex, 17);
            shader.SetTexture("bitanTex", sphereBitanTex, 18);

            // Draw full screen "quad" (big triangle)
            ScreenDrawing.DrawScreenTriangle(shader, screenTriangle);
        }
Exemplo n.º 7
0
 public static void DrawTexturedQuad(Texture texture, float intensity, Mesh3D screenTriangle)
 {
     DrawTexturedQuad(texture, 1, 1, screenTriangle, true, true, true, true, false, intensity, 0);
 }
Exemplo n.º 8
0
        public static Mesh3D CreateScreenTriangle()
        {
            Mesh3D screenTriangle = new Mesh3D(screenTriangleVertices);

            return(screenTriangle);
        }
Exemplo n.º 9
0
 public static void DrawScreenTriangle(Shader shader, Mesh3D screenTriangle)
 {
     screenTriangle.Draw(shader);
 }