[1336] | 1 |
|
---|
| 2 | struct VS_OUT
|
---|
| 3 | {
|
---|
| 4 | float4 hPosition : POSITION;
|
---|
| 5 | float4 cPosition : TEXCOORD0;
|
---|
| 6 | float radius : TEXCOORD2;
|
---|
| 7 | float4 texCoord : TEXCOORD1;
|
---|
| 8 | };
|
---|
| 9 |
|
---|
| 10 | VS_OUT VP(float4 mPosition : POSITION,
|
---|
| 11 | uniform float4x4 worldView,
|
---|
| 12 | uniform float4x4 Proj,
|
---|
| 13 | uniform float4x4 worldViewProj
|
---|
| 14 | float2 texCoord :TEXCOORD0)
|
---|
| 15 | {
|
---|
| 16 | VS_OUT Out;
|
---|
| 17 | Out.texCoord.xy = texCoord;
|
---|
| 18 | Out.texCoord.zw = (texCoord * 2.0) - 1.0;
|
---|
| 19 |
|
---|
| 20 | float2 offset = texCoord.zw;
|
---|
| 21 | float4 cPosition = mul(worldView, mPosition);
|
---|
| 22 | cPosition.xy += offset;
|
---|
| 23 |
|
---|
| 24 | Out.hPosition = mul( Proj, cPosition );
|
---|
| 25 | Out.cPosition = cPosition;
|
---|
| 26 | Out.radius = abs(offset.x);
|
---|
| 27 |
|
---|
| 28 | return OUT;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | float4 FP(VS_OUT In,
|
---|
| 32 | uniform float4x4 Proj,
|
---|
| 33 | uniform sampler2D Texture):COLOR
|
---|
| 34 | {
|
---|
| 35 | float4 color = 1;
|
---|
| 36 | float front = 0;
|
---|
| 37 | float back = 1;
|
---|
| 38 |
|
---|
| 39 | float4 tex = tex2D(Texture, In.texCoord.xy);
|
---|
| 40 | float d = length(In.TexCoord.zw);
|
---|
| 41 | float w = sqrt(In.radius * In.radius - d * d);
|
---|
| 42 | if(d < r)
|
---|
| 43 | {
|
---|
| 44 | float4 positionF; float4 positionB;
|
---|
| 45 | positionF = positionB = In.cPosition;
|
---|
| 46 | positionF.z -= w;
|
---|
| 47 | positionB.z += w;
|
---|
| 48 | positionF = mul(Proj, positionF);
|
---|
| 49 | positionB = mul(Proj, positionB);
|
---|
| 50 | positionF = (positionF / positionF.w + 1.0) / 2.0;
|
---|
| 51 | positionB = (positionB / positionB.w + 1.0) / 2.0;
|
---|
| 52 | }
|
---|
| 53 | color.rgb = positionF.z;
|
---|
| 54 |
|
---|
| 55 | return color;
|
---|
| 56 | }
|
---|