1 | struct VS_OUT
|
---|
2 | {
|
---|
3 | float4 hPosition : POSITION;
|
---|
4 | float4 color : COLOR0;
|
---|
5 | };
|
---|
6 |
|
---|
7 | VS_OUT CauVS(float4 position : POSITION,
|
---|
8 | float4 texCoord : TEXCOORD0,
|
---|
9 | float4 color : COLOR0,
|
---|
10 | uniform float4x4 worldView,
|
---|
11 | uniform float4x4 Proj,
|
---|
12 | uniform float resolution,
|
---|
13 | uniform sampler2D PhotonHitMap : register(s0))
|
---|
14 | {
|
---|
15 | VS_OUT OUT;
|
---|
16 |
|
---|
17 | float4 cPosition;
|
---|
18 | float pixel = 1.0 / resolution;
|
---|
19 | float2 uv = float2(position.x, 1.0 - position.y);
|
---|
20 | float4 pos = tex2Dlod(PhotonHitMap, float4(uv,0,0)).rgba;
|
---|
21 |
|
---|
22 | if(pos.a == 0)//no photon hit
|
---|
23 | {
|
---|
24 | OUT.color = float4(0,0,0,0);
|
---|
25 | OUT.hPosition = float4(0, 0, 100000000, 1);
|
---|
26 | }
|
---|
27 | else
|
---|
28 | {
|
---|
29 | float4 wPosition = float4(normalize(pos.xyz),1);
|
---|
30 | cPosition = mul(worldView, wPosition);
|
---|
31 | OUT.hPosition = mul(Proj, cPosition);
|
---|
32 |
|
---|
33 | float intensity = 0.5;
|
---|
34 |
|
---|
35 | //read four neighbours
|
---|
36 | float valids = 0;
|
---|
37 | float sumdist = 0;
|
---|
38 | float dist;
|
---|
39 | float4 pos1 = tex2Dlod(PhotonHitMap, float4(uv + float2(pixel, pixel),0,0)).rgba;
|
---|
40 | if(pos1.a != 0)
|
---|
41 | {
|
---|
42 | dist = length(pos1.xyz - pos.xyz);
|
---|
43 | valids++;
|
---|
44 | sumdist += dist;
|
---|
45 | }
|
---|
46 | float4 pos2 = tex2Dlod(PhotonHitMap, float4(uv + float2(-pixel, pixel),0,0)).rgba;
|
---|
47 | if(pos2.a != 0)
|
---|
48 | {
|
---|
49 | dist = length(pos2.xyz - pos.xyz);
|
---|
50 | valids++;
|
---|
51 | sumdist += dist;
|
---|
52 | }
|
---|
53 | float4 pos3 = tex2Dlod(PhotonHitMap, float4(uv + float2(pixel, -pixel),0,0)).rgba;
|
---|
54 | if(pos3.a != 0)
|
---|
55 | {
|
---|
56 | dist = length(pos3.xyz - pos.xyz);
|
---|
57 | valids++;
|
---|
58 | sumdist += dist;
|
---|
59 | }
|
---|
60 | float4 pos4 = tex2Dlod(PhotonHitMap, float4(uv + float2(-pixel, -pixel),0,0)).rgba;
|
---|
61 | if(pos4.a != 0)
|
---|
62 | {
|
---|
63 | dist = length(pos4.xyz - pos.xyz);
|
---|
64 | valids++;
|
---|
65 | sumdist += dist;
|
---|
66 | }
|
---|
67 |
|
---|
68 | float avrdist = sumdist / valids;
|
---|
69 | float maxdist = 0.1;
|
---|
70 | intensity = max(maxdist - avrdist, 0.0) / maxdist;
|
---|
71 |
|
---|
72 | OUT.color = float4(1,1,1,intensity);
|
---|
73 | }
|
---|
74 |
|
---|
75 | return OUT;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | float4 CauPS(VS_OUT IN,
|
---|
80 | uniform float3 color ):COLOR
|
---|
81 | {
|
---|
82 | return IN.color * float4(color, 1);
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|