source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/Standalone/Hierarchical Systems Demo [OpenGL]/src/Psystem_Multiply_Forward_Depth.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        float4 Color                            :COLOR0;
10};
11
12
13//
14//  Vertex program for displaying particle system with rectangle rendertexture
15//
16VertexOut VertexProgram( float4 Position :POSITION,
17                                                float4 Texcoord: TEXCOORD,
18                                                float4 Color:COLOR0,
19                                                uniform float4x4 LightModelViewProj,
20                                                uniform float3 LightPosition,
21                                                uniform float3 EyePosition,
22                                                uniform float4x4 ModelViewProj  :state.matrix.mvp,
23                                                uniform float4x4 ModelViewMatrix:state.matrix.modelview
24                                                )                                                                       
25{
26        VertexOut Out; 
27                       
28        Out.Color=Color;
29       
30        Out.VertexPosition=mul(ModelViewProj, Position);
31        Out.TexCoord=Texcoord.xy;
32       
33        Out.LightSpacePos=mul(LightModelViewProj, Position);
34        Out.LightSpacePos.xyz=Out.LightSpacePos.xyz/Out.LightSpacePos.w;
35        Out.LightSpacePos.xyz=(Out.LightSpacePos.xyz+1)/2;
36       
37        Out.Position=Out.VertexPosition;
38        Out.BbSizeAngleCos.x=Texcoord.z;
39       
40        float3 LightToPoint=normalize(Position.xyz-LightPosition);
41        float3 PointToEye=normalize(EyePosition-Position.xyz);
42        Out.BbSizeAngleCos.y=(dot(LightToPoint,PointToEye)+1.0)/2.0;
43       
44        Out.EyePosition=mul(ModelViewMatrix, Position);
45       
46        Out.Position.xyz=(Out.Position.xyz/Out.Position.w+1)/2;
47       
48        return Out;     
49}
50
51//
52//  Fragment program for displaying particle system with rectangle rendertexture
53//
54void FragmentProgram(   VertexOut       In,
55                                                uniform samplerRECT FrontTexture,
56                                                uniform samplerRECT ObjTexture,
57                                                uniform samplerRECT Illum1,
58                                                uniform samplerRECT PhaseTexture,
59                                                uniform float Albedo,
60                                                uniform float Transparency,
61                                                uniform float Symmetry,
62                                                uniform float3 LightColor,
63                                                float4 out Color:COLOR                                         
64                                        )
65{       
66        float2 illumUV=In.LightSpacePos.xy;     
67        illumUV*=256;
68        In.TexCoord*=256;
69        float z=In.LightSpacePos.z;
70       
71        float3 start;
72        float3 end;
73        float3 temp;   
74       
75        float objdepth=texRECT(ObjTexture,In.Position.xy*512).r;
76       
77        float depth=texRECT(FrontTexture,In.TexCoord).r;
78        float density=1;               
79       
80        if(depth.x==1)
81        {
82                Color=float4(0,0,0,1); 
83        }
84        else
85        {                                       
86                float size=0.5*In.BbSizeAngleCos.x;
87                float frontdepth=-In.EyePosition.z-size+texRECT(FrontTexture,In.TexCoord).r*size;
88                float backdepth=-In.EyePosition.z-size+(1-texRECT(FrontTexture,In.TexCoord).g)*size;
89               
90                float d=backdepth-frontdepth;
91                float o=-objdepth-frontdepth;
92                               
93                density*=texRECT(FrontTexture,In.TexCoord).a;//density 
94                density*=saturate(o/d);
95               
96                float4 planes=float4(0.33,0.5,0.66,1);         
97                float t;
98                        if(z<planes.x)
99                        {
100                                start=float3(1,1,1);
101                                end=texRECT(Illum1,illumUV).r;
102                                t=z/planes.x;
103                                temp=lerp(start,end,t);
104                                //temp=float3(1,0,0);
105                        }                       
106                        if(z<planes.y&&z>=planes.x)
107                        {
108                                start=texRECT(Illum1,illumUV).r;
109                                end=texRECT(Illum1,illumUV).g;
110                                t=(z-planes.x)/(planes.y-planes.x);
111                                temp=lerp(start,end,t);
112                                //temp=float3(1,1,0);                   
113                        }       
114                        if(z>=planes.y&&z<planes.z)
115                        {
116                                start=texRECT(Illum1,illumUV).g;
117                                end=texRECT(Illum1,illumUV).b;
118                                t=(z-planes.y)/(planes.z-planes.y);
119                                temp=lerp(start,end,t);         
120                                //temp=float3(0,1,0);                   
121                        }
122                        if(z>=planes.z)
123                        {       
124                                start=texRECT(Illum1,illumUV).b;
125                                end=texRECT(Illum1,illumUV).a;
126                                t=(z-planes.z)/(1-planes.z);
127                                temp=lerp(start,end,t);
128                                //temp=float3(0,1,1);                   
129                        }
130                                               
131                        float phase=texRECT(PhaseTexture,float2(Symmetry,In.BbSizeAngleCos.y)*256);
132                        float realdens=density*Transparency;
133                        float scatter=realdens*Albedo;
134                        float outcol=temp*phase*scatter;
135                        //float3 outcol=temp;//*phase*scatter;
136               
137                        float scateeredforward=scatter*texRECT(PhaseTexture,float2(Symmetry,1)*256);
138                       
139                        Color+=float4((LightColor)*outcol*In.Color.rgb,1-realdens);
140        }
141               
142}
143
Note: See TracBrowser for help on using the repository browser.