예제 #1
0
        private ShaderBytecode AssembleVertexShader(Module shaderLibrary, ModuleInstance shaderLibraryInstance)
        {
            var vertexShaderGraph = new FunctionLinkingGraph();

            // create input node - parameter name, semantic and size in bytes
            var vertexShaderInputNode = vertexShaderGraph.SetInputSignature(CreateInParam("inputPos", "SV_POSITION", 4),
                                                                            CreateInParam("inputTex", "COLOR", 4));

            // create the function call node
            var vertexFunctionCallNode = vertexShaderGraph.CallFunction(shaderLibrary, "VertexFunction");

            // bind input parameters to the function call
            vertexShaderGraph.PassValue(vertexShaderInputNode, 0, vertexFunctionCallNode, 0);
            vertexShaderGraph.PassValue(vertexShaderInputNode, 1, vertexFunctionCallNode, 1);

            // create the output parameters node
            var vertexShaderOutputNode = vertexShaderGraph.SetOutputSignature(CreateOutParam("outputTex", "SV_POSITION", 4),
                                                                              CreateOutParam("outputNorm", "COLOR", 4));

            // bind function call parameters to the output node
            vertexShaderGraph.PassValue(vertexFunctionCallNode, 0, vertexShaderOutputNode, 0);
            vertexShaderGraph.PassValue(vertexFunctionCallNode, 1, vertexShaderOutputNode, 1);

            // create the library instance for the shader
            var vertexShaderGraphInstance = vertexShaderGraph.CreateModuleInstance();

            var linker = new Linker();
            // bind linker to the function library
            linker.UseLibrary(shaderLibraryInstance);
            // link the shader
            return linker.Link(vertexShaderGraphInstance, "main", "vs_5_0", 0);
        }
예제 #2
0
        private ShaderBytecode AssemblePixelShader(Module shaderLibrary, ModuleInstance shaderLibraryInstance)
        {
            var pixelShaderGraph = new FunctionLinkingGraph();

            var pixelShaderInputNode = pixelShaderGraph.SetInputSignature(CreateInParam("inputPos", "SV_POSITION", 4, InterpolationMode.Undefined),
                                                                          CreateInParam("inputTex", "COLOR", 4, InterpolationMode.Undefined));

            var colorValueNode = pixelShaderGraph.CallFunction(shaderLibrary, "ColorFunction");

            pixelShaderGraph.PassValue(pixelShaderInputNode, 0, colorValueNode, 0);
            pixelShaderGraph.PassValue(pixelShaderInputNode, 1, colorValueNode, 1);

            // link additional nodes based on configuration
            if (_data.EnableInvertColor)
            {
                var tempNode = pixelShaderGraph.CallFunction(shaderLibrary, "InvertColor");
                pixelShaderGraph.PassValue(colorValueNode, tempNode, 0);
                colorValueNode = tempNode;
            }

            if (_data.EnableGrayscale)
            {
                var tempNode = pixelShaderGraph.CallFunction(shaderLibrary, "Grayscale");
                pixelShaderGraph.PassValue(colorValueNode, tempNode, 0);
                colorValueNode = tempNode;
            }

            var pixelShaderOutputNode = pixelShaderGraph.SetOutputSignature(CreateOutParam("outputColor", "SV_TARGET", 4));
            pixelShaderGraph.PassValue(colorValueNode, pixelShaderOutputNode, 0);

            var pixelShaderGraphInstance = pixelShaderGraph.CreateModuleInstance();

            var linker = new Linker();
            linker.UseLibrary(shaderLibraryInstance);
            return linker.Link(pixelShaderGraphInstance, "main", "ps_5_0", 0);
        }