Skip to content

Commit

Permalink
let it snow
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-asm committed Dec 3, 2017
1 parent 04b26fe commit bada13a
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 0 deletions.
65 changes: 65 additions & 0 deletions gfx/drivers/gl_shaders/pipeline_snowflake.glsl.frag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* credits to: TheTimJames
https://www.shadertoy.com/view/Md2GRw
*/

#include "shaders_common.h"

static const char* stock_fragment_xmb_snowflake = GLSL(
uniform float time;
uniform float atime;
uniform vec2 OutputSize;
vec2 uv;

float rand(vec2 co)
{
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
}

float snow(vec3 pos, vec2 uv, float o)
{
vec2 d = (pos.xy - uv);
float a = atan(d.y,d.x)+sin(atime*1.+o)*10.;

float dist = d.x*d.x + d.y*d.y;

if(dist < pos.z/400.){
float col = 0.0;
if(sin(a*8.) < 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(i) / 3.) * 15 * 2.0;
float z = rand(float(i) + 13.0);
float x = 1.8 - (3.6) * (rand(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)/4.0;

gl_FragColor = vec4(col(p));
}

);
16 changes: 16 additions & 0 deletions gfx/drivers_shader/shader_glsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ static const char *glsl_prefixes[] = {
#include "../drivers/gl_shaders/modern_pipeline_xmb_ribbon.glsl.vert.h"
#include "../drivers/gl_shaders/pipeline_xmb_ribbon.glsl.frag.h"
#include "../drivers/gl_shaders/pipeline_bokeh.glsl.frag.h"
#include "../drivers/gl_shaders/pipeline_snowflake.glsl.frag.h"
#endif

typedef struct glsl_shader_data
Expand Down Expand Up @@ -1095,6 +1096,21 @@ static void *gl_glsl_init(void *data, const char *path)
&shader_prog_info);
gl_glsl_find_uniforms(glsl, 0, glsl->prg[VIDEO_SHADER_MENU_5].id,
&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.fragment = stock_fragment_xmb_snowflake;

gl_glsl_compile_program(
glsl,
VIDEO_SHADER_MENU_6,
&glsl->prg[VIDEO_SHADER_MENU_6],
&shader_prog_info);
gl_glsl_find_uniforms(glsl, 0, glsl->prg[VIDEO_SHADER_MENU_6].id,
&glsl->uniforms[VIDEO_SHADER_MENU_6]);
#endif

gl_glsl_reset_attrib(glsl);
Expand Down
1 change: 1 addition & 0 deletions gfx/video_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#define VIDEO_SHADER_MENU_3 (GFX_MAX_SHADERS - 4)
#define VIDEO_SHADER_MENU_4 (GFX_MAX_SHADERS - 5)
#define VIDEO_SHADER_MENU_5 (GFX_MAX_SHADERS - 6)
#define VIDEO_SHADER_MENU_6 (GFX_MAX_SHADERS - 7)

#endif

Expand Down
2 changes: 2 additions & 0 deletions intl/msg_hash_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -2542,6 +2542,8 @@ MSG_HASH(
)
MSG_HASH(MENU_ENUM_LABEL_VALUE_SHADER_PIPELINE_BOKEH,
"Bokeh")
MSG_HASH(MENU_ENUM_LABEL_VALUE_SHADER_PIPELINE_SNOWFLAKE,
"Snowflake")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_REFRESH_ROOMS,
"Refresh Room List")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME,
Expand Down
4 changes: 4 additions & 0 deletions menu/cbs/menu_cbs_get_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ static void menu_action_setting_disp_set_label_pipeline(
strlcpy(s,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_SHADER_PIPELINE_BOKEH), len);
case XMB_SHADER_PIPELINE_SNOWFLAKE:
strlcpy(s,
msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_SHADER_PIPELINE_SNOWFLAKE), len);
break;
}

Expand Down
3 changes: 3 additions & 0 deletions menu/drivers/xmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2759,6 +2759,9 @@ static void xmb_draw_bg(
case XMB_SHADER_PIPELINE_BOKEH:
draw.pipeline.id = VIDEO_SHADER_MENU_5;
break;
case XMB_SHADER_PIPELINE_SNOWFLAKE:
draw.pipeline.id = VIDEO_SHADER_MENU_6;
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions menu/drivers_display/menu_display_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ static void menu_display_gl_draw_pipeline(void *data)
case VIDEO_SHADER_MENU_3:
case VIDEO_SHADER_MENU_4:
case VIDEO_SHADER_MENU_5:
case VIDEO_SHADER_MENU_6:
shader_info.data = NULL;
shader_info.idx = draw->pipeline.id;
shader_info.set_active = true;
Expand Down Expand Up @@ -215,6 +216,7 @@ static void menu_display_gl_draw_pipeline(void *data)
case VIDEO_SHADER_MENU_3:
case VIDEO_SHADER_MENU_4:
case VIDEO_SHADER_MENU_5:
case VIDEO_SHADER_MENU_6:
#ifndef HAVE_PSGL
uniform_param.type = UNIFORM_2F;
uniform_param.lookup.ident = "OutputSize";
Expand Down
1 change: 1 addition & 0 deletions menu/menu_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ enum xmb_shader_pipeline
XMB_SHADER_PIPELINE_SIMPLE_SNOW,
XMB_SHADER_PIPELINE_SNOW,
XMB_SHADER_PIPELINE_BOKEH,
XMB_SHADER_PIPELINE_SNOWFLAKE,
XMB_SHADER_PIPELINE_LAST
};

Expand Down
1 change: 1 addition & 0 deletions msg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ enum msg_hash_enums
MENU_LABEL(SHADER_PIPELINE_SIMPLE_SNOW),
MENU_LABEL(SHADER_PIPELINE_SNOW),
MENU_LABEL(SHADER_PIPELINE_BOKEH),
MENU_LABEL(SHADER_PIPELINE_SNOWFLAKE),

MENU_LABEL(MATERIALUI_MENU_HEADER_OPACITY),
MENU_LABEL(MATERIALUI_MENU_FOOTER_OPACITY),
Expand Down

0 comments on commit bada13a

Please sign in to comment.