Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 4 files changed
  • 2 comments
  • 1 contributor
4  Demo/DX10/Demo.vcxproj
@@ -149,10 +149,10 @@
149 149
   </ItemGroup>
150 150
   <ItemGroup>
151 151
     <CustomBuild Include="Shaders\SMAA.fx">
152  
-      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">fxc /Od /Zi /Tfx_4_0 /nologo /I ../.. /Fo"$(IntDir)%(Filename).fxo" /Fc"$(IntDir)%(Filename).asm" "%(FullPath)"
  152
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">fxc /Od /Zi /Tfx_4_0 /Ges /nologo /I ../.. /Fo"$(IntDir)%(Filename).fxo" /Fc"$(IntDir)%(Filename).asm" "%(FullPath)"
153 153
 </Command>
154 154
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)%(Filename).fxo</Outputs>
155  
-      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">fxc /Tfx_4_0 /nologo /I ../.. /Fo"$(IntDir)%(Filename).fxo"  /Fc"$(IntDir)%(Filename).asm" "%(FullPath)"
  155
+      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">fxc /Tfx_4_0 /Ges /nologo /I ../.. /Fo"$(IntDir)%(Filename).fxo"  /Fc"$(IntDir)%(Filename).asm" "%(FullPath)"
156 156
 </Command>
157 157
       <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)%(Filename).fxo</Outputs>
158 158
       <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\SMAA.h</AdditionalInputs>
2  Demo/DX9/Shaders/SMAA.fx
@@ -182,7 +182,7 @@ float4 DX9_SMAABlendingWeightCalculationPS(float4 position : SV_POSITION,
182 182
                                            uniform SMAATexture2D edgesTex, 
183 183
                                            uniform SMAATexture2D areaTex, 
184 184
                                            uniform SMAATexture2D searchTex) : COLOR {
185  
-    return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesTex, areaTex, searchTex);
  185
+    return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesTex, areaTex, searchTex, 0);
186 186
 }
187 187
 
