source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/Standalone/Hierarchical Systems Demo [OpenGL]/src/Psystem_Multiply_Forward.cg @ 3255

Revision 3255, 2.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                                                )                                                                       
24{
25        VertexOut Out; 
26                       
27        Out.Color=Color;
28       
29        Out.VertexPosition=mul(ModelViewProj, Position);
30        Out.TexCoord=Texcoord.xy;
31       
32        Out.LightSpacePos=mul(LightModelViewProj, Position);
33        Out.LightSpacePos.xyz=Out.LightSpacePos.xyz/Out.LightSpacePos.w;
34        Out.LightSpacePos.xyz=(Out.LightSpacePos.xyz+1.0)/2.0;
35               
36        float3 LightToPoint=normalize(Position.xyz-LightPosition);
37        float3 PointToEye=normalize(EyePosition-Position.xyz);
38        Out.BbSizeAngleCos.y=(dot(LightToPoint,PointToEye)+1.0)/2.0;
39       
40        return Out;     
41}
42
43//
44//  Fragment program for displaying particle system with rectangle rendertexture
45//
46void FragmentProgram(   VertexOut       In,
47                                                uniform samplerRECT FrontTexture,
48                                                uniform samplerRECT Illum1,
49                                                uniform samplerRECT PhaseTexture,
50                                                uniform float Albedo,
51                                                uniform float Transparency,
52                                                uniform float Symmetry,
53                                                uniform float3 LightColor,
54                                                float4 out Color:COLOR                                         
55                                        )
56{       
57        float2 illumUV=In.LightSpacePos.xy*256;
58        float z=In.LightSpacePos.z;
59       
60        float3 start;
61        float3 end;
62        float3 temp;   
63                       
64        float density=texRECT(FrontTexture,In.TexCoord*256).a;//density
65       
66        float4 planes=float4(0.33,0.5,0.66,1);         
67        float t;
68        if(z<planes.x)
69        {                               
70                start=float3(1,1,1);
71                end=texRECT(Illum1,illumUV).r;
72                t=z/planes.x;
73                temp=lerp(start,end,t);
74        }                       
75        if(z<planes.y&&z>=planes.x)
76        {                               
77                start=texRECT(Illum1,illumUV).r;
78                end=texRECT(Illum1,illumUV).g;
79                t=(z-planes.x)/(planes.y-planes.x);
80                temp=lerp(start,end,t);                 
81        }       
82                if(z>=planes.y&&z<planes.z)
83        {                               
84                start=texRECT(Illum1,illumUV).g;
85                end=texRECT(Illum1,illumUV).b;
86                t=(z-planes.y)/(planes.z-planes.y);
87                temp=lerp(start,end,t);                                 
88        }
89        if(z>=planes.z)
90        {                                       
91                start=texRECT(Illum1,illumUV).b;
92                end=texRECT(Illum1,illumUV).a;
93                t=(z-planes.z)/(1-planes.z);
94                temp=lerp(start,end,t);                         
95        }                       
96                float phase=texRECT(PhaseTexture,float2(Symmetry,In.BbSizeAngleCos.y)*256);
97                float realdens=density*Transparency;
98               
99                float scatter=realdens*Albedo;
100                float outcol=temp*phase*scatter;
101               
102                float scateeredforward=scatter*texRECT(PhaseTexture,float2(Symmetry,1)*256);                           
103                Color=float4(LightColor*outcol*In.Color.rgb,1-realdens+scateeredforward/6.28);
104                       
105}
106
Note: See TracBrowser for help on using the repository browser.