Advertisement
adsadadss

Untitled

Aug 21st, 2022
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None
  1. init python:
  2.  
  3. renpy.register_shader("shadertoy.rainonwindow", variables="""
  4. uniform float u_time;
  5. uniform vec2 u_model_size;
  6. uniform float u_rain_amount;
  7. uniform sampler2D tex0;
  8. """,
  9. fragment_functions="""
  10. vec3 N13(float p)
  11. {
  12. vec3 p3 = fract(vec3(p) * vec3(.1031,.11369,.13787));
  13. p3 += dot(p3, p3.yzx + 19.19);
  14. return fract(vec3((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y, (p3.y+p3.z)*p3.x));
  15. }
  16. vec4 N14(float t)
  17. {
  18. return fract(sin(t*vec4(123., 1024., 1456., 264.))*vec4(6547., 345., 8799., 1564.));
  19. }
  20.  
  21. float N(float t)
  22. {
  23. return fract(sin(t*12345.564)*7658.76);
  24. }
  25.  
  26. float Saw(float b, float t)
  27. {
  28. return smoothstep(0., b, t) * smoothstep(1., b, t);
  29. }
  30.  
  31. vec2 DropLayer2(vec2 uv, float t)
  32. {
  33. vec2 UV = uv;
  34.  
  35. uv.y += t*0.75;
  36. vec2 a = vec2(6., 1.);
  37. vec2 grid = a*2.;
  38. vec2 id = floor(uv*grid);
  39.  
  40. float colShift = N(id.x);
  41. uv.y += colShift;
  42.  
  43. id = floor(uv*grid);
  44. vec3 n = N13(id.x*35.2+id.y*2376.1);
  45. vec2 st = fract(uv*grid)-vec2(.5, 0);
  46.  
  47. float x = n.x-.5;
  48.  
  49. float y = UV.y*20.;
  50. float wiggle = sin(y+sin(y));
  51. x += wiggle*(.5-abs(x))*(n.z-.5);
  52. x *= .7;
  53. float ti = fract(t+n.z);
  54. y = (Saw(.85, ti)-.5)*.9+.5;
  55. vec2 p = vec2(x, y);
  56.  
  57. float d = length((st-p)*a.yx);
  58.  
  59. float mainDrop = smoothstep(.4, .0, d);
  60.  
  61. float r = sqrt(smoothstep(1., y, st.y));
  62. float cd = abs(st.x-x);
  63. float trail = smoothstep(.23*r, .15*r*r, cd);
  64. float trailFront = smoothstep(-.02, .02, st.y-y);
  65. trail *= trailFront*r*r;
  66.  
  67. y = UV.y;
  68. float trail2 = smoothstep(.2*r, .0, cd);
  69. float droplets = max(0., (sin(y*(1.-y)*120.)-st.y))*trail2*trailFront*n.z;
  70. y = fract(y*10.)+(st.y-.5);
  71. float dd = length(st-vec2(x, y));
  72. droplets = smoothstep(.3, 0., dd);
  73. float m = mainDrop+droplets*r*trailFront;
  74.  
  75. return vec2(m, trail);
  76. }
  77.  
  78. float StaticDrops(vec2 uv, float t)
  79. {
  80. uv *= 40.;
  81.  
  82. vec2 id = floor(uv);
  83. uv = fract(uv)-.5;
  84. vec3 n = N13(id.x*107.45+id.y*3543.654);
  85. vec2 p = (n.xy-.5)*.7;
  86. float d = length(uv-p);
  87.  
  88. float fade = Saw(.025, fract(t+n.z));
  89. float c = smoothstep(.3, 0., d)*fract(n.z*10.)*fade;
  90. return c;
  91. }
  92.  
  93. vec2 Drops(vec2 uv, float t, float l0, float l1, float l2)
  94. {
  95. float s = StaticDrops(uv, t)*l0;
  96. vec2 m1 = DropLayer2(uv, t)*l1;
  97. vec2 m2 = DropLayer2(uv*1.85, t)*l2;
  98.  
  99. float c = s+m1.x+m2.x;
  100. c = smoothstep(.3, 1., c);
  101.  
  102. return vec2(c, max(m1.y*l0, m2.y*l1));
  103. }
  104. """,
  105. vertex_300="""
  106. v_tex_coord = a_tex_coord;
  107. """,
  108.  
  109. fragment_300="""
  110. vec2 uv = (gl_FragCoord.xy - u_model_size.xy*.5) / u_model_size.y;
  111. vec2 UV = gl_FragCoord.xy/u_model_size.xy;
  112. float T = u_time + 2.;
  113.  
  114. float t = T*.2;
  115.  
  116. float rainAmount = u_rain_amount;
  117.  
  118. float maxBlur = mix(3., 6., rainAmount);
  119. float minBlur = 2.;
  120.  
  121. float story = 0.;
  122. float heart = 0.;
  123.  
  124.  
  125. float zoom = 1.0;
  126. uv *= .7+zoom*.3;
  127.  
  128. UV = (UV-.5)*(.9+zoom*.1)+.5;
  129.  
  130. float staticDrops = smoothstep(-.5, 1., rainAmount)*2.;
  131. float layer1 = smoothstep(.25, .75, rainAmount);
  132. float layer2 = smoothstep(.0, .5, rainAmount);
  133.  
  134.  
  135. vec2 c = Drops(uv, t, staticDrops, layer1, layer2);
  136.  
  137. vec2 e = vec2(.001, 0.);
  138. float cx = Drops(uv+e, t, staticDrops, layer1, layer2).x;
  139. float cy = Drops(uv+e.yx, t, staticDrops, layer1, layer2).x;
  140. vec2 n = vec2(cx-c.x, cy-c.x);
  141.  
  142.  
  143. float focus = mix(maxBlur-c.y, minBlur, smoothstep(.1, .2, c.x));
  144. vec3 col = texture2DLod(tex0, UV+n, focus).rgb;
  145.  
  146. gl_FragColor = vec4(col, 1.);
  147. """)
  148.  
  149. init python:
  150.  
  151. class RainOnWindow(renpy.Displayable):
  152.  
  153. def __init__(self, child, width, height, rainamount=1.0, **kwargs):
  154. super(RainOnWindow, self).__init__(**kwargs)
  155.  
  156. self.child = renpy.displayable(child)
  157. self.width = width
  158. self.height = height
  159. self.rainamount = rainamount;
  160.  
  161. def render(self, width, height, st, at):
  162. render = renpy.Render(self.width, self.height)
  163. render.place(self.child)
  164. render.add_shader("shadertoy.rainonwindow")
  165. render.add_uniform("u_time", st)
  166. render.add_uniform("u_model_size", (self.width, self.height))
  167. render.add_uniform("u_rain_amount", self.rainamount)
  168. renpy.redraw(self, 0)
  169. return render
  170.  
  171. image rainonwindow = RainOnWindow("bgafterwindow", width = 1280, height = 720, rainamount = 1.0)
  172.  
  173. label main_menu:
  174. return
  175.  
  176.  
  177. label start:
  178.  
  179. show rainonwindow
  180.  
  181. pause
Advertisement
RAW Paste Data Copied
Advertisement