source: GTP/trunk/App/Demos/Illum/Illumination Networks Demo [OpenGL]/src/Interpol_FinalDisplay.cg @ 845

Revision 845, 1.7 KB checked in by szirmay, 18 years ago (diff)
Line 
1struct VertexOut
2{
3        float4 Position                         :POSITION;
4        float2 TexCoord                         :TEXCOORD;
5        float2 PolarCoord                       :TEXCOORD1;
6        float ID                                        :TEXCOORD2;
7        float PSize                                     :PSIZE;
8};
9
10
11VertexOut VertexProgram(
12                  float4 Position   : POSITION,
13          float ID : TEXCOORD0,
14          float4 Color : COLOR0,         
15          uniform float4 PSize : state.point.size,
16          uniform float4x4 modelView : state.matrix.modelview,
17          uniform float4x4 modelViewProj:state.matrix.mvp,
18                uniform float3 EyePosition
19          )
20{
21        VertexOut Out;
22        Out.ID=ID*512;
23         
24   float4 pos_eye = mul(modelView, Position);
25    float dist = length(pos_eye.xyz);
26    Out.PSize =PSize.x*sqrt(1.0 / (1 + dist*dist));
27               
28        Out.Position = mul(modelViewProj, Position);
29   
30    float3 toLight=-1*pos_eye.xyz;
31    //polar coord
32    float3 dir0=normalize(toLight);
33       
34        float2 angles;
35        angles.y=asin(dir0.y); // -pi/2 -- pi/2
36               
37        float2 d=normalize(dir0.xz);
38        angles.x=acos(d.x)*sign(d.y); // -pi -- pi
39        angles.x=angles.x/6.28+0.5; // 0 -- 1
40        angles.y=angles.y/3.14+0.5; // 0 -- 1
41       
42        Out.PolarCoord=angles;
43       
44    return Out;
45}
46
47float4 FragmentProgram(VertexOut In,
48                                        uniform sampler2D BbTexture,
49                                        uniform sampler2D DirMap,                                               
50                                        uniform samplerRECT IllumTexture ) : COLOR
51{
52        float4 Color=float4(0,0,0,0);
53                       
54        float nearestdir=tex2D(DirMap,In.PolarCoord).r;
55        float nearestdir2=tex2D(DirMap,In.PolarCoord).g;
56        float weight1=tex2D(DirMap,In.PolarCoord).b;
57        float weight2=tex2D(DirMap,In.PolarCoord).a;
58       
59       
60        Color.rgb=texRECT(IllumTexture,float2(In.ID,nearestdir*64))*weight1;
61        Color.rgb+=texRECT(IllumTexture,float2(In.ID,nearestdir2*64))*weight2;
62       
63        Color.a=tex2D(BbTexture, In.TexCoord.xy).r*0.6;
64    return  Color;
65}
Note: See TracBrowser for help on using the repository browser.