1 | float cutNearness2;// 100.0
|
---|
2 |
|
---|
3 | bool red;
|
---|
4 | float alphaCounterStep;
|
---|
5 |
|
---|
6 |
|
---|
7 | struct vsInputBushToAtlas
|
---|
8 | {
|
---|
9 | float4 pos : POSITION;
|
---|
10 | float2 tex : TEXCOORD0;
|
---|
11 | float2 texAtlas : TEXCOORD1;
|
---|
12 | float3 normal : NORMAL;
|
---|
13 | };
|
---|
14 |
|
---|
15 |
|
---|
16 | struct vsOutputBushToAtlas
|
---|
17 | {
|
---|
18 | float4 pos : POSITION;
|
---|
19 | float2 tex : TEXCOORD0;
|
---|
20 | float4 worldPos : TEXCOORD2;
|
---|
21 | float3 normal : TEXCOORD3;
|
---|
22 | float4 occProjPos : TEXCOORD4;
|
---|
23 | };
|
---|
24 |
|
---|
25 | vsOutputBushToAtlas
|
---|
26 | vsRenderBushToAtlas(vsInputBushToAtlas input)
|
---|
27 | {
|
---|
28 | vsOutputBushToAtlas output = (vsOutputBushToAtlas)0;
|
---|
29 |
|
---|
30 | output.pos.xy=float2(2,2)*input.texAtlas-float2(1, 1);
|
---|
31 | // output.pos.y=-1*output.pos.y; //Texture space to screen space.
|
---|
32 | output.pos.z=0;
|
---|
33 | output.pos.w=1;
|
---|
34 |
|
---|
35 | output.worldPos = mul(input.pos, modelToWorldMatrix);
|
---|
36 | output.normal = mul(inverseTransposedModelToWorldMatrix, float4(input.normal, 0));
|
---|
37 | output.occProjPos = mul(output.worldPos, occWorldToProjMatrix);
|
---|
38 | output.tex = input.tex;
|
---|
39 |
|
---|
40 | return output;
|
---|
41 | }
|
---|
42 |
|
---|
43 | float4
|
---|
44 | psRenderBushToAtlas(vsOutputBushToAtlas input) : COLOR0
|
---|
45 | {
|
---|
46 |
|
---|
47 | // return float4(0.1, 0.0, 0.0, alphaCounterStep);
|
---|
48 |
|
---|
49 | input.occProjPos /= input.occProjPos.w;
|
---|
50 | float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix);
|
---|
51 |
|
---|
52 | input.normal = normalize(input.normal);
|
---|
53 | float3 diff = lightPos - input.worldPos.xyz;
|
---|
54 | float4 retVal = float4(0, 0, 0, 1);
|
---|
55 | float3 diffDir = normalize(diff);
|
---|
56 | float cosa = dot(diffDir, input.normal);
|
---|
57 | float cosb = -dot(diffDir, normalize(lightDir));
|
---|
58 | float dist2 = dot(diff, diff);
|
---|
59 |
|
---|
60 | float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, input.occProjPos.z, 1) );
|
---|
61 | float formFactor;
|
---|
62 | if( cosa > 0.0)
|
---|
63 | {
|
---|
64 | if( cosb < 0.01 && cosb > -0.1)
|
---|
65 | cosb = 0.01;
|
---|
66 | float nearness = cosb * cosb * dist2;
|
---|
67 | if( nearness < cutNearness2)
|
---|
68 | {
|
---|
69 | float e2 = dist2 * (1.0 - cosb * cosb);
|
---|
70 | float dist2dash = e2 + cutNearness2;
|
---|
71 | formFactor = cosa * sqrt(cutNearness2 / dist2dash ) / dist2dash;
|
---|
72 | }
|
---|
73 | else
|
---|
74 | formFactor = cosa * cosb / dist2;
|
---|
75 |
|
---|
76 | if( cosb > 0.0)
|
---|
77 | {
|
---|
78 | retVal = float4(lightPower * formFactor * visibility , 1);
|
---|
79 | }
|
---|
80 | }
|
---|
81 | retVal.a = alphaCounterStep;
|
---|
82 | return retVal;// + float4(0.3, 0, 0, 1);
|
---|
83 |
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | technique BushToAtlas{
|
---|
88 | pass P0
|
---|
89 | {
|
---|
90 | VertexShader = compile vs_3_0 vsRenderBushToAtlas();
|
---|
91 | PixelShader = compile ps_3_0 psRenderBushToAtlas();
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|