コード例 #1
0
ファイル: GenericMaterial.cs プロジェクト: Hengle/SFGraphics
        public void SetShaderUniforms(Shader shader)
        {
            foreach (var uniform in intUniformsByName)
            {
                shader.SetInt(uniform.Key, uniform.Value);
            }

            foreach (var uniform in floatUniformsByName)
            {
                shader.SetFloat(uniform.Key, uniform.Value);
            }

            foreach (var uniform in vec2UniformsByName)
            {
                shader.SetVector2(uniform.Key, uniform.Value);
            }

            foreach (var uniform in vec3UniformsByName)
            {
                shader.SetVector3(uniform.Key, uniform.Value);
            }

            foreach (var uniform in vec4UniformsByName)
            {
                shader.SetVector4(uniform.Key, uniform.Value);
            }

            foreach (var uniform in mat4UniformsByName)
            {
                Matrix4 value = uniform.Value;
                shader.SetMatrix4x4(uniform.Key, ref value);
            }
        }
コード例 #2
0
        public static void DrawTexturedQuad(int texture, int width, int height, VertexArrayObject screenVao,
                                            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, TextureTarget.Texture2D, 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, screenVao);
        }