source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/Standalone/Hierarchical Systems Demo [OpenGL]/src/Másolat - DepthPrograms.cg @ 3255

Revision 3255, 3.8 KB checked in by szirmay, 15 years ago (diff)
Line 
1struct VertexOut
2{
3        float4 VertexPosition           :POSITION;
4        float2 TexCoord                         :TEXCOORD;
5        float4 Position                         :TEXCOORD1;
6        float4 EyePosition                      :TEXCOORD2;
7        float2 BbSizeAngleCos           :TEXCOORD3;
8        float4 LightSpacePos            :TEXCOORD4;     
9};
10
11
12//
13//  Vertex program for displaying particle system with rectangle rendertexture
14//
15VertexOut VertexProgram( float4 Position :POSITION,
16                                                float4 Texcoord: TEXCOORD,
17                                                uniform float4x4 LightModelViewProj,
18                                                uniform float3 LightPosition,
19                                                uniform float3 EyePosition,
20                                                uniform float4x4 ModelViewProj  :state.matrix.mvp,
21                                                uniform float4x4 ModelViewMatrix:state.matrix.modelview
22                                                )                                                                       
23{
24        VertexOut Out; 
25       
26        float3 LightToPoint=normalize(Position.xyz-LightPosition);
27        float3 PointToEye=normalize(EyePosition-Position.xyz);
28               
29        Out.BbSizeAngleCos.y=dot(LightToPoint,PointToEye);     
30       
31        Out.LightSpacePos=mul(LightModelViewProj, Position);
32        Out.LightSpacePos.xyz=Out.LightSpacePos.xyz/Out.LightSpacePos.w;
33        Out.LightSpacePos.xyz=(Out.LightSpacePos.xyz+1)/2;
34       
35        Out.VertexPosition=mul(ModelViewProj, Position);
36        Out.TexCoord=Texcoord.xy;
37       
38        Out.Position=Out.VertexPosition;
39        Out.BbSizeAngleCos.x=Texcoord.z;
40       
41        Out.EyePosition=mul(ModelViewMatrix, Position);
42       
43        Out.Position.xyz=(Out.Position.xyz/Out.Position.w+1)/2;
44       
45        return Out;     
46}
47
48//
49//  Fragment program for displaying particle system with rectangle rendertexture
50//
51void FragmentProgram(   VertexOut       In,
52                                                uniform samplerRECT Texture,
53                                                uniform samplerRECT FrontTexture,
54                                                uniform samplerRECT BackTexture,
55                                                uniform samplerRECT ObjTexture,
56                                                uniform samplerRECT Illum1,
57                                                uniform samplerRECT Illum2,
58                                                uniform samplerRECT Illum3,
59                                                uniform samplerRECT Illum4,
60                                                uniform float Transparency,
61                                                uniform float Symmetry,
62                                                uniform float Albedo,                                           
63                                                uniform float4x4 LightModelViewProjInv,
64                                                uniform float4x4 ProjMatrixInv:state.matrix.projection.inverse,
65                                                uniform float4x4 ProjMatrix:state.matrix.projection,
66                                                float4 out Color:COLOR
67                                                ,float out Depth:DEPTH
68                                                )
69{
70        Color=float4(1,1,1,1); 
71        /*
72        float2 illumUV=In.LightSpacePos.xy;     
73        float z=In.LightSpacePos.z;
74       
75        float3 start;
76        float3 end;
77        float3 temp;   
78       
79        float g2=pow(Symmetry,2);
80        float phase=3*(1-g2)*(1+pow(In.BbSizeAngleCos.y,2))/2/(2+g2)/pow((1+g2+2*Symmetry*In.BbSizeAngleCos.y),1.5);
81        float reflect=phase*Albedo*(1-Transparency);
82        */
83        float objdepth=texRECT(ObjTexture,In.Position.xy*512).r;
84        float backdepth=texRECT(BackTexture,In.TexCoord*512).r;
85        float frontdepth=texRECT(FrontTexture,In.TexCoord*512).r;
86               
87        if(frontdepth==1)
88        {
89                Color.a=0;
90                Depth=1;
91        }
92        else
93        {
94               
95                float4 frontpos=In.EyePosition+float4(0,0,In.BbSizeAngleCos.x*(0.5-frontdepth),0);
96                float frontdepth2=frontpos.z;
97                frontpos=mul(ProjMatrix,frontpos);
98                frontpos.z=(frontpos.z/frontpos.w+1)/2;
99                Depth=frontpos.z;
100                       
101                float4 backpos=In.EyePosition+float4(0,0,In.BbSizeAngleCos.x*(0.5-backdepth),0);
102                float backdepth2=backpos.z;
103                                       
104                float d=backdepth2-frontdepth2;                 
105                float o=objdepth-frontdepth2;
106       
107                Color.a=backdepth-frontdepth;   
108                Color.a*=saturate(o/d);
109               
110                /*     
111                        if(z<0.25)
112                        {
113                                start=float3(1,1,1);
114                                end=texRECT(Illum1,illumUV*256).xyz;
115                                temp=lerp(start,end,z*4);       
116                        }                       
117                        if(z<0.5&&z>=0.25)
118                        {
119                                start=texRECT(Illum1,illumUV*256).xyz;
120                                end=texRECT(Illum2,illumUV*256).xyz;
121                                temp=lerp(start,end,(z-0.25)*4);                       
122                        }       
123                        if(z>=0.5&&z<0.75)
124                        {
125                                start=texRECT(Illum2,illumUV*256).xyz;
126                                end=texRECT(Illum3,illumUV*256).xyz;
127                                temp=lerp(start,end,(z-0.5)*4);                                 
128                        }
129                        if(z>=0.75)
130                        {       
131                                start=texRECT(Illum3,illumUV*256).xyz;
132                                end=texRECT(Illum4,illumUV*256).xyz;
133                                temp=lerp(start,end,(z-0.75)*4);                               
134                        }*/                             
135        }
136        //Color*=float4(temp,reflect*texRECT(Texture,In.TexCoord*256).r);
137        //Color*=float4(temp,reflect);
138       
139}
140
Note: See TracBrowser for help on using the repository browser.