Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Samples/Media/materials/programs/HeatVision.cg @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 6.0 KB
Line 
1//////////////////////////////////////////////
2//                               CASTER PASS                            //
3//                                  HEAT                                        //
4//////////////////////////////////////////////
5
6// vs_1_1
7void HeatCaster_vp(
8              // in
9              float4 vPos: POSITION,
10              float4 vNormal: NORMAL,
11             
12              // out
13              out float4 oPos: POSITION,
14              out float2 oNDotV: TEXCOORD0,
15             
16              // parameters
17              uniform float4x4 worldViewProj,
18              uniform float3 eyePosition        // object space
19            )
20{
21   float4 eyeDir = float4(eyePosition - vPos.xyz, 0);
22   eyeDir = normalize(eyeDir);
23   oPos   = mul( worldViewProj, vPos );
24   oNDotV = clamp( dot( vNormal, eyeDir ), 0, 1 );
25}
26
27// ps_2_0
28float4 HeatCaster_fp(
29                        // input from vp
30                        float2 iNDotV: TEXCOORD0
31                     ) : COLOR0
32{
33   return iNDotV.x;
34}
35
36
37//////////////////////////////////////////////
38//                               CASTER PASS                            //
39//                                  COLD                                        //
40//////////////////////////////////////////////
41
42// vs_1_1
43void ColdCaster_vp(
44              // in
45              float4 vPos: POSITION,
46              float4 vNormal: NORMAL,
47             
48              // out
49              out float4 oPos: POSITION,
50              out float2 oNDotV: TEXCOORD0,
51             
52              // parameters
53              uniform float4x4 worldViewProj,
54              uniform float3 eyePosition        // object space
55            )
56{
57   float4 eyeDir = float4(eyePosition - vPos.xyz, 0);
58   eyeDir = normalize(eyeDir);
59   oPos   = mul( worldViewProj, vPos );
60   oNDotV = clamp( dot( vNormal, eyeDir ), 0, 1 );
61}
62
63// ps_2_0
64float4 ColdCaster_fp(
65                        // input from vp
66                        float2 iNDotV: TEXCOORD0
67                     ) : COLOR0
68{
69   return iNDotV.x / 2;
70}
71
72
73//////////////////////////////////////////////
74//         PASS 1 - Light to heat conversion    //
75//////////////////////////////////////////////
76
77// vs_1_1
78void LightToHeat_vp(
79                    // in
80                    float4 inPos: POSITION,
81                   
82                    uniform float flipping,
83
84                    // out
85                    out float4 Pos: POSITION,
86                    out float2 uv0: TEXCOORD0
87                   )
88{
89    Pos = float4(inPos.x, flipping * inPos.y, 0.0f, 1.0f);
90    inPos.xy = sign(inPos.xy);
91    uv0  = (float2(inPos.x, -inPos.y) + 1.0f)/2.0f;
92}
93
94
95// ps_2_0
96void LightToHeat_fp(
97                        // input from vp
98                        float4 inDiffuse: COLOR0,
99                        float2 inUV0: TEXCOORD0,
100                       
101                        // out
102                        out float4 outColor: COLOR0,
103                       
104                        // params
105                        uniform float4 random_fractions,
106                        uniform float4 heatBiasScale,
107                        uniform float4 depth_modulator,
108
109                        uniform sampler2D Input,         // output of HeatVisionCaster_fp (NdotV)
110                        uniform sampler2D NoiseMap,
111                        uniform sampler2D HeatLookup
112                     )
113{
114   float  depth, heat, interference;
115
116   //  Output constant color:
117   depth = tex2D( Input, inUV0 );
118   depth *= (depth * depth_modulator);
119
120   heat  = (depth * heatBiasScale.y);
121
122//   if (depth > 0)
123   {
124                interference = -0.5 + tex2D( NoiseMap, inUV0 + float2( random_fractions.x, random_fractions.y ) );
125                interference *= interference;
126                interference *= 1 - heat;
127                heat += interference;//+ heatBiasScale.x;
128   }
129
130/*
131        heatBias isn't used for now
132   if (heat > 0)
133       heat += heatBiasScale.x;
134*/
135
136   // Clamp UVs
137   heat  = max( 0.005, min( 0.995, heat ) );
138   outColor = tex2D( HeatLookup, float2( heat, 0.f ) );
139}
140
141
142//////////////////////////////////////////////
143// PASS 2 - add simple blur (final pass)        //
144//////////////////////////////////////////////
145
146// vs_1_1
147void Blur_vp(
148                    // in
149                    float4 inPos: POSITION,
150                   
151                    uniform float flipping,
152
153                    // out
154                    out float4 Pos: POSITION,
155                    out float2 uv0: TEXCOORD0
156                   )
157{
158    Pos = float4(inPos.x, flipping * inPos.y, 0.0f, 1.0f);
159    inPos.xy = sign(inPos.xy);
160    uv0  = (float2(inPos.x, -inPos.y) + 1.0f)/2.0f;
161}
162
163// ps_2_0
164void Blur_fp(
165                    // input from vp
166                    float4 inDiffuse: COLOR0,
167                    float2 inUV0: TEXCOORD0,
168                   
169                    // out
170                    out float4 outColor: COLOR0,
171                   
172                    // parameters
173                    uniform sampler2D Input,             // output of HeatVision_fp1 (HeatRenderTexture)
174                    uniform float4 blurAmount
175                    )
176{
177   int i;
178   float4 tmpOutColor;
179   float  diffuseGlowFactor;
180   const float2 offsets[4] =
181   {
182/*
183                // hazy blur
184                -1.8, -1.8,
185                -1.8, 1.8,
186                1.8, -1.8,
187                1.8, 1.8
188*/
189/*
190                // less-hazy blur
191          -1.0,  2.0,
192          -1.0, -1.0,
193           1.0, -1.0,
194           1.0,  1.0
195*/
196/*
197      -0.326212, -0.405805,
198      -0.840144, -0.073580,
199      -0.695914,  0.457137,
200      -0.203345,  0.620716
201*/
202
203          -0.3,  0.4,
204          -0.3, -0.4,
205           0.3, -0.4,
206           0.3,  0.4
207
208   };
209
210   tmpOutColor = tex2D( Input, inUV0 ); // UV coords are in image space
211
212   // calculate glow amount
213   diffuseGlowFactor = 0.0113f * (2.0 - max( tmpOutColor.r, tmpOutColor.g ));
214
215   // basic blur filter
216   for (i = 0; i < 4; i++) {
217      tmpOutColor += tex2D( Input, inUV0 + blurAmount.x * diffuseGlowFactor * offsets[i] );
218   }
219
220   tmpOutColor *= 0.25;
221
222   // TIPS (old-skool strikes again!)
223   // Pay attention here! If you use the "out float4 outColor" directly
224   // in your steps while creating the output color (like you remove
225   // the "tmpOutColor" var and just use the "outColor" directly)
226   // your pixel-color output IS CHANGING EACH TIME YOU DO AN ASSIGNMENT TOO!
227   // A temporary variable, instead, acts like a per-pixel double buffer, and
228   // best of all, lead to better performance.
229   outColor = tmpOutColor;
230}
Note: See TracBrowser for help on using the repository browser.