public static string GetFragmentSource() { return(GetVersion() + SrgbShader.ToSrgbFunction() + // uniforms "layout(binding = 0) uniform sampler2DArray tex;\n" + "layout(location = 2) uniform float layer;\n" + "layout(location = 3) uniform float level;\n" + "layout(location = 4) uniform uint grayscale;\n" + "layout(location = 6) uniform vec4 crop;\n" + // in out "layout(location = 0) in vec3 raydir;\n" + "out vec4 fragColor;\n" + "const float PI = 3.14159265358979323846264;" + "void main(void){\n" + "vec2 polarDirection;\n" + // t computation "vec3 normalizedDirection = normalize(raydir);\n" + "polarDirection.t = acos(normalizedDirection.y)/PI;\n" + // s computation "polarDirection.s = normalizedDirection.x == 0.0 ? " + "PI/2*sign(normalizedDirection.z) :" + "atan(normalizedDirection.z, normalizedDirection.x);\n" + "polarDirection.s = polarDirection.s / (2*PI) + 0.25;\n" + "if( polarDirection.s < 0.0) polarDirection.s += 1.0;\n" + "vec4 color = textureLod(tex, vec3(polarDirection.st, layer), level);\n" + ApplyGrayscale() + ApplyColorCrop("polarDirection") + "fragColor = toSrgb(color);\n" + "}\n"); }
public void Dispose() { CheckersShader.Dispose(); Vao.Dispose(); samplerLinear.Dispose(); samplerLinearMip.Dispose(); samplerNearest.Dispose(); samplerNearestMip.Dispose(); TextureCache.Clear(); GetPixelShader.Dispose(); SrgbShader.Dispose(); ExportShader.Dispose(); LinearMaxStatistics.Dispose(); SrgbMaxStatistics.Dispose(); LinearMinStatistics.Dispose(); SrgbMinStatistics.Dispose(); }
public static string GetFragmentSource() { return(GetVersion() + SrgbShader.ToSrgbFunction() + // uniforms "layout(binding = 0) uniform samplerCube tex;\n" + "layout(location = 3) uniform float level;\n" + "layout(location = 4) uniform uint grayscale;\n" + // in out "layout(location = 0) in vec3 viewdir;\n" + "out vec4 fragColor;\n" + "void main(void){\n" + "vec4 color = textureLod(tex, viewdir, level);\n" + ApplyGrayscale() + "fragColor = toSrgb(color);\n" + "}\n"); }
public OpenGlModel(OpenGlContext context, ImagesModel images) { Debug.Assert(context.GlEnabled); Vao = new VertexArray(); CheckersShader = new CheckersShader(); samplerLinear = new Sampler(TextureMinFilter.Linear, TextureMagFilter.Linear); samplerLinearMip = new Sampler(TextureMinFilter.LinearMipmapLinear, TextureMagFilter.Linear); samplerNearest = new Sampler(TextureMinFilter.Nearest, TextureMagFilter.Nearest); samplerNearestMip = new Sampler(TextureMinFilter.NearestMipmapNearest, TextureMagFilter.Nearest); TextureCache = new TextureCacheModel(images, context); GetPixelShader = new PixelValueShader(); SrgbShader = new SrgbShader(); ExportShader = new PixelExportShader(); LinearMaxStatistics = new MaxStatistics(false); SrgbMaxStatistics = new MaxStatistics(true); LinearMinStatistics = new MinStatistics(false); SrgbMinStatistics = new MinStatistics(true); LinearAvgStatistics = new AverageStatistics(false, images); SrgbAvgStatistics = new AverageStatistics(true, images); }
public static string GetFragmentSource() { return(GetVersion() + SrgbShader.ToSrgbFunction() + // uniforms "layout(binding = 0) uniform sampler2DArray tex;\n" + "layout(location = 2) uniform float layer;\n" + "layout(location = 3) uniform float level;\n" + "layout(location = 4) uniform uint grayscale;\n" + "layout(location = 5) uniform vec4 crop;\n" + // in out "layout(location = 0) in vec2 texcoord;\n" + "out vec4 fragColor;\n" + "void main(void){\n" + "vec4 color = textureLod(tex, vec3(texcoord, layer), level);\n" + ApplyGrayscale() + ApplyColorCrop() + "color = toSrgb(color);\n" + "fragColor = color;\n" + "}\n"); }
private static string GenerateShaderSource(string colorFormula, string alphaFormula, int numImages) { return(OpenGlContext.ShaderVersion + "\n" + $"layout(local_size_x = {LocalSize}, local_size_y = {LocalSize}) in;\n" + // output image "layout(rgba32f, binding = 0) uniform writeonly image2D out_image;\n" + // global variables "ivec2 pixelPos;\n" + // uniforms "layout(location = 1) uniform int layer;\n" + "layout(location = 2) uniform int level;\n" + SrgbShader.FromSrgbFunction() + SrgbShader.ToSrgbFunction() + GetTextureBindings(numImages) + GetTextureGetters(numImages) + GetHelperFunctions() + "void main(){\n" + "pixelPos = ivec2(gl_GlobalInvocationID.xy);\n" + "ivec2 imgSize = imageSize(out_image);\n" + "if(pixelPos.x >= imgSize.x || pixelPos.y >= imgSize.y) return;\n" + "vec4 color = " + GetImageColor(colorFormula, alphaFormula) + ";\n" + "imageStore(out_image, pixelPos, color);\n" + "}\n"); }