From 6b5ade4ac3b98ce03a08a6a1bd9c385726b43e8f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 12 Jul 2018 22:03:37 +0200 Subject: [PATCH] Should be no more deprecated warnings with core context GL for menu shaders --- .../core_pipeline_bokeh.glsl.frag.h | 33 ++++++++ .../gl_shaders/core_pipeline_snow.glsl.frag.h | 72 +++++++++++++++++ .../core_pipeline_snow_simple.glsl.frag.h | 72 +++++++++++++++++ .../core_pipeline_snowflake.glsl.frag.h | 77 +++++++++++++++++++ .../modern_pipeline_snow.glsl.vert.h | 8 +- gfx/drivers_shader/shader_glsl.c | 40 ++++++---- 6 files changed, 282 insertions(+), 20 deletions(-) create mode 100644 gfx/drivers/gl_shaders/core_pipeline_bokeh.glsl.frag.h create mode 100644 gfx/drivers/gl_shaders/core_pipeline_snow.glsl.frag.h create mode 100644 gfx/drivers/gl_shaders/core_pipeline_snow_simple.glsl.frag.h create mode 100644 gfx/drivers/gl_shaders/core_pipeline_snowflake.glsl.frag.h diff --git a/gfx/drivers/gl_shaders/core_pipeline_bokeh.glsl.frag.h b/gfx/drivers/gl_shaders/core_pipeline_bokeh.glsl.frag.h new file mode 100644 index 0000000000..94a9360c60 --- /dev/null +++ b/gfx/drivers/gl_shaders/core_pipeline_bokeh.glsl.frag.h @@ -0,0 +1,33 @@ +#include "shaders_common.h" + +static const char* stock_fragment_xmb_bokeh_core = GLSL( + uniform float time; + uniform vec2 OutputSize; + out vec4 FragColor; + + void main(void) + { + float speed = time * 4.0; + vec2 uv = -1.0 + 2.0 * gl_FragCoord.xy / OutputSize.xy; + uv.x *= OutputSize.x / OutputSize.y; + vec3 color = vec3(0.0); + + for( int i=0; i < 8; i++ ) + { + float pha = sin(float(i) * 546.13 + 1.0) * 0.5 + 0.5; + float siz = pow(sin(float(i) * 651.74 + 5.0) * 0.5 + 0.5, 4.0); + float pox = sin(float(i) * 321.55 + 4.1) * OutputSize.x / OutputSize.y; + float rad = 0.1 + 0.5 * siz + sin(pha + siz) / 4.0; + vec2 pos = vec2(pox + sin(speed / 15. + pha + siz), - 1.0 - rad + (2.0 + 2.0 * rad) * fract(pha + 0.3 * (speed / 7.) * (0.2 + 0.8 * siz))); + float dis = length(uv - pos); + if(dis < rad) + { + vec3 col = mix(vec3(0.194 * sin(speed / 6.0) + 0.3, 0.2, 0.3 * pha), vec3(1.1 * sin(speed / 9.0) + 0.3, 0.2 * pha, 0.4), 0.5 + 0.5 * sin(float(i))); + color += col.zyx * (1.0 - smoothstep(rad * 0.15, rad, dis)); + } + } + color *= sqrt(1.5 - 0.5 * length(uv)); + FragColor = vec4(color.r, color.g, color.b , 0.5); + } + +); diff --git a/gfx/drivers/gl_shaders/core_pipeline_snow.glsl.frag.h b/gfx/drivers/gl_shaders/core_pipeline_snow.glsl.frag.h new file mode 100644 index 0000000000..b7c61c620d --- /dev/null +++ b/gfx/drivers/gl_shaders/core_pipeline_snow.glsl.frag.h @@ -0,0 +1,72 @@ +#include "shaders_common.h" + +static const char* stock_fragment_xmb_snow_core = GLSL( + uniform float time; + uniform vec2 OutputSize; + out vec4 FragColor; + + float baseScale = 3.5; /* [1.0 .. 10.0] */ + float density = 0.7; /* [0.01 .. 1.0] */ + float speed = 0.25; /* [0.1 .. 1.0] */ + + float rand(vec2 co) + { + return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); + } + + float dist_func(vec2 distv) + { + float dist = sqrt((distv.x * distv.x) + (distv.y * distv.y)) * (40.0 / baseScale); + dist = clamp(dist, 0.0, 1.0); + return cos(dist * (3.14159265358 * 0.5)) * 0.5; + } + + float random_dots(vec2 co) + { + float part = 1.0 / 20.0; + vec2 cd = floor(co / part); + float p = rand(cd); + + if (p > 0.005 * (density * 40.0)) + return 0.0; + + vec2 dpos = (vec2(fract(p * 2.0) , p) + vec2(2.0, 2.0)) * 0.25; + + vec2 cellpos = fract(co / part); + vec2 distv = (cellpos - dpos); + + return dist_func(distv); + } + + float snow(vec2 pos, float time, float scale) + { + /* add wobble */ + pos.x += cos(pos.y * 1.2 + time * 3.14159 * 2.0 + 1.0 / scale) / (8.0 / scale) * 4.0; + /* add gravity */ + pos += time * scale * vec2(-0.5, 1.0) * 4.0; + return random_dots(pos / scale) * (scale * 0.5 + 0.5); + } + + void main(void) + { + float tim = time * 0.4 * speed; + vec2 pos = gl_FragCoord.xy / OutputSize.xx; + float a = 0.0; + /** + * Each of these is a layer of snow + * Remove some for better performance + * Changing the scale (3rd value) will mess with the looping + **/ + a += snow(pos, tim, 1.0); + a += snow(pos, tim, 0.7); + a += snow(pos, tim, 0.6); + a += snow(pos, tim, 0.5); + a += snow(pos, tim, 0.4); + a += snow(pos, tim, 0.3); + a += snow(pos, tim, 0.25); + a += snow(pos, tim, 0.125); + a = a * min(pos.y * 4.0, 1.0); + FragColor = vec4(1.0, 1.0, 1.0, a); + } + +); diff --git a/gfx/drivers/gl_shaders/core_pipeline_snow_simple.glsl.frag.h b/gfx/drivers/gl_shaders/core_pipeline_snow_simple.glsl.frag.h new file mode 100644 index 0000000000..7368542409 --- /dev/null +++ b/gfx/drivers/gl_shaders/core_pipeline_snow_simple.glsl.frag.h @@ -0,0 +1,72 @@ +#include "shaders_common.h" + +static const char *stock_fragment_xmb_simple_snow_core = GLSL( + uniform float time; + uniform vec2 OutputSize; + out vec4 FragColor; + + float baseScale = 1.25; /* [1.0 .. 10.0] */ + float density = 0.5; /* [0.01 .. 1.0] */ + float speed = 0.15; /* [0.1 .. 1.0] */ + + float rand(vec2 co) + { + return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); + } + + float dist_func(vec2 distv) + { + float dist = sqrt((distv.x * distv.x) + (distv.y * distv.y)) * (40.0 / baseScale); + dist = clamp(dist, 0.0, 1.0); + return cos(dist * (3.14159265358 * 0.5)) * 0.5; + } + + float random_dots(vec2 co) + { + float part = 1.0 / 20.0; + vec2 cd = floor(co / part); + float p = rand(cd); + + if (p > 0.005 * (density * 40.0)) + return 0.0; + + vec2 dpos = (vec2(fract(p * 2.0) , p) + vec2(2.0, 2.0)) * 0.25; + + vec2 cellpos = fract(co / part); + vec2 distv = (cellpos - dpos); + + return dist_func(distv); + } + + float snow(vec2 pos, float time, float scale) + { + /* add wobble */ + pos.x += cos(pos.y * 1.2 + time * 3.14159 * 2.0 + 1.0 / scale) / (8.0 / scale) * 4.0; + /* add gravity */ + pos += time * scale * vec2(-0.5, 1.0) * 4.0; + return random_dots(pos / scale) * (scale * 0.5 + 0.5); + } + + void main(void) + { + float tim = time * 0.4 * speed; + vec2 pos = gl_FragCoord.xy / OutputSize.xx; + float a = 0.0; + /** + * Each of these is a layer of snow + * Remove some for better performance + * Changing the scale (3rd value) will mess with the looping + **/ + a += snow(pos, tim, 1.0); + a += snow(pos, tim, 0.7); + a += snow(pos, tim, 0.6); + a += snow(pos, tim, 0.5); + a += snow(pos, tim, 0.4); + a += snow(pos, tim, 0.3); + a += snow(pos, tim, 0.25); + a += snow(pos, tim, 0.125); + a = a * min(pos.y * 4.0, 1.0); + FragColor = vec4(1.0, 1.0, 1.0, a); + } + +); diff --git a/gfx/drivers/gl_shaders/core_pipeline_snowflake.glsl.frag.h b/gfx/drivers/gl_shaders/core_pipeline_snowflake.glsl.frag.h new file mode 100644 index 0000000000..99620f3ec7 --- /dev/null +++ b/gfx/drivers/gl_shaders/core_pipeline_snowflake.glsl.frag.h @@ -0,0 +1,77 @@ +/* credits to: TheTimJames + https://www.shadertoy.com/view/Md2GRw +*/ + +#include "shaders_common.h" + +static const char* stock_fragment_xmb_snowflake_core = GLSL( + uniform float time; + uniform vec2 OutputSize; + vec2 uv; + out vec4 FragColor; + + float atime; + + float rand(vec2 co) + { + return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); + } + + float rand_float(float x) + { + return rand(vec2(x, 1.0)); + } + + float snow(vec3 pos, vec2 uv, float o) + { + vec2 d = (pos.xy - uv); + float a = atan(d.y,d.x) + sin(time*1.0 + o) * 10.0; + + float dist = d.x*d.x + d.y*d.y; + + if(dist < pos.z/400.0) + { + float col = 0.0; + if(sin(a * 8.0) < 0.0) + { + col=1.0; + } + if(dist < pos.z/800.0) + { + col+=1.0; + } + return col * pos.z; + } + + return 0.0; + } + + float col(vec2 c) + { + float color = 0.0; + for (int i = 1; i < 15; i++) + { + float o = rand_float(float(i) / 3.0) * 15.0; + float z = rand_float(float(i) + 13.0); + float x = 1.8 - (3.6) * (rand_float(floor((time*((z + 1.0) / 2.0) +o) / 2.0)) + sin(time * o /1000.0) / 10.0); + float y = 1.0 - mod((time * ((z + 1.0)/2.0)) + o, 2.0); + + color += snow(vec3(x,y,z), c, o); + } + + return color; + } + + void main(void) + { + uv = gl_FragCoord.xy / OutputSize.xy; + uv = uv * 2.0 - 1.0; + vec2 p = uv; + p.x *= OutputSize.x / OutputSize.y; + + atime = (time + 1.0) / 4.0; + + FragColor = vec4(col(p)); + } + +); diff --git a/gfx/drivers/gl_shaders/modern_pipeline_snow.glsl.vert.h b/gfx/drivers/gl_shaders/modern_pipeline_snow.glsl.vert.h index 405ab02e96..7e7719fdad 100644 --- a/gfx/drivers/gl_shaders/modern_pipeline_snow.glsl.vert.h +++ b/gfx/drivers/gl_shaders/modern_pipeline_snow.glsl.vert.h @@ -3,11 +3,11 @@ /* Need to duplicate these to work around broken stuff on Android. * Must enforce alpha = 1.0 or 32-bit games can potentially go black. */ static const char *stock_vertex_xmb_snow_modern = GLSL( - attribute vec2 TexCoord; - attribute vec2 VertexCoord; - attribute vec4 Color; + in vec2 TexCoord; + in vec2 VertexCoord; + in vec4 Color; uniform mat4 MVPMatrix; - varying vec2 tex_coord; + out vec2 tex_coord; void main() { gl_Position = MVPMatrix * vec4(VertexCoord, 0.0, 1.0); diff --git a/gfx/drivers_shader/shader_glsl.c b/gfx/drivers_shader/shader_glsl.c index 026e2da5f8..3a0683422d 100644 --- a/gfx/drivers_shader/shader_glsl.c +++ b/gfx/drivers_shader/shader_glsl.c @@ -117,8 +117,12 @@ static const char *glsl_prefixes[] = { #include "../drivers/gl_shaders/core_alpha_blend.glsl.frag.h" #ifdef HAVE_SHADERPIPELINE +#include "../drivers/gl_shaders/core_pipeline_snow.glsl.frag.h" +#include "../drivers/gl_shaders/core_pipeline_snow_simple.glsl.frag.h" #include "../drivers/gl_shaders/core_pipeline_xmb_ribbon.glsl.frag.h" #include "../drivers/gl_shaders/core_pipeline_xmb_ribbon_simple.glsl.frag.h" +#include "../drivers/gl_shaders/core_pipeline_bokeh.glsl.frag.h" +#include "../drivers/gl_shaders/core_pipeline_snowflake.glsl.frag.h" #include "../drivers/gl_shaders/legacy_pipeline_xmb_ribbon_simple.glsl.vert.h" #include "../drivers/gl_shaders/modern_pipeline_xmb_ribbon_simple.glsl.vert.h" #include "../drivers/gl_shaders/modern_pipeline_snow.glsl.vert.h" @@ -839,11 +843,12 @@ static void gl_glsl_init_menu_shaders(void *data) &glsl->uniforms[VIDEO_SHADER_MENU_2]); #if defined(HAVE_OPENGLES) - shader_prog_info.vertex = stock_vertex_xmb_snow_modern; -#else - shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; -#endif + shader_prog_info.vertex = stock_vertex_xmb_snow_modern; shader_prog_info.fragment = stock_fragment_xmb_simple_snow; +#else + shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; + shader_prog_info.fragment = glsl_core ? stock_fragment_xmb_simple_snow_core : stock_fragment_xmb_simple_snow; +#endif RARCH_LOG("[GLSL]: Compiling snow shader..\n"); gl_glsl_compile_program( @@ -855,11 +860,12 @@ static void gl_glsl_init_menu_shaders(void *data) &glsl->uniforms[VIDEO_SHADER_MENU_3]); #if defined(HAVE_OPENGLES) - shader_prog_info.vertex = stock_vertex_xmb_snow_modern; -#else - shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; -#endif + shader_prog_info.vertex = stock_vertex_xmb_snow_modern; shader_prog_info.fragment = stock_fragment_xmb_snow; +#else + shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; + shader_prog_info.fragment = glsl_core ? stock_fragment_xmb_snow_core : stock_fragment_xmb_snow; +#endif RARCH_LOG("[GLSL]: Compiling modern snow shader..\n"); gl_glsl_compile_program( @@ -871,11 +877,12 @@ static void gl_glsl_init_menu_shaders(void *data) &glsl->uniforms[VIDEO_SHADER_MENU_4]); #if defined(HAVE_OPENGLES) - shader_prog_info.vertex = stock_vertex_xmb_snow_modern; -#else - shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; -#endif + shader_prog_info.vertex = stock_vertex_xmb_snow_modern; shader_prog_info.fragment = stock_fragment_xmb_bokeh; +#else + shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; + shader_prog_info.fragment = glsl_core ? stock_fragment_xmb_bokeh_core : stock_fragment_xmb_bokeh; +#endif RARCH_LOG("[GLSL]: Compiling bokeh shader..\n"); gl_glsl_compile_program( @@ -887,11 +894,12 @@ static void gl_glsl_init_menu_shaders(void *data) &glsl->uniforms[VIDEO_SHADER_MENU_5]); #if defined(HAVE_OPENGLES) - shader_prog_info.vertex = stock_vertex_xmb_snow_modern; -#else - shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; -#endif + shader_prog_info.vertex = stock_vertex_xmb_snow_modern; shader_prog_info.fragment = stock_fragment_xmb_snowflake; +#else + shader_prog_info.vertex = glsl_core ? stock_vertex_xmb_snow_modern : stock_vertex_xmb_snow_legacy; + shader_prog_info.fragment = glsl_core ? stock_fragment_xmb_snowflake_core : stock_fragment_xmb_snowflake; +#endif RARCH_LOG("[GLSL]: Compiling snowflake shader..\n"); gl_glsl_compile_program(