Exemple #1
0
        public SplineTubesTess(string shaderPath, TessTubeShadingStyle shadingStyle, TessTubeRenderSetting renderSettings, BufferUsageHint bufferUsageHintType, int bufferMaxElementCount, int[] nodeCount, int vertexRingCount, int vertexRingVertexCount)
            : base(renderSettings.HasFlag(TessTubeRenderSetting.ShaderBufferTypeIsSSBO) ? ShaderBufferType.SSBO : ShaderBufferType.UBO, bufferUsageHintType, bufferMaxElementCount, nodeCount, 1 + vertexRingCount / 2)
        {
            this.shadingStyle = shadingStyle;
            this.renderSettings = renderSettings;

            this.vertexRingVertexCount = vertexRingVertexCount;
            this.vertexRingCount = vertexRingCount;

            this.maxLayerId = vertexRingCount - 1;

            if (shadingStyle == TessTubeShadingStyle.HardNormalWF || shadingStyle == TessTubeShadingStyle.BlueWF)
                renderSettings |= TessTubeRenderSetting.UseGeoShader;

            if (renderSettings.HasFlag(TessTubeRenderSetting.UseCaps))
                cylIB = IndexBuffer.CreateClosedQuadCylinder(vertexRingVertexCount, vertexRingCount);
            else
                cylIB = IndexBuffer.CreateQuadCylinder(vertexRingVertexCount, vertexRingCount);

            var definesStr = shadingStyle.ToDefineString() + renderSettings.ToDefineString();
            definesStr += "#define TUBES_BUFFER_SIZE " + this.shaderBuffer.Float4BlockCount.ToString();
            definesStr += Environment.NewLine;
            definesStr += "#define VRING_VERTEX_COUNT " + vertexRingVertexCount.ToString();
            definesStr += Environment.NewLine;
            definesStr += "#define VRING_COUNT " + vertexRingCount.ToString();
            definesStr += Environment.NewLine;

            if (renderSettings.HasFlag(TessTubeRenderSetting.UseGeoShader))
            {
                shader = new Shader(
                "#version 440",
                definesStr,
                shaderPath + ".defs",
                new Shader.Desc(ShaderType.VertexShader, shaderPath + ".vs"),
                new Shader.Desc(ShaderType.TessControlShader, shaderPath + ".tc"),
                new Shader.Desc(ShaderType.TessEvaluationShader, shaderPath + ".te"),
                new Shader.Desc(ShaderType.GeometryShader, shaderPath + ".gs"),
                new Shader.Desc(ShaderType.FragmentShader, shaderPath + ".fs"));
            }
            else
            {
                shader = new Shader(
                "#version 440",
                definesStr,
                shaderPath + ".defs",
                new Shader.Desc(ShaderType.VertexShader, shaderPath + ".vs"),
                new Shader.Desc(ShaderType.TessControlShader, shaderPath + ".tc"),
                new Shader.Desc(ShaderType.TessEvaluationShader, shaderPath + ".te"),
                new Shader.Desc(ShaderType.FragmentShader, shaderPath + ".fs"));
            }
        }
Exemple #2
0
        public void BindShaderAndShaderBuffer(Shader shader, int bufferIndex, string uniformBlockName)
        {
            shaderBuffer.BindToIndex(bufferIndex);

            shader.BindShaderBuffer(shaderBuffer, uniformBlockName);

            shader.Bind();
        }