188 188
 float4 DX9_SMAANeighborhoodBlendingPS(float4 position : SV_POSITION,
34  README.md
Source Rendered
@@ -8,6 +8,28 @@ SMAA is a very efficient GPU-based MLAA implementation, capable of handling subp
8 8
 Checkout the [technical paper](http://www.iryoku.com/smaa/) for more info!
9 9
 
10 10
 
  11
+Thanks To
  12
+---------
  13
+
  14
+**Stephen Hill** ‒ for its invaluable support.
  15
+
  16
+**Alex Fry** ‒ for its priceless help with the devkit.
  17
+
  18
+**Naty Hoffman** ‒ for helping us to touch base with the game developer community.
  19
+
  20
+**Jean-Francois St-Amour** ‒ for providing us great images for testing.
  21
+
  22
+**Johan Andersson** ‒ for providing the fantastic BF3 image and clearing important questions.
  23
+
  24
+**Dmitriy Jdone** ‒ for porting the code to GLSL.
  25
+
  26
+**Weibo Xie** ‒ for the suggested optimizations.
  27
+
  28
+**Alexander Reshetov** ‒ for creating MLAA, and opening our mind.
  29
+
  30
+**Everyone on the [SIGGRAPH course](http://iryoku.com/aacourse/)** ‒ for the incredible inspiration.
  31
+
  32
+
11 33
 Usage
12 34
 -----
13 35
 
@@ -25,21 +47,17 @@ https://github.com/iryoku/smaa/issues
25 47
 Authors
26 48
 -------
27 49
 
28  
-**Jorge Jimenez**
29  
-
30  
-+ http://www.iryoku.com/
  50
+**Jorge Jimenez** http://www.iryoku.com/
31 51
 
32  
-**Jose I. Echevarria**
  52
+**Jose I. Echevarria** http://cheveone.blogspot.com/
33 53
 
34  
-+ http://cheveone.blogspot.com/
  54
+**Tiago Sousa** https://twitter.com/#!/CRYTEK_TIAGO
35 55
 
36 56
 **Belen Masia**
37 57
 
38 58
 **Fernando Navarro**
39 59
 
40  
-**Diego Gutierrez**
41  
-
42  
-+ http://giga.cps.unizar.es/~diegog/
  60
+**Diego Gutierrez** http://giga.cps.unizar.es/~diegog/
43 61
 
44 62
 
45 63
 Copyright and License
205  SMAA.h
@@ -132,13 +132,17 @@
132 132
  *         SMAA_HLSL_3
133 133
  *         SMAA_HLSL_4
134 134
  *         SMAA_HLSL_4_1
  135
+ *         SMAA_GLSL_3 *
  136
+ *         SMAA_GLSL_4 *
  137
+ *
  138
+ *         * (See SMAA_ONLY_COMPILE_VS below).
135 139
  *
136 140
  *     And four presets:
137 141
  *         SMAA_PRESET_LOW          (%60 of the quality)
138 142
  *         SMAA_PRESET_MEDIUM       (%80 of the quality)
139 143
  *         SMAA_PRESET_HIGH         (%95 of the quality)
140 144
  *         SMAA_PRESET_ULTRA        (%99 of the quality)
141  
- *         
  145
+ *
142 146
  *     For example:
143 147
  *         #define SMAA_PIXEL_SIZE float2(1.0 / 1280.0, 1.0 / 720.0)
144 148
  *         #define SMAA_HLSL_4 1 
@@ -186,10 +190,16 @@
186 190
  *    'SMAABlendingWeightCalculationPS' must be set as follows, for our T2x
187 191
  *    mode:
188 192
  *
  193
+ *    @SUBSAMPLE_INDICES
  194
+ *
189 195
  *             |         jitter         |    subsampleIndices    |
190 196
  *             +------------------------+------------------------|
191 197
  *             | float2(-0.25f,  0.25f) |    int4(1, 1, 1, 0)    |
192 198
  *             | float2( 0.25f, -0.25f) |    int4(2, 2, 2, 0)    |
  199
+ *       OR
  200
+ *             +------------------------+------------------------|
  201
+ *             | float2( 0.25f,  0.25f) |    int4(2, 1, 0, 2)    |
  202
+ *             | float2(-0.25f, -0.25f) |    int4(1, 2, 0, 1)    |
193 203
  *
194 204
  *    These jitter positions assume a bottom-to-top y axis.
195 205
  *
@@ -304,7 +314,8 @@
304 314
  * Predicated thresholding allows to better preserve texture details and to
305 315
  * improve performance, by decreasing the number of detected edges using an
306 316
  * additional buffer like the light accumulation buffer, object ids or even the
307  
- * depth buffer.
  317
+ * depth buffer (the depth buffer usage may be limited to indoor or short range
  318
+ * scenes).
308 319
  *
309 320
  * It locally decreases the luma or color threshold if an edge is found in an
310 321
  * additional buffer (so the global threshold can be higher).
@@ -390,6 +401,17 @@
390 401
 #define SMAA_DIRECTX9_LINEAR_BLEND 0
391 402
 #endif
392 403
 
  404
+/**
  405
+ * On ATI compilers, discard cannot be used in vertex shaders. Thus, they need
  406
+ * to be compiled separately. These macros allow to easily accomplish it.
  407
+ */
  408
+#ifndef SMAA_ONLY_COMPILE_VS
  409
+#define SMAA_ONLY_COMPILE_VS 0
  410
+#endif
  411
+#ifndef SMAA_ONLY_COMPILE_PS
  412
+#define SMAA_ONLY_COMPILE_PS 0
  413
+#endif
  414
+
393 415
 //-----------------------------------------------------------------------------
394 416
 // Non-Configurable Defines
395 417
 
@@ -411,8 +433,13 @@
411 433
 #define SMAASampleLevelZeroPoint(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
412 434
 #define SMAASample(tex, coord) tex2D(tex, coord)
413 435
 #define SMAASamplePoint(tex, coord) tex2D(tex, coord)
414  
-#define SMAASampleLevelZeroOffset(tex, coord, off) tex2Dlod(tex, float4(coord + off * SMAA_PIXEL_SIZE, 0.0, 0.0))
415  
-#define SMAASampleOffset(tex, coord, off) tex2D(tex, coord + off * SMAA_PIXEL_SIZE)
  436
+#define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlod(tex, float4(coord + offset * SMAA_PIXEL_SIZE, 0.0, 0.0))
  437
+#define SMAASampleOffset(tex, coord, offset) tex2D(tex, coord + offset * SMAA_PIXEL_SIZE)
  438
+#define SMAALerp(a, b, t) lerp(a, b, t)
  439
+#define SMAASaturate(a) saturate(a)
  440
+#define SMAAMad(a, b, c) mad(a, b, c)
  441
+#define SMAA_FLATTEN [flatten]
  442
+#define SMAA_BRANCH [branch]
416 443
 #endif
417 444
 #if SMAA_HLSL_4 == 1 || SMAA_HLSL_4_1 == 1
418 445
 SamplerState LinearSampler { Filter = MIN_MAG_LINEAR_MIP_POINT; AddressU = Clamp; AddressV = Clamp; };
@@ -422,12 +449,43 @@ SamplerState PointSampler { Filter = MIN_MAG_MIP_POINT; AddressU = Clamp; Addres
422 449
 #define SMAASampleLevelZeroPoint(tex, coord) tex.SampleLevel(PointSampler, coord, 0)
423 450
 #define SMAASample(tex, coord) SMAASampleLevelZero(tex, coord)
424 451
 #define SMAASamplePoint(tex, coord) SMAASampleLevelZeroPoint(tex, coord)
425  
-#define SMAASampleLevelZeroOffset(tex, coord, off) tex.SampleLevel(LinearSampler, coord, 0, off)
426  
-#define SMAASampleOffset(tex, coord, off) SMAASampleLevelZeroOffset(tex, coord, off)
  452
+#define SMAASampleLevelZeroOffset(tex, coord, offset) tex.SampleLevel(LinearSampler, coord, 0, offset)
  453
+#define SMAASampleOffset(tex, coord, offset) SMAASampleLevelZeroOffset(tex, coord, offset)
  454
+#define SMAALerp(a, b, t) lerp(a, b, t)
  455
+#define SMAASaturate(a) saturate(a)
  456
+#define SMAAMad(a, b, c) mad(a, b, c)
  457
+#define SMAA_FLATTEN [flatten]
  458
+#define SMAA_BRANCH [branch]
427 459
 #endif
428 460
 #if SMAA_HLSL_4_1 == 1
429 461
 #define SMAAGather(tex, coord) tex.Gather(LinearSampler, coord, 0)
430 462
 #endif
  463
+#if SMAA_GLSL_3 == 1 || SMAA_GLSL_4 == 1
  464
+#define SMAATexture2D sampler2D
  465
+#define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0)
  466
+#define SMAASampleLevelZeroPoint(tex, coord) textureLod(tex, coord, 0.0)
  467
+#define SMAASample(tex, coord) texture(tex, coord)
  468
+#define SMAASamplePoint(tex, coord) texture(tex, coord)
  469
+#define SMAASampleLevelZeroOffset(tex, coord, offset) textureLodOffset(tex, coord, 0.0, offset)
  470
+#define SMAASampleOffset(tex, coord, offset) texture(tex, coord, offset)
  471
+#define SMAALerp(a, b, t) mix(a, b, t)
  472
+#define SMAASaturate(a) clamp(a, 0.0, 1.0)
  473
+#define SMAA_FLATTEN
  474
+#define SMAA_BRANCH
  475
+#define float2 vec2
  476
+#define float3 vec3
  477
+#define float4 vec4
  478
+#define int2 ivec2
  479
+#define int3 ivec3
  480
+#define int4 ivec4
  481
+#endif
  482
+#if SMAA_GLSL_3 == 1
  483
+#define SMAAMad(a, b, c) (a * b + c)
  484
+#endif
  485
+#if SMAA_GLSL_4 == 1
  486
+#define SMAAMad(a, b, c) fma(a, b, c)
  487
+#define SMAAGather(tex, coord) textureGather(tex, coord)
  488
+#endif
431 489
 
432 490
 //-----------------------------------------------------------------------------
433 491
 // Misc functions
@@ -461,6 +519,7 @@ float2 SMAACalculatePredicatedThreshold(float2 texcoord,
461 519
     return SMAA_PREDICATION_SCALE * SMAA_THRESHOLD * (1.0 - SMAA_PREDICATION_STRENGTH * edges);
462 520
 }
463 521
 
  522
+#if SMAA_ONLY_COMPILE_PS == 0
464 523
 //-----------------------------------------------------------------------------
465 524
 // Vertex Shaders
466 525
 
@@ -497,7 +556,7 @@ void SMAABlendWeightCalculationVS(float4 position,
497 556
     // And these for the searches, they indicate the ends of the loops:
498 557
     offset[2] = float4(offset[0].xz, offset[1].yw) + 
499 558
                 float4(-2.0, 2.0, -2.0, 2.0) *
500  
-                SMAA_PIXEL_SIZE.xxyy * SMAA_MAX_SEARCH_STEPS;
  559
+                SMAA_PIXEL_SIZE.xxyy * float(SMAA_MAX_SEARCH_STEPS);
501 560
 }
502 561
 
503 562
 /**
@@ -521,7 +580,9 @@ void SMAAResolveVS(float4 position,
521 580
                    inout float2 texcoord) {
522 581
     svPosition = position;
523 582
 }
  583
+#endif // SMAA_ONLY_COMPILE_PS == 0
524 584
 
  585
+#if SMAA_ONLY_COMPILE_VS == 0
525 586
 //-----------------------------------------------------------------------------
526 587
 // Edge Detection Pixel Shaders (First Pass)
527 588
 
@@ -542,7 +603,7 @@ float4 SMAALumaEdgeDetectionPS(float2 texcoord,
542 603
     #if SMAA_PREDICATION == 1
543 604
     float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, colorTex, predicationTex);
544 605
     #else
545  
-    float2 threshold = SMAA_THRESHOLD;
  606
+    float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD);
546 607
     #endif
547 608
 
548 609
     // Calculate lumas:
@@ -553,20 +614,21 @@ float4 SMAALumaEdgeDetectionPS(float2 texcoord,
553 614
 
554 615
     // We do the usual threshold:
555 616
     float4 delta;
556  
-    delta.xy = abs(L.xx - float2(Lleft, Ltop));
  617
+    delta.xy = abs(L - float2(Lleft, Ltop));
557 618
     float2 edges = step(threshold, delta.xy);
558 619
 
559 620
     // Then discard if there is no edge:
560  
-    if (dot(edges, 1.0) == 0.0)
  621
+    if (dot(edges, float2(1.0, 1.0)) == 0.0)
561 622
         discard;
562 623
 
563 624
     // Calculate right and bottom deltas:
564 625
     float Lright = dot(SMAASample(colorTex, offset[1].xy).rgb, weights);
565 626
     float Lbottom  = dot(SMAASample(colorTex, offset[1].zw).rgb, weights);
566  
-    delta.zw = abs(L.xx - float2(Lright, Lbottom));
  627
+    delta.zw = abs(L - float2(Lright, Lbottom));
567 628
 
568 629
     // Calculate the maximum delta in the direct neighborhood:
569  
-    float2 maxDelta = max(max(max(delta.x, delta.y), delta.z), delta.w);
  630
+    float2 maxDelta = max(delta.xy, delta.zw);
  631
+    maxDelta = max(maxDelta.xx, maxDelta.yy);
570 632
 
571 633
     // Calculate left-left and top-top deltas:
572 634
     float Lleftleft = dot(SMAASample(colorTex, offset[2].xy).rgb, weights);
@@ -574,7 +636,7 @@ float4 SMAALumaEdgeDetectionPS(float2 texcoord,
574 636
     delta.zw = abs(float2(Lleft, Ltop) - float2(Lleftleft, Ltoptop));
575 637
 
576 638
     // Calculate the final maximum delta:
577  
-    maxDelta = float2(max(maxDelta.x, delta.z), max(maxDelta.y, delta.w));
  639
+    maxDelta = max(maxDelta.xy, delta.zw);
578 640
 
579 641
     /**
580 642
      * Each edge with a delta in luma of less than 50% of the maximum luma
@@ -608,7 +670,7 @@ float4 SMAAColorEdgeDetectionPS(float2 texcoord,
608 670
     #if SMAA_PREDICATION == 1
609 671
     float2 threshold = SMAACalculatePredicatedThreshold(texcoord, offset, colorTex, predicationTex);
610 672
     #else
611  
-    float2 threshold = SMAA_THRESHOLD;
  673
+    float2 threshold = float2(SMAA_THRESHOLD, SMAA_THRESHOLD);
612 674
     #endif
613 675
 
614 676
     // Calculate color deltas:
@@ -627,7 +689,7 @@ float4 SMAAColorEdgeDetectionPS(float2 texcoord,
627 689
     float2 edges = step(threshold, delta.xy);
628 690
 
629 691
     // Then discard if there is no edge:
630  
-    if (dot(edges, 1.0) == 0.0)
  692
+    if (dot(edges, float2(1.0, 1.0)) == 0.0)
631 693
         discard;
632 694
 
633 695
     // Calculate right and bottom deltas:
@@ -670,7 +732,7 @@ float4 SMAADepthEdgeDetectionPS(float2 texcoord,
670 732
     float2 delta = abs(neighbours.xx - float2(neighbours.y, neighbours.z));
671 733
     float2 edges = step(SMAA_DEPTH_THRESHOLD, delta);
672 734
 
673  
-    if (dot(edges, 1.0) == 0.0)
  735
+    if (dot(edges, float2(1.0, 1.0)) == 0.0)
674 736
         discard;
675 737
 
676 738
     return float4(edges, 0.0, 0.0);
@@ -686,10 +748,11 @@ float4 SMAADepthEdgeDetectionPS(float2 texcoord,
686 748
  */
687 749
 float SMAASearchDiag1(SMAATexture2D edgesTex, float2 texcoord, float2 dir, float c) {
688 750
     texcoord += dir * SMAA_PIXEL_SIZE;
689  
-    float2 e = 0;
690  
-    for (float i = 0; i < SMAA_MAX_SEARCH_STEPS_DIAG; i++) {
  751
+    float2 e = float2(0.0, 0.0);
  752
+    float i;
  753
+    for (i = 0.0; i < float(SMAA_MAX_SEARCH_STEPS_DIAG); i++) {
691 754
         e.rg = SMAASampleLevelZero(edgesTex, texcoord).rg;
692  
-        [flatten] if (dot(e, 1.0) < 1.9) break;
  755
+        SMAA_FLATTEN if (dot(e, float2(1.0, 1.0)) < 1.9) break;
693 756
         texcoord += dir * SMAA_PIXEL_SIZE;
694 757
     }
695 758
     return i + float(e.g > 0.9) * c;
@@ -697,11 +760,12 @@ float SMAASearchDiag1(SMAATexture2D edgesTex, float2 texcoord, float2 dir, float
697 760
 
698 761
 float SMAASearchDiag2(SMAATexture2D edgesTex, float2 texcoord, float2 dir, float c) {
699 762
     texcoord += dir * SMAA_PIXEL_SIZE;
700  
-    float2 e = 0;
701  
-    for (float i = 0; i < SMAA_MAX_SEARCH_STEPS_DIAG; i++) {
  763
+    float2 e = float2(0.0, 0.0);
  764
+    float i;
  765
+    for (i = 0.0; i < float(SMAA_MAX_SEARCH_STEPS_DIAG); i++) {
702 766
         e.g = SMAASampleLevelZero(edgesTex, texcoord).g;
703 767
         e.r = SMAASampleLevelZeroOffset(edgesTex, texcoord, int2(1, 0)).r;
704  
-        [flatten] if (dot(e, 1.0) < 1.9) break;
  768
+        SMAA_FLATTEN if (dot(e, float2(1.0, 1.0)) < 1.9) break;
705 769
         texcoord += dir * SMAA_PIXEL_SIZE;
706 770
     }
707 771
     return i + float(e.g > 0.9) * c;
@@ -711,8 +775,8 @@ float SMAASearchDiag2(SMAATexture2D edgesTex, float2 texcoord, float2 dir, float
711 775
  * Similar to SMAAArea, this calculates the area corresponding to a certain
712 776
  * diagonal distance and crossing edges 'e'.
713 777
  */
714  
-float2 SMAAAreaDiag(SMAATexture2D areaTex, float2 distance, float2 e, float offset) {
715  
-    float2 texcoord = SMAA_AREATEX_MAX_DISTANCE_DIAG * e + distance;
  778
+float2 SMAAAreaDiag(SMAATexture2D areaTex, float2 dist, float2 e, float offset) {
  779
+    float2 texcoord = float(SMAA_AREATEX_MAX_DISTANCE_DIAG) * e + dist;
716 780
 
717 781
     // We do a scale and bias for mapping to texel space:
718 782
     texcoord = SMAA_AREATEX_PIXEL_SIZE * texcoord + (0.5 * SMAA_AREATEX_PIXEL_SIZE);
@@ -735,15 +799,15 @@ float2 SMAAAreaDiag(SMAATexture2D areaTex, float2 distance, float2 e, float offs
735 799
  * This searches for diagonal patterns and returns the corresponding weights.
736 800
  */
737 801
 float2 SMAACalculateDiagWeights(SMAATexture2D edgesTex, SMAATexture2D areaTex, float2 texcoord, float2 e, int4 subsampleIndices) {
738  
-    float2 weights = 0.0;
  802
+    float2 weights = float2(0.0, 0.0);
739 803
 
740 804
     float2 d;
741  
-    d.x = e.r? SMAASearchDiag1(edgesTex, texcoord, float2(-1.0,  1.0), 1.0) : 0.0;
  805
+    d.x = e.r > 0.0? SMAASearchDiag1(edgesTex, texcoord, float2(-1.0,  1.0), 1.0) : 0.0;
742 806
     d.y = SMAASearchDiag1(edgesTex, texcoord, float2(1.0, -1.0), 0.0);
743 807
 
744  
-    [branch]
745  
-    if (d.r + d.g > 2) { // d.r + d.g + 1 > 3
746  
-        float4 coords = mad(float4(-d.r, d.r, d.g, -d.g), SMAA_PIXEL_SIZE.xyxy, texcoord.xyxy);
  808
+    SMAA_BRANCH
  809
+    if (d.r + d.g > 2.0) { // d.r + d.g + 1 > 3
  810
+        float4 coords = SMAAMad(float4(-d.r, d.r, d.g, -d.g), SMAA_PIXEL_SIZE.xyxy, texcoord.xyxy);
747 811
 
748 812
         float4 c;
749 813
         c.x = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1,  0)).g;
@@ -751,27 +815,29 @@ float2 SMAACalculateDiagWeights(SMAATexture2D edgesTex, SMAATexture2D areaTex, f
751 815
         c.z = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1,  0)).g;
752 816
         c.w = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1, -1)).r;
753 817
         float2 e = 2.0 * c.xz + c.yw;
754  
-        e *= step(d.rg, SMAA_MAX_SEARCH_STEPS_DIAG - 1);
  818
+        float t = float(SMAA_MAX_SEARCH_STEPS_DIAG) - 1.0;
  819
+        e *= step(d.rg, float2(t, t));
755 820
 
756  
-        weights += SMAAAreaDiag(areaTex, d, e, subsampleIndices.z);
  821
+        weights += SMAAAreaDiag(areaTex, d, e, float(subsampleIndices.z));
757 822
     }
758 823
 
759 824
     d.x = SMAASearchDiag2(edgesTex, texcoord, float2(-1.0, -1.0), 0.0);
760 825
     float right = SMAASampleLevelZeroOffset(edgesTex, texcoord, int2(1, 0)).r;
761  
-    d.y = right? SMAASearchDiag2(edgesTex, texcoord, float2(1.0, 1.0), 1.0) : 0.0;
  826
+    d.y = right > 0.0? SMAASearchDiag2(edgesTex, texcoord, float2(1.0, 1.0), 1.0) : 0.0;
762 827
 
763  
-    [branch]
764  
-    if (d.r + d.g > 2) { // d.r + d.g + 1 > 3
765  
-        float4 coords = mad(float4(-d.r, -d.r, d.g, d.g), SMAA_PIXEL_SIZE.xyxy, texcoord.xyxy);
  828
+    SMAA_BRANCH
  829
+    if (d.r + d.g > 2.0) { // d.r + d.g + 1 > 3
  830
+        float4 coords = SMAAMad(float4(-d.r, -d.r, d.g, d.g), SMAA_PIXEL_SIZE.xyxy, texcoord.xyxy);
766 831
 
767 832
         float4 c;
768 833
         c.x  = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-1,  0)).g;
769 834
         c.y  = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2( 0, -1)).r;
770 835
         c.zw = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1,  0)).gr;
771 836
         float2 e = 2.0 * c.xz + c.yw;
772  
-        e *= step(d.rg, SMAA_MAX_SEARCH_STEPS_DIAG - 1);
  837
+        float t = float(SMAA_MAX_SEARCH_STEPS_DIAG) - 1.0;
  838
+        e *= step(d.rg, float2(t, t));
773 839
 
774  
-        weights += SMAAAreaDiag(areaTex, d, e, subsampleIndices.w).gr;
  840
+        weights += SMAAAreaDiag(areaTex, d, e, float(subsampleIndices.w)).gr;
775 841
     }
776 842
 
777 843
     return weights;
@@ -880,9 +946,9 @@ float SMAASearchYDown(SMAATexture2D edgesTex, SMAATexture2D searchTex, float2 te
880 946
  * Ok, we have the distance and both crossing edges. So, what are the areas
881 947
  * at each side of current edge?
882 948
  */
883  
-float2 SMAAArea(SMAATexture2D areaTex, float2 distance, float e1, float e2, float offset) {
  949
+float2 SMAAArea(SMAATexture2D areaTex, float2 dist, float e1, float e2, float offset) {
884 950
     // Rounding prevents precision errors of bilinear filtering:
885  
-    float2 texcoord = SMAA_AREATEX_MAX_DISTANCE * round(4.0 * float2(e1, e2)) + distance;
  951
+    float2 texcoord = float(SMAA_AREATEX_MAX_DISTANCE) * round(4.0 * float2(e1, e2)) + dist;
886 952
     
887 953
     // We do a scale and bias for mapping to texel space:
888 954
     texcoord = SMAA_AREATEX_PIXEL_SIZE * texcoord + (0.5 * SMAA_AREATEX_PIXEL_SIZE);
@@ -903,33 +969,33 @@ float2 SMAAArea(SMAATexture2D areaTex, float2 distance, float e1, float e2, floa
903 969
 
904 970
 void SMAADetectHorizontalCornerPattern(SMAATexture2D edgesTex, inout float2 weights, float2 texcoord, float2 d) {
905 971
     #if SMAA_CORNER_ROUNDING < 100 || SMAA_FORCE_CORNER_DETECTION == 1
906  
-    float4 coords = mad(float4(d.x, 0.0, d.y, 0.0),
907  
-                        SMAA_PIXEL_SIZE.xyxy, texcoord.xyxy);
  972
+    float4 coords = SMAAMad(float4(d.x, 0.0, d.y, 0.0),
  973
+                            SMAA_PIXEL_SIZE.xyxy, texcoord.xyxy);
908 974
     float2 e;
909 975
     e.r = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(0.0,  1.0)).r;
910 976
     bool left = abs(d.x) < abs(d.y);
911 977
     e.g = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(0.0, -2.0)).r;
912  
-    if (left) weights *= saturate(SMAA_CORNER_ROUNDING / 100.0 + 1.0 - e);
  978
+    if (left) weights *= SMAASaturate(float(SMAA_CORNER_ROUNDING) / 100.0 + 1.0 - e);
913 979
 
914 980
     e.r = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2(1.0,  1.0)).r;
915 981
     e.g = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2(1.0, -2.0)).r;
916  
-    if (!left) weights *= saturate(SMAA_CORNER_ROUNDING / 100.0 + 1.0 - e);
  982
+    if (!left) weights *= SMAASaturate(float(SMAA_CORNER_ROUNDING) / 100.0 + 1.0 - e);
917 983
     #endif
918 984
 }
919 985
 
920 986
 void SMAADetectVerticalCornerPattern(SMAATexture2D edgesTex, inout float2 weights, float2 texcoord, float2 d) {
921 987
     #if SMAA_CORNER_ROUNDING < 100 || SMAA_FORCE_CORNER_DETECTION == 1
922  
-    float4 coords = mad(float4(0.0, d.x, 0.0, d.y),
923  
-                        SMAA_PIXEL_SIZE.xyxy, texcoord.xyxy);
  988
+    float4 coords = SMAAMad(float4(0.0, d.x, 0.0, d.y),
  989
+                            SMAA_PIXEL_SIZE.xyxy, texcoord.xyxy);
924 990
     float2 e;
925 991
     e.r = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2( 1.0, 0.0)).g;
926 992
     bool left = abs(d.x) < abs(d.y);
927 993
     e.g = SMAASampleLevelZeroOffset(edgesTex, coords.xy, int2(-2.0, 0.0)).g;
928  
-    if (left) weights *= saturate(SMAA_CORNER_ROUNDING / 100.0 + 1.0 - e);
  994
+    if (left) weights *= SMAASaturate(float(SMAA_CORNER_ROUNDING) / 100.0 + 1.0 - e);
929 995
 
930 996
     e.r = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2( 1.0, 1.0)).g;
931 997
     e.g = SMAASampleLevelZeroOffset(edgesTex, coords.zw, int2(-2.0, 1.0)).g;
932  
-    if (!left) weights *= saturate(SMAA_CORNER_ROUNDING / 100.0 + 1.0 - e);
  998
+    if (!left) weights *= SMAASaturate(float(SMAA_CORNER_ROUNDING) / 100.0 + 1.0 - e);
933 999
     #endif
934 1000
 }
935 1001
 
@@ -942,13 +1008,13 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord,
942 1008
                                        SMAATexture2D edgesTex, 
943 1009
                                        SMAATexture2D areaTex, 
944 1010
                                        SMAATexture2D searchTex,
945  
-                                       int4 subsampleIndices=0) {
946  
-    float4 weights = 0.0;
  1011
+                                       int4 subsampleIndices) { // Just pass zero for SMAA 1x, see @SUBSAMPLE_INDICES.
  1012
+    float4 weights = float4(0.0, 0.0, 0.0, 0.0);
947 1013
 
948 1014
     float2 e = SMAASample(edgesTex, texcoord).rg;
949 1015
 
950  
-    [branch]
951  
-    if (e.g) { // Edge at north
  1016
+    SMAA_BRANCH
  1017
+    if (e.g > 0.0) { // Edge at north
952 1018
         #if SMAA_MAX_SEARCH_STEPS_DIAG > 0 || SMAA_FORCE_DIAGONAL_DETECTION == 1
953 1019
         // Diagonals have both north and west edges, so searching for them in
954 1020
         // one of the boundaries is enough.
@@ -956,8 +1022,8 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord,
956 1022
 
957 1023
         // We give priority to diagonals, so if we find a diagonal we skip 
958 1024
         // horizontal/vertical processing.
959  
-        [branch]
960  
-        if (dot(weights.rg, 1.0) == 0.0) {
  1025
+        SMAA_BRANCH
  1026
+        if (dot(weights.rg, float2(1.0, 1.0)) == 0.0) {
961 1027
         #endif
962 1028
 
963 1029
         float2 d;
@@ -990,7 +1056,7 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord,
990 1056
 
991 1057
         // Ok, we know how this pattern looks like, now it is time for getting
992 1058
         // the actual area:
993  
-        weights.rg = SMAAArea(areaTex, sqrt_d, e1, e2, subsampleIndices.y);
  1059
+        weights.rg = SMAAArea(areaTex, sqrt_d, e1, e2, float(subsampleIndices.y));
994 1060
 
995 1061
         // Fix corners:
996 1062
         SMAADetectHorizontalCornerPattern(edgesTex, weights.rg, texcoord, d);
@@ -1001,8 +1067,8 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord,
1001 1067
         #endif
1002 1068
     }
1003 1069
 
1004  
-    [branch]
1005  
-    if (e.r) { // Edge at west
  1070
+    SMAA_BRANCH
  1071
+    if (e.r > 0.0) { // Edge at west
1006 1072
         float2 d;
1007 1073
 
1008 1074
         // Find the distance to the top:
@@ -1029,7 +1095,7 @@ float4 SMAABlendingWeightCalculationPS(float2 texcoord,
1029 1095
         float e2 = SMAASampleLevelZeroOffset(edgesTex, coords, int2(0, 1)).g;
1030 1096
 
1031 1097
         // Get the area for this direction:
1032  
-        weights.ba = SMAAArea(areaTex, sqrt_d, e1, e2, subsampleIndices.x);
  1098
+        weights.ba = SMAAArea(areaTex, sqrt_d, e1, e2, float(subsampleIndices.x));
1033 1099
 
1034 1100
         // Fix corners:
1035 1101
         SMAADetectVerticalCornerPattern(edgesTex, weights.ba, texcoord, d);
@@ -1046,17 +1112,17 @@ float4 SMAANeighborhoodBlendingPS(float2 texcoord,
1046 1112
                                   SMAATexture2D colorTex,
1047 1113
                                   SMAATexture2D blendTex) {
1048 1114
     // Fetch the blending weights for current pixel:
1049  
-    float4 topLeft = SMAASample(blendTex, texcoord);
1050  
-    float bottom = SMAASample(blendTex, offset[1].zw).g;
1051  
-    float right = SMAASample(blendTex, offset[1].xy).a;
1052  
-    float4 a = float4(topLeft.r, bottom, topLeft.b, right);
  1115
+    float4 a;
  1116
+    a.xz = SMAASample(blendTex, texcoord).xz;
  1117
+    a.y = SMAASample(blendTex, offset[1].zw).g;
  1118
+    a.w = SMAASample(blendTex, offset[1].xy).a;
1053 1119
 
1054 1120
     // Is there any blending weight with a value greater than 0.0?
1055  
-    [branch]
1056  
-    if (dot(a, 1.0) < 1e-5)
  1121
+    SMAA_BRANCH
  1122
+    if (dot(a, float4(1.0, 1.0, 1.0, 1.0)) < 1e-5)
1057 1123
         return SMAASampleLevelZero(colorTex, texcoord);
1058 1124
     else {
1059  
-        float4 color = 0.0;
  1125
+        float4 color = float4(0.0, 0.0, 0.0, 0.0);
1060 1126
 
1061 1127
         // Up to 4 lines can be crossing a pixel (one through each edge). We
1062 1128
         // favor blending by choosing the line with the maximum weight for each
@@ -1083,7 +1149,7 @@ float4 SMAANeighborhoodBlendingPS(float2 texcoord,
1083 1149
         Cop.a *= Cop.a;
1084 1150
 
1085 1151
         // Lerp the colors:
1086  
-        float4 Caa = lerp(C, Cop, s);
  1152
+        float4 Caa = SMAALerp(C, Cop, s);
1087 1153
 
1088 1154
         // Unpack velocity and return the resulting value:
1089 1155
         Caa.a = sqrt(Caa.a);
@@ -1100,7 +1166,7 @@ float4 SMAANeighborhoodBlendingPS(float2 texcoord,
1100 1166
         texcoord += sign(offset) * SMAA_PIXEL_SIZE;
1101 1167
         float4 Cop = SMAASampleLevelZero(colorTex, texcoord);
1102 1168
         float s = abs(offset.x) > abs(offset.y)? abs(offset.x) : abs(offset.y);
1103  
-        return lerp(C, Cop, s);
  1169
+        return SMAALerp(C, Cop, s);
1104 1170
         #endif
1105 1171
         #endif
1106 1172
     }
@@ -1129,16 +1195,17 @@ float4 SMAAResolvePS(float2 texcoord,
1129 1195
 
1130 1196
     // Attenuate the previous pixel if the velocity is different:
1131 1197
     float delta = abs(current.a * current.a - previous.a * previous.a) / 5.0;
1132  
-    float weight = 0.5 * saturate(1.0 - (sqrt(delta) * SMAA_REPROJECTION_WEIGHT_SCALE));
  1198
+    float weight = 0.5 * SMAASaturate(1.0 - (sqrt(delta) * SMAA_REPROJECTION_WEIGHT_SCALE));
1133 1199
 
1134 1200
     // Blend the pixels according to the calculated weight:
1135  
-    return lerp(current, previous, weight);
  1201
+    return SMAALerp(current, previous, weight);
1136 1202
     #else
1137 1203
     // Just blend the pixels:
1138 1204
     float4 current = SMAASample(colorTexCurr, texcoord);
1139 1205
     float4 previous = SMAASample(colorTexPrev, texcoord);
1140  
-    return lerp(current, previous, 0.5);
  1206
+    return SMAALerp(current, previous, 0.5);
1141 1207
     #endif
1142 1208
 }
1143 1209
 
1144 1210
 //-----------------------------------------------------------------------------
  1211
+#endif // SMAA_ONLY_COMPILE_VS == 0

Showing you all comments on commits in this comparison.

chiguireitor

Where's the GLSL code? can't seem to find it in the downloads... is it included in previous files?

Jorge Jimenez
Owner

It's all bundled in SMAA.h, search for SMAA_GLSL_* defines.

Something went wrong with that request. Please try again.