-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathlens_flare.sha
54 lines (48 loc) · 2.23 KB
/
lens_flare.sha
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
//Cg
// Second part of lens flare postprocess filter from this article http://www.john-chapman.net/content.php?id=18
// Panda3d interpretation by 09th ([email protected])
void vshader(
float4 vtx_position : POSITION,
float2 vtx_texcoord0 : TEXCOORD0,
out float4 l_position : POSITION,
out float2 l_texcoord0 : TEXCOORD0,
out float2 l_texcoord1 : TEXCOORD1,
uniform float4 texpad_tex1,
uniform float4x4 mat_modelproj)
{
l_position=mul(mat_modelproj, vtx_position);
l_texcoord0 = vtx_position.xz * texpad_tex1.xy + texpad_tex1.xy;
//l_texcoord0 = vtx_position.xz + float2(0.4, 0.3);// * texpad_tex.xy + texpad_tex.xy;
l_texcoord1 = 1.0 - (vtx_position.xz * texpad_tex1.xy - texpad_tex1.xy);
}
void fshader(float2 l_texcoord0 : TEXCOORD0,
float2 l_texcoord1 : TEXCOORD1,
out float4 o_color : COLOR,
uniform float4 texpad_tex1,
uniform sampler2D k_tex1 : TEXUNIT0,
uniform sampler2D k_tex2 : TEXUNIT1,
uniform sampler2D k_tex3 : TEXUNIT2)
{
int NSAMPLES = 5;
float FLARE_HALO_WIDTH = 0.2;
float FLARE_DISPERSAL = 0.3;
float3 CHROMA_DISTORT = float3(0.004, -0.004, 0.0);
float4 c = tex2D(k_tex1, l_texcoord0);
float2 sample_vector = (texpad_tex1.xy - l_texcoord0) * FLARE_DISPERSAL;
float2 halo_vector = normalize(sample_vector) * FLARE_HALO_WIDTH;
float3 tmp = float3(0.0);
float3 result = 0.0;
result.x = tex2D(k_tex3, l_texcoord0 + halo_vector + halo_vector * CHROMA_DISTORT.x).x;
result.y = tex2D(k_tex3, l_texcoord0 + halo_vector + halo_vector * CHROMA_DISTORT.y).y;
result.z = tex2D(k_tex3, l_texcoord0 + halo_vector + halo_vector * CHROMA_DISTORT.z).z;
for (int i = 0; i < NSAMPLES; ++i) {
float2 offset = sample_vector * float(i);
tmp.x = tex2D(k_tex3, l_texcoord0 + offset + offset * CHROMA_DISTORT.x).x;
tmp.y = tex2D(k_tex3, l_texcoord0 + offset + offset * CHROMA_DISTORT.y).y;
tmp.z = tex2D(k_tex3, l_texcoord0 + offset + offset * CHROMA_DISTORT.z).z;
result += tmp;
}
result /= float(NSAMPLES);
o_color = (float4(result.x + c.x, result.y + c.y, result.z + c.z, 1.0));// +
//tex2D(k_tex3, l_texcoord0));
}