Ejemplo n.º 1
0
        protected override IShader compilePixelShader(iShaderFactory compiler, iStorageFolder assets,
                                                      string uvMin, string uvMax, string colorString)
        {
            StringBuilder sb = new StringBuilder(readSource(assets));

            sb.Replace("$( UV_MIN )", uvMin);
            sb.Replace("$( UV_MAX )", uvMax);
            sb.Replace("$( BORDER_COLOR )", colorString);
            string glsl = sb.ToString();

            ShaderSourceInfo sourceInfo = new ShaderSourceInfo(ShaderType.Pixel, ShaderSourceLanguage.Glsl);

            sourceInfo.combinedTextureSamplers = true;
            return(compiler.compileFromSource(glsl, sourceInfo, "RenderVideoPS"));
        }
Ejemplo n.º 2
0
        protected override void createResources(IRenderDevice device)
        {
            // Diligent Engine can use HLSL source on all supported platforms.
            // It will convert HLSL to GLSL in OpenGL mode, while Vulkan backend will compile it directly to SPIRV.
            string VSSource = @"
struct PSInput 
{ 
    float4 Pos   : SV_POSITION; 
    float3 Color : COLOR; 
};

void main( in uint VertId : SV_VertexID, out PSInput PSIn ) 
{
    float4 Pos[3];
    Pos[0] = float4(-0.5, -0.5, 0.0, 1.0);
    Pos[1] = float4( 0.0, +0.5, 0.0, 1.0);
    Pos[2] = float4(+0.5, -0.5, 0.0, 1.0);

    float3 Col[3];
    Col[0] = float3(1.0, 0.0, 0.0); // red
    Col[1] = float3(0.0, 1.0, 0.0); // green
    Col[2] = float3(0.0, 0.0, 1.0); // blue

    PSIn.Pos   = Pos[VertId];
    PSIn.Color = Col[VertId];
}";

            string            PSSource = @"
struct PSInput 
{ 
    float4 Pos   : SV_POSITION; 
    float3 Color : COLOR; 
};

struct PSOutput
{ 
    float4 Color : SV_TARGET; 
};

void main( in PSInput PSIn, out PSOutput PSOut )
{
    PSOut.Color = float4(PSIn.Color.rgb, 1.0);
}
";
            PipelineStateDesc PSODesc  = new PipelineStateDesc(false);

            PSODesc.setBufferFormats(context);

            // Primitive topology defines what kind of primitives will be rendered by this pipeline state
            PSODesc.GraphicsPipeline.PrimitiveTopology = PrimitiveTopology.TriangleList;
            // No back face culling for this tutorial
            PSODesc.GraphicsPipeline.RasterizerDesc.CullMode = CullMode.None;
            // Disable depth testing
            PSODesc.GraphicsPipeline.DepthStencilDesc.DepthEnable = false;

            iShaderFactory shaderFactory = device.GetShaderFactory();

            // We won't be using the device object after this, `using` is to release the COM interface once finished
            using (iPipelineStateFactory stateFactory = device.CreatePipelineStateFactory())
            {
                // Compile the two shaders
                ShaderSourceInfo sourceInfo = new ShaderSourceInfo(ShaderType.Vertex, ShaderSourceLanguage.Hlsl);
                sourceInfo.combinedTextureSamplers = true;                  // This appears to be the requirement of OpenGL backend.

                using (var vs = shaderFactory.compileFromSource(VSSource, sourceInfo))
                    stateFactory.graphicsVertexShader(vs);

                sourceInfo.shaderType = ShaderType.Pixel;
                using (var ps = shaderFactory.compileFromSource(PSSource, sourceInfo))
                    stateFactory.graphicsPixelShader(ps);

                stateFactory.apply(ref PSODesc);

                pipelineState = device.CreatePipelineState(ref PSODesc);
            }
        }