source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/OgreGames/CarGame/Media/materials/programs/GameTools_Sprite.hlsl @ 3255

Revision 3255, 3.2 KB checked in by szirmay, 15 years ago (diff)
Line 
1struct VS_OUT
2{
3        float4 hPosition        : POSITION;
4        float4 texCoord         : TEXCOORD0;
5        float4 color            : COLOR0;
6};
7
8VS_OUT SpriteVS(float4 position : POSITION,     
9                float4 texCoord : TEXCOORD0,
10                float4 color    : COLOR0,
11                uniform float4x4 worldView,
12                uniform float4x4 Proj,
13                uniform float4x4 worldViewProj)
14{
15  VS_OUT OUT;
16
17   //texCoord.y = 1.0 - texCoord.y;
18   float2 offset = texCoord.zw;
19   float4 cPosition = mul(worldView, position);
20   cPosition.xy += offset;
21   
22        OUT.hPosition = mul( Proj, cPosition );
23   OUT.texCoord = texCoord;
24   OUT.color = float4(offset,1,1.0);
25
26
27  return OUT;
28}
29
30
31float4 SpritePS(VS_OUT IN ,
32                uniform sampler2D colorTexture : register(s0)):COLOR
33{
34
35        return tex2D( colorTexture, IN.texCoord.xy) * IN.color;
36}
37
38
39
40
41
42
43//////////-----------------------------------------
44
45
46float farplane = 1000.0; //far plane
47float nearplane = 0.1; //far plane
48float width = 800;
49float height = 600;
50
51struct SBB_VS_OUT
52{
53        float4 hPosition        : POSITION;
54        float4 texCoord         : TEXCOORD0;
55        float3 P                : TEXCOORD1;
56        float3 Q                : TEXCOORD2;
57        float r                 : TEXCOORD3;
58        float2 screenCoord      : TEXCOORD4;   
59        float4 color            : COLOR0;
60};
61
62SBB_VS_OUT SBB_SpriteVS (float4 position : POSITION,   
63                float4 texCoord : TEXCOORD0,
64                float4 color    : COLOR,
65                uniform float4x4 worldView,
66                uniform float4x4 Proj,
67                uniform float4x4 worldViewProj)
68{
69        SBB_VS_OUT OUT;
70 
71        float2 offset = texCoord.zw;
72        float4 cPosition;   
73        float4 wPosition = position;   
74        cPosition = mul(worldView, wPosition); 
75        OUT.P = cPosition.xyz;
76        OUT.P.z = - 1 * OUT.P.z;
77        cPosition.xy += offset;                         
78        OUT.Q = cPosition.xyz; 
79        OUT.Q.z = OUT.P.z;
80        OUT.r = abs(texCoord.z);               
81
82   /*texCoord.y = 1.0 - texCoord.y;
83   float2 offset = texCoord.xy * 2.0 - 1.0;
84   float4 cPosition = mul(worldView, position);
85   OUT.P = cPosition.xyz;
86   OUT.P.z = - 1 * OUT.P.z; // - texCoord.w;
87   cPosition.xy += offset * texCoord.w;
88   OUT.Q = cPosition.xyz;
89   OUT.Q.z = OUT.P.z;
90   OUT.r = texCoord.w;*/
91 
92   OUT.hPosition = mul( Proj, cPosition );
93   OUT.screenCoord =  (OUT.hPosition.xy / OUT.hPosition.w + 1.0) / 2.0;
94   OUT.screenCoord.y = 1.0 - OUT.screenCoord.y;
95   OUT.screenCoord += float2(0.5/width, 0.5/height);   
96   
97   OUT.texCoord = texCoord;
98   OUT.color = color;
99
100
101  return OUT;
102}
103
104
105float4 SBB_SpritePS(SBB_VS_OUT IN ,
106        //      in screenCoord : VPOS,
107                uniform sampler2D colorTexture : register(s0),
108                uniform sampler2D DepthMap : register(s1)
109                ,uniform sampler2D PlanckMap : register(s2),
110                uniform sampler2D gradTex : register(s3)
111                ) : COLOR
112{
113        float4 Color = IN.color;
114        float alpha = 0;
115       
116       
117        float d = length( IN.Q - IN.P );
118        float Zs;
119       
120        if( d < IN.r )
121        {       
122                float w = sqrt( IN.r * IN.r - d * d );
123                alpha = w / IN.r;
124                //alpha *= pow( (IN.r-d) / IN.r , 2);
125       
126                float F = IN.Q.z - w;
127                float B = IN.Q.z + w;   
128
129                Zs = tex2D( DepthMap, IN.screenCoord ).r;
130                if(Zs == 0) Zs = farplane;
131                float ds = min( Zs, B ) - max( nearplane, F );   
132               
133                alpha *=  ds / w * 0.5;
134        }
135       
136        Color.a = saturate(alpha) * tex2D( colorTexture, IN.texCoord.xy).r ;
137        Color.a *= IN.color.a;
138        Color.rgb = tex2D( PlanckMap, Color.aa).rgb;
139        Color.a *= tex2D(gradTex, IN.texCoord.xy).r;
140       
141       
142        return Color;
143}
144
145
Note: See TracBrowser for help on using the repository browser.