public static string ShaderFileToSourceCode(string fileName, ResourceFactory resourceFactory) { var dir = Path.GetDirectoryName(fileName); var shaderCode = File.ReadAllText(fileName); string GetIncludeCode(string includeName) { var includeFileName = Path.Combine(dir, includeName); var includeCode = File.ReadAllText(includeFileName); try { var conformalIncludeCode = GlslTools.MakeConformal(includeCode); var fragmentShaderDesc = new ShaderDescription(ShaderStages.Fragment, Encoding.UTF8.GetBytes(conformalIncludeCode), "main"); using (resourceFactory.CreateShader(fragmentShaderDesc)) { return(includeCode); } } catch (VeldridException vex) { throw new ShaderIncludeException($"Error compiling include file '{includeName}'", vex); } } var expandedShaderCode = Transformation.ExpandIncludes(shaderCode, GetIncludeCode); return(GlslTools.MakeConformal(expandedShaderCode)); }
public ShaderViewModel() { var sourceCode = @"void main() { vec2 uv = gl_FragCoord.xy / iResolution; gl_FragColor = vec4(uv, abs(sin(iGlobalTime)), 1.0); }" ; sourceCode = GlslTools.MakeConformal(sourceCode); var framebuffer = IoC.Resolve <GraphicsDevice>().SwapchainFramebuffer; //ResolutionX = shaderVisual = new ShaderVisual(framebuffer.Width, framebuffer.Height, sourceCode); }
public ShaderVisual(uint width, uint height, string sourceCode) { graphicsDevice = IoC.Resolve <GraphicsDevice>(); renderSurface = new RenderSurface(graphicsDevice.ResourceFactory, width, height); shaderQuad = new PrimitiveShaderQuad(null, sourceCode, renderSurface.FrameBuffer); const string copyShaderSourceCode = @"in vec2 uv; void main() { vec4 color = texture(texInput, uv); gl_FragColor = color; }" ; shaderQuadCopy = new PrimitiveShaderQuad(renderSurface.View, GlslTools.MakeConformal(copyShaderSourceCode), graphicsDevice.SwapchainFramebuffer); Width = width; Height = height; SourceCode = sourceCode; }