Skip to content
Browse files

Revamped and simplified the interface. We now have a single MLAA.h fo…

…r DX9 and DX10
  • Loading branch information...
1 parent 74d98bd commit 34868de8f9fa10237251f5930021f3421af0adaa @iryoku committed Aug 25, 2011
Showing with 1,438 additions and 1,179 deletions.
  1. +15 −0 .gitignore
  2. BIN AreaTex.dds
  3. 0 {dx10 → Demo/DX10}/Code/Copy.cpp
  4. 0 {dx10 → Demo/DX10}/Code/Copy.h
  5. +69 −18 {dx10 → Demo/DX10}/Code/Demo.cpp
  6. +65 −44 {dx10 → Demo/DX10}/Code/MLAA.cpp
  7. +28 −47 {dx10 → Demo/DX10}/Code/MLAA.h
  8. 0 {dx10 → Demo/DX10}/Code/RenderTarget.cpp
  9. 0 {dx10 → Demo/DX10}/Code/RenderTarget.h
  10. +1 −1 {dx10 → Demo/DX10}/Code/Timer.cpp
  11. +2 −0 {dx10 → Demo/DX10}/Code/Timer.h
  12. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUT.cpp
  13. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUT.h
  14. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUTCore_2005.sln
  15. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUTCore_2005.vcproj
  16. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUTCore_2008.sln
  17. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUTCore_2008.vcproj
  18. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUTenum.cpp
  19. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUTenum.h
  20. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUTmisc.cpp
  21. 0 {dx10 → Demo/DX10}/DXUT/Core/DXUTmisc.h
  22. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTLockFreePipe.h
  23. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTOptional_2005.sln
  24. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTOptional_2005.vcproj
  25. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTOptional_2008.sln
  26. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTOptional_2008.vcproj
  27. 0 {dx9 → Demo/DX10}/DXUT/Optional/DXUTShapes.cpp
  28. 0 {dx9 → Demo/DX10}/DXUT/Optional/DXUTShapes.h
  29. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTcamera.cpp
  30. 0 {dx9 → Demo/DX10}/DXUT/Optional/DXUTcamera.h
  31. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTgui.cpp
  32. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTgui.h
  33. 0 {dx9 → Demo/DX10}/DXUT/Optional/DXUTguiIME.cpp
  34. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTguiIME.h
  35. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTres.cpp
  36. 0 {dx9 → Demo/DX10}/DXUT/Optional/DXUTres.h
  37. 0 {dx10 → Demo/DX10}/DXUT/Optional/DXUTsettingsdlg.cpp
  38. 0 {dx9 → Demo/DX10}/DXUT/Optional/DXUTsettingsdlg.h
  39. 0 {dx9 → Demo/DX10}/DXUT/Optional/ImeUi.cpp
  40. 0 {dx9 → Demo/DX10}/DXUT/Optional/ImeUi.h
  41. 0 {dx10 → Demo/DX10}/DXUT/Optional/SDKmesh.cpp
  42. 0 {dx10 → Demo/DX10}/DXUT/Optional/SDKmesh.h
  43. 0 {dx10 → Demo/DX10}/DXUT/Optional/SDKmisc.cpp
  44. 0 {dx10 → Demo/DX10}/DXUT/Optional/SDKmisc.h
  45. 0 {dx9 → Demo/DX10}/DXUT/Optional/SDKsound.cpp
  46. 0 {dx9 → Demo/DX10}/DXUT/Optional/SDKsound.h
  47. 0 {dx10 → Demo/DX10}/DXUT/Optional/SDKwavefile.cpp
  48. 0 {dx9 → Demo/DX10}/DXUT/Optional/SDKwavefile.h
  49. 0 {dx9 → Demo/DX10}/DXUT/Optional/directx.ico
  50. 0 {dx10 → Demo/DX10}/Demo DX10.sln
  51. +4 −7 {dx10 → Demo/DX10}/Demo.rc
  52. +5 −2 {dx10 → Demo/DX10}/Demo.vcxproj
  53. +3 −0 {dx10 → Demo/DX10}/Demo.vcxproj.filters
  54. 0 {dx9 → Demo/DX10}/Icon.ico
  55. 0 {dx9 → Demo/DX10}/Media/Images/Unigine01.dds
  56. 0 {dx9 → Demo/DX10}/Media/Images/Unigine01.png
  57. 0 {dx10 → Demo/DX10}/Media/Images/Unigine02.dds
  58. 0 {dx10 → Demo/DX10}/Media/Images/Unigine02.png
  59. 0 {dx10 → Demo/DX10}/Media/Images/Unigine03.dds
  60. 0 {dx10 → Demo/DX10}/Media/Images/Unigine03.png
  61. 0 {dx10 → Demo/DX10}/Media/Images/Unigine04.dds
  62. 0 {dx10 → Demo/DX10}/Media/Images/Unigine04.png
  63. 0 {dx10 → Demo/DX10}/Media/Images/Unigine05.dds
  64. 0 {dx10 → Demo/DX10}/Media/Images/Unigine05.png
  65. 0 {dx10 → Demo/DX10}/Media/Images/Unigine06.dds
  66. 0 {dx10 → Demo/DX10}/Media/Images/Unigine06.png
  67. 0 {dx10 → Demo/DX10}/Media/Images/Unigine07.dds
  68. 0 {dx10 → Demo/DX10}/Media/Images/Unigine07.png
  69. 0 {dx10 → Demo/DX10}/README.txt
  70. +222 −0 Demo/DX10/Shaders/MLAA.fx
  71. +1 −1 {dx9 → Demo/DX9}/Code/Demo.cpp
  72. +56 −44 {dx9 → Demo/DX9}/Code/MLAA.cpp
  73. +26 −19 {dx9 → Demo/DX9}/Code/MLAA.h
  74. 0 {dx9 → Demo/DX9}/Code/Timer.cpp
  75. 0 {dx9 → Demo/DX9}/Code/Timer.h
  76. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUT.cpp
  77. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUT.h
  78. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUT_2008.sln
  79. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUT_2008.vcproj
  80. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUT_2010.sln
  81. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUT_2010.vcxproj
  82. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUT_2010.vcxproj.filters
  83. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUTenum.cpp
  84. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUTenum.h
  85. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUTmisc.cpp
  86. 0 {dx9 → Demo/DX9}/DXUT/Core/DXUTmisc.h
  87. 0 {dx9 → Demo/DX9}/DXUT/Core/dpiaware.manifest
  88. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTLockFreePipe.h
  89. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTOpt_2008.sln
  90. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTOpt_2008.vcproj
  91. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTOpt_2010.sln
  92. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTOpt_2010.vcxproj
  93. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTOpt_2010.vcxproj.filters
  94. 0 {dx10 → Demo/DX9}/DXUT/Optional/DXUTShapes.cpp
  95. 0 {dx10 → Demo/DX9}/DXUT/Optional/DXUTShapes.h
  96. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTcamera.cpp
  97. 0 {dx10 → Demo/DX9}/DXUT/Optional/DXUTcamera.h
  98. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTgui.cpp
  99. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTgui.h
  100. 0 {dx10 → Demo/DX9}/DXUT/Optional/DXUTguiIME.cpp
  101. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTguiIME.h
  102. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTres.cpp
  103. 0 {dx10 → Demo/DX9}/DXUT/Optional/DXUTres.h
  104. 0 {dx9 → Demo/DX9}/DXUT/Optional/DXUTsettingsdlg.cpp
  105. 0 {dx10 → Demo/DX9}/DXUT/Optional/DXUTsettingsdlg.h
  106. 0 {dx10 → Demo/DX9}/DXUT/Optional/ImeUi.cpp
  107. 0 {dx10 → Demo/DX9}/DXUT/Optional/ImeUi.h
  108. 0 {dx9 → Demo/DX9}/DXUT/Optional/SDKmesh.cpp
  109. 0 {dx9 → Demo/DX9}/DXUT/Optional/SDKmesh.h
  110. 0 {dx9 → Demo/DX9}/DXUT/Optional/SDKmisc.cpp
  111. 0 {dx9 → Demo/DX9}/DXUT/Optional/SDKmisc.h
  112. 0 {dx10 → Demo/DX9}/DXUT/Optional/SDKsound.cpp
  113. 0 {dx10 → Demo/DX9}/DXUT/Optional/SDKsound.h
  114. 0 {dx9 → Demo/DX9}/DXUT/Optional/SDKwavefile.cpp
  115. 0 {dx10 → Demo/DX9}/DXUT/Optional/SDKwavefile.h
  116. 0 {dx10 → Demo/DX9}/DXUT/Optional/directx.ico
  117. 0 {dx9 → Demo/DX9}/Demo DX9.sln
  118. +10 −0 Demo/DX9/Demo.rc
  119. +5 −2 {dx9 → Demo/DX9}/Demo.vcxproj
  120. +3 −0 {dx9 → Demo/DX9}/Demo.vcxproj.filters
  121. 0 {dx9 → Demo/DX9}/Demo.vcxproj.user
  122. 0 {dx10 → Demo/DX9}/Icon.ico
  123. 0 {dx10 → Demo/DX9}/Media/Images/Unigine01.dds
  124. 0 {dx10 → Demo/DX9}/Media/Images/Unigine01.png
  125. +253 −0 Demo/DX9/Shaders/MLAA.fx
  126. +9 −11 {dx9 → }/LICENSE.txt
  127. +606 −0 MLAA.h
  128. +55 −11 dx10/LICENSE.txt → README.md
  129. 0 dx9/Media/SearchLengthMap.dds → SearchTex.dds
  130. BIN dx10/Media/AreaMap129.dds
  131. BIN dx10/Media/AreaMap17.dds
  132. BIN dx10/Media/AreaMap33.dds
  133. BIN dx10/Media/AreaMap65.dds
  134. BIN dx10/Media/AreaMap9.dds
  135. BIN dx10/Media/SearchLengthMap.dds
  136. +0 −438 dx10/Shaders/MLAA.fx
  137. +0 −14 dx9/Demo.rc
  138. BIN dx9/Media/AreaMap129.dds
  139. BIN dx9/Media/AreaMap17.dds
  140. BIN dx9/Media/AreaMap33.dds
  141. BIN dx9/Media/AreaMap65.dds
  142. BIN dx9/Media/AreaMap9.dds
  143. +0 −520 dx9/Shaders/MLAA.fx
