module

PointClickEngine::Graphics::Shaders::ShaderHelpers

Constants

BLOOM_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform float threshold;\nuniform float intensity;\nout vec4 finalColor;\n\nvoid main() {\n vec4 color = texture(texture0, fragTexCoord) * fragColor;\n float brightness = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));\n if (brightness > threshold) {\n finalColor = color * (1.0 + intensity);\n } else {\n finalColor = color;\n }\n}"

Bloom shader (simplified)

CHROMATIC_ABERRATION_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform float offset;\nout vec4 finalColor;\n\nvoid main() {\n vec2 direction = fragTexCoord - vec2(0.5, 0.5);\n float r = texture(texture0, fragTexCoord + direction * offset).r;\n float g = texture(texture0, fragTexCoord).g;\n float b = texture(texture0, fragTexCoord - direction * offset).b;\n float a = texture(texture0, fragTexCoord).a;\n finalColor = vec4(r, g, b, a) * fragColor;\n}"

Chromatic aberration shader

CRT_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform float scanlineIntensity;\nuniform float pixelHeight;\nout vec4 finalColor;\n\nvoid main() {\n vec4 color = texture(texture0, fragTexCoord) * fragColor;\n float scanline = sin(fragTexCoord.y * pixelHeight * 3.14159) * scanlineIntensity;\n color.rgb -= scanline;\n finalColor = color;\n}"

CRT/Scanline effect shader

DEFAULT_VERTEX = "#version 330\nin vec3 vertexPosition;\nin vec2 vertexTexCoord;\nin vec4 vertexColor;\nuniform mat4 mvp;\nout vec2 fragTexCoord;\nout vec4 fragColor;\n\nvoid main() {\n fragTexCoord = vertexTexCoord;\n fragColor = vertexColor;\n gl_Position = mvp * vec4(vertexPosition, 1.0);\n}"

Default vertex shader for all effects

GRAYSCALE_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform float intensity;\nout vec4 finalColor;\n\nvoid main() {\n vec4 color = texture(texture0, fragTexCoord) * fragColor;\n float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));\n finalColor = mix(color, vec4(gray, gray, gray, color.a), intensity);\n}"

Grayscale shader

OUTLINE_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform vec4 outlineColor;\nuniform float outlineSize;\nout vec4 finalColor;\n\nvoid main() {\n vec4 color = texture(texture0, fragTexCoord);\n if (color.a == 0.0) {\n vec2 size = vec2(outlineSize) / vec2(textureSize(texture0, 0));\n for (int x = -1; x <= 1; x++) {\n for (int y = -1; y <= 1; y++) {\n if (x == 0 && y == 0) continue;\n vec2 offset = vec2(float(x), float(y)) * size;\n if (texture(texture0, fragTexCoord + offset).a > 0.0) {\n finalColor = outlineColor;\n return;\n }\n }\n }\n }\n finalColor = color * fragColor;\n}"

Outline shader (for highlighting objects)

PIXELATE_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform float pixelSize;\nout vec4 finalColor;\n\nvoid main() {\n vec2 size = vec2(pixelSize, pixelSize);\n vec2 pos = floor(fragTexCoord / size) * size;\n finalColor = texture(texture0, pos) * fragColor;\n}"

Pixelation effect shader

SEPIA_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform float intensity;\nout vec4 finalColor;\n\nvoid main() {\n vec4 color = texture(texture0, fragTexCoord) * fragColor;\n vec3 sepia;\n sepia.r = dot(color.rgb, vec3(0.393, 0.769, 0.189));\n sepia.g = dot(color.rgb, vec3(0.349, 0.686, 0.168));\n sepia.b = dot(color.rgb, vec3(0.272, 0.534, 0.131));\n finalColor = vec4(mix(color.rgb, sepia, intensity), color.a);\n}"

Sepia tone shader

VIGNETTE_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform float radius;\nuniform float softness;\nout vec4 finalColor;\n\nvoid main() {\n vec4 color = texture(texture0, fragTexCoord) * fragColor;\n vec2 center = vec2(0.5, 0.5);\n float dist = distance(fragTexCoord, center);\n float vignette = smoothstep(radius, radius - softness, dist);\n finalColor = vec4(color.rgb * vignette, color.a);\n}"

Vignette shader

WAVE_FRAGMENT = "#version 330\nin vec2 fragTexCoord;\nin vec4 fragColor;\nuniform sampler2D texture0;\nuniform float time;\nuniform float amplitude;\nuniform float frequency;\nout vec4 finalColor;\n\nvoid main() {\n vec2 uv = fragTexCoord;\n uv.x += sin(uv.y * frequency + time) * amplitude;\n finalColor = texture(texture0, uv) * fragColor;\n}"

Wave distortion shader

Class methods

create_bloom_shader(shader_system : ShaderSystem, threshold : Float32 = 0.8_f32, intensity : Float32 = 0.5_f32)
Source
create_chromatic_aberration_shader(shader_system : ShaderSystem, offset : Float32 = 0.005_f32)
Source
create_crt_shader(shader_system : ShaderSystem, scanline_intensity : Float32 = 0.1_f32, pixel_height : Float32 = 480.0_f32)
Source
create_grayscale_shader(shader_system : ShaderSystem, intensity : Float32 = 1.0_f32)
Source
create_outline_shader(shader_system : ShaderSystem, color : Raylib::Color = Raylib::WHITE, size : Float32 = 2.0_f32)
Source
create_pixelate_shader(shader_system : ShaderSystem, pixel_size : Float32 = 4.0_f32)
Source
create_sepia_shader(shader_system : ShaderSystem, intensity : Float32 = 0.8_f32)
Source
create_vignette_shader(shader_system : ShaderSystem, radius : Float32 = 0.8_f32, softness : Float32 = 0.5_f32)
Source
create_wave_shader(shader_system : ShaderSystem, amplitude : Float32 = 0.01_f32, frequency : Float32 = 10.0_f32)
Source