forked from libretro/common-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quilez.cg
63 lines (50 loc) · 1.23 KB
/
quilez.cg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* COMPATIBILITY
- HLSL compilers
- Cg compilers
*/
/*
Fragment shader based on "Improved texture interpolation" by Iñigo Quílez
Original description: http://www.iquilezles.org/www/articles/texture/texture.htm
*/
void main_vertex
(
float4 position : POSITION,
float4 color : COLOR,
float2 texCoord : TEXCOORD0,
uniform float4x4 modelViewProj,
out float4 oPosition : POSITION,
out float4 oColor : COLOR,
out float2 otexCoord : TEXCOORD
)
{
oPosition = mul(modelViewProj, position);
oColor = color;
otexCoord = texCoord;
}
struct output
{
float4 color : COLOR;
};
struct input
{
float2 video_size;
float2 texture_size;
float2 output_size;
float frame_count;
float frame_direction;
float frame_rotation;
};
output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2D s_p : TEXUNIT0)
{
float2 p = tex.xy;
p = p * IN.texture_size + float2(0.5, 0.5);
float2 i = floor(p);
float2 f = p - i;
f = f * f * f * (f * (f * 6.0 - float2(15.0, 15.0)) + float2(10.0, 10.0));
p = i + f;
p = (p - float2(0.5, 0.5)) / IN.texture_size;
// final sum and weight normalization
output OUT;
OUT.color = tex2D(s_p, p);
return OUT;
}