ProjectArcade
36 строк · 1.3 Кб
1// Simple fake reflection shader; created to use in PPSSPP.
2// Without excessive samples and complex nested loops
3// (to make it compatible with low-end GPUs and to ensure ps_2_0 compatibility).
4
5#ifdef GL_ES
6precision mediump float;
7precision mediump int;
8#endif
9
10uniform sampler2D sampler0;
11varying vec2 v_texcoord0;
12
13uniform vec4 u_setting;
14
15void main()
16{
17//get the pixel color
18vec3 color = texture2D(sampler0, v_texcoord0.xy).rgb;
19float gray = (color.r + color.g + color.b) / 3.0;
20float saturation = (abs(color.r - gray) + abs(color.g - gray) + abs(color.b - gray)) / 3.0;
21
22//persistent random offset to hide that the reflection is wrong
23float rndx = mod(v_texcoord0.x + gray, 0.03) + mod(v_texcoord0.y + saturation, 0.05);
24float rndy = mod(v_texcoord0.y + saturation, 0.03) + mod(v_texcoord0.x + gray, 0.05);
25
26//show the effect mainly on the bottom part of the screen
27float step = (max(gray, saturation) + 0.1) * v_texcoord0.y;
28
29//the fake reflection is just a watered copy of the frame moved slightly lower
30vec3 reflection = texture2D(sampler0, v_texcoord0 + vec2(rndx, rndy - min(v_texcoord0.y, 0.25)) * step).rgb;
31
32//apply parameters and mix the colors
33reflection *= 4.0 * (1.0 - gray) * u_setting.x;
34reflection *= reflection * step * u_setting.y;
35gl_FragColor = vec4(color + reflection, 1.0);
36}
37