View
15 .gitignore
@@ -0,0 +1,15 @@
+Demo/DX9/Debug/
+Demo/DX9/Release/
+Demo/DX9/ipch/
+Demo/DX9/Demo/
+Demo/DX9/Demo DX9.opensdf
+Demo/DX9/Demo DX9.sdf
+Demo/DX9/Demo DX9.suo
+
+Demo/DX10/Debug/
+Demo/DX10/Release/
+Demo/DX10/ipch/
+Demo/DX10/Demo DX10.opensdf
+Demo/DX10/Demo DX10.sdf
+Demo/DX10/Demo DX10.suo
+Demo/DX10/Demo.vcxproj.user
View
BIN AreaTex.dds
Binary file not shown.
View
0 dx10/Code/Copy.cpp → Demo/DX10/Code/Copy.cpp
File renamed without changes.
View
0 dx10/Code/Copy.h → Demo/DX10/Code/Copy.h
File renamed without changes.
View
87 dx10/Code/Demo.cpp → Demo/DX10/Code/Demo.cpp
@@ -35,7 +35,9 @@
#include "SDKmisc.h"
#include <sstream>
+#include <fstream>
#include <iomanip>
+#include <cmath>
#include "Timer.h"
#include "RenderTarget.h"
@@ -68,6 +70,9 @@ ID3D10ShaderResourceView *testDepthView = NULL;
bool showHud = true;
+bool benchmark = false;
+fstream benchmarkFile;
+
struct {
float threshold;
int distance;
@@ -90,6 +95,11 @@ struct {
#define IDC_THRESHOLD 12
+float round(float n) {
+ return floor(n + 0.5f);
+}
+
+
bool CALLBACK isDeviceAcceptable(UINT adapter, UINT output, D3D10_DRIVER_TYPE deviceType, DXGI_FORMAT format, bool windowed, void *context) {
return true;
}
@@ -142,9 +152,13 @@ void loadImage() {
}
}
- hud.GetComboBox(IDC_DETECTIONMODE)->SetEnabled(testDepthView != NULL);
- if (testDepthView == NULL)
- hud.GetComboBox(IDC_DETECTIONMODE)->SetSelectedByIndex(0);
+ int selectedIndex = hud.GetComboBox(IDC_DETECTIONMODE)->GetSelectedIndex();
+ hud.GetComboBox(IDC_DETECTIONMODE)->RemoveAllItems();
+ hud.GetComboBox(IDC_DETECTIONMODE)->AddItem(L"Luma edge det.", (LPVOID) 0);
+ hud.GetComboBox(IDC_DETECTIONMODE)->AddItem(L"Color edge det.", (LPVOID) 1);
+ if (testDepthView != NULL)
+ hud.GetComboBox(IDC_DETECTIONMODE)->AddItem(L"Depth edge det.", (LPVOID) 2);
+ hud.GetComboBox(IDC_DETECTIONMODE)->SetSelectedByIndex(selectedIndex);
}
@@ -180,9 +194,6 @@ HRESULT CALLBACK onCreateDevice(ID3D10Device *device, const DXGI_SURFACE_DESC *d
loadImage();
- if (testDepthView != NULL)
- hud.GetComboBox(IDC_DETECTIONMODE)->SetSelectedByIndex(1);
-
return S_OK;
}
@@ -212,7 +223,7 @@ void initMLAA() {
CDXUTSlider *slider = hud.GetSlider(IDC_MAXSEARCHSTEPS);
slider->GetRange(min, max);
scale = float(slider->GetValue()) / (max - min);
- mlaa->setMaxSearchSteps(int(scale * 16.0f));
+ mlaa->setMaxSearchSteps(int(round(scale * 98.0f)));
slider = hud.GetSlider(IDC_THRESHOLD);
slider->GetRange(min, max);
@@ -266,7 +277,7 @@ void drawHud(ID3D10Device *device, float elapsedTime) {
if (timer->isEnabled()) {
wstringstream s;
- s << setprecision(5) << std::fixed;
+ s << setprecision(2) << std::fixed;
s << *timer;
txtHelper->DrawTextLine(s.str().c_str());
}
@@ -285,6 +296,23 @@ void saveBackbuffer(ID3D10Device *device) {
}
+void doBenchmark() {
+ benchmarkFile << timer->getSection(L"MLAA") << endl;
+
+ int next = hud.GetComboBox(IDC_INPUT)->GetSelectedIndex() + 1;
+ int n = hud.GetComboBox(IDC_INPUT)->GetNumItems();
+ hud.GetComboBox(IDC_INPUT)->SetSelectedByIndex(next < n? next : n);
+ loadImage();
+
+ timer->reset();
+
+ if (next == n) {
+ benchmark = false;
+ benchmarkFile.close();
+ }
+}
+
+
void drawTextures(ID3D10Device *device) {
switch (int(hud.GetComboBox(IDC_VIEWMODE)->GetSelectedData())) {
case 1:
@@ -316,15 +344,20 @@ void CALLBACK onFrameRender(ID3D10Device *device, double time, float elapsedTime
// Run MLAA
if (hud.GetCheckBox(IDC_ANTIALIASING)->GetChecked()) {
- bool useDepth = int(hud.GetComboBox(IDC_DETECTIONMODE)->GetSelectedData()) == 1;
+ MLAA::Input input = MLAA::Input(int(hud.GetComboBox(IDC_DETECTIONMODE)->GetSelectedData()));
int n = hud.GetCheckBox(IDC_PROFILE)->GetChecked()? timer->getRepetitionsCount() : 1;
timer->start();
for (int i = 0; i < n; i++) { // This loop is just for profiling.
- if (useDepth)
- mlaa->goDepth(*depthBufferRenderTarget, *finalRenderTargetSRGB, *backbufferRenderTarget, *depthStencil);
- else
- mlaa->goColor(*finalRenderTarget, *finalRenderTargetSRGB, *backbufferRenderTarget, *depthStencil);
+ switch (input) {
+ case MLAA::INPUT_LUMA:
+ case MLAA::INPUT_COLOR:
+ mlaa->go(*finalRenderTarget, *finalRenderTargetSRGB, *backbufferRenderTarget, *depthStencil, input);
+ break;
+ case MLAA::INPUT_DEPTH:
+ mlaa->go(*depthBufferRenderTarget, *finalRenderTargetSRGB, *backbufferRenderTarget, *depthStencil, input);
+ break;
+ }
}
timer->clock(L"MLAA");
} else {
@@ -336,6 +369,9 @@ void CALLBACK onFrameRender(ID3D10Device *device, double time, float elapsedTime
exit(0);
}
+ if (benchmark)
+ doBenchmark();
+
DXUT_BeginPerfEvent(DXUT_PERFEVENTCOLOR, L"HUD / Stats"); // These events are to help PIX identify what the code is doing
drawTextures(device);
drawHud(device, elapsedTime);
@@ -362,6 +398,7 @@ LRESULT CALLBACK msgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, bool
void CALLBACK keyboardProc(UINT nchar, bool keyDown, bool altDown, void *context) {
+ if (keyDown)
switch (nchar) {
case VK_TAB: {
if (keyDown)
@@ -385,6 +422,19 @@ void CALLBACK keyboardProc(UINT nchar, bool keyDown, bool altDown, void *context
}
break;
}
+ case 'X':
+ hud.GetCheckBox(IDC_PROFILE)->SetChecked(!hud.GetCheckBox(IDC_PROFILE)->GetChecked());
+ timer->setEnabled(hud.GetCheckBox(IDC_PROFILE)->GetChecked());
+ break;
+ case 'Z':
+ hud.GetCheckBox(IDC_ANTIALIASING)->SetChecked(!hud.GetCheckBox(IDC_ANTIALIASING)->GetChecked());
+ break;
+ case 'P':
+ hud.GetCheckBox(IDC_PROFILE)->SetChecked(true);
+ timer->setEnabled(true);
+ benchmark = true;
+ benchmarkFile.open("Benchmark.txt", ios_base::out);
+ break;
}
}
@@ -529,10 +579,10 @@ void CALLBACK onGUIEvent(UINT event, int id, CDXUTControl *control, void *contex
slider->GetRange(min, max);
float scale = float(slider->GetValue()) / (max - min);
- mlaa->setMaxSearchSteps(int(scale * 16.0f));
+ mlaa->setMaxSearchSteps(int(round(scale * 98.0f)));
wstringstream s;
- s << L"Max Search Steps: " << int(scale * 16.0f);
+ s << L"Max Search Steps: " << int(round(scale * 98.0f));
hud.GetStatic(IDC_MAXSEARCHSTEPS_LABEL)->SetText(s.str().c_str());
}
break;
@@ -568,8 +618,9 @@ void initApp() {
hud.AddButton(IDC_LOADIMAGE, L"Load image", 35, iY += 24, HUD_WIDTH, 22);
hud.AddComboBox(IDC_DETECTIONMODE, 35, iY += 24, HUD_WIDTH, 22, 0, false);
- hud.GetComboBox(IDC_DETECTIONMODE)->AddItem(L"Color edge det.", (LPVOID) 0);
- hud.GetComboBox(IDC_DETECTIONMODE)->AddItem(L"Depth edge det.", (LPVOID) 1);
+ hud.GetComboBox(IDC_DETECTIONMODE)->AddItem(L"Luma edge det.", (LPVOID) 0);
+ hud.GetComboBox(IDC_DETECTIONMODE)->AddItem(L"Color edge det.", (LPVOID) 1);
+ hud.GetComboBox(IDC_DETECTIONMODE)->AddItem(L"Depth edge det.", (LPVOID) 2);
hud.AddComboBox(IDC_VIEWMODE, 35, iY += 24, HUD_WIDTH, 22, 0, false);
hud.GetComboBox(IDC_VIEWMODE)->AddItem(L"View image", (LPVOID) 0);
@@ -589,7 +640,7 @@ void initApp() {
wstringstream s;
s << L"Max Search Steps: " << commandlineOptions.distance;
hud.AddStatic(IDC_MAXSEARCHSTEPS_LABEL, s.str().c_str(), 35, iY += 24, HUD_WIDTH, 22);
- hud.AddSlider(IDC_MAXSEARCHSTEPS, 35, iY += 24, HUD_WIDTH, 22, 0, 100, int(100.0f * commandlineOptions.distance / 16.0f));
+ hud.AddSlider(IDC_MAXSEARCHSTEPS, 35, iY += 24, HUD_WIDTH, 22, 0, 100, int(100.0f * commandlineOptions.distance / 98.0f));
s = wstringstream();
s << L"Threshold: " << commandlineOptions.threshold;
View
109 dx10/Code/MLAA.cpp → Demo/DX10/Code/MLAA.cpp
@@ -1,22 +1,24 @@
/**
- * Copyright (C) 2010 Jorge Jimenez (jorge@iryoku.com)
- * Copyright (C) 2010 Belen Masia (bmasia@unizar.es)
- * Copyright (C) 2010 Jose I. Echevarria (joseignacioechevarria@gmail.com)
- * Copyright (C) 2010 Fernando Navarro (fernandn@microsoft.com)
- * Copyright (C) 2010 Diego Gutierrez (diegog@unizar.es)
+ * Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
+ * Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
+ * Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
+ * Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
+ * Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the following statement:
- *
- * "Uses Jimenez's MLAA. Copyright (C) 2010 by Jorge Jimenez, Belen Masia,
- * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
- *
+ *
+ * 2. Redistributions in binary form must reproduce the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution:
+ *
+ * "Uses Jimenez's MLAA. Copyright (C) 2011 by Jorge Jimenez, Belen Masia,
+ * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -28,7 +30,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holders.
@@ -68,26 +70,41 @@ using namespace std;
#endif
#pragma endregion
+#pragma region This stuff is for loading headers from resources
+class ID3D10IncludeResource : public ID3D10Include {
+ public:
+ STDMETHOD(Open)(THIS_ D3D_INCLUDE_TYPE, LPCSTR pFileName, LPCVOID, LPCVOID *ppData, UINT *pBytes) {
+ wstringstream s;
+ s << pFileName;
+ HRSRC src = FindResource(GetModuleHandle(NULL), s.str().c_str(), RT_RCDATA);
+ HGLOBAL res = LoadResource(GetModuleHandle(NULL), src);
+
+ *pBytes = SizeofResource(GetModuleHandle(NULL), src);
+ *ppData = (LPCVOID) LockResource(res);
+
+ return S_OK;
+ }
+
+ STDMETHOD(Close)(THIS_ LPCVOID) {
+ return S_OK;
+ }
+};
+#pragma endregion
+
MLAA::MLAA(ID3D10Device *device, int width, int height, const ExternalStorage &storage)
: device(device),
maxSearchSteps(8),
- threshold(0.1f),
- backbufferRenderTarget(NULL) {
+ threshold(0.1f) {
HRESULT hr;
// Setup the defines for compiling the effect.
stringstream s;
s << "float2(1.0 / " << width << ", 1.0 / " << height << ")";
string pixelSizeText = s.str();
- s.str("");
- s << MAX_DISTANCE;
- string maxDistanceText = s.str();
-
D3D10_SHADER_MACRO defines[3] = {
- {"PIXEL_SIZE", pixelSizeText.c_str()},
- {"MAX_DISTANCE", maxDistanceText.c_str()},
+ {"MLAA_PIXEL_SIZE", pixelSizeText.c_str()},
{NULL, NULL}
};
@@ -96,7 +113,8 @@ MLAA::MLAA(ID3D10Device *device, int width, int height, const ExternalStorage &s
* (Yeah, we like all-in-one executables for demos =)
* In case you want it to be loaded from other place change this line accordingly.
*/
- V(D3DX10CreateEffectFromResource(GetModuleHandle(NULL), L"MLAA.fx", NULL, defines, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, device, NULL, NULL, &effect, NULL, NULL));
+ ID3D10IncludeResource includeResource;
+ V(D3DX10CreateEffectFromResource(GetModuleHandle(NULL), L"MLAA.fx", NULL, defines, &includeResource, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, device, NULL, NULL, &effect, NULL, NULL));
// This is for rendering the typical fullscreen quad later on.
D3D10_PASS_DESC desc;
@@ -116,28 +134,26 @@ MLAA::MLAA(ID3D10Device *device, int width, int height, const ExternalStorage &s
blendRenderTarget = new RenderTarget(device, width, height, DXGI_FORMAT_R8G8B8A8_UNORM);
// Load the pre-computed areas texture.
- wstringstream ss;
- ss << L"AreaMap" << MAX_DISTANCE << L".dds";
-
D3DX10_IMAGE_LOAD_INFO info = D3DX10_IMAGE_LOAD_INFO();
info.MipLevels = 1;
info.Format = DXGI_FORMAT_R8G8_UNORM;
- V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), ss.str().c_str(), &info, NULL, &areaMapView, NULL));
+ V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), L"AreaTex.dds", &info, NULL, &areaTexView, NULL));
// Load the pre-computed search length texture.
info.Format = DXGI_FORMAT_R8_UNORM;
- V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), L"SearchLengthMap.dds", &info, NULL, &searchLengthMapView, NULL));
+ V(D3DX10CreateShaderResourceViewFromResource(device, GetModuleHandle(NULL), L"SearchTex.dds", &info, NULL, &searchTexView, NULL));
// Create some handles for techniques and variables.
thresholdVariable = effect->GetVariableByName("threshold")->AsScalar();
maxSearchStepsVariable = effect->GetVariableByName("maxSearchSteps")->AsScalar();
areaTexVariable = effect->GetVariableByName("areaTex")->AsShaderResource();
- searchLengthTexVariable = effect->GetVariableByName("searchLengthTex")->AsShaderResource();
+ searchTexVariable = effect->GetVariableByName("searchTex")->AsShaderResource();
colorTexVariable = effect->GetVariableByName("colorTex")->AsShaderResource();
colorGammaTexVariable = effect->GetVariableByName("colorGammaTex")->AsShaderResource();
depthTexVariable = effect->GetVariableByName("depthTex")->AsShaderResource();
edgesTexVariable = effect->GetVariableByName("edgesTex")->AsShaderResource();
blendTexVariable = effect->GetVariableByName("blendTex")->AsShaderResource();
+ lumaEdgeDetectionTechnique = effect->GetTechniqueByName("LumaEdgeDetection");
colorEdgeDetectionTechnique = effect->GetTechniqueByName("ColorEdgeDetection");
depthEdgeDetectionTechnique = effect->GetTechniqueByName("DepthEdgeDetection");
blendWeightCalculationTechnique = effect->GetTechniqueByName("BlendingWeightCalculation");
@@ -150,17 +166,16 @@ MLAA::~MLAA() {
SAFE_DELETE(quad);
SAFE_DELETE(edgeRenderTarget);
SAFE_DELETE(blendRenderTarget);
- SAFE_RELEASE(areaMapView);
- SAFE_RELEASE(searchLengthMapView);
- SAFE_DELETE(backbufferRenderTarget);
+ SAFE_RELEASE(areaTexView);
+ SAFE_RELEASE(searchTexView);
}
void MLAA::go(ID3D10ShaderResourceView *srcEdges,
ID3D10ShaderResourceView *srcSRGB,
ID3D10RenderTargetView *dst,
- ID3D10DepthStencilView *depthStencil,
- bool isDepth) {
+ ID3D10DepthStencilView *depthStencil,
+ Input input) {
HRESULT hr;
// Save the state.
@@ -182,33 +197,39 @@ MLAA::~MLAA() {
// Setup variables.
V(thresholdVariable->SetFloat(threshold));
- V(maxSearchStepsVariable->SetInt(maxSearchSteps));
+ V(maxSearchStepsVariable->SetFloat(float(maxSearchSteps)));
V(colorTexVariable->SetResource(srcSRGB));
V(edgesTexVariable->SetResource(*edgeRenderTarget));
V(blendTexVariable->SetResource(*blendRenderTarget));
- V(areaTexVariable->SetResource(areaMapView));
- V(searchLengthTexVariable->SetResource(searchLengthMapView));
- if (isDepth) {
+ V(areaTexVariable->SetResource(areaTexView));
+ V(searchTexVariable->SetResource(searchTexView));
+ if (input == INPUT_DEPTH) {
V(depthTexVariable->SetResource(srcEdges));
} else {
V(colorGammaTexVariable->SetResource(srcEdges));
}
// And here we go!
- edgesDetectionPass(depthStencil, isDepth);
+ edgesDetectionPass(depthStencil, input);
blendingWeightsCalculationPass(depthStencil);
neighborhoodBlendingPass(srcSRGB, dst, depthStencil);
}
-void MLAA::edgesDetectionPass(ID3D10DepthStencilView *depthStencil, bool isDepth) {
+void MLAA::edgesDetectionPass(ID3D10DepthStencilView *depthStencil, Input input) {
HRESULT hr;
// Select the technique accordingly.
- if (isDepth) {
- V(depthEdgeDetectionTechnique->GetPassByIndex(0)->Apply(0));
- } else {
- V(colorEdgeDetectionTechnique->GetPassByIndex(0)->Apply(0));
+ switch (input) {
+ case INPUT_LUMA:
+ V(lumaEdgeDetectionTechnique->GetPassByIndex(0)->Apply(0));
+ break;
+ case INPUT_COLOR:
+ V(colorEdgeDetectionTechnique->GetPassByIndex(0)->Apply(0));
+ break;
+ case INPUT_DEPTH:
+ V(depthEdgeDetectionTechnique->GetPassByIndex(0)->Apply(0));
+ break;
}
// Do it!
@@ -241,7 +262,7 @@ void MLAA::neighborhoodBlendingPass(ID3D10ShaderResourceView *src, ID3D10RenderT
// Setup the technique (once again).
V(neighborhoodBlendingTechnique->GetPassByIndex(0)->Apply(0));
- // Yeah! We will finally have the antialiased image :D
+ // Yeah! We finally have the antialiased image!
device->OMSetRenderTargets(1, &dst, depthStencil);
quad->draw();
device->OMSetRenderTargets(0, NULL, NULL);
View
75 dx10/Code/MLAA.h → Demo/DX10/Code/MLAA.h
@@ -1,22 +1,24 @@
/**
- * Copyright (C) 2010 Jorge Jimenez (jorge@iryoku.com)
- * Copyright (C) 2010 Belen Masia (bmasia@unizar.es)
- * Copyright (C) 2010 Jose I. Echevarria (joseignacioechevarria@gmail.com)
- * Copyright (C) 2010 Fernando Navarro (fernandn@microsoft.com)
- * Copyright (C) 2010 Diego Gutierrez (diegog@unizar.es)
+ * Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
+ * Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
+ * Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
+ * Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
+ * Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
- * 2. Redistributions in binary form must reproduce the following statement:
+ * 2. Redistributions in binary form must reproduce the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution:
+ *
+ * "Uses Jimenez's MLAA. Copyright (C) 2011 by Jorge Jimenez, Belen Masia,
+ * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
*
- * "Uses Jimenez's MLAA. Copyright (C) 2010 by Jorge Jimenez, Belen Masia,
- * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
- *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -47,6 +49,8 @@ class MLAA {
public:
class ExternalStorage;
+ enum Input { INPUT_LUMA, INPUT_COLOR, INPUT_DEPTH };
+
/**
* If you have one or two spare DXGI_FORMAT_R8G8B8A8_UNORM render
* targets of the same size as the backbuffer, you may want to pass
@@ -60,13 +64,10 @@ class MLAA {
~MLAA();
/**
- * MLAA processing using color-based edge detection
- * ************************************************
+ * 'srcEdges' should be the input for using for edge detection:
+ * either a depth buffer or a non-sRGB color buffer.
*
- * 'src' and 'srcSRGB' should be views of the src texture, for
- * detecting edges in gamma space and for blending the neighborhood of
- * each pixel in linear space, respectively. Note that 'src' and 'dst'
- * cannot be associated to the same buffer.
+ * 'srcSRGB' should be a sRGB view of the input image'.
*
* IMPORTANT: The stencil component of 'depthStencil' is used to mask
* the zones to be processed. It is assumed to be already cleared to
@@ -77,28 +78,11 @@ class MLAA {
* and restored accordingly. However, we modify but not restore the
* depth-stencil and blend states.
*/
- void goColor(ID3D10ShaderResourceView *src,
- ID3D10ShaderResourceView *srcSRGB,
- ID3D10RenderTargetView *dst,
- ID3D10DepthStencilView *depthStencil)
- { go(src, srcSRGB, dst, depthStencil, false); }
-
- /**
- * MLAA processing using depth-based edge detection
- * ************************************************
- *
- * Same as above, but in this case a depth-based edge detection will be
- * performed.
- *
- * 'depth' should contain the linearized depth buffer to be used for
- * edge detection. Some people seem to work better with non-linearized
- * buffers, so you may want to try that as well.
- */
- void goDepth(ID3D10ShaderResourceView *depth,
- ID3D10ShaderResourceView *srcSRGB,
- ID3D10RenderTargetView *dst,
- ID3D10DepthStencilView *depthStencil)
- { go(depth, srcSRGB, dst, depthStencil, true); }
+ void go(ID3D10ShaderResourceView *srcEdges,
+ ID3D10ShaderResourceView *srcSRGB,
+ ID3D10RenderTargetView *dst,
+ ID3D10DepthStencilView *depthStencil,
+ Input input);
/**
* Maximum length to search for patterns. Each step is two pixels wide.
@@ -137,31 +121,28 @@ class MLAA {
};
private:
- void go(ID3D10ShaderResourceView *srcEdges, ID3D10ShaderResourceView *srcSRGB, ID3D10RenderTargetView *dst, ID3D10DepthStencilView *depthStencil, bool isDepth);
- void edgesDetectionPass(ID3D10DepthStencilView *depthStencil, bool isDepth);
+ void edgesDetectionPass(ID3D10DepthStencilView *depthStencil, Input input);
void blendingWeightsCalculationPass(ID3D10DepthStencilView *depthStencil);
void neighborhoodBlendingPass(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst, ID3D10DepthStencilView *depthStencil);
void copy(ID3D10ShaderResourceView *src, ID3D10RenderTargetView *dst);
- static const int MAX_DISTANCE = 33; // We have precomputed textures for 9, 17, 33, 65 and 129.
-
ID3D10Device *device;
ID3D10Effect *effect;
Quad *quad;
RenderTarget *edgeRenderTarget;
RenderTarget *blendRenderTarget;
- BackbufferRenderTarget *backbufferRenderTarget;
- ID3D10ShaderResourceView *areaMapView;
- ID3D10ShaderResourceView *searchLengthMapView;
+ ID3D10ShaderResourceView *areaTexView;
+ ID3D10ShaderResourceView *searchTexView;
ID3D10EffectScalarVariable *thresholdVariable;
ID3D10EffectScalarVariable *maxSearchStepsVariable;
- ID3D10EffectShaderResourceVariable *areaTexVariable, *searchLengthTexVariable,
+ ID3D10EffectShaderResourceVariable *areaTexVariable, *searchTexVariable,
*colorTexVariable, *colorGammaTexVariable, *depthTexVariable,
*edgesTexVariable, *blendTexVariable;
- ID3D10EffectTechnique *colorEdgeDetectionTechnique,
+ ID3D10EffectTechnique *lumaEdgeDetectionTechnique,
+ *colorEdgeDetectionTechnique,
*depthEdgeDetectionTechnique,
*blendWeightCalculationTechnique,
*neighborhoodBlendingTechnique;
View
0 dx10/Code/RenderTarget.cpp → Demo/DX10/Code/RenderTarget.cpp
File renamed without changes.
View
0 dx10/Code/RenderTarget.h → Demo/DX10/Code/RenderTarget.h
File renamed without changes.
View
2 dx10/Code/Timer.cpp → Demo/DX10/Code/Timer.cpp
@@ -170,7 +170,7 @@ wostream &operator<<(wostream &out, const Timer &timer) {
const wstring &name = section->first;
float mean = section->second.mean / timer.repetitionCount;
float accum = timer.accum / timer.repetitionCount;
- out << name << L" : " << mean << L"s : " << int(100.0f * mean / accum) << L"% : " << int(1.0 / mean) << L"fps [" << int(100.0f * section->second.completed) << L"%]" << endl;
+ out << name << L" : " << 1000.0f * mean << L"ms : " << int(100.0f * mean / accum) << L"% : " << int(1.0 / mean) << L"fps [" << int(100.0f * section->second.completed) << L"%]" << endl;
}
return out;
}
View
2 dx10/Code/Timer.h → Demo/DX10/Code/Timer.h
@@ -75,6 +75,8 @@ class Timer {
void setRepetitionsCount(int repetitionCount) { this->repetitionCount = repetitionCount; }
int getRepetitionsCount() const { return repetitionCount; }
+ float getSection(const std::wstring &name) { return 1000.0f * sections[name].mean / repetitionCount; }
+
friend std::wostream &operator<<(std::wostream &out, const Timer &timer);
private:
View
0 dx10/DXUT/Core/DXUT.cpp → Demo/DX10/DXUT/Core/DXUT.cpp
File renamed without changes.
View
0 dx10/DXUT/Core/DXUT.h → Demo/DX10/DXUT/Core/DXUT.h
File renamed without changes.
View
0 dx10/DXUT/Core/DXUTCore_2005.sln → Demo/DX10/DXUT/Core/DXUTCore_2005.sln
File renamed without changes.
View
0 dx10/DXUT/Core/DXUTCore_2005.vcproj → Demo/DX10/DXUT/Core/DXUTCore_2005.vcproj
File renamed without changes.
View
0 dx10/DXUT/Core/DXUTCore_2008.sln → Demo/DX10/DXUT/Core/DXUTCore_2008.sln
File renamed without changes.
View
0 dx10/DXUT/Core/DXUTCore_2008.vcproj → Demo/DX10/DXUT/Core/DXUTCore_2008.vcproj
File renamed without changes.
View
0 dx10/DXUT/Core/DXUTenum.cpp → Demo/DX10/DXUT/Core/DXUTenum.cpp
File renamed without changes.
View
0 dx10/DXUT/Core/DXUTenum.h → Demo/DX10/DXUT/Core/DXUTenum.h
File renamed without changes.
View
0 dx10/DXUT/Core/DXUTmisc.cpp → Demo/DX10/DXUT/Core/DXUTmisc.cpp
File renamed without changes.
View
0 dx10/DXUT/Core/DXUTmisc.h → Demo/DX10/DXUT/Core/DXUTmisc.h
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTLockFreePipe.h → Demo/DX10/DXUT/Optional/DXUTLockFreePipe.h
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTOptional_2005.sln → .../DX10/DXUT/Optional/DXUTOptional_2005.sln
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTOptional_2005.vcproj → ...10/DXUT/Optional/DXUTOptional_2005.vcproj
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTOptional_2008.sln → .../DX10/DXUT/Optional/DXUTOptional_2008.sln
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTOptional_2008.vcproj → ...10/DXUT/Optional/DXUTOptional_2008.vcproj
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTShapes.cpp → Demo/DX10/DXUT/Optional/DXUTShapes.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTShapes.h → Demo/DX10/DXUT/Optional/DXUTShapes.h
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTcamera.cpp → Demo/DX10/DXUT/Optional/DXUTcamera.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTcamera.h → Demo/DX10/DXUT/Optional/DXUTcamera.h
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTgui.cpp → Demo/DX10/DXUT/Optional/DXUTgui.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTgui.h → Demo/DX10/DXUT/Optional/DXUTgui.h
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTguiIME.cpp → Demo/DX10/DXUT/Optional/DXUTguiIME.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTguiIME.h → Demo/DX10/DXUT/Optional/DXUTguiIME.h
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTres.cpp → Demo/DX10/DXUT/Optional/DXUTres.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTres.h → Demo/DX10/DXUT/Optional/DXUTres.h
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTsettingsdlg.cpp → Demo/DX10/DXUT/Optional/DXUTsettingsdlg.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTsettingsdlg.h → Demo/DX10/DXUT/Optional/DXUTsettingsdlg.h
File renamed without changes.
View
0 dx9/DXUT/Optional/ImeUi.cpp → Demo/DX10/DXUT/Optional/ImeUi.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/ImeUi.h → Demo/DX10/DXUT/Optional/ImeUi.h
File renamed without changes.
View
0 dx10/DXUT/Optional/SDKmesh.cpp → Demo/DX10/DXUT/Optional/SDKmesh.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/SDKmesh.h → Demo/DX10/DXUT/Optional/SDKmesh.h
File renamed without changes.
View
0 dx10/DXUT/Optional/SDKmisc.cpp → Demo/DX10/DXUT/Optional/SDKmisc.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/SDKmisc.h → Demo/DX10/DXUT/Optional/SDKmisc.h
File renamed without changes.
View
0 dx9/DXUT/Optional/SDKsound.cpp → Demo/DX10/DXUT/Optional/SDKsound.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/SDKsound.h → Demo/DX10/DXUT/Optional/SDKsound.h
File renamed without changes.
View
0 dx10/DXUT/Optional/SDKwavefile.cpp → Demo/DX10/DXUT/Optional/SDKwavefile.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/SDKwavefile.h → Demo/DX10/DXUT/Optional/SDKwavefile.h
File renamed without changes.
View
0 dx9/DXUT/Optional/directx.ico → Demo/DX10/DXUT/Optional/directx.ico
File renamed without changes.
View
0 dx10/Demo DX10.sln → Demo/DX10/Demo DX10.sln
File renamed without changes.
View
11 dx10/Demo.rc → Demo/DX10/Demo.rc
@@ -2,6 +2,10 @@
MLAA.fx RCDATA Shaders\MLAA.fx
+MLAA.h RCDATA "..\\..\\MLAA.h"
+AreaTex.dds RCDATA "..\\..\\AreaTex.dds"
+SearchTex.dds RCDATA "..\\..\\SearchTex.dds"
+
Unigine01.png RCDATA Media\Images\Unigine01.png
Unigine02.png RCDATA Media\Images\Unigine02.png
Unigine03.png RCDATA Media\Images\Unigine03.png
@@ -18,10 +22,3 @@ Unigine05.dds RCDATA Media\Images\Unigine05.dds
Unigine06.dds RCDATA Media\Images\Unigine06.dds
Unigine07.dds RCDATA Media\Images\Unigine07.dds
-AreaMap9.dds RCDATA Media\AreaMap9.dds
-AreaMap17.dds RCDATA Media\AreaMap17.dds
-AreaMap33.dds RCDATA Media\AreaMap33.dds
-AreaMap65.dds RCDATA Media\AreaMap65.dds
-AreaMap129.dds RCDATA Media\AreaMap129.dds
-
-SearchLengthMap.dds RCDATA Media\SearchLengthMap.dds
View
7 dx10/Demo.vcxproj → Demo/DX10/Demo.vcxproj
@@ -128,6 +128,7 @@
<ClCompile Include="Code\Timer.cpp" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="..\..\MLAA.h" />
<ClInclude Include="Code\Copy.h" />
<ClInclude Include="DXUT\Core\DXUT.h" />
<ClInclude Include="DXUT\Optional\DXUTcamera.h" />
@@ -144,12 +145,14 @@
</ItemGroup>
<ItemGroup>
<CustomBuild Include="Shaders\MLAA.fx">
- <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">fxc /Od /Zi /Tfx_4_0 /nologo /Fo"$(IntDir)%(Filename).fxo" "%(FullPath)"
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">fxc /Od /Zi /Tfx_4_0 /nologo /I ../.. /Fo"$(IntDir)%(Filename).fxo" /Fc"$(IntDir)%(Filename).asm" "%(FullPath)"
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)%(Filename).fxo</Outputs>
- <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">fxc /Tfx_4_0 /nologo /Fo"$(IntDir)%(Filename).fxo" "%(FullPath)"
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">fxc /Tfx_4_0 /nologo /I ../.. /Fo"$(IntDir)%(Filename).fxo" /Fc"$(IntDir)%(Filename).asm" "%(FullPath)"
</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)%(Filename).fxo</Outputs>
+ <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\MLAA.h</AdditionalInputs>
+ <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\MLAA.h</AdditionalInputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
View
3 dx10/Demo.vcxproj.filters → Demo/DX10/Demo.vcxproj.filters
@@ -98,6 +98,9 @@
<ClInclude Include="Code\MLAA.h">
<Filter>Headers</Filter>
</ClInclude>
+ <ClInclude Include="..\..\MLAA.h">
+ <Filter>Shaders</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="Shaders\MLAA.fx">
View
0 dx9/Icon.ico → Demo/DX10/Icon.ico
File renamed without changes.
View
0 dx9/Media/Images/Unigine01.dds → Demo/DX10/Media/Images/Unigine01.dds
File renamed without changes.
View
0 dx9/Media/Images/Unigine01.png → Demo/DX10/Media/Images/Unigine01.png
File renamed without changes
View
0 dx10/Media/Images/Unigine02.dds → Demo/DX10/Media/Images/Unigine02.dds
File renamed without changes.
View
0 dx10/Media/Images/Unigine02.png → Demo/DX10/Media/Images/Unigine02.png
File renamed without changes
View
0 dx10/Media/Images/Unigine03.dds → Demo/DX10/Media/Images/Unigine03.dds
File renamed without changes.
View
0 dx10/Media/Images/Unigine03.png → Demo/DX10/Media/Images/Unigine03.png
File renamed without changes
View
0 dx10/Media/Images/Unigine04.dds → Demo/DX10/Media/Images/Unigine04.dds
File renamed without changes.
View
0 dx10/Media/Images/Unigine04.png → Demo/DX10/Media/Images/Unigine04.png
File renamed without changes
View
0 dx10/Media/Images/Unigine05.dds → Demo/DX10/Media/Images/Unigine05.dds
File renamed without changes.
View
0 dx10/Media/Images/Unigine05.png → Demo/DX10/Media/Images/Unigine05.png
File renamed without changes
View
0 dx10/Media/Images/Unigine06.dds → Demo/DX10/Media/Images/Unigine06.dds
File renamed without changes.
View
0 dx10/Media/Images/Unigine06.png → Demo/DX10/Media/Images/Unigine06.png
File renamed without changes
View
0 dx10/Media/Images/Unigine07.dds → Demo/DX10/Media/Images/Unigine07.dds
File renamed without changes.
View
0 dx10/Media/Images/Unigine07.png → Demo/DX10/Media/Images/Unigine07.png
File renamed without changes
View
0 dx10/README.txt → Demo/DX10/README.txt
File renamed without changes.
View
222 Demo/DX10/Shaders/MLAA.fx
@@ -0,0 +1,222 @@
+/**
+ * Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
+ * Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
+ * Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
+ * Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
+ * Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution:
+ *
+ * "Uses Jimenez's MLAA. Copyright (C) 2011 by Jorge Jimenez, Belen Masia,
+ * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are
+ * those of the authors and should not be interpreted as representing official
+ * policies, either expressed or implied, of the copyright holders.
+ */
+
+
+// Some configuration variables:
+float threshold;
+float maxSearchSteps;
+
+/**
+ * Setup mandatory defines. Use a real macro here for maximum performance!
+ */
+#ifndef MLAA_PIXEL_SIZE // It's actually set on runtime, this is for compilation time syntax checking.
+#define MLAA_PIXEL_SIZE float2(1.0 / 1280.0, 1.0 / 720.0)
+#endif
+
+/**
+ * Setup optional defines.
+ */
+#define MLAA_THRESHOLD threshold
+#define MLAA_MAX_SEARCH_STEPS maxSearchSteps
+
+// Set the HLSL version:
+#define MLAA_HLSL_4 1
+
+// And include our header!
+#include "MLAA.h"
+
+
+/**
+ * DepthStencilState's and company.
+ */
+DepthStencilState DisableDepthStencil {
+ DepthEnable = FALSE;
+ StencilEnable = FALSE;
+};
+
+DepthStencilState DisableDepthReplaceStencil {
+ DepthEnable = FALSE;
+ StencilEnable = TRUE;
+ FrontFaceStencilPass = REPLACE;
+};
+
+DepthStencilState DisableDepthUseStencil {
+ DepthEnable = FALSE;
+ StencilEnable = TRUE;
+ FrontFaceStencilFunc = EQUAL;
+};
+
+BlendState NoBlending {
+ AlphaToCoverageEnable = FALSE;
+ BlendEnable[0] = FALSE;
+};
+
+
+/**
+ * Input textures.
+ */
+Texture2D colorTex;
+Texture2D colorGammaTex;
+Texture2D depthTex;
+Texture2D edgesTex;
+Texture2D blendTex;
+Texture2D areaTex;
+Texture2D searchTex;
+
+
+/**
+ * Function wrappers
+ */
+void DX10_MLAAEdgeDetectionVS(float4 position : POSITION,
+ out float4 svPosition : SV_POSITION,
+ inout float2 texcoord : TEXCOORD0,
+ out float4 offset[2] : TEXCOORD1) {
+ MLAAEdgeDetectionVS(position, svPosition, texcoord, offset);
+}
+
+void DX10_MLAABlendWeightCalculationVS(float4 position : POSITION,
+ out float4 svPosition : SV_POSITION,
+ inout float2 texcoord : TEXCOORD0,
+ out float4 offset[2] : TEXCOORD1) {
+ MLAABlendWeightCalculationVS(position, svPosition, texcoord, offset);
+}
+
+void DX10_MLAANeighborhoodBlendingVS(float4 position : POSITION,
+ out float4 svPosition : SV_POSITION,
+ inout float2 texcoord : TEXCOORD0,
+ out float4 offset[2] : TEXCOORD1) {
+ MLAANeighborhoodBlendingVS(position, svPosition, texcoord, offset);
+}
+
+
+float4 DX10_MLAALumaEdgeDetectionPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D colorGammaTex) : SV_TARGET {
+ return MLAALumaEdgeDetectionPS(texcoord, offset, colorGammaTex);
+}
+
+float4 DX10_MLAAColorEdgeDetectionPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D colorGammaTex) : SV_TARGET {
+ return MLAAColorEdgeDetectionPS(texcoord, offset, colorGammaTex);
+}
+
+float4 DX10_MLAADepthEdgeDetectionPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D depthTex) : SV_TARGET {
+ return MLAADepthEdgeDetectionPS(texcoord, offset, depthTex);
+}
+
+float4 DX10_MLAABlendingWeightCalculationPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D edgesTex,
+ uniform MLAATexture2D areaTex,
+ uniform MLAATexture2D searchTex) : SV_TARGET {
+ return MLAABlendingWeightCalculationPS(texcoord, offset, edgesTex, areaTex, searchTex);
+}
+
+float4 DX10_MLAANeighborhoodBlendingPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D colorTex,
+ uniform MLAATexture2D blendTex) : SV_TARGET {
+ return MLAANeighborhoodBlendingPS(texcoord, offset, colorTex, blendTex);
+}
+
+
+/**
+ * Time for some techniques!
+ */
+technique10 LumaEdgeDetection {
+ pass LumaEdgeDetection {
+ SetVertexShader(CompileShader(vs_4_0, DX10_MLAAEdgeDetectionVS()));
+ SetGeometryShader(NULL);
+ SetPixelShader(CompileShader(ps_4_0, DX10_MLAALumaEdgeDetectionPS(colorGammaTex)));
+
+ SetDepthStencilState(DisableDepthReplaceStencil, 1);
+ SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
+ }
+}
+
+technique10 ColorEdgeDetection {
+ pass ColorEdgeDetection {
+ SetVertexShader(CompileShader(vs_4_0, DX10_MLAAEdgeDetectionVS()));
+ SetGeometryShader(NULL);
+ SetPixelShader(CompileShader(ps_4_0, DX10_MLAAColorEdgeDetectionPS(colorGammaTex)));
+
+ SetDepthStencilState(DisableDepthReplaceStencil, 1);
+ SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
+ }
+}
+
+technique10 DepthEdgeDetection {
+ pass DepthEdgeDetection {
+ SetVertexShader(CompileShader(vs_4_0, DX10_MLAAEdgeDetectionVS()));
+ SetGeometryShader(NULL);
+ SetPixelShader(CompileShader(ps_4_0, DX10_MLAADepthEdgeDetectionPS(depthTex)));
+
+ SetDepthStencilState(DisableDepthReplaceStencil, 1);
+ SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
+ }
+}
+
+technique10 BlendingWeightCalculation {
+ pass BlendingWeightCalculation {
+ SetVertexShader(CompileShader(vs_4_0, DX10_MLAABlendWeightCalculationVS()));
+ SetGeometryShader(NULL);
+ SetPixelShader(CompileShader(ps_4_0, DX10_MLAABlendingWeightCalculationPS(edgesTex, areaTex, searchTex)));
+
+ SetDepthStencilState(DisableDepthUseStencil, 1);
+ SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
+ }
+}
+
+technique10 NeighborhoodBlending {
+ pass NeighborhoodBlending {
+ SetVertexShader(CompileShader(vs_4_0, DX10_MLAANeighborhoodBlendingVS()));
+ SetGeometryShader(NULL);
+ SetPixelShader(CompileShader(ps_4_0, DX10_MLAANeighborhoodBlendingPS(colorTex, blendTex)));
+
+ SetDepthStencilState(DisableDepthUseStencil, 1);
+ SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
+ }
+}
View
2 dx9/Code/Demo.cpp → Demo/DX9/Code/Demo.cpp
@@ -106,7 +106,7 @@ HRESULT CALLBACK onResetDevice(IDirect3DDevice9 *device, const D3DSURFACE_DESC *
timer->setEnabled(hud.GetCheckBox(IDC_PROFILE)->GetChecked());
timer->setRepetitionsCount(100);
- mlaa = new MLAA(device, desc->Width, desc->Height, 8);
+ mlaa = new MLAA(device, desc->Width, desc->Height);
V(device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbufferSurface));
View
100 dx9/Code/MLAA.cpp → Demo/DX9/Code/MLAA.cpp
@@ -1,22 +1,24 @@
/**
- * Copyright (C) 2010 Jorge Jimenez (jorge@iryoku.com)
- * Copyright (C) 2010 Belen Masia (bmasia@unizar.es)
- * Copyright (C) 2010 Jose I. Echevarria (joseignacioechevarria@gmail.com)
- * Copyright (C) 2010 Fernando Navarro (fernandn@microsoft.com)
- * Copyright (C) 2010 Diego Gutierrez (diegog@unizar.es)
+ * Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
+ * Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
+ * Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
+ * Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
+ * Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the following statement:
- *
- * "Uses Jimenez's MLAA. Copyright (C) 2010 by Jorge Jimenez, Belen Masia,
- * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
- *
+ *
+ * 2. Redistributions in binary form must reproduce the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution:
+ *
+ * "Uses Jimenez's MLAA. Copyright (C) 2011 by Jorge Jimenez, Belen Masia,
+ * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -28,7 +30,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holders.
@@ -68,33 +70,42 @@ using namespace std;
#endif
#pragma endregion
+#pragma region This stuff is for loading headers from resources
+class ID3D10IncludeResource : public ID3DXInclude {
+ public:
+ STDMETHOD(Open)(THIS_ D3DXINCLUDE_TYPE, LPCSTR pFileName, LPCVOID, LPCVOID *ppData, UINT *pBytes) {
+ wstringstream s;
+ s << pFileName;
+ HRSRC src = FindResource(GetModuleHandle(NULL), s.str().c_str(), RT_RCDATA);
+ HGLOBAL res = LoadResource(GetModuleHandle(NULL), src);
+
+ *pBytes = SizeofResource(GetModuleHandle(NULL), src);
+ *ppData = (LPCVOID) LockResource(res);
+
+ return S_OK;
+ }
+
+ STDMETHOD(Close)(THIS_ LPCVOID) {
+ return S_OK;
+ }
+};
+#pragma endregion
+
-MLAA::MLAA(IDirect3DDevice9 *device, int width, int height, int maxSearchSteps, const ExternalStorage &storage)
+MLAA::MLAA(IDirect3DDevice9 *device, int width, int height, const ExternalStorage &storage)
: device(device),
threshold(0.1f),
+ maxSearchSteps(8),
width(width), height(height) {
HRESULT hr;
- if (maxSearchSteps * 2 >= MAX_DISTANCE)
- throw logic_error("come on, this is too much for me :S");
-
// Setup the defines for compiling the effect.
stringstream s;
s << "float2(1.0 / " << width << ", 1.0 / " << height << ")";
string pixelSizeText = s.str();
- s.str("");
- s << maxSearchSteps;
- string maxSearchStepsText = s.str();
-
- s.str("");
- s << MAX_DISTANCE;
- string maxDistanceText = s.str();
-
D3DXMACRO defines[4] = {
- {"PIXEL_SIZE", pixelSizeText.c_str()},
- {"MAX_SEARCH_STEPS", maxSearchStepsText.c_str()},
- {"MAX_DISTANCE", maxDistanceText.c_str()},
+ {"MLAA_PIXEL_SIZE", pixelSizeText.c_str()},
{NULL, NULL}
};
@@ -109,7 +120,8 @@ MLAA::MLAA(IDirect3DDevice9 *device, int width, int height, int maxSearchSteps,
* (Yeah, we like all-in-one executables for demos =)
* In case you want it to be loaded from other place change this line accordingly.
*/
- V(D3DXCreateEffectFromResource(device, NULL, L"MLAA.fx", defines, NULL, flags, NULL, &effect, NULL));
+ ID3D10IncludeResource includeResource;
+ V(D3DXCreateEffectFromResource(device, NULL, L"MLAA.fx", defines, &includeResource, flags, NULL, &effect, NULL));
// Vertex declaration for rendering the typical fullscreen quad later on.
const D3DVERTEXELEMENT9 vertexElements[3] = {
@@ -144,23 +156,22 @@ MLAA::MLAA(IDirect3DDevice9 *device, int width, int height, int maxSearchSteps,
// Load the pre-computed areas texture.
// For some obscure reason, if if we use D3DX_DEFAULT as the width and height parameters of D3DXCreateTextureFromResourceEx, the texture gets scaled down.
D3DXIMAGE_INFO info;
- wstringstream ss;
- ss << L"AreaMap" << MAX_DISTANCE << L".dds";
- V(D3DXGetImageInfoFromResource(NULL, ss.str().c_str(), &info));
- V(D3DXCreateTextureFromResourceEx(device, NULL, ss.str().c_str(), info.Width, info.Height, 1, 0, D3DFMT_A8L8, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, &info, NULL, &areaTexture));
+ V(D3DXGetImageInfoFromResource(NULL, L"AreaTex.dds", &info));
+ V(D3DXCreateTextureFromResourceEx(device, NULL, L"AreaTex.dds", info.Width, info.Height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, &info, NULL, &areaTexture));
// Load the pre-computed search length texture.
- V(D3DXGetImageInfoFromResource(NULL, L"SearchLengthMap.dds", &info));
- V(D3DXCreateTextureFromResourceEx(device, NULL, L"SearchLengthMap.dds", info.Width, info.Height, 1, 0, D3DFMT_L8, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, &info, NULL, &searchLengthTexture));
+ V(D3DXGetImageInfoFromResource(NULL, L"SearchTex.dds", &info));
+ V(D3DXCreateTextureFromResourceEx(device, NULL, L"SearchTex.dds", info.Width, info.Height, 1, 0, D3DFMT_L8, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, &info, NULL, &searchTexture));
// Create some handles for techniques and variables.
thresholdHandle = effect->GetParameterByName(NULL, "threshold");
- areaTexHandle = effect->GetParameterByName(NULL, "areaTex");
- searchLengthTexHandle = effect->GetParameterByName(NULL, "searchLengthTex");
- colorTexHandle = effect->GetParameterByName(NULL, "colorTex");
- depthTexHandle = effect->GetParameterByName(NULL, "depthTex");
- edgesTexHandle = effect->GetParameterByName(NULL, "edgesTex");
- blendTexHandle = effect->GetParameterByName(NULL, "blendTex");
+ maxSearchStepsHandle = effect->GetParameterByName(NULL, "maxSearchSteps");
+ areaTexHandle = effect->GetParameterByName(NULL, "areaTex2D");
+ searchTexHandle = effect->GetParameterByName(NULL, "searchTex2D");
+ colorTexHandle = effect->GetParameterByName(NULL, "colorTex2D");
+ depthTexHandle = effect->GetParameterByName(NULL, "depthTex2D");
+ edgesTexHandle = effect->GetParameterByName(NULL, "edgesTex2D");
+ blendTexHandle = effect->GetParameterByName(NULL, "blendTex2D");
colorEdgeDetectionHandle = effect->GetTechniqueByName("ColorEdgeDetection");
depthEdgeDetectionHandle = effect->GetTechniqueByName("DepthEdgeDetection");
blendWeightCalculationHandle = effect->GetTechniqueByName("BlendWeightCalculation");
@@ -183,7 +194,7 @@ MLAA::~MLAA() {
}
SAFE_RELEASE(areaTexture);
- SAFE_RELEASE(searchLengthTexture);
+ SAFE_RELEASE(searchTexture);
}
@@ -211,6 +222,7 @@ void MLAA::edgesDetectionPass(IDirect3DTexture9 *src, IDirect3DTexture9 *depth)
// Setup variables.
V(effect->SetFloat(thresholdHandle, threshold));
+ V(effect->SetFloat(maxSearchStepsHandle, float(maxSearchSteps)));
V(effect->SetTexture(colorTexHandle, src));
V(effect->SetTexture(depthTexHandle, depth));
@@ -242,7 +254,7 @@ void MLAA::blendingWeightsCalculationPass() {
// Setup the variables and the technique (yet again).
V(effect->SetTexture(edgesTexHandle, edgeTexture));
V(effect->SetTexture(areaTexHandle, areaTexture));
- V(effect->SetTexture(searchLengthTexHandle, searchLengthTexture));
+ V(effect->SetTexture(searchTexHandle, searchTexture));
V(effect->SetTechnique(blendWeightCalculationHandle));
// And here we go!
View
45 dx9/Code/MLAA.h → Demo/DX9/Code/MLAA.h
@@ -1,22 +1,24 @@
/**
- * Copyright (C) 2010 Jorge Jimenez (jorge@iryoku.com)
- * Copyright (C) 2010 Belen Masia (bmasia@unizar.es)
- * Copyright (C) 2010 Jose I. Echevarria (joseignacioechevarria@gmail.com)
- * Copyright (C) 2010 Fernando Navarro (fernandn@microsoft.com)
- * Copyright (C) 2010 Diego Gutierrez (diegog@unizar.es)
+ * Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
+ * Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
+ * Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
+ * Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
+ * Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
- * 2. Redistributions in binary form must reproduce the following statement:
+ * 2. Redistributions in binary form must reproduce the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution:
+ *
+ * "Uses Jimenez's MLAA. Copyright (C) 2011 by Jorge Jimenez, Belen Masia,
+ * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
*
- * "Uses Jimenez's MLAA. Copyright (C) 2010 by Jorge Jimenez, Belen Masia,
- * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
- *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -28,7 +30,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
- *
+ *
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holders.
@@ -59,7 +61,7 @@ class MLAA {
* By default, two render targets will be created for storing
* intermediate calculations.
*/
- MLAA(IDirect3DDevice9 *device, int width, int height, int maxSearchSteps,
+ MLAA(IDirect3DDevice9 *device, int width, int height,
const ExternalStorage &storage=ExternalStorage());
~MLAA();
@@ -97,6 +99,12 @@ class MLAA {
void go(IDirect3DTexture9 *src,
IDirect3DSurface9 *dst,
IDirect3DTexture9 *depth);
+
+ /**
+ * Maximum length to search for patterns. Each step is two pixels wide.
+ */
+ int getMaxSearchSteps() const { return maxSearchSteps; }
+ void setMaxSearchSteps(int maxSearchSteps) { this->maxSearchSteps = maxSearchSteps; }
/**
* Threshold for the edge detection.
@@ -128,8 +136,6 @@ class MLAA {
void neighborhoodBlendingPass(IDirect3DTexture9 *src, IDirect3DSurface9 *dst);
void quad(int width, int height);
- static const int MAX_DISTANCE = 33; // We have precomputed textures for 9, 17, 33, 65 and 129.
-
IDirect3DDevice9 *device;
ID3DXEffect *effect;
IDirect3DVertexDeclaration9 *vertexDeclaration;
@@ -143,15 +149,16 @@ class MLAA {
bool releaseBlendResources;
IDirect3DTexture9 *areaTexture;
- IDirect3DTexture9 *searchLengthTexture;
+ IDirect3DTexture9 *searchTexture;
- D3DXHANDLE thresholdHandle;
- D3DXHANDLE areaTexHandle, searchLengthTexHandle;
+ D3DXHANDLE thresholdHandle, maxSearchStepsHandle;
+ D3DXHANDLE areaTexHandle, searchTexHandle;
D3DXHANDLE colorTexHandle, depthTexHandle;
D3DXHANDLE edgesTexHandle, blendTexHandle;
D3DXHANDLE colorEdgeDetectionHandle, depthEdgeDetectionHandle,
blendWeightCalculationHandle, neighborhoodBlendingHandle;
-
+
+ int maxSearchSteps;
float threshold;
int width, height;
};
View
0 dx9/Code/Timer.cpp → Demo/DX9/Code/Timer.cpp
File renamed without changes.
View
0 dx9/Code/Timer.h → Demo/DX9/Code/Timer.h
File renamed without changes.
View
0 dx9/DXUT/Core/DXUT.cpp → Demo/DX9/DXUT/Core/DXUT.cpp
File renamed without changes.
View
0 dx9/DXUT/Core/DXUT.h → Demo/DX9/DXUT/Core/DXUT.h
File renamed without changes.
View
0 dx9/DXUT/Core/DXUT_2008.sln → Demo/DX9/DXUT/Core/DXUT_2008.sln
File renamed without changes.
View
0 dx9/DXUT/Core/DXUT_2008.vcproj → Demo/DX9/DXUT/Core/DXUT_2008.vcproj
File renamed without changes.
View
0 dx9/DXUT/Core/DXUT_2010.sln → Demo/DX9/DXUT/Core/DXUT_2010.sln
File renamed without changes.
View
0 dx9/DXUT/Core/DXUT_2010.vcxproj → Demo/DX9/DXUT/Core/DXUT_2010.vcxproj
File renamed without changes.
View
0 dx9/DXUT/Core/DXUT_2010.vcxproj.filters → Demo/DX9/DXUT/Core/DXUT_2010.vcxproj.filters
File renamed without changes.
View
0 dx9/DXUT/Core/DXUTenum.cpp → Demo/DX9/DXUT/Core/DXUTenum.cpp
File renamed without changes.
View
0 dx9/DXUT/Core/DXUTenum.h → Demo/DX9/DXUT/Core/DXUTenum.h
File renamed without changes.
View
0 dx9/DXUT/Core/DXUTmisc.cpp → Demo/DX9/DXUT/Core/DXUTmisc.cpp
File renamed without changes.
View
0 dx9/DXUT/Core/DXUTmisc.h → Demo/DX9/DXUT/Core/DXUTmisc.h
File renamed without changes.
View
0 dx9/DXUT/Core/dpiaware.manifest → Demo/DX9/DXUT/Core/dpiaware.manifest
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTLockFreePipe.h → Demo/DX9/DXUT/Optional/DXUTLockFreePipe.h
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTOpt_2008.sln → Demo/DX9/DXUT/Optional/DXUTOpt_2008.sln
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTOpt_2008.vcproj → Demo/DX9/DXUT/Optional/DXUTOpt_2008.vcproj
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTOpt_2010.sln → Demo/DX9/DXUT/Optional/DXUTOpt_2010.sln
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTOpt_2010.vcxproj → Demo/DX9/DXUT/Optional/DXUTOpt_2010.vcxproj
File renamed without changes.
View
0 ...XUT/Optional/DXUTOpt_2010.vcxproj.filters → ...XUT/Optional/DXUTOpt_2010.vcxproj.filters
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTShapes.cpp → Demo/DX9/DXUT/Optional/DXUTShapes.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTShapes.h → Demo/DX9/DXUT/Optional/DXUTShapes.h
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTcamera.cpp → Demo/DX9/DXUT/Optional/DXUTcamera.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTcamera.h → Demo/DX9/DXUT/Optional/DXUTcamera.h
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTgui.cpp → Demo/DX9/DXUT/Optional/DXUTgui.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTgui.h → Demo/DX9/DXUT/Optional/DXUTgui.h
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTguiIME.cpp → Demo/DX9/DXUT/Optional/DXUTguiIME.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTguiIME.h → Demo/DX9/DXUT/Optional/DXUTguiIME.h
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTres.cpp → Demo/DX9/DXUT/Optional/DXUTres.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTres.h → Demo/DX9/DXUT/Optional/DXUTres.h
File renamed without changes.
View
0 dx9/DXUT/Optional/DXUTsettingsdlg.cpp → Demo/DX9/DXUT/Optional/DXUTsettingsdlg.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/DXUTsettingsdlg.h → Demo/DX9/DXUT/Optional/DXUTsettingsdlg.h
File renamed without changes.
View
0 dx10/DXUT/Optional/ImeUi.cpp → Demo/DX9/DXUT/Optional/ImeUi.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/ImeUi.h → Demo/DX9/DXUT/Optional/ImeUi.h
File renamed without changes.
View
0 dx9/DXUT/Optional/SDKmesh.cpp → Demo/DX9/DXUT/Optional/SDKmesh.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/SDKmesh.h → Demo/DX9/DXUT/Optional/SDKmesh.h
File renamed without changes.
View
0 dx9/DXUT/Optional/SDKmisc.cpp → Demo/DX9/DXUT/Optional/SDKmisc.cpp
File renamed without changes.
View
0 dx9/DXUT/Optional/SDKmisc.h → Demo/DX9/DXUT/Optional/SDKmisc.h
File renamed without changes.
View
0 dx10/DXUT/Optional/SDKsound.cpp → Demo/DX9/DXUT/Optional/SDKsound.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/SDKsound.h → Demo/DX9/DXUT/Optional/SDKsound.h
File renamed without changes.
View
0 dx9/DXUT/Optional/SDKwavefile.cpp → Demo/DX9/DXUT/Optional/SDKwavefile.cpp
File renamed without changes.
View
0 dx10/DXUT/Optional/SDKwavefile.h → Demo/DX9/DXUT/Optional/SDKwavefile.h
File renamed without changes.
View
0 dx10/DXUT/Optional/directx.ico → Demo/DX9/DXUT/Optional/directx.ico
File renamed without changes.
View
0 dx9/Demo DX9.sln → Demo/DX9/Demo DX9.sln
File renamed without changes.
View
10 Demo/DX9/Demo.rc
@@ -0,0 +1,10 @@
+1 ICON "Icon.ico"
+
+MLAA.fx RCDATA Shaders\MLAA.fx
+
+MLAA.h RCDATA "..\\..\\MLAA.h"
+AreaTex.dds RCDATA "..\\..\\AreaTex.dds"
+SearchTex.dds RCDATA "..\\..\\SearchTex.dds"
+
+Unigine01.png RCDATA Media\Images\Unigine01.png
+Unigine01.dds RCDATA Media\Images\Unigine01.dds
View
7 dx9/Demo.vcxproj → Demo/DX9/Demo.vcxproj
@@ -131,6 +131,7 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClInclude Include="..\..\MLAA.h" />
<ClInclude Include="Code\MLAA.h" />
<ClInclude Include="Code\Timer.h" />
<ClInclude Include="DXUT\Core\DXUT.h" />
@@ -159,10 +160,12 @@
</ItemGroup>
<ItemGroup>
<CustomBuild Include="Shaders\MLAA.fx">
- <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">fxc /Od /Zi /Tfx_2_0 /nologo /Fo"$(IntDir)%(Filename).fxo" "%(FullPath)"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">fxc /Od /Zi /Tfx_2_0 /nologo /I ../.. /Fo"$(IntDir)%(Filename).fxo" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)%(Filename).fxo</Outputs>
- <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">fxc /Tfx_2_0 /nologo /Fo"$(IntDir)%(Filename).fxo" "%(FullPath)"</Command>
+ <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">fxc /Tfx_2_0 /nologo /I ../.. /Fo"$(IntDir)%(Filename).fxo" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)%(Filename).fxo</Outputs>
+ <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\MLAA.h</AdditionalInputs>
+ <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\MLAA.h</AdditionalInputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
View
3 dx9/Demo.vcxproj.filters → Demo/DX9/Demo.vcxproj.filters
@@ -73,6 +73,9 @@
<ClInclude Include="Code\Timer.h">
<Filter>Code</Filter>
</ClInclude>
+ <ClInclude Include="..\..\MLAA.h">
+ <Filter>Shaders</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Demo.rc" />
View
0 dx9/Demo.vcxproj.user → Demo/DX9/Demo.vcxproj.user
File renamed without changes.
View
0 dx10/Icon.ico → Demo/DX9/Icon.ico
File renamed without changes.
View
0 dx10/Media/Images/Unigine01.dds → Demo/DX9/Media/Images/Unigine01.dds
File renamed without changes.
View
0 dx10/Media/Images/Unigine01.png → Demo/DX9/Media/Images/Unigine01.png
File renamed without changes
View
253 Demo/DX9/Shaders/MLAA.fx
@@ -0,0 +1,253 @@
+/**
+ * Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
+ * Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
+ * Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
+ * Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
+ * Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution:
+ *
+ * "Uses Jimenez's MLAA. Copyright (C) 2011 by Jorge Jimenez, Belen Masia,
+ * Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are
+ * those of the authors and should not be interpreted as representing official
+ * policies, either expressed or implied, of the copyright holders.
+ */
+
+
+// Some configuration variables:
+float threshold;
+float maxSearchSteps;
+
+/**
+ * Setup mandatory defines. Use a real macro here for maximum performance!
+ */
+#ifndef MLAA_PIXEL_SIZE // It's actually set on runtime, this is for compilation time syntax checking.
+#define MLAA_PIXEL_SIZE float2(1.0 / 1280.0, 1.0 / 720.0)
+#endif
+
+/**
+ * Setup optional defines.
+ */
+#define MLAA_THRESHOLD threshold
+#define MLAA_MAX_SEARCH_STEPS maxSearchSteps
+
+// Set the HLSL version:
+#define MLAA_HLSL_3 1
+
+// And include our header!
+#include "MLAA.h"
+
+
+/**
+ * Input vars and textures.
+ */
+
+texture2D colorTex2D;
+texture2D depthTex2D;
+texture2D edgesTex2D;
+texture2D blendTex2D;
+texture2D areaTex2D;
+texture2D searchTex2D;
+
+
+/**
+ * DX9 samplers.
+ */
+sampler2D colorTex {
+ Texture = <colorTex2D>;
+ AddressU = Clamp; AddressV = Clamp;
+ MipFilter = Point; MinFilter = Linear; MagFilter = Linear;
+ SRGBTexture = true;
+};
+
+sampler2D colorTexG {
+ Texture = <colorTex2D>;
+ AddressU = Clamp; AddressV = Clamp;
+ MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
+ SRGBTexture = false;
+};
+
+sampler2D depthTex {
+ Texture = <depthTex2D>;
+ AddressU = Clamp; AddressV = Clamp;
+ MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
+ SRGBTexture = false;
+};
+
+sampler2D edgesTex {
+ Texture = <edgesTex2D>;
+ AddressU = Clamp; AddressV = Clamp;
+ MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
+ SRGBTexture = false;
+};
+
+sampler2D blendTex {
+ Texture = <blendTex2D>;
+ AddressU = Clamp; AddressV = Clamp;
+ MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
+ SRGBTexture = false;
+};
+
+sampler2D areaTex {
+ Texture = <areaTex2D>;
+ AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
+ MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
+ SRGBTexture = false;
+};
+
+sampler2D searchTex {
+ Texture = <searchTex2D>;
+ AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
+ MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
+ SRGBTexture = false;
+};
+
+
+/**
+ * Function wrappers
+ */
+void DX9_MLAAEdgeDetectionVS(inout float4 position : POSITION,
+ inout float2 texcoord : TEXCOORD0,
+ out float4 offset[2] : TEXCOORD1) {
+ MLAAEdgeDetectionVS(position, position, texcoord, offset);
+}
+
+void DX9_MLAABlendWeightCalculationVS(inout float4 position : POSITION,
+ inout float2 texcoord : TEXCOORD0,
+ out float4 offset[2] : TEXCOORD1) {
+ MLAABlendWeightCalculationVS(position, position, texcoord, offset);
+}
+
+void DX9_MLAANeighborhoodBlendingVS(inout float4 position : POSITION,
+ inout float2 texcoord : TEXCOORD0,
+ out float4 offset[2] : TEXCOORD1) {
+ MLAANeighborhoodBlendingVS(position, position, texcoord, offset);
+}
+
+
+float4 DX9_MLAALumaEdgeDetectionPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D colorGammaTex) : COLOR {
+ return MLAALumaEdgeDetectionPS(texcoord, offset, colorGammaTex);
+}
+
+float4 DX9_MLAAColorEdgeDetectionPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D colorGammaTex) : COLOR {
+ return MLAAColorEdgeDetectionPS(texcoord, offset, colorGammaTex);
+}
+
+float4 DX9_MLAADepthEdgeDetectionPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D depthTex) : COLOR {
+ return MLAADepthEdgeDetectionPS(texcoord, offset, depthTex);
+}
+
+float4 DX9_MLAABlendingWeightCalculationPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D edgesTex,
+ uniform MLAATexture2D areaTex,
+ uniform MLAATexture2D searchTex) : COLOR {
+ return MLAABlendingWeightCalculationPS(texcoord, offset, edgesTex, areaTex, searchTex);
+}
+
+float4 DX9_MLAANeighborhoodBlendingPS(float4 position : SV_POSITION,
+ float2 texcoord : TEXCOORD0,
+ float4 offset[2] : TEXCOORD1,
+ uniform MLAATexture2D colorTex,
+ uniform MLAATexture2D blendTex) : COLOR {
+ return MLAANeighborhoodBlendingPS(texcoord, offset, colorTex, blendTex);
+}
+
+
+/**
+ * Time for some techniques!
+ */
+technique ColorEdgeDetection {
+ pass ColorEdgeDetection {
+ VertexShader = compile vs_3_0 DX9_MLAAEdgeDetectionVS();
+ PixelShader = compile ps_3_0 DX9_MLAAColorEdgeDetectionPS(colorTexG);
+ ZEnable = false;
+ SRGBWriteEnable = false;
+ AlphaBlendEnable = false;
+
+ // We will be creating the stencil buffer for later usage.
+ StencilEnable = true;
+ StencilPass = REPLACE;
+ StencilRef = 1;
+ }
+}
+
+technique DepthEdgeDetection {
+ pass DepthEdgeDetection {
+ VertexShader = compile vs_3_0 DX9_MLAAEdgeDetectionVS();
+ PixelShader = compile ps_3_0 DX9_MLAADepthEdgeDetectionPS(depthTex);
+ ZEnable = false;
+ SRGBWriteEnable = false;
+ AlphaBlendEnable = false;
+
+ // We will be creating the stencil buffer for later usage.
+ StencilEnable = true;
+ StencilPass = REPLACE;
+ StencilRef = 1;
+ }
+}
+
+technique BlendWeightCalculation {
+ pass BlendWeightCalculation {
+ VertexShader = compile vs_3_0 DX9_MLAABlendWeightCalculationVS();
+ PixelShader = compile ps_3_0 DX9_MLAABlendingWeightCalculationPS(edgesTex, areaTex, searchTex);
+ ZEnable = false;
+ SRGBWriteEnable = false;
+ AlphaBlendEnable = false;
+
+ // Here we want to process only marked pixels.
+ StencilEnable = true;
+ StencilPass = KEEP;
+ StencilFunc = EQUAL;
+ StencilRef = 1;
+ }
+}
+
+technique NeighborhoodBlending {
+ pass NeighborhoodBlending {
+ VertexShader = compile vs_3_0 DX9_MLAANeighborhoodBlendingVS();
+ PixelShader = compile ps_3_0 DX9_MLAANeighborhoodBlendingPS(colorTex, blendTex);
+ ZEnable = false;
+ SRGBWriteEnable = true;
+ AlphaBlendEnable = false;
+
+ // Here we want to process only marked pixels.
+ StencilEnable = true;
+ StencilPass = KEEP;
+ StencilFunc = EQUAL;
+ StencilRef = 1;
+ }
+}
View
20 dx9/LICENSE.txt → LICENSE.txt
@@ -1,12 +1,8 @@
-The src code of the MLAA shader (files MLAA.h, MLAA.cpp and MLAA.fx) is
-distributed under the following license, which a modified version of the
-Simplified BSD License, with a more specific second clause.
-
-Copyright (C) 2010 Jorge Jimenez (jorge@iryoku.com)
-Copyright (C) 2010 Belen Masia (bmasia@unizar.es)
-Copyright (C) 2010 Jose I. Echevarria (joseignacioechevarria@gmail.com)
-Copyright (C) 2010 Fernando Navarro (fernandn@microsoft.com)
-Copyright (C) 2010 Diego Gutierrez (diegog@unizar.es)
+Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
+Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
+Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
+Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
+Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -15,9 +11,11 @@ modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the following statement:
+ 2. Redistributions in binary form must reproduce the following disclaimer
+ in the documentation and/or other materials provided with the
+ distribution:
- "Uses Jimenez's MLAA. Copyright (C) 2010 by Jorge Jimenez, Belen Masia,
+ "Uses Jimenez's MLAA. Copyright (C) 2011 by Jorge Jimenez, Belen Masia,
Jose I. Echevarria, Fernando Navarro and Diego Gutierrez."
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
View
606 MLAA.h
@@ -0,0 +1,606 @@
+/**
+ * Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
+ * Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
+ * Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
+ * Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
+ * Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution:
+ *