Exemple #3
0
        public SplineTubesRaycast(string shaderPath, RaycastTubeShadingStyle shadingStyle, RaycastTubeRenderSetting renderSettings, BufferUsageHint bufferUsageHintType, int bufferMaxElementCount, int[] nodeCount)
            : base(renderSettings.HasFlag(RaycastTubeRenderSetting.ShaderBufferTypeIsSSBO) ? ShaderBufferType.SSBO : ShaderBufferType.UBO, bufferUsageHintType, bufferMaxElementCount, nodeCount, 1)
        {
            this.shadingStyle = shadingStyle;
            this.renderSettings = renderSettings;

            cube = new Mesh<Vector3>(
            new[]
            {
                new VertexAttribute()
                {
                    Index = 0,
                    Size = 3,
                    Type = VertexAttribPointerType.Float,
                    Normalized = false,
                    Stride = Vector3.SizeInBytes,
                    Offset = 0,
                }
            },
            new[]
            {
                new Vector3(-1f, +1f, +1f),
                new Vector3(-1f, -1f, +1f),
                new Vector3(+1f, +1f, +1f),
                new Vector3(+1f, -1f, +1f),
                new Vector3(+1f, -1f, -1f),
                new Vector3(+1f, +1f, -1f),
                new Vector3(-1f, +1f, -1f),
                new Vector3(-1f, -1f, -1f)
            },
            new uint[]
            {
                0, 1, 2,
                2, 1, 3,
                3, 4, 2,
                2, 4, 5,
                5, 4, 6,
                6, 4, 7,
                7, 1, 0,
                0, 6, 7,
                7, 4, 3,
                3, 1, 7,
                6, 0, 2,
                2, 5, 6,
            });

            if (renderSettings.HasFlag(RaycastTubeRenderSetting.SplitIn4Segments))
                qSegmentCount = 4;
            else
                qSegmentCount = 2;

            var definesStr = shadingStyle.ToDefineString() + renderSettings.ToDefineString();
            definesStr += "#define TUBES_BUFFER_SIZE " + this.shaderBuffer.Float4BlockCount.ToString();
            definesStr += Environment.NewLine;

            shader = new Shader(
                    "#version 440",
                    definesStr,
                    shaderPath + ".defs",
                    new Shader.Desc(ShaderType.VertexShader, shaderPath + ".vs"),
                    new Shader.Desc(ShaderType.FragmentShader, shaderPath + ".fs"));
        }
Exemple #4
0
        protected override void OnLoad(EventArgs e)
        {
            GL.ClearColor(Color4.Brown);

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);

            //GL.Enable(EnableCap.CullFace);
            //GL.CullFace(CullFaceMode.Back);

            vertexBuffer = new VertexBuffer<Vector3>
            (
                new Vector3(-1f, +1f, +1f),
                new Vector3(-1f, -1f, +1f),
                new Vector3(+1f, +1f, +1f),
                new Vector3(+1f, -1f, +1f),
                new Vector3(+1f, -1f, -1f),
                new Vector3(+1f, +1f, -1f),
                new Vector3(-1f, +1f, -1f),
                new Vector3(-1f, -1f, -1f)
            );

            //indexBuffer = new IndexBuffer
            //(
            //    0, 1, 3, 2,
            //    2, 3, 4, 5,
            //    5, 4, 7, 6,
            //    6, 7, 1, 0,
            //    0, 2, 5, 6,
            //    1, 7, 4, 3
            //);

            indexBuffer = IndexBuffer.CreateQuadCylinder(8, 16);

            string shaderPath = projectPath + "TessTriCube";
            string shaderPath2 = projectPath + "TessQuadCube";
            string shaderPath3 = projectPath + "TessCyl";

            shader = new Shader(
            new Shader.Desc(ShaderType.VertexShader, shaderPath3 + ".vs"),
            new Shader.Desc(ShaderType.TessControlShader, shaderPath2 + ".tc"),
                //new Shader.Desc(ShaderType.TessControlShader, shaderPath + ".tc"),
            new Shader.Desc(ShaderType.TessEvaluationShader, shaderPath3 + ".te"),
                //new Shader.Desc(ShaderType.TessEvaluationShader, shaderPath + ".te"),
            new Shader.Desc(ShaderType.FragmentShader, shaderPath + ".ps"));

            shader.Bind();

            //uniformScale = GL.GetUniformLocation(shaderProgramHandle, "scale");
            //uniformMatViewProj = GL.GetUniformLocation(shader.Handle, "viewProjMat");

            ubuffer = new ShaderBuffer(ShaderBufferType.UBO, 4, BufferUsageHint.StreamDraw);
            ubuffer.BindToIndex(0);
            //ubuffer.BindToProgram(shader.Handle, "shader_data");
            shader.BindShaderBuffer(ubuffer, "shader_data");

            query = new PerfQuery();

            projMat = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI * 0.25f, Width / (float)Height, 1f, 5000f);
        }