source: GTP/trunk/App/Demos/Illum/StochasticIteration/hlsl.fx @ 1808

Revision 1808, 23.5 KB checked in by szirmay, 18 years ago (diff)
RevLine 
[1808]1#define SHADOW_EPSILON 0.3f
2#define reciproc        1.0f/512.0f
3#define textureSize     256.0f
4#define textureSize2 128.0f
5
6//Model view matrix
7uniform float4x4 modelview;
8//Model view inverse transpose matrix
9uniform float4x4 modelviewIT;
10//Model view projection matrix
11uniform float4x4 modelviewproj;
12//Shooter colors.
13uniform float4   Lshoot;
14//Current number of iterations.
15uniform float    niteration;
16//The reciproc of resolution.
17uniform float    recres2;
18//Random number.
19uniform float    RandomNum;
20//The current search coordinates.
21uniform float2   searchCoords;
22//The first sum.
23uniform float    firstsum;
24//The eye position.
25uniform float3   eyePos;
26//Py parameter.
27uniform float    py;
28//Render full or half screen.
29uniform bool     fullScreen;
30//The shininess parameter for specular.
31uniform float    shininess;
32
33
34//Texture for the original visibility map.
35texture visibility_map;
36sampler VisMapSampler = sampler_state
37{
38   Texture = <visibility_map>;
39   MinFilter = Point;
40   MagFilter = Point;
41   MipFilter = None;   
42   //AddressU  = Clamp;
43   //AddressV  = Clamp;
44};
45//Texture for radiosity map.
46texture radiosity_map;
47sampler RadMapSampler = sampler_state
48{
49   Texture = <radiosity_map>;
50   MinFilter = Point;
51   MagFilter = Point;
52   MipFilter = None;   
53   //AddressU  = Clamp;
54   //AddressV  = Clamp;
55};
56//Texure for actual radiosity map.
57texture act_radiosity_map;
58sampler ActRadMapSampler = sampler_state
59{
60   Texture = <act_radiosity_map>;
61   MinFilter = Point;
62   MagFilter = Point;
63   MipFilter = None;   
64   //AddressU  = Clamp;
65   //AddressV  = Clamp;
66};
67//Texture for luminance.
68texture luminance_map;
69sampler LumMapSampler = sampler_state
70{
71   Texture = <luminance_map>;
72   MinFilter = Point;
73   MagFilter = Point;
74   MipFilter = None;   
75   //AddressU  = Wrap;
76   //AddressV  = Wrap;
77};
78//Texture for emission.
79texture emission_map;
80sampler EmissionMapSampler = sampler_state
81{
82   Texture = <emission_map>;
83   MinFilter = Point;
84   MagFilter = Point;
85   MipFilter = None;   
86   //AddressU  = Clamp;
87   //AddressV  = Clamp;
88};
89//Texture for the sum of the mipmap levels.
90texture sum_map;
91sampler SumSampler = sampler_state
92{
93   Texture = <sum_map>;
94   MinFilter = Point;
95   MagFilter = Point;
96   MipFilter = None;   
97   AddressU  = Clamp;
98   AddressV  = Clamp;
99};
100//Mipmap level texture
101texture mipmap;
102sampler MipmapSampler = sampler_state
103{
104   Texture = <mipmap>;
105   MinFilter = Point;
106   MagFilter = Point;
107   MipFilter = None;   
108   AddressU  = Clamp;
109   AddressV  = Clamp;
110};
111//The BRDF map.
112texture BRDFMap;
113sampler BRDFMapSampler = sampler_state
114{
115   Texture = <BRDFMap>;
116   MinFilter = Linear;
117   MagFilter = Linear;
118   MipFilter = None;   
119   AddressU  = Clamp;
120   AddressV  = Clamp;
121};
122//The specular map.
123texture Specular_Map;
124sampler SpecularMapSampler = sampler_state
125{
126   Texture = <Specular_Map>;
127   MinFilter = Linear;
128   MagFilter = Linear;
129   MipFilter = None;   
130   AddressU  = Clamp;
131   AddressV  = Clamp;
132};
133
134//The map for the final rendered image.
135texture final_map;
136sampler FinalMapSampler = sampler_state
137{
138   Texture = <final_map>;
139   MinFilter = Point;
140   MagFilter = Point;
141   MipFilter = None;   
142   AddressU  = Clamp;
143   AddressV  = Clamp;
144};
145
146
147//Multiple render target PS output for 2 targets.
148struct MRT_Output_2 {   
149    float4 firstcolor    : COLOR0;
150    float4 secondcolor   : COLOR1;
151};
152//Vertex shader input structure.
153struct inputs {   
154    float4 position    : POSITION;
155    float4 patch_index : COLOR0;
156    float2 texcoord    : TEXCOORD0;
157        float3 brdf        : TEXCOORD1;
158        float4 emission    : TEXCOORD2;
159        float4 normal      : NORMAL;
160};
161//Complex vertex shader output structure.
162struct vs_outputs {
163    float4 hposition   : POSITION;
164    float2 texcoord    : TEXCOORD0;
165    float4 viscoord    : TEXCOORD1;
166    float4 emission    : TEXCOORD2;
167    float3 x           : TEXCOORD3;
168    float3 brdf            : TEXCOORD4;
169    float3 normal          : TEXCOORD5;
170 };
171//Simple vertex shader output for initializing BRDF maps.
172struct text_vs_output{
173        float4 hposition:POSITION;
174        float2 texcoord:TEXCOORD0;
175};
176
177
178//Renders vertex output to a texture atlas.
179text_vs_output BRDFMAP_VS(inputs IN){
180        text_vs_output OUT;
181        OUT.hposition.xy = 2*IN.texcoord.xy-float2(1,1);
182        OUT.hposition.z = 0;
183        OUT.hposition.w = 1;
184        OUT.texcoord.x          = IN.texcoord.x+reciproc;
185        OUT.texcoord.y          = 1-IN.texcoord.y+reciproc;
186        return(OUT);
187}
188//Pixel shader for BRDF atlas rendering.
189float4 BRDFMAP_PS(float4 texcoord:TEXCOORD0):COLOR{
190        float4 retval;
191        retval.rgb=tex2D(BRDFMapSampler,texcoord).rgb/3.1415f;
192        retval.a=shininess;
193        return retval;
194}
195
196//Renders visibility map.
197vs_outputs ORIGVISMAP_VS( inputs IN) {
198                         
199    vs_outputs OUT;
200   
201    OUT.hposition=float4(0.0f,0.0f,0.0f,0.0f);
202    OUT.texcoord=float2(0.0f,0.0f);
203    OUT.viscoord=float4(0.0f,0.0f,0.0f,0.0f);
204    OUT.emission=float4(0.0f,0.0f,0.0f,0.0f);
205    OUT.x =float3(0.0f,0.0f,0.0f);
206    OUT.brdf=float3(0.0f,0.0f,0.0f);
207    OUT.normal=float3(0.0f,0.0f,0.0f);
208        OUT.hposition.xy = 2*IN.texcoord.xy-float2(1,1);
209        OUT.hposition.z = 0;
210        OUT.hposition.w = 1;
211        OUT.emission.rgb = IN.patch_index.xyz;
212        OUT.emission.a   = 1.0f;
213        OUT.viscoord=IN.emission.rgba;
214        return(OUT);
215}
216
217//Renders emission map.
218vs_outputs EMISSION_VS( inputs IN) {
219                         
220    vs_outputs OUT;
221   
222    OUT.hposition=float4(0.0f,0.0f,0.0f,0.0f);
223    OUT.texcoord=float2(0.0f,0.0f);
224    OUT.viscoord=float4(0.0f,0.0f,0.0f,0.0f);
225    OUT.emission=float4(0.0f,0.0f,0.0f,0.0f);
226    OUT.x =float3(0.0f,0.0f,0.0f);
227    OUT.brdf=float3(0.0f,0.0f,0.0f);
228    OUT.normal=float3(0.0f,0.0f,0.0f);
229    OUT.hposition.xy = 2 * IN.texcoord.xy - float2(1, 1);
230        OUT.hposition.z = 0;
231        OUT.hposition.w = 1;
232        OUT.emission.rgba = IN.emission.rgba;
233    return(OUT);
234}
235
236
237//Renders iterated visibility map.
238vs_outputs ITVIS_VS( inputs IN) {
239                         
240    vs_outputs OUT;
241   
242    OUT.hposition=float4(0.0f,0.0f,0.0f,0.0f);
243    OUT.texcoord=float2(0.0f,0.0f);
244    OUT.viscoord=float4(0.0f,0.0f,0.0f,0.0f);
245    OUT.emission=float4(0.0f,0.0f,0.0f,0.0f);
246    OUT.x =float3(0.0f,0.0f,0.0f);
247    OUT.brdf=float3(0.0f,0.0f,0.0f);
248    OUT.normal=float3(0.0f,0.0f,0.0f);
249    OUT.hposition       = mul(IN.position,modelviewproj);
250        OUT.emission.r  = OUT.hposition.z;
251        OUT.emission.g  = abs(dot(IN.normal,normalize(IN.position-eyePos)));    //cosine
252    return(OUT);
253}
254//Vertex shader for rendering one shot from the current shooter.
255vs_outputs SHOOT_VS( inputs IN) {
256                         
257    vs_outputs OUT;
258   
259    OUT.hposition=float4(0.0f,0.0f,0.0f,0.0f);
260    OUT.texcoord=float2(0.0f,0.0f);
261    OUT.viscoord=float4(0.0f,0.0f,0.0f,0.0f);
262    OUT.emission=float4(0.0f,0.0f,0.0f,0.0f);
263    OUT.x =float3(0.0f,0.0f,0.0f);
264    OUT.brdf=float3(0.0f,0.0f,0.0f);
265    OUT.normal=float3(0.0f,0.0f,0.0f);
266        OUT.hposition.xy        = 2 * IN.texcoord.xy - float2(1, 1);
267        OUT.hposition.z         = 0;
268        OUT.hposition.w         = 1;
269        OUT.texcoord.x          = IN.texcoord.x+reciproc;
270        OUT.texcoord.y          = 1-IN.texcoord.y+reciproc;
271       
272        OUT.x                           = mul(IN.position, modelview).xyz;
273        OUT.normal                      = mul(IN.normal, modelviewIT).xyz;
274
275        OUT.emission.rgba       = IN.emission.rgba;             
276        OUT.brdf                        = IN.brdf;
277        OUT.viscoord        = mul(IN.position,modelviewproj);
278        return OUT;
279}
280//Rendering the final output.
281vs_outputs FINAL_VS( inputs IN) {
282                         
283    vs_outputs OUT;
284   
285    OUT.hposition=float4(0.0f,0.0f,0.0f,0.0f);
286    OUT.texcoord=float2(0.0f,0.0f);
287    OUT.viscoord=float4(0.0f,0.0f,0.0f,0.0f);
288    OUT.emission=float4(0.0f,0.0f,0.0f,0.0f);
289    OUT.x =float3(0.0f,0.0f,0.0f);
290    OUT.brdf=float3(0.0f,0.0f,0.0f);
291    OUT.normal=float3(0.0f,0.0f,0.0f);
292   
293    OUT.hposition.xyzw = mul(IN.position,modelviewproj).xyzw;
294        OUT.texcoord.x = IN.texcoord.x;
295        OUT.texcoord.y = 1.0f-IN.texcoord.y;
296       
297    return OUT;
298}
299
300//Rendering a shot from the current shooter.
301float4 SHOOT_PS(
302                        float2 texcoord        : TEXCOORD0,
303                float4 viscoord        : TEXCOORD1,
304                float4 emission        : TEXCOORD2,
305                float3 x               : TEXCOORD3,
306                float3 brdf                        : TEXCOORD4,
307                float3 xnormal             : TEXCOORD5
308                        ) : COLOR
309{
310       
311        float3 ytox                     = normalize( x );                       // direction from y to x
312        float  xydist2          = dot( x, x );                          // |x - y|^2
313
314        float  costhetax        = dot(xnormal, -ytox);          //cosine(thetax)
315        if(costhetax<0.0f) costhetax=0.0f;
316               
317        float  costhetay        = (fullScreen) ? ytox.z : ytox.y; //cosine(thetay) is fullscreen side of the visibility hemicube?
318        if(costhetay<0.0f) costhetay=0.0f;
319        if(xydist2<1.0f) xydist2 = 1.0f;
320        float G = costhetax * costhetay / (xydist2+4.0f*Lshoot.w);      //Geometry factor. Uniform disc method.
321       
322        float3 Lref     = Lshoot.xyz * G;
323       
324       
325        float visible;
326       
327        float2 depthmap;
328       
329        float2 viscoord2=(viscoord.xy/viscoord.w+1)/2;
330        viscoord2.y=1-viscoord2.y+reciproc;
331        viscoord2.x+=reciproc;
332        float depth=viscoord.z;
333        float yLimit= (fullScreen)? 1 :0.5;
334        if((viscoord2.x>=0)&&(viscoord2.x<=1)&&(viscoord2.y>=0)&&(viscoord2.y<yLimit)){
335                depthmap  = tex2D(VisMapSampler, viscoord2).rg;
336
337                visible =       (abs(depthmap.r-depth)<(0.09-0.06*depthmap.g));
338               
339        }
340        else{
341                visible=0;
342        }
343       
344        /*
345        //V has is a normalized vector from patch to eye pos.
346        //L is -ytox.
347        //N is xnormal.
348        //R is L mirrored to N.
349        float4 brdf2=tex2D(BRDFSampler,texcoord);
350        float3 eyePos2=normalize(x-eyePos);
351        float3 R=xnormal*(2.0f*costhetax)+ytox;
352        float cos_out=dot(R,eyePos2);
353        //brdf2.a is specular shininess;
354        float specular=0.1f*pow(cos_out,brdf2.a)/max(dot(xnormal,eyePos2),dot(xnormal,-ytox));
355        float3 lrNew= visible * Lref.xyz * (brdf2.xyz+specular);
356        */
357       
358        float3 lrNew= visible * Lref.xyz * brdf.xyz;
359
360       
361        float g;
362        if(py==0.0f){
363                g=0.0f;
364        }
365        else{
366                g = G*visible/py;
367        }
368       
369        float4 oldActual=tex2D(ActRadMapSampler,texcoord).rgba;
370       
371        float4 retColor=float4(lrNew,g)+oldActual.rgba;
372       
373        return retColor;
374       
375       
376}
377
378float4 TEXTURE_PS( in float2 texcoord        : TEXCOORD0
379                         ) : COLOR
380{
381       
382        texcoord*=textureSize2;
383       
384        int2 itexcoord0=texcoord;
385       
386        float2 itexcoord1=float2(itexcoord0.x+1,itexcoord0.y);
387        float2 itexcoord2=float2(itexcoord0.x,itexcoord0.y+1);
388        float2 itexcoord3=float2(itexcoord0.x+1,itexcoord0.y+1);
389        float4 color0=tex2D(FinalMapSampler, itexcoord0/textureSize2).rgba;
390        float4 color1=tex2D(FinalMapSampler, itexcoord1/textureSize2).rgba;
391        float4 color2=tex2D(FinalMapSampler, itexcoord2/textureSize2).rgba;
392        float4 color3=tex2D(FinalMapSampler, itexcoord3/textureSize2).rgba;
393        color0*=(1-(texcoord.x-itexcoord0.x))*(1-(texcoord.y-itexcoord0.y));
394        color1*=((texcoord.x-itexcoord0.x))*(1-(texcoord.y-itexcoord0.y));
395        color2*=(1-(texcoord.x-itexcoord0.x))*((texcoord.y-itexcoord0.y));
396        color3*=((texcoord.x-itexcoord0.x))*((texcoord.y-itexcoord0.y));
397        if(color1.a!=0.0){
398                color0+=color1;
399               
400        }
401        if(color2.a!=0.0){
402                color0+=color2;
403               
404        }
405        if(color3.a!=0.0){
406                color0+=color3;
407        }
408       
409        return float4(color0.rgb/color0.a,1);
410       
411}
412
413//Writes float4(TEXCOORD2.x,TEXCOORD2.y,TEXCOORD2.z,(sum(TEXCOORD2.x,TEXCOORD2.y,TEXCOORD2.z)*TEXCOORD2.w)) to the output.
414float4 WRITETHROUGH_PS(in float4 emission : TEXCOORD2) : COLOR {
415        float lumPower=(emission.r+emission.g+emission.b)/3.0f*emission.a;
416        return(float4(emission.rgb,lumPower));
417        //return(float4(0,emission.a,0,1));
418}
419
420
421//Writes TEXCOORD2.r and TEXCOORD1.r to the output.
422float4 ORIGVISMAP_PS(   in float4 emission : TEXCOORD1,
423                                                in float4 patch_index : TEXCOORD2
424                                         
425                                         ) : COLOR {
426        return float4(patch_index.r,emission.a,0.0f,0.0f);
427}
428//Writes TEXCOORD2.r, TEXCOORD2.g to the output.
429float4 WRITETHROUGH_VISMAP_PS(in float4 emission : TEXCOORD2) : COLOR {
430        return(float4(emission.r,emission.g,0,1));
431}
432//Creates the base level for the radiosity sum map.
433float4 MIPMAP_CREATE_BASE( in float2 texcoord        : TEXCOORD0,
434                                                   in float4 color               : COLOR0
435             
436                 ) : COLOR
437{
438               
439        float col=tex2D(RadMapSampler, float2(texcoord.x,texcoord.y)).a;
440        col+=tex2D(RadMapSampler, float2(texcoord.x+recres2, texcoord.y)).a;
441        col+=tex2D(RadMapSampler, float2(texcoord.x, texcoord.y+recres2)).a;
442        col+=tex2D(RadMapSampler, float2(texcoord.x+recres2, texcoord.y+recres2)).a;
443        return float4(col,0,0,0);
444}
445//Creates a sum map level.
446float4 MIPMAP_CREATE_LEVEL( in float2 texcoord        : TEXCOORD0,
447                                                        in float4 color               : COLOR0
448             
449                 ) : COLOR
450{
451               
452        float col=tex2D(LumMapSampler, float2(texcoord.x,texcoord.y)).r;
453        col+=tex2D(LumMapSampler, float2(texcoord.x+recres2, texcoord.y)).r;
454        col+=tex2D(LumMapSampler, float2(texcoord.x, texcoord.y+recres2)).r;
455        col+=tex2D(LumMapSampler, float2(texcoord.x+recres2, texcoord.y+recres2)).r;
456        return float4(col,0,0,0);
457}
458
459//Starts the search of the sum map levels for a shooter.
460float4 SEARCH_PS_START( in float2 texcoord        : TEXCOORD0,
461                                  in float4 color               : COLOR0
462             
463                 ) : COLOR
464{
465        //float3 sumColor=tex2D(SumSampler,float2(0.5f,0.5f));
466        float r=firstsum;
467        float color1=tex2D(MipmapSampler ,float2(0,0)).r;
468        float colMax=color1;
469        float colMin=0;
470        float retval=0;
471        float2 retCoords;
472        if(r<=colMax){
473                retval=r;
474                retCoords=float2(0,0);
475               
476        }
477        else{
478                colMin=colMax;
479                float color2=tex2D(MipmapSampler ,float2(searchCoords.x+recres2,searchCoords.y)).r;
480                colMax+=color2;
481                if(r<=colMax){
482                        retval=r-colMin;
483                        retCoords=float2(searchCoords.x+recres2,searchCoords.y);
484                }
485                else{
486                        colMin=colMax;
487                        float color3=tex2D(MipmapSampler ,float2(searchCoords.x,searchCoords.y+recres2)).r;
488                        colMax+=color3;
489                        if(r<=colMax){
490                                retval=r-colMin;
491                                retCoords=float2(searchCoords.x,searchCoords.y+recres2);
492                        }
493                        else{
494                                colMin=colMax;
495                                retval=r-colMin;
496                                retCoords=float2(searchCoords.x+recres2,searchCoords.y+recres2);
497                        }
498                }
499        }       
500       
501        return float4(retval,retCoords.x,retCoords.y,1.0f);
502}
503//Searches the sum map levels for a shooter.
504float4 SEARCH_PS( in float2 texcoord        : TEXCOORD0,
505                                  in float4 color               : COLOR0             
506                 ) : COLOR
507{
508        float3 sumColor=tex2D(SumSampler,float2(0.5f,0.5f));
509       
510        float r=sumColor.r;
511        float2 searchCoords1=float2(sumColor.g,sumColor.b);
512        float color1=tex2D(MipmapSampler ,searchCoords1).r;
513        float colMax=color1;
514        float colMin=0;
515        float2 retCoords;
516        float retval=0;
517        if(r<=colMax){
518                retval=r;
519                retCoords=searchCoords1;
520        }
521        else{
522                colMin=colMax;
523                float color2=tex2D(MipmapSampler ,float2(searchCoords1.x+recres2,searchCoords1.y)).r;
524                colMax+=color2;
525                if(r<=colMax){
526                        retval=r-colMin;
527                        retCoords=float2(searchCoords1.x+recres2,searchCoords1.y);
528                }
529                else{
530                        colMin=colMax;
531                        float color3=tex2D(MipmapSampler ,float2(searchCoords1.x,searchCoords1.y+recres2)).r;
532                        colMax+=color3;
533                        if(r<=colMax){
534                                retval=r-colMin;
535                                retCoords=float2(searchCoords1.x,searchCoords1.y+recres2);
536                        }
537                        else{
538                                colMin=colMax;
539                                retval=r-colMin;
540                                retCoords=float2(searchCoords1.x+recres2,searchCoords1.y+recres2);
541                        }
542                }
543        }       
544       
545        return float4(retval,retCoords.x,retCoords.y,1.0f);
546}
547
548
549//Ends the search for sum map levels for a shooter.
550MRT_Output_2 SEARCH_PS_END( in float2 texcoord        : TEXCOORD0,
551                                                        in float4 color               : COLOR0             
552                                                        )
553{
554        MRT_Output_2 output1;
555        float3 sumColor=tex2D(SumSampler,float2(0.5f,0.5f));
556        float r=sumColor.r;
557        float2 searchCoords1=float2(sumColor.g,sumColor.b);
558        float retval=0;
559        float color1=tex2D(MipmapSampler ,searchCoords1).a;
560        float colMax=color1;
561        float colMin=0;
562        float2 retCoords;
563        if(r<=colMax){
564                retval=r;
565                retCoords=searchCoords1;
566        }
567        else{
568                colMin=colMax;
569                float color2=tex2D(MipmapSampler ,float2(searchCoords1.x+recres2,searchCoords1.y)).a;
570                colMax+=color2;
571                if(r<=colMax){
572                        retval=r-colMin;
573                        retCoords=float2(searchCoords1.x+recres2,searchCoords1.y);
574                }
575                else{
576                        colMin=colMax;
577                        float color3=tex2D(MipmapSampler ,float2(searchCoords1.x,searchCoords1.y+recres2)).a;
578                        colMax+=color3;
579                        if(r<=colMax){
580                                retval=r-colMin;
581                                retCoords=float2(searchCoords1.x,searchCoords1.y+recres2);
582                        }
583                        else{
584                                colMin=colMax;
585                                retval=r-colMin;
586                                retCoords=float2(searchCoords1.x+recres2,searchCoords1.y+recres2);
587                        }
588                }
589        }
590        float3 radiosityColor=tex2D(MipmapSampler,retCoords).rgb;
591        //The output is the value of the shooter. And the texture coordinates of the shooter.
592        output1.firstcolor=float4(retval,retCoords.x,retCoords.y,1.0f);
593        //The output is the value. And the texture coordinates of the shooter.
594        output1.secondcolor=float4(radiosityColor.r,radiosityColor.g,radiosityColor.b,1.0f);
595        return output1;
596}
597
598//The vertex shader input structure for sum maping.
599struct mipmap_inputs {   
600    float4 position    : POSITION;
601    float2 texcoord    : TEXCOORD0;
602   
603};
604//The input structure for sum maping.
605struct mipmap_outputs {
606    float4 hposition   : POSITION;
607    float2 texcoord    : TEXCOORD0;
608 };
609
610//Sum map vertex shader.
611mipmap_outputs  MIPMAP_VS(mipmap_inputs IN)  {
612        mipmap_outputs OUT;
613        OUT.hposition.w=1;
614        OUT.hposition=IN.position;
615        OUT.texcoord=IN.texcoord;
616        return OUT;
617}
618//Averages the current radiosity map.
619float4 AVERAGING_PS(mipmap_outputs IN):COLOR{
620        float4 retval;
621        float w=tex2D(RadMapSampler,IN.texcoord).a/3.1415f;
622        float3 retcolor=tex2D(RadMapSampler,IN.texcoord).rgb;
623        retcolor-=tex2D(EmissionMapSampler,IN.texcoord).rgb;
624        retcolor/=niteration;
625        retcolor+=tex2D(EmissionMapSampler,IN.texcoord).rgb;
626        retval = float4(retcolor,1);
627        return retval;
628}
629
630
631
632//Vertex shader. Averages the actual radiosity mipmap.
633text_vs_output ACTUAL_AVG_VS(inputs IN){
634        text_vs_output OUT;
635       
636        OUT.hposition.xy = 2*IN.texcoord.xy-float2(1,1);
637        OUT.hposition.z = 0;
638        OUT.hposition.w = 1;
639        OUT.texcoord.x = IN.texcoord.x+reciproc;
640        OUT.texcoord.y = 1-IN.texcoord.y+reciproc;
641        return OUT;
642}
643
644//Pixel shader. Averages the actual radiosity mipmap.
645float4 ACTUAL_AVG_PS(float2 texcoord:TEXCOORD0):COLOR{
646        float recres2=1.0f/textureSize;
647        float2 texcoord1=float2(texcoord.x+recres2,texcoord.y);
648        float2 texcoord2=float2(texcoord.x,texcoord.y+recres2);
649        float2 texcoord3=float2(texcoord.x+recres2,texcoord.y+recres2);
650       
651        float4 highResActual0=tex2D(ActRadMapSampler,texcoord);
652        float3 emission0=tex2D(EmissionMapSampler,texcoord).rgb;
653        float2 mask0=tex2D(VisMapSampler,texcoord).rg;  //green channel contains area/texarea
654        highResActual0.rgb+=emission0.rgb;
655       
656        float4 highResActual1=tex2D(ActRadMapSampler,texcoord1);
657        float3 emission1=tex2D(EmissionMapSampler,texcoord1).rgb;
658        highResActual1.rgb+=emission1.rgb;
659        float2 mask1=tex2D(VisMapSampler,texcoord1).rg;
660       
661        float4 highResActual2=tex2D(ActRadMapSampler,texcoord2);
662        float3 emission2=tex2D(EmissionMapSampler,texcoord2).rgb;
663        highResActual2.rgb+=emission2.rgb;;
664        float2 mask2=tex2D(VisMapSampler,texcoord2).rg;
665       
666        float4 highResActual3=tex2D(ActRadMapSampler,texcoord3);
667        float3 emission3=tex2D(EmissionMapSampler,texcoord3).rgb;
668        highResActual3.rgb+=emission3.rgb;
669        float2 mask3=tex2D(VisMapSampler,texcoord3).rg;
670       
671       
672        float  lNewLum=0;
673       
674        lNewLum+=(highResActual0.r+highResActual0.g+highResActual0.b)/3.0f*mask0.g;
675        lNewLum+=(highResActual1.r+highResActual1.g+highResActual1.b)/3.0f*mask1.g;
676        lNewLum+=(highResActual2.r+highResActual2.g+highResActual2.b)/3.0f*mask2.g;
677        lNewLum+=(highResActual3.r+highResActual3.g+highResActual3.b)/3.0f*mask3.g;
678       
679        return float4(lNewLum,0,0,0);
680}
681//Pixel shader. Masks the averaging output with the original visibility map. Keeps texture atlas
682//pixels originally visible only.
683float4 ACTUAL_AVG_PS2(float2 texcoord:TEXCOORD0):COLOR{
684        float recres2=1.0f/textureSize;
685        float2 texcoord1=float2(texcoord.x+recres2,texcoord.y);
686        float2 texcoord2=float2(texcoord.x,texcoord.y+recres2);
687        float2 texcoord3=float2(texcoord.x+recres2,texcoord.y+recres2);
688       
689        float4 highResActual0=tex2D(ActRadMapSampler,texcoord);
690        float mask0=tex2D(VisMapSampler,texcoord).r;
691        float4 highResActual1=tex2D(ActRadMapSampler,texcoord1);
692        float mask1=tex2D(VisMapSampler,texcoord1).r;
693       
694        float4 highResActual2=tex2D(ActRadMapSampler,texcoord2);
695        float mask2=tex2D(VisMapSampler,texcoord2).r;
696       
697        float4 highResActual3=tex2D(ActRadMapSampler,texcoord3);
698        float mask3=tex2D(VisMapSampler,texcoord3).r;
699       
700        float divisor=1.0f;
701       
702        float4 sum=highResActual0;
703       
704        if(mask0==mask1){
705                divisor++;
706                sum+=highResActual1;
707        }
708        if(mask0==mask2){
709                divisor++;
710                sum+=highResActual2;
711        }
712        if(mask0==mask3){
713                divisor++;
714                sum+=highResActual3;   
715        }
716        sum/=divisor;
717       
718        return(tex2D(RadMapSampler,texcoord)+sum);
719}
720
721// -------------------------------------------------------------
722// Name technique | how to compile
723// -------------------------------------------------------------
724
725technique OriginalVisibilityMapShader
726{
727    pass P0
728    {
729        // compiler directives
730        VertexShader = compile vs_3_0 ORIGVISMAP_VS();
731        PixelShader  = compile ps_3_0 ORIGVISMAP_PS();
732    }
733}
734technique EmissionMapTech
735{
736    pass P0
737    {
738        // compiler directives
739        VertexShader = compile vs_3_0 EMISSION_VS();
740        PixelShader  = compile ps_3_0 WRITETHROUGH_PS();
741    }
742}
743technique ITVisShader
744{
745    pass P0
746    {
747        // compiler directives
748        VertexShader = compile vs_3_0 ITVIS_VS();
749        PixelShader  = compile ps_3_0 WRITETHROUGH_VISMAP_PS();
750    }
751}
752
753technique MipmapBaseCreate
754{
755    pass P0{
756                Sampler[0] = (RadMapSampler);
757        // compiler directives
758        VertexShader = compile vs_3_0 MIPMAP_VS();
759        PixelShader  = compile ps_3_0 MIPMAP_CREATE_BASE();
760    }
761}
762technique MipmapLevelCreate
763{
764    pass P0{
765                Sampler[0] = (LumMapSampler);
766        // compiler directives
767        VertexShader = compile vs_3_0 MIPMAP_VS();
768        PixelShader  = compile ps_3_0 MIPMAP_CREATE_LEVEL();
769    }
770}
771technique SearchStartTech
772{
773    pass P0{
774                Sampler[0] = (MipmapSampler);
775                Sampler[1] = (SumSampler);
776        // compiler directives
777        VertexShader = compile vs_3_0 MIPMAP_VS();
778        PixelShader  = compile ps_3_0 SEARCH_PS_START();
779    }
780}
781technique SearchTech
782{
783    pass P0{
784               
785                Sampler[0] = (SumSampler);
786                Sampler[1] = (MipmapSampler);
787        // compiler directives
788        VertexShader = compile vs_3_0 MIPMAP_VS();
789        PixelShader  = compile ps_3_0 SEARCH_PS();
790    }
791}
792technique SearchEndTech
793{
794    pass P0{
795                /*
796                Sampler[0] = (SumSampler);
797                Sampler[1] = (MipmapSampler);
798                Sampler[2] = (RadMapSampler);
799                */
800        // compiler directives
801        VertexShader = compile vs_3_0 MIPMAP_VS();
802        PixelShader  = compile ps_3_0 SEARCH_PS_END();
803    }
804}
805technique Shoot
806{
807    pass P0{
808                Sampler[0] = (VisMapSampler);           
809                Sampler[1] = (RadMapSampler);
810        // compiler directives
811        VertexShader = compile vs_3_0 SHOOT_VS();
812        PixelShader  = compile ps_3_0 SHOOT_PS();
813    }
814}
815technique RadAveragingTech
816{
817    pass P0{
818        // compiler directives
819        VertexShader = compile vs_3_0 MIPMAP_VS();
820        PixelShader  = compile ps_3_0 AVERAGING_PS();
821    }
822}
823technique RenderFinal
824{
825    pass P0{
826                Sampler[0] = (RadMapSampler);           
827        // compiler directives
828        VertexShader = compile vs_3_0 FINAL_VS();
829        PixelShader  = compile ps_3_0 TEXTURE_PS();
830    }
831}
832technique ActualAveragingTech
833{
834    pass P0{
835        // compiler directives
836        VertexShader = compile vs_3_0 ACTUAL_AVG_VS();
837        PixelShader  = compile ps_3_0 ACTUAL_AVG_PS();
838    }
839}
840technique ActualAveragingTech2
841{
842    pass P0{
843        // compiler directives
844        VertexShader = compile vs_3_0 ACTUAL_AVG_VS();
845        PixelShader  = compile ps_3_0 ACTUAL_AVG_PS2();
846    }
847}
848technique BRDFShader
849{
850    pass P0{
851        // compiler directives
852        VertexShader = compile vs_3_0 BRDFMAP_VS();
853        PixelShader  = compile ps_3_0 BRDFMAP_PS();
854    }
855}
Note: See TracBrowser for help on using the repository browser.