RetroArch
snow_sm4.hlsl.h
Go to the documentation of this file.
1 
2 #define SRC(...) #__VA_ARGS__
3 SRC(
4 struct UBO
5 {
6  float4x4 modelViewProj;
7  float2 OutputSize;
8  float time;
9 };
10 uniform UBO global;
11 
12 struct PSInput
13 {
14  float4 position : SV_POSITION;
15  float2 texcoord : TEXCOORD0;
16 };
17 
18 PSInput VSMain(float4 position : POSITION, float2 texcoord : TEXCOORD0)
19 {
20  PSInput result;
21  result.position = mul(global.modelViewProj, position);
22  result.texcoord = texcoord;
23  return result;
24 }
25 
26 static const float baseScale = 3.5; // [1.0 .. 10.0]
27 static const float density = 0.7; // [0.01 .. 1.0]
28 static const float speed = 0.25; // [0.1 .. 1.0]
29 
30 float rand(float2 co)
31 {
32  return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453);
33 }
34 
35 float dist_func(float2 distv)
36 {
37  float dist = sqrt((distv.x * distv.x) + (distv.y * distv.y)) * (40.0 / baseScale);
38  dist = clamp(dist, 0.0, 1.0);
39  return cos(dist * (3.14159265358 * 0.5)) * 0.5;
40 }
41 
42 float random_dots(float2 co)
43 {
44  float part = 1.0 / 20.0;
45  float2 cd = floor(co / part);
46  float p = rand(cd);
47 
48  if (p > 0.005 * (density * 40.0))
49  return 0.0;
50 
51  float2 dpos = (float2(frac(p * 2.0) , p) + float2(2.0, 2.0)) * 0.25;
52 
53  float2 cellpos = frac(co / part);
54  float2 distv = (cellpos - dpos);
55 
56  return dist_func(distv);
57 }
58 
59 float snow(float2 pos, float time, float scale)
60 {
61  // add wobble
62  pos.x += cos(pos.y * 1.2 + time * 3.14159 * 2.0 + 1.0 / scale) / (8.0 / scale) * 4.0;
63  // add gravity
64  pos += time * scale * float2(-0.5, 1.0) * 4.0;
65  return random_dots(pos / scale) * (scale * 0.5 + 0.5);
66 }
67 
68 
69 float4 PSMain(PSInput input) : SV_TARGET
70 {
71  float tim = global.time * 0.4 * speed;
72  float2 pos = input.position.xy / global.OutputSize.xx;
73  pos.y = 1.0 - pos.y; // Flip Y
74  float a = 0.0;
75  // Each of these is a layer of snow
76  // Remove some for better performance
77  // Changing the scale (3rd value) will mess with the looping
78  a += snow(pos, tim, 1.0);
79  a += snow(pos, tim, 0.7);
80  a += snow(pos, tim, 0.6);
81  a += snow(pos, tim, 0.5);
82  a += snow(pos, tim, 0.4);
83  a += snow(pos, tim, 0.3);
84  a += snow(pos, tim, 0.25);
85  a += snow(pos, tim, 0.125);
86  a = a * min(pos.y * 4.0, 1.0);
87  return float4(1.0, 1.0, 1.0, a);
88 };
89 )
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9939
#define floor(x)
Definition: math.h:25
GLenum GLenum GLenum input
Definition: glext.h:9938
#define sqrt(x)
Definition: math.h:26
#define SRC(...)
Definition: snow_sm4.hlsl.h:2
std::shared_ptr< Ope > dot()
Definition: peglib.h:1603
time_t time(time_t *timer)
GLuint64EXT * result
Definition: glext.h:12211
GLenum clamp
Definition: glext.h:6856
GLfloat GLfloat p
Definition: glext.h:9809
#define sin(x)
Definition: math.h:23
#define cos(x)
Definition: math.h:21
def cd(new_dir)
Definition: build.py:40
Definition: retroarch.h:240
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844