[2197] | 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 | input.occProjPos /= input.occProjPos.w;
|
---|
| 48 | float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix);
|
---|
| 49 |
|
---|
| 50 | input.normal = normalize(input.normal);
|
---|
| 51 | float3 diff = lightPos - input.worldPos.xyz;
|
---|
| 52 | float4 retVal = float4(0, 0, 0, 1);
|
---|
| 53 | float3 diffDir = normalize(diff);
|
---|
| 54 | float cosa = dot(diffDir, input.normal);
|
---|
| 55 | float cosb = -dot(diffDir, normalize(lightDir));
|
---|
| 56 | float dist2 = dot(diff, diff);
|
---|
| 57 |
|
---|
| 58 | float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, input.occProjPos.z, 1) );
|
---|
| 59 | float formFactor;
|
---|
| 60 | if( cosa > 0.0)
|
---|
| 61 | {
|
---|
| 62 | if( cosb < 0.01 && cosb > -0.1)
|
---|
| 63 | cosb = 0.01;
|
---|
| 64 | float nearness = cosb * cosb * dist2;
|
---|
| 65 | if( nearness < cutNearness2)
|
---|
| 66 | {
|
---|
| 67 | float e2 = dist2 * (1.0 - cosb * cosb);
|
---|
| 68 | float dist2dash = e2 + cutNearness2;
|
---|
| 69 | formFactor = cosa * sqrt(cutNearness2 / dist2dash ) / dist2dash;
|
---|
| 70 | }
|
---|
| 71 | else
|
---|
| 72 | formFactor = cosa * cosb / dist2;
|
---|
| 73 |
|
---|
| 74 | if( cosb > 0.0)
|
---|
| 75 | {
|
---|
| 76 | retVal = float4(lightPower * formFactor * visibility , 1);
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | retVal.a = alphaCounterStep;
|
---|
| 80 | return retVal;// + float4(0.3, 0, 0, 1);
|
---|
| 81 |
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 | technique BushToAtlas{
|
---|
| 86 | pass P0
|
---|
| 87 | {
|
---|
| 88 | VertexShader = compile vs_3_0 vsRenderBushToAtlas();
|
---|
| 89 | PixelShader = compile ps_3_0 psRenderBushToAtlas();
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|