From ff771b1761e78bea1a247856d494bc75bcd46025 Mon Sep 17 00:00:00 2001 From: rhailrake <49613070+rhailrake@users.noreply.github.com> Date: Tue, 16 May 2023 10:57:46 +0600 Subject: [PATCH] anime (#62) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * кумыс шейдер * crt shader --- Resources/Textures/Shaders/White/anime.swsl | 31 +++++++ .../Textures/Shaders/White/bettercrt.swsl | 83 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 Resources/Textures/Shaders/White/anime.swsl create mode 100644 Resources/Textures/Shaders/White/bettercrt.swsl diff --git a/Resources/Textures/Shaders/White/anime.swsl b/Resources/Textures/Shaders/White/anime.swsl new file mode 100644 index 0000000000..916c9d61a2 --- /dev/null +++ b/Resources/Textures/Shaders/White/anime.swsl @@ -0,0 +1,31 @@ +const highp float shake_power = 0.03; +const highp float shake_block_size = 30.5; +const highp float fade = 0.01; +const highp vec2 direction_r = vec2( 1.0, 0.0 ); +const highp vec2 direction_g = vec2( 0.4, 1.0 ); +const highp vec2 direction_b = vec2( -0.7, -0.3 ); +uniform sampler2D SCREEN_TEXTURE; + +highp float random (highp float seed) +{ + return fract ( 543.2543 * sin( dot( vec2( seed, seed ), vec2( 3525.46, -54.3415 ) ) ) ); +} + +void fragment() +{ + highp vec2 fixed_uv = UV; + fixed_uv.x += ( + random( + ( trunc( UV.y * shake_block_size ) / shake_block_size ) + + TIME + ) - 0.5 + ) * shake_power * ( fade * 12.0 ); + + COLOR = vec4( + textureLod( SCREEN_TEXTURE, fixed_uv + normalize( direction_r ) * fade, 0.0 ).r + , textureLod( SCREEN_TEXTURE, fixed_uv + normalize( direction_g ) * fade, 0.0 ).g + , textureLod( SCREEN_TEXTURE, fixed_uv + normalize( direction_b ) * fade, 0.0 ).b + , 0.0 + ) * ( 1.0 - fade ); + COLOR.a = 1.0; +} diff --git a/Resources/Textures/Shaders/White/bettercrt.swsl b/Resources/Textures/Shaders/White/bettercrt.swsl new file mode 100644 index 0000000000..8eab619a99 --- /dev/null +++ b/Resources/Textures/Shaders/White/bettercrt.swsl @@ -0,0 +1,83 @@ +uniform sampler2D SCREEN_TEXTURE; + +const highp float PI = 3.1415926535; + +// ブラウン管のガラスの曲がり具合(フラットなやつは0.0でいいかな) +const highp float crt_curve = 0.02; +// 走査線の濃さ +const highp float crt_scan_line_color = 0.348; +// 光量 +const highp float aperture_grille_rate = 0.5; +// RFスイッチ的ブラー +const highp float rf_switch_esque_blur = 1.1; +// 白色ノイズ +const highp float white_noise_rate = 0.05; + +highp float random( highp vec2 pos ) +{ + return fract(sin(dot(pos, vec2(12.9898,78.233))) * 43758.5453); +} + +void fragment( ) +{ + // ガラスの曲がり具合 + highp vec2 crt_curve_shift = ( vec2( 1.0, 1.0 ) - sin( UV.yx * PI ) ) * crt_curve; + highp vec2 crt_curve_scale = vec2( 1.0, 1.0 ) + crt_curve_shift * 2.0; + highp vec2 texture_fixed_uv = UV * crt_curve_scale - crt_curve_shift; + highp vec2 fixed_uv = UV * crt_curve_scale - crt_curve_shift; + // 範囲外を消す + highp float enable_color = float( 0.0 <= texture_fixed_uv.x && texture_fixed_uv.x <= 1.0 && 0.0 <= texture_fixed_uv.y && texture_fixed_uv.y <= 1.0 ); + + // ガラスの曲がり具合から元色を取得 + RFスイッチ的ブラー + COLOR.rgb = ( + ( + texture( SCREEN_TEXTURE, fixed_uv ).rgb + * ( 1.0 - rf_switch_esque_blur * 0.5 ) + ) + + ( + ( + texture( SCREEN_TEXTURE, fixed_uv + vec2( -SCREEN_PIXEL_SIZE.x * 3.1, 0.0 ) ).rgb + + texture( SCREEN_TEXTURE, fixed_uv + vec2( SCREEN_PIXEL_SIZE.x * 3.1, 0.0 ) ).rgb + ) + * ( rf_switch_esque_blur * 0.25 ) // (RFノイズ)0.5 * (テクスチャから読んだ2箇所を半分にしたい)0.5 + ) + ) * enable_color; + COLOR.a = 1.0; + + // ------------------------------------------------ + // 以下はアパーチャグリル上の1ピクセルごとの処理 + highp vec2 aperture_grille_pixel = vec2( floor( ( fixed_uv.x / SCREEN_PIXEL_SIZE.x ) / 3.0 ) * 3.0, fixed_uv.y ); + + // 白色ノイズ + highp float white_noise = random( aperture_grille_pixel + vec2( sin( TIME * 0.543254 ), cos( TIME * 0.254323563 ) ) ); + COLOR.rgb = mix( + COLOR.rgb + , vec3( white_noise, white_noise, white_noise ) + , white_noise_rate * enable_color + ); + + // アパーチャグリル再現 + highp float aperture_grille_point = mod( ( ( UV.x * crt_curve_scale.x ) - crt_curve_shift.x ) / SCREEN_PIXEL_SIZE.x, 3.0 ); + highp float aperture_grille_r_rate = clamp( 1.0 - aperture_grille_point, 0.0, 1.0 ) + clamp( aperture_grille_point - 2.0, 0.0, 1.0 ); + highp float aperture_grille_g_rate = clamp( 1.0 - abs( 1.0 - aperture_grille_point ), 0.0, 1.0 ); + highp float aperture_grille_b_rate = 1.0 - aperture_grille_r_rate - aperture_grille_g_rate; + COLOR = clamp( + COLOR * vec4( + normalize( vec3( + clamp( aperture_grille_r_rate, aperture_grille_rate, 1.0 ) + , clamp( aperture_grille_g_rate, aperture_grille_rate, 1.0 ) + , clamp( aperture_grille_b_rate, aperture_grille_rate, 1.0 ) + ) ) + , 1.0 + ) + , vec4( 0.0, 0.0, 0.0, 0.0 ) + , vec4( 1.0, 1.0, 1.0, 1.0 ) + ); + + // 走査線 + COLOR = mix( + COLOR + , vec4( 0.0, 0.0, 0.0, 1.0 ) + , float( 0 == int( fixed_uv.y / SCREEN_PIXEL_SIZE.y ) % 2 ) * crt_scan_line_color + ); +}